-
Notifications
You must be signed in to change notification settings - Fork 246
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
Skip loading of head revision on write calls #1176
Conversation
func MustRevisionFromContext(ctx context.Context) (datastore.Revision, *v1.ZedToken) { | ||
// RevisionFromContextOrError reads the selected revision out of a context.Context, computes a zedtoken | ||
// from it, and returns an error if it has not been set on the context. | ||
func RevisionFromContextOrError(ctx context.Context) (datastore.Revision, *v1.ZedToken, 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.
I don't think this name needs the OrError
as the common idiom in Go already -- just drop the Must
so that it's RevisionFromContext
} | ||
|
||
return rev, zedtoken.MustNewFromRevision(rev) | ||
// RevisionFromContextOrError reads the selected revision out of a context.Context, computes a zedtoken |
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.
same nitpick
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.
Other than jimmy's suggestion on the naming, this looks good to me
internal/services/v1/schema.go
Outdated
@@ -46,15 +45,21 @@ type schemaServer struct { | |||
} | |||
|
|||
func (ss *schemaServer) ReadSchema(ctx context.Context, in *v1.ReadSchemaRequest) (*v1.ReadSchemaResponse, error) { | |||
readRevision, _ := consistency.MustRevisionFromContext(ctx) | |||
ds := datastoremw.MustFromContext(ctx).SnapshotReader(readRevision) | |||
// Schema is already read from the head revision. |
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.
hrm, this comment assumes the reader has context about the previous implementation. I'd clarify that this method does not have consistency specified and thus we need to explicitly get head
revision as it won't be available in the context.
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; should have said "always". I've fixed
return nil, rewriteError(ctx, err) | ||
} | ||
|
||
reader := ds.SnapshotReader(headRevision) |
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.
a potential optimization would be to have a method like HeadReader
which executes the first query and returning the revision, and uses that revision for any potential subsequent queries. That way we avoid one roundtrip
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.
Not sure how it avoids a roundtrip; SnapshotReader(...)
should not be making a DB call until its actually used
These APIs do not use consistency blocks, so there is no need to load the head revision outside of their transactions
65d2d85
to
0c738ab
Compare
Rebased and updated |
These APIs do not use consistency blocks, so there is no need to load the head revision outside of their transactions