-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
always try to read ahead by at least 5 blocks in the PBDagReader #5162
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
12719a7
use `copy` instead of looping
Stebalien 0344e3e
better handle context cancellations in the PBDagReader
Stebalien ff3efb5
always prefetch at least 5 blocks ahead
Stebalien 5c0dc6a
test dag reader context cancellation
Stebalien 7fd3404
explain when a promise can be canceled in pbdagreader
Stebalien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,10 +95,27 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error { | |
} | ||
|
||
nxt, err := dr.promises[dr.linkPosition].Get(ctx) | ||
if err != nil { | ||
dr.promises[dr.linkPosition] = nil | ||
switch err { | ||
case nil: | ||
case context.DeadlineExceeded, context.Canceled: | ||
err = ctx.Err() | ||
if err != nil { | ||
return ctx.Err() | ||
} | ||
// In this case, the context used to *preload* the node has been canceled. | ||
// We need to retry the load with our context and we might as | ||
// well preload some extra nodes while we're at it. | ||
dr.preload(ctx, dr.linkPosition) | ||
nxt, err = dr.promises[dr.linkPosition].Get(ctx) | ||
dr.promises[dr.linkPosition] = nil | ||
if err != nil { | ||
return err | ||
} | ||
default: | ||
return err | ||
} | ||
dr.promises[dr.linkPosition] = nil | ||
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. Always remove the promise. There's no reason to leave this around. |
||
|
||
dr.linkPosition++ | ||
|
||
switch nxt := nxt.(type) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we elaborate a bit more on this? I had the impression we're always using the same
Context
from thePBDagReader
structure. In which case the localctx
won't be cancelled but the one from theNodePromise
will be? The context from the promise comes from this function, maybe in another call (at it may have been preloaded before), but at which point can the global context from the DAG reader change?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.
We're using the context from the call Read call. IMO, that's the correct context as it allows us to cancel reads and seek elsewhere (canceling any associated preloading as well).
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.
Sorry, scratch that. If the user is using
Read
, we use the reader's cotnext. If the user is manually callingCtxReadFull
(a context aware read), we use the supplied context. I don't really think any additional comments will help as the context is just whatever gets passed in (and listing every possible context is just going to lead to comment rot when that changes).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.
It seems to me there are only (or mainly) two possibilities. The most common (by far I think) is that the reader's context is used everywhere, so in fact there is only one context (and this part of the code isn't executed). The second, and less common,
which is when this scenario takes place (if I understand correctly).
Clarifying that distinction seems worth it, IMO.
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.
Fair enough.