-
Notifications
You must be signed in to change notification settings - Fork 38
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
rework the graph walking functions with functional options #42
Conversation
This commit: - reduce the API to 2 simpler functions - add consistent and clear control over if the root should be visited - add control over the concurrency factor
merkledag.go
Outdated
// | ||
// NOTE: It *does not* make multiple concurrent calls to the passed `visit` function. | ||
func WalkParallelDepth(ctx context.Context, getLinks GetLinks, c cid.Cid, startDepth int, visit func(cid.Cid, int) bool) error { | ||
func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, visit func(cid.Cid, int) bool, options *WalkOptions) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I kept this function at the same place as before for an easier review, but it would make sense to move it just after sequentialWalkDepth
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ this is much nicer. I have some suggestions but I'd be happy to merge it as-is if you disagree (no strong opinions).
merkledag.go
Outdated
} | ||
|
||
links, err := getLinks(ctx, root) | ||
if err != nil { | ||
if err != nil && !options.IgnoreErrors { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the idea is that getLinks
should this internally. But I agree this option is convenient.
What if we changed this to an error handler (func(cid.Cid, error) error
)? That way, we can provide options like:
IgnoreErrors()
IgnoreMissing() // only ignores ipld.ErrorNotFound.
OnMissing(func(c cid.Cid))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I'll add a generic OnError(func(err error, c cid.Cid) bool)
as well.
merkledag.go
Outdated
const defaultConcurrentFetch = 32 | ||
|
||
// WalkOptions represent the parameters of a graph walking algorithm | ||
type WalkOptions struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this private (or at least make the fields private). Yeah, I know I don't usually do that but that was a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
It should be good now. |
Thanks! |
…nal-opts rework the graph walking functions with functional options This commit was moved from ipfs/go-merkledag@89dd2ad
This PR:
I also want to implement a
IgnoreBadBlock()
options to continue walking even when a bad block is read.Note:
FetchGraphWithDepthLimit
could be made simpler with aDepthLimit()
option as well.@Stebalien