swarm/api: improved traces for manifest retrieval

This commit is contained in:
Anton Evangelatov 2018-03-15 15:12:09 +01:00
parent 4279486671
commit a23a9d826a
2 changed files with 12 additions and 11 deletions

View file

@ -308,6 +308,7 @@ func (self *Api) Put(content, contentType string) (k storage.Key, wait func(), e
// to resolve basePath to content using dpa retrieve // to resolve basePath to content using dpa retrieve
// it returns a section reader, mimeType, status and an error // it returns a section reader, mimeType, status and an error
func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionReader, mimeType string, status int, err error) { func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionReader, mimeType string, status int, err error) {
log.Debug("api.get", "key", key)
apiGetCount.Inc(1) apiGetCount.Inc(1)
trie, err := loadManifest(self.dpa, key, nil) trie, err := loadManifest(self.dpa, key, nil)
if err != nil { if err != nil {
@ -317,8 +318,7 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe
return return
} }
log.Trace(fmt.Sprintf("getEntry(%s)", path)) log.Trace("trie.getentry", "key", key, "path", path)
entry, _ := trie.getEntry(path) entry, _ := trie.getEntry(path)
if entry != nil { if entry != nil {
@ -331,7 +331,7 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe
// we return a typed error instead. Since for all other purposes this is an invalid manifest, // we return a typed error instead. Since for all other purposes this is an invalid manifest,
// any normal interfacing code will just see an error fail accordingly. // any normal interfacing code will just see an error fail accordingly.
if entry.ContentType == ResourceContentType { if entry.ContentType == ResourceContentType {
log.Warn("resource type", "hash", entry.Hash) log.Warn("resource type", "key", key, "hash", entry.Hash)
return nil, entry.ContentType, http.StatusOK, &ErrResourceReturn{entry.Hash} return nil, entry.ContentType, http.StatusOK, &ErrResourceReturn{entry.Hash}
} }
key = common.Hex2Bytes(entry.Hash) key = common.Hex2Bytes(entry.Hash)
@ -341,14 +341,14 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe
return return
} else { } else {
mimeType = entry.ContentType mimeType = entry.ContentType
log.Trace(fmt.Sprintf("content lookup key: '%v' (%v)", key, mimeType)) log.Trace("content lookup key", "key", key, "mimetype", mimeType)
reader = self.dpa.Retrieve(key) reader = self.dpa.Retrieve(key)
} }
} else { } else {
status = http.StatusNotFound status = http.StatusNotFound
apiGetNotFound.Inc(1) apiGetNotFound.Inc(1)
err = fmt.Errorf("manifest entry for '%s' not found", path) err = fmt.Errorf("manifest entry for '%s' not found", path)
log.Warn(fmt.Sprintf("%v", err)) log.Trace("manifest entry not found", "key", key, "path", path)
} }
return return
} }

View file

@ -201,10 +201,10 @@ type manifestTrieEntry struct {
} }
func loadManifest(dpa *storage.DPA, hash storage.Key, quitC chan bool) (trie *manifestTrie, err error) { // non-recursive, subtrees are downloaded on-demand func loadManifest(dpa *storage.DPA, hash storage.Key, quitC chan bool) (trie *manifestTrie, err error) { // non-recursive, subtrees are downloaded on-demand
log.Trace("manifest lookup", "key", hash)
log.Trace(fmt.Sprintf("manifest lookup key: '%v'.", hash.Log()))
// retrieve manifest via DPA // retrieve manifest via DPA
manifestReader := dpa.Retrieve(hash) manifestReader := dpa.Retrieve(hash)
log.Trace("reader retrieved", "key", hash)
return readManifest(manifestReader, hash, dpa, quitC) return readManifest(manifestReader, hash, dpa, quitC)
} }
@ -214,31 +214,32 @@ func readManifest(manifestReader storage.LazySectionReader, hash storage.Key, dp
size, err := manifestReader.Size(quitC) size, err := manifestReader.Size(quitC)
if err != nil { // size == 0 if err != nil { // size == 0
// can't determine size means we don't have the root chunk // can't determine size means we don't have the root chunk
log.Trace("manifest not found", "key", hash)
err = fmt.Errorf("Manifest not Found") err = fmt.Errorf("Manifest not Found")
return return
} }
manifestData := make([]byte, size) manifestData := make([]byte, size)
read, err := manifestReader.Read(manifestData) read, err := manifestReader.Read(manifestData)
if int64(read) < size { if int64(read) < size {
log.Trace(fmt.Sprintf("Manifest %v not found.", hash.Log())) log.Trace("manifest not found", "key", hash)
if err == nil { if err == nil {
err = fmt.Errorf("Manifest retrieval cut short: read %v, expect %v", read, size) err = fmt.Errorf("Manifest retrieval cut short: read %v, expect %v", read, size)
} }
return return
} }
log.Trace(fmt.Sprintf("Manifest %v retrieved", hash.Log())) log.Trace("manifest retrieved", "key", hash)
var man struct { var man struct {
Entries []*manifestTrieEntry `json:"entries"` Entries []*manifestTrieEntry `json:"entries"`
} }
err = json.Unmarshal(manifestData, &man) err = json.Unmarshal(manifestData, &man)
if err != nil { if err != nil {
err = fmt.Errorf("Manifest %v is malformed: %v", hash.Log(), err) err = fmt.Errorf("Manifest %v is malformed: %v", hash.Log(), err)
log.Trace(fmt.Sprintf("%v", err)) log.Trace("malformed manifest", "key", hash)
return return
} }
log.Trace(fmt.Sprintf("Manifest %v has %d entries.", hash.Log(), len(man.Entries))) log.Trace("manifest entries", "key", hash, "len", len(man.Entries))
trie = &manifestTrie{ trie = &manifestTrie{
dpa: dpa, dpa: dpa,