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

Skip loading of head revision on write calls #1176

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

josephschorr
Copy link
Member

These APIs do not use consistency blocks, so there is no need to load the head revision outside of their transactions

@josephschorr josephschorr requested a review from a team as a code owner February 20, 2023 22:38
@github-actions github-actions bot added area/api v1 Affects the v1 API area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Feb 20, 2023
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) {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same nitpick

vroldanbet
vroldanbet previously approved these changes Feb 22, 2023
Copy link
Contributor

@vroldanbet vroldanbet left a 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

@@ -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.
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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

Copy link
Member Author

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
@josephschorr
Copy link
Member Author

Rebased and updated

@josephschorr josephschorr merged commit 64e3c41 into authzed:main Feb 22, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Feb 22, 2023
@josephschorr josephschorr deleted the skip-rev-write branch February 22, 2023 17:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v1 Affects the v1 API area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants