Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better logging for Graphsync traversal #167

Merged
merged 4 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/ipfs/go-ipld-cbor v0.0.4 // indirect
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-log v1.0.4
github.com/ipfs/go-log/v2 v2.1.1
github.com/ipfs/go-merkledag v0.3.1
github.com/ipfs/go-peertaskqueue v0.2.0
github.com/ipfs/go-unixfs v0.2.4
Expand Down
19 changes: 17 additions & 2 deletions responsemanager/runtraversal/runtraversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bytes"
"io"

"github.com/ipfs/go-graphsync/ipldutil"
logging "github.com/ipfs/go-log/v2"
ipld "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/traversal"

"github.com/ipfs/go-graphsync/ipldutil"
)

var logger = logging.Logger("gs-traversal")

// ResponseSender sends responses over the network
type ResponseSender func(
link ipld.Link,
Expand All @@ -22,15 +24,24 @@ func RunTraversal(
loader ipld.Loader,
traverser ipldutil.Traverser,
sendResponse ResponseSender) error {
nBlocksRead := 0

for {
isComplete, err := traverser.IsComplete()
if isComplete {
if err != nil {
logger.Infof("traversal completion check failed, nBlocksRead=%d, err=%s", nBlocksRead, err)
} else {
logger.Infof("traversal completed successfully, nBlocksRead=%d", nBlocksRead)
}
return err
}
lnk, lnkCtx := traverser.CurrentRequest()
logger.Debugf("will load link=%s", lnk)
result, err := loader(lnk, lnkCtx)
var data []byte
if err != nil {
logger.Errorf("failed to load link=%s, nBlocksRead=%d, err=%s", lnk, nBlocksRead, err)
traverser.Error(traversal.SkipMe{})
} else {
blockBuffer, ok := result.(*bytes.Buffer)
Expand All @@ -39,14 +50,18 @@ func RunTraversal(
_, err = io.Copy(blockBuffer, result)
}
if err != nil {
logger.Errorf("failed to write to buffer, link=%s, nBlocksRead=%d, err=%s", lnk, nBlocksRead, err)
traverser.Error(err)
} else {
data = blockBuffer.Bytes()
err = traverser.Advance(blockBuffer)
if err != nil {
logger.Errorf("failed to advance traversal, link=%s, nBlocksRead=%d, err=%s", lnk, nBlocksRead, err)
return err
}
}
nBlocksRead++
logger.Debugf("successfully loaded link=%s, nBlocksRead=%d", lnk, nBlocksRead)
}
err = sendResponse(lnk, data)
if err != nil {
Expand Down