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

storage: Refactor pagination for the Get command into the MVCC layer #94698

Merged

Conversation

KaiSun314
Copy link
Contributor

@KaiSun314 KaiSun314 commented Jan 4, 2023

Informs: #77228

Refactor key and byte pagination for the Get command into the MVCC layer Previously, pagination was done in pkg/kv/kvserver/batcheval/cmd_get.go, but to ensure consistency in where pagination logic is located across all commands, we move the pagination logic for the Get command to the MVCC layer where the pagination logic for most other commands is. This also enables better parameter testing in the storage package since we can leverage e.g. data-driven tests like TestMVCCHistories.

Release note: None

@KaiSun314 KaiSun314 requested review from a team as code owners January 4, 2023 16:27
@blathers-crl
Copy link

blathers-crl bot commented Jan 4, 2023

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added the O-community Originated from the community label Jan 4, 2023
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch from 805f133 to 4b3134a Compare January 6, 2023 17:01
@blathers-crl
Copy link

blathers-crl bot commented Jan 6, 2023

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@knz
Copy link
Contributor

knz commented Jan 6, 2023

cc @nicktrav

@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch from 4b3134a to dff430b Compare January 6, 2023 22:57
Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @KaiSun314)


pkg/storage/mvcc.go line 1027 at r2 (raw file):

		//
		// This mirrors the logic in MVCCScan, though the logic in MVCCScan is
		// slightly lower in the stack.

stale comment "This mirrors ..."

@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch from dff430b to bb7daa9 Compare January 10, 2023 13:39
Copy link
Contributor Author

@KaiSun314 KaiSun314 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @sumeerbhola)


pkg/storage/mvcc.go line 1027 at r2 (raw file):

Previously, sumeerbhola wrote…

stale comment "This mirrors ..."

Done.

@sumeerbhola
Copy link
Collaborator

The storage changes are fine with me, but added @nvanbenschoten to give final approval.

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @KaiSun314 and @sumeerbhola)


pkg/storage/mvcc.go line 917 at r3 (raw file):

	// TargetBytes limit.
	AllowEmpty bool
	// Reply is a pointer to the Get response object.

This feels like a layering violation. MVCC is not currently aware of roachpb.Response types. I don't think we want it to be.

Instead of pushing a pointer to the response to be modified into MVCCGet, we could return the information we need to populate this response, like we do with MVCCScan. Then we keep the decision of how to use this information (e.g. to populate a *roachpb.GetResponse) up in kv/kv/server/batcheval.

That might mean creating a MVCCGetResult struct, which feels like a nice change.

@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch from bb7daa9 to cc2c72f Compare January 10, 2023 18:59
@KaiSun314 KaiSun314 requested a review from a team January 10, 2023 18:59
@KaiSun314 KaiSun314 requested a review from a team as a code owner January 10, 2023 18:59
@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch 2 times, most recently from b9a4ddc to d84236f Compare January 10, 2023 19:11
Copy link
Contributor Author

@KaiSun314 KaiSun314 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten and @sumeerbhola)


pkg/storage/mvcc.go line 917 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

This feels like a layering violation. MVCC is not currently aware of roachpb.Response types. I don't think we want it to be.

Instead of pushing a pointer to the response to be modified into MVCCGet, we could return the information we need to populate this response, like we do with MVCCScan. Then we keep the decision of how to use this information (e.g. to populate a *roachpb.GetResponse) up in kv/kv/server/batcheval.

That might mean creating a MVCCGetResult struct, which feels like a nice change.

True agreed, I have migrated to returning a MVCCGetResult struct containing the fields to populate the Get response

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 21 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @KaiSun314 and @sumeerbhola)


pkg/storage/mvcc.go line 917 at r3 (raw file):

Previously, KaiSun314 (Kai Sun) wrote…

True agreed, I have migrated to returning a MVCCGetResult struct containing the fields to populate the Get response

Should we include the *roachpb.Value and *roachpb.Intent in the MVCCGetResult as well? That's what we do in MVCCScanResult.

@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch from d84236f to 69b4133 Compare January 10, 2023 21:57
@blathers-crl
Copy link

blathers-crl bot commented Jan 10, 2023

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch from 69b4133 to 1b7bf08 Compare January 10, 2023 22:19
Copy link
Contributor Author

@KaiSun314 KaiSun314 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten and @sumeerbhola)


pkg/storage/mvcc.go line 917 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Should we include the *roachpb.Value and *roachpb.Intent in the MVCCGetResult as well? That's what we do in MVCCScanResult.

Yep that sounds great, added Value *roachpb.Value and Intent *roachpb.Intent to MVCCGetresult

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 19 of 23 files at r5, 4 of 4 files at r6, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @KaiSun314 and @sumeerbhola)


-- commits line 9 at r6:
Did you mean for these to be two different commits?


pkg/kv/kvserver/replica.go line 1808 at r6 (raw file):

	desc := r.descRLocked()
	descKey := keys.RangeDescriptorKey(desc.StartKey)
	res, err := storage.MVCCGet(ctx, r.Engine(), descKey, hlc.MaxTimestamp,

intentRes


pkg/kv/kvserver/replica.go line 1815 at r6 (raw file):

		return false, nil
	}
	getRes, err := storage.MVCCGetAsTxn(

valRes


pkg/kv/kvserver/replica_rangefeed.go line 538 at r4 (raw file):

		// Read the previous value from the prev Reader. Unlike the new value
		// (see handleLogicalOpLogRaftMuLocked), this one may be missing.
		prevVal, _, _, err := storage.MVCCGet(

In cases where the variable names before carried some context to help readers understand the code, we should try to incorporate that into the new name. For instance, it would be clearer if this was prevValRes. I left comments about this in a few other places.

@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch 2 times, most recently from f7ec51f to 6811a7e Compare January 11, 2023 07:30
Return MVCCGetResult containing values needed to populate the Get
response.

Release note: None
Informs: cockroachdb#77228

Refactor key and byte pagination for the Get command into the MVCC layer
Previously, pagination was done in pkg/kv/kvserver/batcheval/cmd_get.go,
but to ensure consistency in where pagination logic is located across
all commands, we move the pagination logic for the Get command to the
MVCC layer where the pagination logic for most other commands is. This
also enables better parameter testing in the storage package since we
can leverage e.g. data-driven tests like TestMVCCHistories.

Release note: None
@KaiSun314 KaiSun314 force-pushed the push-get-pagination-into-mvcc branch from 6811a7e to ce24131 Compare January 11, 2023 07:59
Copy link
Contributor Author

@KaiSun314 KaiSun314 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten and @sumeerbhola)


-- commits line 9 at r6:

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Did you mean for these to be two different commits?

Oh yep I wanted to split into two commits to make it easier to read and review. One commit refactors MVCCGetResult into the return values and one commit pushes pagination for Get into MVCC.


pkg/kv/kvserver/replica_rangefeed.go line 538 at r4 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

In cases where the variable names before carried some context to help readers understand the code, we should try to incorporate that into the new name. For instance, it would be clearer if this was prevValRes. I left comments about this in a few other places.

Done, incorporated previous variable names into the new name

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 11 of 15 files at r7, 4 of 4 files at r8, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @sumeerbhola)

@nvanbenschoten nvanbenschoten merged commit e8a5d34 into cockroachdb:master Jan 12, 2023
@KaiSun314
Copy link
Contributor Author

Thank you so much for the review Nathan and Sumeer!

nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this pull request Jan 12, 2023
Resolves merge skew between cockroachdb#94814 and cockroachdb#94698.

Release note: None
Epic: None
KaiSun314 added a commit to KaiSun314/cockroach that referenced this pull request Jan 12, 2023
Informs: cockroachdb#77228

cmd_resolve_intent_test.go calls MVCCGet, which originally
returned 3 values, but in cockroachdb#94698, returns 2 values (MVCCGetResult).
Unfortunately, the PR containing changes to cmd_resolve_intent_test.go
used the original MVCCGet with 3 return values and was merged at
around the same time as the change to MVCCGet, and the changes to
cmd_resolve_intent_test.go calling the original MVCCGet with 3
return values was merged, which causes CI failures after the change
to MVCCGet from 3 to 2 return values was also merged as is.

Release note: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants