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

kvserver: fix a reproposal check #59502

Merged
merged 1 commit into from
Feb 9, 2021

Conversation

andreimatei
Copy link
Contributor

@andreimatei andreimatei commented Jan 28, 2021

In some situations, we repropose a command with a new LAI. When doing
so, we need to make sure that the closed timestamp has not advanced past
the command's write timestamp since the original proposal. Except we
were checking the command's read timestamp, not write timestamp.
Also changes a Less to a LessEq when comparing with the closed
timestamp, which I think is how that comparison should be.

Release note (bug fix): Fixed a very rare chance of inconsistent
follower reads.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

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.

Nice catch!

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andreimatei)


pkg/kv/kvserver/replica_application_result.go, line 208 at r1 (raw file):

	minTS, untrack := r.store.cfg.ClosedTimestamp.Tracker.Track(ctx)
	defer untrack(ctx, 0, 0, 0) // covers all error paths below
	if p.Request.WriteTimestamp().Less(minTS) {

Should this be LessEq? I think we need to push all writes above the closed timestamp, not just to it.


pkg/kv/kvserver/replica_application_result.go, line 208 at r1 (raw file):

	minTS, untrack := r.store.cfg.ClosedTimestamp.Tracker.Track(ctx)
	defer untrack(ctx, 0, 0, 0) // covers all error paths below
	if p.Request.WriteTimestamp().Less(minTS) {

I wonder if we should be checking what's in the request and only doing this if the request needs to respect the closed timestamp. There are certain requests, like a lone EndTxn request that we don't want bumped by the closed timestamp, which is currently the behavior they get in applyTimestampCache.


pkg/roachpb/batch.go, line 77 at r1 (raw file):

}

// WriteTimestamp returns the timestamps at which this request is writing. For

Did you consider LatestActiveTimestamp instead, to be slightly more general and to parallel the method above this?

Either way, thanks for adding this!

Copy link
Contributor Author

@andreimatei andreimatei 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)


pkg/kv/kvserver/replica_application_result.go, line 208 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Should this be LessEq? I think we need to push all writes above the closed timestamp, not just to it.

Fuck if I know. The variable is called minTS and there's no comments on TrackerI.Track(). applyTimestampCache() indeed bumps above this. I've changed it in the hope it'll all go away soon.


pkg/kv/kvserver/replica_application_result.go, line 208 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

I wonder if we should be checking what's in the request and only doing this if the request needs to respect the closed timestamp. There are certain requests, like a lone EndTxn request that we don't want bumped by the closed timestamp, which is currently the behavior they get in applyTimestampCache.

good point, see now


pkg/roachpb/batch.go, line 77 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Did you consider LatestActiveTimestamp instead, to be slightly more general and to parallel the method above this?

Either way, thanks for adding this!

I've considered it but... I wouldn't know what "latest active" would mean. For "earliest active" there seem to be some subtleties needed to separate it from ReadTimestamp, but not so here.

@andreimatei andreimatei force-pushed the repropose-write-timestamp branch 2 times, most recently from 73e4d81 to c8f5cd2 Compare January 28, 2021 14:33
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 2 of 3 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andreimatei and @nvanbenschoten)


pkg/roachpb/batch.go, line 95 at r2 (raw file):

// avoid re-writing history.
func (ba *BatchRequest) ConsultsTimestampCache() bool {
	for _, union := range ba.Requests {

You can move this down right below IsUnsplittable and implement it as return ba.hasFlag(consultsTSCache)

In some situations, we repropose a command with a new LAI. When doing
so, we need to make sure that the closed timestamp has not advanced past
the command's write timestamp since the original proposal. Except we
were checking the command's read timestamp, not write timestamp.
Also changes a Less to a LessEq when comparing with the closed
timestamp, which I think is how that comparison should be.

Release note (bug fix): Fixed a very rare chance of inconsistent
follower reads.
Copy link
Contributor Author

@andreimatei andreimatei 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! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/roachpb/batch.go, line 95 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

You can move this down right below IsUnsplittable and implement it as return ba.hasFlag(consultsTSCache)

done

@andreimatei andreimatei force-pushed the repropose-write-timestamp branch from c8f5cd2 to 645882d Compare February 9, 2021 00:22
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 2 of 3 files at r3.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)

Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

bors r+

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

@craig
Copy link
Contributor

craig bot commented Feb 9, 2021

Build succeeded:

@craig craig bot merged commit a8532bc into cockroachdb:master Feb 9, 2021
@andreimatei andreimatei deleted the repropose-write-timestamp branch February 12, 2021 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants