Skip to content

storage: prevent concurrent proposals and lease transfers#41473

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/remove-ambiguity-for-pending-commands-after-lease-transfer
Nov 6, 2019
Merged

storage: prevent concurrent proposals and lease transfers#41473
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/remove-ambiguity-for-pending-commands-after-lease-transfer

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner commented Oct 9, 2019

Before this PR we would not fail proposals when we learned about a lease
transfer. Instead we waited for a raft election before attempting to repropose.
Furthermore we generally just waited for those proposals to be committed but
fail to apply before notifying clients. This lazy failure detection is
problematic when the proposing replica is removed before the entries are
committed as it can lead to an ambiguous result.

Informs #37815.

Release justification: low risk, high benefit changes to existing functionality.

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner ajwerner force-pushed the ajwerner/remove-ambiguity-for-pending-commands-after-lease-transfer branch from 06ae164 to bf195f7 Compare October 9, 2019 17:18
@ajwerner ajwerner requested a review from nvb October 9, 2019 18:21
@ajwerner ajwerner changed the title storage: fail pending proposal when applying lease transfer storage: fail pending proposals when applying lease transfer Oct 9, 2019
@ajwerner
Copy link
Copy Markdown
Contributor Author

ajwerner commented Oct 9, 2019

I've now typed the latching code and I think it is just simpler and better than the first commit.

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.

I agree with your preference for the second commit. However, I think the first commit does still serve a purpose. By placing the failure code in leasePostApply, we also avoid ambiguous errors on non-cooperative leaseholder changes. Weren't you were seeing a case where a leaseholder had its lease revoked without it immediately knowing (due to a disjoint raft leader) and only later finding this out when it applied the raft entry with the new lease?

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @nvanbenschoten)


pkg/storage/client_replica_test.go, line 2824 at r2 (raw file):

//      but it potentially still has pending commands which it thinks might
//      have been proposed. This can occur if there are commands which are
//      proposed after lease transfer has been proposed but before the lease

"a lease transfer" or "the lease transfer"


pkg/storage/batcheval/cmd_lease_transfer.go, line 33 at r2 (raw file):

	// current range descriptor (desc) but it could potentially change due to an
	// as of yet unapplied merge.
	spans.Add(spanset.SpanReadOnly, roachpb.Span{Key: keys.LocalMax, EndKey: keys.MaxKey})

This will play well with #39765. With that change, you could declare this span as non-MVCC so that it will interfere with writes at a higher timestamp.

@ajwerner
Copy link
Copy Markdown
Contributor Author

ajwerner commented Nov 5, 2019

However, I think the first commit does still serve a purpose. By placing the failure code in leasePostApply, we also avoid ambiguous errors on non-cooperative leaseholder changes. Weren't you were seeing a case where a leaseholder had its lease revoked without it immediately knowing (due to a disjoint raft leader) and only later finding this out when it applied the raft entry with the new lease?

The case where we'll avoid ambiguous errors in a non-cooperative lease transfer case requires the old leaseholder to append and apply the lease transfer before it realizes that its been removed. The only source of ambiguity is when the replica has been removed. I suspect this case is pretty rare as generally if a leaseholder has had its lease taken non-cooperatively it probably was partitioned. If it was removed while it was partitioned it seems pretty likely that it will receive a ReplicaTooOldError before it actually applies the lease transfer. We'd need a different mitigation to ensure that the old leaseholder properly disambiguated the results. Generally speaking I'm less concerned about ambiguity in the face of network partitions. That being said, I agree we could do something. In the short term I think I'm going to update this PR to just include the second commit and will create an issue to deal with the ambiguity in cases of non-cooperative lease transfer.

@ajwerner ajwerner force-pushed the ajwerner/remove-ambiguity-for-pending-commands-after-lease-transfer branch 3 times, most recently from 947304e to 52e7747 Compare November 5, 2019 15:20
Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

This is RFAL

cc @irfansharif

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


pkg/storage/batcheval/cmd_lease_transfer.go, line 33 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

This will play well with #39765. With that change, you could declare this span as non-MVCC so that it will interfere with writes at a higher timestamp.

Done.

Copy link
Copy Markdown
Contributor

@irfansharif irfansharif 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 4 of 4 files at r3.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

Copy link
Copy Markdown
Contributor

@irfansharif irfansharif 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 @ajwerner)


pkg/storage/client_replica_test.go, line 2824 at r3 (raw file):

//      but it potentially still has pending commands which it thinks might
//      have been proposed. This can occur if there are commands which are
//      proposed after thje lease transfer has been proposed but before the lease

"thje" -> "the".

…sfers

This commit prevents ambiguous response errors which were previously
possible due replicas which were formerly lease holders being removed while
holding pending proposals. The change ensures that there cannot be pending
proposals concurrent with a lease transfer.

Release note: None
@ajwerner ajwerner force-pushed the ajwerner/remove-ambiguity-for-pending-commands-after-lease-transfer branch from 52e7747 to ab9f433 Compare November 5, 2019 21:28
Copy link
Copy Markdown
Contributor Author

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

@nvanbenschoten do you agree that this commit should not be backported? How do you feel about backporting the logic in the old first commit?

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


pkg/storage/client_replica_test.go, line 2824 at r3 (raw file):

Previously, irfansharif (irfan sharif) wrote…

"thje" -> "the".

Done.

Copy link
Copy Markdown
Contributor

@irfansharif irfansharif 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 r4.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@ajwerner ajwerner changed the title storage: fail pending proposals when applying lease transfer storage: prevent concurrent proposals and lease transfers Nov 5, 2019
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:

do you agree that this commit should not be backported? How do you feel about backporting the logic in the old first commit?

I don't think we should backport any of this. The potential for stalls or other fallout seems too high to me and this isn't addressing a new issue.

Reviewed 1 of 4 files at r3, 1 of 1 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale)

@ajwerner
Copy link
Copy Markdown
Contributor Author

ajwerner commented Nov 6, 2019

TFTR!

bors r+

craig bot pushed a commit that referenced this pull request Nov 6, 2019
41473: storage: prevent concurrent proposals and lease transfers r=ajwerner a=ajwerner

Before this PR we would not fail proposals when we learned about a lease
transfer. Instead we waited for a raft election before attempting to repropose.
Furthermore we generally just waited for those proposals to be committed but
fail to apply before notifying clients. This lazy failure detection is
problematic when the proposing replica is removed before the entries are
committed as it can lead to an ambiguous result.

Informs #37815.

Release justification: low risk, high benefit changes to existing functionality.

Release note: None

Co-authored-by: Andrew Werner <ajwerner@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Nov 6, 2019

Build succeeded

@craig craig bot merged commit ab9f433 into cockroachdb:master Nov 6, 2019
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