-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,9 +288,9 @@ const defaultConcurrentFetch = 32 | |
|
||
// WalkOptions represent the parameters of a graph walking algorithm | ||
type WalkOptions struct { | ||
WithRoot bool | ||
IgnoreBadBlock bool | ||
Concurrency int | ||
WithRoot bool | ||
IgnoreErrors bool | ||
Concurrency int | ||
} | ||
|
||
// WalkOption is a setter for WalkOptions | ||
|
@@ -323,6 +323,14 @@ func Concurrency(worker int) WalkOption { | |
} | ||
} | ||
|
||
// IgnoreErrors is a WalkOption indicating that the walk should attempt to | ||
// continue even when an error occur. | ||
func IgnoreErrors() WalkOption { | ||
return func(walkOptions *WalkOptions) { | ||
walkOptions.IgnoreErrors = true | ||
} | ||
} | ||
|
||
// WalkGraph will walk the dag in order (depth first) starting at the given root. | ||
func Walk(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid.Cid) bool, options ...WalkOption) error { | ||
visitDepth := func(c cid.Cid, depth int) bool { | ||
|
@@ -356,7 +364,7 @@ func sequentialWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, d | |
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. So, the idea is that What if we changed this to an error handler (
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I'll add a generic |
||
return err | ||
} | ||
|
||
|
@@ -437,7 +445,7 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis | |
|
||
if shouldVisit { | ||
links, err := getLinks(ctx, ci) | ||
if err != nil { | ||
if err != nil && !options.IgnoreErrors { | ||
select { | ||
case errChan <- err: | ||
case <-fetchersCtx.Done(): | ||
|
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.