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: don't leak committed protos to pushers on reproposal #34659

Merged
merged 1 commit into from
Feb 6, 2019

Conversation

tbg
Copy link
Member

@tbg tbg commented Feb 6, 2019

TODO: test


A recent commit (master only) reintroduced a bug that we ironically had
spent a lot of time on before. In summary, it would allow the result
of an EndTransaction which would in itself not apply to leak and would
result in intents being committed even though their transaction
ultimately would not:

#34025 (comment)

We've diagnosed this pretty quickly the second time around, but clearly
we didn't do a good job at preventing the regression. I can see how this
would happen as the method this code is in is notoriously difficult to
test for it interfaces so much with everything else that it's difficult
to unit test it; one needs to jump through lots of hoops to target it,
and so we do it less than we ought to.

I believe this wasn't released in any alpha (nor backported anywhere),
so no release note is necessary.

Fixes #34025.

Release note: None

@tbg tbg requested a review from a team February 6, 2019 12:25
@cockroach-teamcity
Copy link
Member

This change is Reviewable

A recent commit (master only) reintroduced a bug that we ironically had
spent a lot of time on [before]. In summary, it would allow the result
of an EndTransaction which would in itself *not* apply to leak and would
result in intents being committed even though their transaction
ultimately would not:

cockroachdb#34025 (comment)

We've diagnosed this pretty quickly the second time around, but clearly
we didn't do a good job at preventing the regression. I can see how this
would happen as the method this code is in is notoriously difficult to
test for it interfaces so much with everything else that it's difficult
to unit test it; one needs to jump through lots of hoops to target it,
and so we do it less than we ought to.

I believe this wasn't released in any alpha (nor backported anywhere),
so no release note is necessary.

Fixes cockroachdb#34025.

[before]: cockroachdb#30792 (comment)

Release note: None
@tbg tbg force-pushed the fix/response-perr branch from c956ab9 to 1fb8d87 Compare February 6, 2019 12:26
Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

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

Nice find! Definitely need to write a test for this. This also seems worthy of listing in the Core fault lines: our inability to unit test complex logic.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@asubiotto asubiotto mentioned this pull request Feb 6, 2019
17 tasks
@tbg
Copy link
Member Author

tbg commented Feb 6, 2019

How do we proceed regarding the alpha? I won't be able to write the test today. Either someone else can pick this up or I can commit to making this tested a priority for tomorrow. This would allow me a little bit of breathing room to see about making this kind of thing easier to test.

@petermattis
Copy link
Collaborator

I'm not super familiar with this code, so I'd want to have a few other folks sign off on this change (@nvanbenschoten, @bdarnell, @andreimatei). Assuming that happens, I'm fine with merging for the alpha along with a promise to get a test written as soon as possible.

@tbg
Copy link
Member Author

tbg commented Feb 6, 2019

👍 @bdarnell and/or @nvanbenschoten, your turn.

Copy link
Contributor

@bdarnell bdarnell left a comment

Choose a reason for hiding this comment

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

:lgtm: to merge for the alpha with my suggested change below and add tests later.

As I'm looking at this code, I think we can get rid of the whole alwaysReturn concept in the eval results by adding a path to the intent resolver in the eval context. Whenever we would add alwaysReturn intents/txns to the result, just hand them directly to the resolver at evaluation time. If application of the command doesn't make any difference, there's no reason to defer this until it applies. Then we can simplify the apply-time logic to only look at intents/txns in the eval result if the command fully succeeded.

Reviewed 1 of 1 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten and @tbg)


pkg/storage/replica_raft.go, line 1930 at r1 (raw file):

			}
			response.Intents = proposal.Local.DetachIntents()
			response.EndTxns = proposal.Local.DetachEndTxns(pErr != nil)

These two error variables are extremely subtle. I think this should be pErr != nil && response.Err != nil. Looking back at the introduction of this alwaysReturn feature (#17074), it was concerned with response errors, not raft/"forced" errors.

I don't think the response.Err clause actually matters because EndTransaction never returns both a non-always updated txn and a response error, but including this clause would be the more conservative option while we're fast-tracking this into the alpha.

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

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


pkg/storage/replica_raft.go, line 1930 at r1 (raw file):

Previously, bdarnell (Ben Darnell) wrote…

These two error variables are extremely subtle. I think this should be pErr != nil && response.Err != nil. Looking back at the introduction of this alwaysReturn feature (#17074), it was concerned with response errors, not raft/"forced" errors.

I don't think the response.Err clause actually matters because EndTransaction never returns both a non-always updated txn and a response error, but including this clause would be the more conservative option while we're fast-tracking this into the alpha.

response isn't the original proposal, it's one that is populated by it. Can you double-check, too? Afaict this is the only write to response.Err. The proposal is in proposal but we copy its fields over piecemeal.

Copy link
Contributor

@bdarnell bdarnell 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 and @tbg)


pkg/storage/replica_raft.go, line 1930 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

response isn't the original proposal, it's one that is populated by it. Can you double-check, too? Afaict this is the only write to response.Err. The proposal is in proposal but we copy its fields over piecemeal.

You're right; ignore this.

Copy link
Contributor

@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.

LGTM good find!
Have you looked into why TestFailureToProcessCommandClearsLocalResult didn't catch this?

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

@tbg
Copy link
Member Author

tbg commented Feb 6, 2019 via email

@asubiotto
Copy link
Contributor

bors r=bdarnell,andreimatei

@craig
Copy link
Contributor

craig bot commented Feb 6, 2019

Build failed (retrying...)

craig bot pushed a commit that referenced this pull request Feb 6, 2019
34651: server: rework TestClusterVersionBootstrapStrict r=andreimatei a=andreimatei

This test... I'm not entirely sure what it was supposed to test to be
honest, but it seemed to be more complicated than it needed to be. It
forced and emphasized MinSupportedVersion being equal to
BinaryServerVersion (which is generally not a thing). I've simplified
it, making it not muck with the versions, while keep (I think) the
things it was testing (to the extent that it was testing anything).

This test was also in my way because it created servers that pretended
to be versions that are not technically supported by the binary, and
this kind of funkiness is making my life hard as I'm trying to rework
the way in which versions are propagated and what knobs servers have,
etc.

Release note: None

34659: storage: don't leak committed protos to pushers on reproposal r=bdarnell,andreimatei a=tbg

TODO: test

----

A recent commit (master only) reintroduced a bug that we ironically had
spent a lot of time on [before]. In summary, it would allow the result
of an EndTransaction which would in itself *not* apply to leak and would
result in intents being committed even though their transaction
ultimately would not:

#34025 (comment)

We've diagnosed this pretty quickly the second time around, but clearly
we didn't do a good job at preventing the regression. I can see how this
would happen as the method this code is in is notoriously difficult to
test for it interfaces so much with everything else that it's difficult
to unit test it; one needs to jump through lots of hoops to target it,
and so we do it less than we ought to.

I believe this wasn't released in any alpha (nor backported anywhere),
so no release note is necessary.

Fixes #34025.

[before]: #30792 (comment)

Release note: None

Co-authored-by: Andrei Matei <[email protected]>
Co-authored-by: Tobias Schottdorf <[email protected]>
@craig
Copy link
Contributor

craig bot commented Feb 6, 2019

Build succeeded

@craig craig bot merged commit 1fb8d87 into cockroachdb:master Feb 6, 2019
@nvanbenschoten
Copy link
Member

LGTM, fantastic find!

tbg added a commit to tbg/cockroach that referenced this pull request Feb 8, 2019
This adds the test promised in the PR below. When a transaction
committed but the commit applied at an invalid lease applied index,
we'd formerly (due to a recent change) leak the intents as committed
which would cause dirty writes. Adapt an existing test to roughly
do the following to prevent regression.

The test (now) sets up two ranges and lets a transaction (anchored on
the left) write to both of them. It then starts readers for both keys
written by the txn and waits for them to enter the txn wait queue. Next,
it lets the txn attempt to commit but injects a forced error below Raft.
The bugs would formerly notify the txn wait queue that the transaction
had committed (not true) and that its external intent (i.e. the one on
the right range) could be resolved (not true). Verify that neither
occurs.

See cockroachdb#34659.

Release note: None
tbg added a commit to tbg/cockroach that referenced this pull request Feb 11, 2019
This adds the test promised in the PR below. When a transaction
committed but the commit applied at an invalid lease applied index,
we'd formerly (due to a recent change) leak the intents as committed
which would cause dirty writes. Adapt an existing test to roughly
do the following to prevent regression.

The test (now) sets up two ranges and lets a transaction (anchored on
the left) write to both of them. It then starts readers for both keys
written by the txn and waits for them to enter the txn wait queue. Next,
it lets the txn attempt to commit but injects a forced error below Raft.
The bugs would formerly notify the txn wait queue that the transaction
had committed (not true) and that its external intent (i.e. the one on
the right range) could be resolved (not true). Verify that neither
occurs.

See cockroachdb#34659.

Release note: None
craig bot pushed a commit that referenced this pull request Feb 11, 2019
34733: storage: regression test leaked intents on bounced proposal r=petermattis a=tbg

This adds the test promised in the PR below. When a transaction
committed but the commit applied at an invalid lease applied index,
we'd formerly (due to a recent change) leak the intents as committed
which would cause dirty writes. Adapt an existing test to roughly
do the following to prevent regression.

The test (now) sets up two ranges and lets a transaction (anchored on
the left) write to both of them. It then starts readers for both keys
written by the txn and waits for them to enter the txn wait queue. Next,
it lets the txn attempt to commit but injects a forced error below Raft.
The bugs would formerly notify the txn wait queue that the transaction
had committed (not true) and that its external intent (i.e. the one on
the right range) could be resolved (not true). Verify that neither
occurs.

See #34659.

Release note: None

Co-authored-by: Tobias Schottdorf <[email protected]>
@tbg tbg deleted the fix/response-perr branch March 13, 2019 11:51
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.

7 participants