Skip to content

kvcoord: simplify txn already committed assertion#73843

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
tbg:commit-assertion
Dec 20, 2021
Merged

kvcoord: simplify txn already committed assertion#73843
craig[bot] merged 2 commits intocockroachdb:masterfrom
tbg:commit-assertion

Conversation

@tbg
Copy link
Copy Markdown
Member

@tbg tbg commented Dec 15, 2021

  • kvcoord: improve TestCommitSanityCheckAssertionFiresOnUndetectedAmbiguousCommit
  • kvcoord: simplify txn already committed assertion

@tbg tbg requested a review from a team as a code owner December 15, 2021 10:47
@tbg tbg requested a review from nvb December 15, 2021 10:47
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@aliher1911 aliher1911 left a comment

Choose a reason for hiding this comment

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

👍

if errTxn := pErr.GetTxn(); errTxn != nil {
if errTxn.Status == roachpb.COMMITTED {
pErr = sanityCheckCommittedErr(ctx, pErr, ba)
if err := maybeSanityCheckCommittedErr(ctx, pErr, ba, &tc.testingKnobs); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think previous version was more readable because of explicit check for COMMITTED status prior to trying a sanity check. With new version I had to drill down into impl to understand why we feed all errors into commit check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

interesting, the reason I pulled it in is because I had the opposite problem, that in the assertion we had to trust the caller that they had already checked the status. I felt that it needed to be either all in the method or completely inline, and I didn't want to inline it to keep the main code.

Were you thrown off by the name of the method referencing "committed"? We can rename it so that it's a general sanity check that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think a better name would make sense. But I failed to come up with something sensible myself.

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aliher1911 and @tbg)


pkg/kv/kvclient/kvcoord/txn_coord_sender.go, line 919 at r2 (raw file):

Previously, aliher1911 (Oleg) wrote…

I think a better name would make sense. But I failed to come up with something sensible myself.

I had the same reaction as Oleg. It's strange to see pErr passed to a function called maybeSanityCheckCommittedErr that accepts a param called pErrWithCommittedTxn before we've determined that the pErr has a committed txn.

If we're going to restructure the code like this, the function should be called maybeSanityCheckErr, its comment should be made more general, and the parameter should be called pErr. Or go back to what we had before.


pkg/kv/kvclient/kvcoord/replayed_commit_test.go, line 105 at r1 (raw file):

			return err
		}
		// We need to give the txn an external lock (i.e. one on a different range),

Do you want to disable async intent resolution so that this is not racy? There's an intent resolver testing knob for that.


pkg/kv/kvclient/kvcoord/replayed_commit_test.go, line 79 at r2 (raw file):

			},
		}, nil
	},

nit: The indentation looks off here. At first I didn't even think it would compile or pass gofmt, but I see why it does. Still, I think it's worth fixing.

…uousCommit

It was overriding `txnAutoGC`, which is not a clean knob to use, and it
was stating an incorrect reason for even using that knob. Now we're
preventing GC of the txn record by writing an additional intent, which
is cleaner.

Release note: None
@tbg tbg force-pushed the commit-assertion branch from 79745c0 to 4fcfa00 Compare December 20, 2021 08:35
Copy link
Copy Markdown
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

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

TFTRs, PTAL

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


pkg/kv/kvclient/kvcoord/replayed_commit_test.go, line 105 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Do you want to disable async intent resolution so that this is not racy? There's an intent resolver testing knob for that.

Good idea, done.

Copy link
Copy Markdown
Contributor

@nvb nvb 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 3 of 3 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @tbg)

Also improves
TestCommitSanityCheckAssertionFiresOnUndetectedAmbiguousCommit to use a
testing knob as opposed to updating the env var, which is always going
to carry some residual risk of a data race.

Release note: None
@tbg tbg force-pushed the commit-assertion branch from 4fcfa00 to 1de1865 Compare December 20, 2021 14:59
@tbg
Copy link
Copy Markdown
Member Author

tbg commented Dec 20, 2021

TFTR!

bors r=nvanbenschoten

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 20, 2021

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 20, 2021

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 20, 2021

Build succeeded:

@craig craig bot merged commit 9838965 into cockroachdb:master Dec 20, 2021
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.

4 participants