mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
swarm/api: improved traces for manifest retrieval
This commit is contained in:
parent
4279486671
commit
a23a9d826a
2 changed files with 12 additions and 11 deletions
|
|
@ -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
|
||||
// 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) {
|
||||
log.Debug("api.get", "key", key)
|
||||
apiGetCount.Inc(1)
|
||||
trie, err := loadManifest(self.dpa, key, nil)
|
||||
if err != nil {
|
||||
|
|
@ -317,8 +318,7 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe
|
|||
return
|
||||
}
|
||||
|
||||
log.Trace(fmt.Sprintf("getEntry(%s)", path))
|
||||
|
||||
log.Trace("trie.getentry", "key", key, "path", path)
|
||||
entry, _ := trie.getEntry(path)
|
||||
|
||||
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,
|
||||
// any normal interfacing code will just see an error fail accordingly.
|
||||
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}
|
||||
}
|
||||
key = common.Hex2Bytes(entry.Hash)
|
||||
|
|
@ -341,14 +341,14 @@ func (self *Api) Get(key storage.Key, path string) (reader storage.LazySectionRe
|
|||
return
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
status = http.StatusNotFound
|
||||
apiGetNotFound.Inc(1)
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
log.Trace(fmt.Sprintf("manifest lookup key: '%v'.", hash.Log()))
|
||||
log.Trace("manifest lookup", "key", hash)
|
||||
// retrieve manifest via DPA
|
||||
manifestReader := dpa.Retrieve(hash)
|
||||
log.Trace("reader retrieved", "key", hash)
|
||||
return readManifest(manifestReader, hash, dpa, quitC)
|
||||
}
|
||||
|
||||
|
|
@ -214,31 +214,32 @@ func readManifest(manifestReader storage.LazySectionReader, hash storage.Key, dp
|
|||
size, err := manifestReader.Size(quitC)
|
||||
if err != nil { // size == 0
|
||||
// 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")
|
||||
return
|
||||
}
|
||||
manifestData := make([]byte, size)
|
||||
read, err := manifestReader.Read(manifestData)
|
||||
if int64(read) < size {
|
||||
log.Trace(fmt.Sprintf("Manifest %v not found.", hash.Log()))
|
||||
log.Trace("manifest not found", "key", hash)
|
||||
if err == nil {
|
||||
err = fmt.Errorf("Manifest retrieval cut short: read %v, expect %v", read, size)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace(fmt.Sprintf("Manifest %v retrieved", hash.Log()))
|
||||
log.Trace("manifest retrieved", "key", hash)
|
||||
var man struct {
|
||||
Entries []*manifestTrieEntry `json:"entries"`
|
||||
}
|
||||
err = json.Unmarshal(manifestData, &man)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Manifest %v is malformed: %v", hash.Log(), err)
|
||||
log.Trace(fmt.Sprintf("%v", err))
|
||||
log.Trace("malformed manifest", "key", hash)
|
||||
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{
|
||||
dpa: dpa,
|
||||
|
|
|
|||
Loading…
Reference in a new issue