swarm/api, swarm/storage: improved tracing

This commit is contained in:
Anton Evangelatov 2018-03-14 17:22:07 +01:00
parent 4d7361f65f
commit 719da647d8
5 changed files with 22 additions and 11 deletions

View file

@ -480,16 +480,16 @@ func (tab *Table) doRevalidate(done chan<- struct{}) {
b := tab.buckets[bi]
if err == nil {
// The node responded, move it to the front.
log.Debug("Revalidated node", "b", bi, "id", last.ID)
log.Trace("Revalidated node", "b", bi, "id", last.ID)
b.bump(last)
return
}
// No reply received, pick a replacement or delete the node if there aren't
// any replacements.
if r := tab.replace(b, last); r != nil {
log.Debug("Replaced dead node", "b", bi, "id", last.ID, "ip", last.IP, "r", r.ID, "rip", r.IP)
log.Trace("Replaced dead node", "b", bi, "id", last.ID, "ip", last.IP, "r", r.ID, "rip", r.IP)
} else {
log.Debug("Removed dead node", "b", bi, "id", last.ID, "ip", last.IP)
log.Trace("Removed dead node", "b", bi, "id", last.ID, "ip", last.IP)
}
}

View file

@ -594,13 +594,13 @@ running:
// This channel is used by AddPeer to add to the
// ephemeral static peer list. Add it to the dialer,
// it will keep the node connected.
srv.log.Debug("Adding static node", "node", n)
srv.log.Trace("Adding static node", "node", n)
dialstate.addStatic(n)
case n := <-srv.removestatic:
// This channel is used by RemovePeer to send a
// disconnect request to a peer and begin the
// stop keeping the node connected
srv.log.Debug("Removing static node", "node", n)
srv.log.Trace("Removing static node", "node", n)
dialstate.removeStatic(n)
if p, ok := peers[n.ID]; ok {
p.Disconnect(DiscRequested)

View file

@ -242,6 +242,7 @@ func (self *Api) Retrieve(key storage.Key) storage.LazySectionReader {
}
func (self *Api) Store(data io.Reader, size int64) (key storage.Key, wait func(), err error) {
log.Debug("api.store", "size", size)
return self.dpa.Store(data, size)
}

View file

@ -121,6 +121,8 @@ type Request struct {
// HandlePostRaw handles a POST request to a raw bzz-raw:/ URI, stores the request
// body in swarm and returns the resulting storage key as a text/plain response
func (s *Server) HandlePostRaw(w http.ResponseWriter, r *Request) {
log.Debug("http.server handle.post.raw", "ruid", r.ruid)
postRawCount.Inc(1)
if r.uri.Path != "" {
postRawFail.Inc(1)
@ -398,6 +400,7 @@ func (s *Server) HandleGetResource(w http.ResponseWriter, r *Request) {
}
func (s *Server) handleGetResource(w http.ResponseWriter, r *Request, name string) {
log.Debug("handle.get.resource", "ruid", r.ruid)
var params []string
if len(r.uri.Path) > 0 {
params = strings.Split(r.uri.Path, "/")
@ -470,6 +473,7 @@ func (s *Server) translateResourceError(w http.ResponseWriter, r *Request, supEr
// - bzz-hash://<key> and responds with the hash of the content stored
// at the given storage key as a text/plain response
func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
log.Debug("handle.get", "ruid", r.ruid, "uri", r.uri)
getCount.Inc(1)
key, err := s.api.Resolve(r.uri)
if err != nil {
@ -477,6 +481,7 @@ func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
Respond(w, r, fmt.Sprintf("cannot resolve %s: %s", r.uri.Addr, err), http.StatusNotFound)
return
}
log.Debug("handle.get: resolved", "ruid", r.ruid, "key", key)
// if path is set, interpret <key> as a manifest and return the
// raw entry at the given path
@ -548,6 +553,7 @@ func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
// header of "application/x-tar" and returns a tar stream of all files
// contained in the manifest
func (s *Server) HandleGetFiles(w http.ResponseWriter, r *Request) {
log.Debug("handle.get.files", "ruid", r.ruid, "uri", r.uri)
getFilesCount.Inc(1)
if r.uri.Path != "" {
getFilesFail.Inc(1)
@ -561,6 +567,7 @@ func (s *Server) HandleGetFiles(w http.ResponseWriter, r *Request) {
Respond(w, r, fmt.Sprintf("cannot resolve %s: %s", r.uri.Addr, err), http.StatusNotFound)
return
}
log.Debug("handle.get.files: resolved", "ruid", r.ruid, "key", key)
walker, err := s.api.NewManifestWalker(key, nil)
if err != nil {
@ -621,6 +628,7 @@ func (s *Server) HandleGetFiles(w http.ResponseWriter, r *Request) {
// a list of all files contained in <manifest> under <path> grouped into
// common prefixes using "/" as a delimiter
func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
log.Debug("handle.get.list", "ruid", r.ruid, "uri", r.uri)
getListCount.Inc(1)
// ensure the root path has a trailing slash so that relative URLs work
if r.uri.Path == "" && !strings.HasSuffix(r.URL.Path, "/") {
@ -634,6 +642,7 @@ func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
Respond(w, r, fmt.Sprintf("cannot resolve %s: %s", r.uri.Addr, err), http.StatusNotFound)
return
}
log.Debug("handle.get.list: resolved", "ruid", r.ruid, "key", key)
list, err := s.getManifestList(key, r.uri.Path)
@ -725,6 +734,7 @@ func (s *Server) getManifestList(key storage.Key, prefix string) (list api.Manif
// HandleGetFile handles a GET request to bzz://<manifest>/<path> and responds
// with the content of the file at <path> from the given <manifest>
func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) {
log.Debug("handle.get.file", "ruid", r.ruid)
getFileCount.Inc(1)
// ensure the root path has a trailing slash so that relative URLs work
if r.uri.Path == "" && !strings.HasSuffix(r.URL.Path, "/") {
@ -738,6 +748,7 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) {
Respond(w, r, fmt.Sprintf("cannot resolve %s: %s", r.uri.Addr, err), http.StatusNotFound)
return
}
log.Debug("handle.get.file: resolved", "ruid", r.ruid, "key", key)
reader, contentType, status, err := s.api.Get(key, r.uri.Path)

View file

@ -169,7 +169,7 @@ func (self *PyramidChunker) decrementWorkerCount() {
}
func (self *PyramidChunker) Split(data io.Reader, size int64, chunkC chan *Chunk) (k Key, wait func(), err error) {
log.Trace("pyramid.chunker: Split()")
log.Debug("pyramid.chunker: Split()", "size", size)
jobC := make(chan *chunkJob, 2*ChunkProcessors)
wg := &sync.WaitGroup{}
storageWG := &sync.WaitGroup{}
@ -204,11 +204,10 @@ func (self *PyramidChunker) Split(data io.Reader, size int64, chunkC chan *Chunk
case <-time.NewTimer(splitTimeout).C:
}
return rootKey, storageWG.Wait, nil
}
func (self *PyramidChunker) Append(key Key, data io.Reader, chunkC chan *Chunk) (k Key, wait func(), err error) {
log.Trace("pyramid.chunker: Append()")
log.Debug("pyramid.chunker: Append()")
quitC := make(chan bool)
rootKey := make([]byte, self.hashSize)
chunkLevel := make([][]*TreeEntry, self.branches)
@ -267,7 +266,7 @@ func (self *PyramidChunker) processor(id int64, jobC chan *chunkJob, chunkC chan
}
func (self *PyramidChunker) processChunk(id int64, hasher SwarmHash, job *chunkJob, chunkC chan *Chunk, storageWG *sync.WaitGroup) {
log.Trace("pyramid.chunker: processChunk()", "id", id)
log.Debug("pyramid.chunker: processChunk()", "id", id)
hasher.ResetWithLength(job.chunk[:8]) // 8 bytes of length
hasher.Write(job.chunk[8:]) // minus 8 []byte length
@ -294,7 +293,7 @@ func (self *PyramidChunker) processChunk(id int64, hasher SwarmHash, job *chunkJ
}
func (self *PyramidChunker) loadTree(chunkLevel [][]*TreeEntry, key Key, chunkC chan *Chunk, quitC chan bool) error {
log.Trace("pyramid.chunker: loadTree()")
log.Debug("pyramid.chunker: loadTree()")
// Get the root chunk to get the total size
chunk := retrieve(key, chunkC, quitC)
if chunk == nil {
@ -377,7 +376,7 @@ func (self *PyramidChunker) loadTree(chunkLevel [][]*TreeEntry, key Key, chunkC
}
func (self *PyramidChunker) prepareChunks(isAppend bool, chunkLevel [][]*TreeEntry, data io.Reader, rootKey []byte, quitC chan bool, wg *sync.WaitGroup, jobC chan *chunkJob, chunkC chan *Chunk, errC chan error, storageWG *sync.WaitGroup) {
log.Trace("pyramid.chunker: prepareChunks", "isAppend", isAppend)
log.Debug("pyramid.chunker: prepareChunks", "isAppend", isAppend)
defer wg.Done()
chunkWG := &sync.WaitGroup{}