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: fix the setting of br.Timestamp #44411

Merged
merged 2 commits into from
Jan 30, 2020

Conversation

andreimatei
Copy link
Contributor

@andreimatei andreimatei commented Jan 27, 2020

Before this patch, evaluateBatch() had special code to deal with
transactions committed at a different timestamp than txn.ReadTimestamp.
This was useful when the EndTxn request decided that it can commit
despite a bumped write timestamp. The code was broken because it was not
dealing with STAGING txns.
This patch simplifies this code by having EndTxn update the read
timestamp. This way, evaluateBatch() no longer needs to consider the
transaction's disposition. The burden is moved to EndTxn, which is
already in this dirty business.

The change is also in the spirit of how timestamps are supposed to work.
For transactional requests, code should generally look at
ba.Txn.ReadTimestamp, not at ba.Timestamp. However, evaluateBatch() was
using ba.Timestamp around the affected code.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andreimatei
Copy link
Contributor Author

r1 is #44407

This was attempted before in #42969 (it's one of the preliminary commits there), but rolled back because it broke backwards compatibility. #44407 fixes that backwards compatibility.
Since #42969, the patch changed a little bit.

@andreimatei andreimatei force-pushed the txn.rationalize-br-timestamp branch 3 times, most recently from d4f1a45 to 604dbd8 Compare January 27, 2020 22:08
@andreimatei andreimatei changed the title storage: improve the setting of br.Timestamp storage: fix the setting of br.Timestamp Jan 27, 2020
@andreimatei andreimatei force-pushed the txn.rationalize-br-timestamp branch 2 times, most recently from 720cd8d to b566254 Compare January 29, 2020 19:52
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.

now r1 and r2 are #44407

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

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 1 of 1 files at r1, 4 of 4 files at r2, 2 of 2 files at r3, 1 of 2 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andreimatei and @nvanbenschoten)


pkg/storage/replica_evaluate.go, line 350 at r4 (raw file):

	// Update the batch response timestamp field to the timestamp at which the
	// batch's reads were evaluated.
	if !br.Timestamp.IsEmpty() {

Is this worth asserting? We created the object in this function.


pkg/storage/replica_evaluate.go, line 357 at r4 (raw file):

		br.Txn = baHeader.Txn
		// Note that br.Txn.ReadTimestamp might be higher than baHeader.Timestamp if
		// we had an EndTxn that decided that it can essentially refresh to

s/essentially//

Let's just move towards calling this a "server-side refresh". Same thing in cmd_end_transaction.go.

@andreimatei andreimatei force-pushed the txn.rationalize-br-timestamp branch from b566254 to 5bb386d Compare January 30, 2020 16:34
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 (and 1 stale) (waiting on @nvanbenschoten)


pkg/storage/replica_evaluate.go, line 350 at r4 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Is this worth asserting? We created the object in this function.

removed


pkg/storage/replica_evaluate.go, line 357 at r4 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

s/essentially//

Let's just move towards calling this a "server-side refresh". Same thing in cmd_end_transaction.go.

done

Fix an incorrect comment on br.Timestamp that mistakenly indicated that
the field is only relevant for non-transactional requests.

Release note: None
Before this patch, evaluateBatch() had special code to deal with
transactions committed at a different timestamp than txn.ReadTimestamp.
This was useful when the EndTxn request decided that it can commit
despite a bumped write timestamp. The code was broken because it was not
dealing with STAGING txns.
This patch simplifies this code by having EndTxn update the read
timestamp. This way, evaluateBatch() no longer needs to consider the
transaction's disposition. The burden is moved to EndTxn, which is
already in this dirty business.

The change is also in the spirit of how timestamps are supposed to work.
For transactional requests, code should generally look at
ba.Txn.ReadTimestamp, not at ba.Timestamp. However, evaluateBatch() was
using ba.Timestamp around the affected code.

Release note: None
@andreimatei andreimatei force-pushed the txn.rationalize-br-timestamp branch from 5bb386d to b04f474 Compare January 30, 2020 18:52
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! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @nvanbenschoten)

@craig
Copy link
Contributor

craig bot commented Jan 30, 2020

Build failed

@andreimatei
Copy link
Contributor Author

flaked on #43949

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 30, 2020

Build failed (retrying...)

craig bot pushed a commit that referenced this pull request Jan 30, 2020
44411: storage: fix the setting of br.Timestamp  r=andreimatei a=andreimatei

Before this patch, evaluateBatch() had special code to deal with
transactions committed at a different timestamp than txn.ReadTimestamp.
This was useful when the EndTxn request decided that it can commit
despite a bumped write timestamp. The code was broken because it was not
dealing with STAGING txns.
This patch simplifies this code by having EndTxn update the read
timestamp. This way, evaluateBatch() no longer needs to consider the
transaction's disposition. The burden is moved to EndTxn, which is
already in this dirty business.

The change is also in the spirit of how timestamps are supposed to work.
For transactional requests, code should generally look at
ba.Txn.ReadTimestamp, not at ba.Timestamp. However, evaluateBatch() was
using ba.Timestamp around the affected code.

Release note: None

Co-authored-by: Andrei Matei <andrei@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Jan 30, 2020

Build succeeded

@craig craig bot merged commit b04f474 into cockroachdb:master Jan 30, 2020
@andreimatei andreimatei deleted the txn.rationalize-br-timestamp branch January 30, 2020 20:54
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