Skip to content

storage: avoid client-side retries on CPut/Inc write-too-old errors#22234

Merged
spencerkimball merged 1 commit intocockroachdb:masterfrom
spencerkimball:avoid-client-retries-on-cput
Feb 2, 2018
Merged

storage: avoid client-side retries on CPut/Inc write-too-old errors#22234
spencerkimball merged 1 commit intocockroachdb:masterfrom
spencerkimball:avoid-client-retries-on-cput

Conversation

@spencerkimball
Copy link
Copy Markdown
Member

@spencerkimball spencerkimball commented Jan 30, 2018

Previously, a conditional put or increment ops that experienced a write-too-old error
would not immediately return an error. Instead, it would proceed to lay
down the intent, set the WriteTooOld bool on the Transaction, and
continue so that intents might be laid down to assure succes on the
eventual retry. The EndTransaction request triggers restart at commit
time in the event that WriteTooOld is set.

The problem with this is that refreshing the conditional put key is
guaranteed to fail because there is a known, newer version of the key
written. This implies a client-side retry.

This change makes conditional puts immediately return a WriteTooOldError
instead of just swallowing the error and setting the WriteTooOld
flag. The returned error allows the TxnCoordSender to refresh all
spans mid-transaction, and hopefully retry the conditional put at the
advanced timestamp, to either succeed or fail on the conditional put.
This allows the transaction to continue on success, or return a
ConditionFailedError on failure.

@spencerkimball spencerkimball requested review from a team and nvb January 30, 2018 23:28
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@spencerkimball
Copy link
Copy Markdown
Member Author

@nvanbenschoten, ignore first commit; that's the serializable txn retries. This is the change I was telling you about to avoid client-side transaction retries for conditional puts.

@andreimatei this solves the case where the old auto-retry mechanism might have saved us from a client visible restart with conditional puts that we whiteboarded yesterday.

@nvb
Copy link
Copy Markdown
Contributor

nvb commented Jan 31, 2018

The code all looks good. I do have a general question about WriteTooOldErrors - now that we have the ability to refresh spans within a txn to a higher timestamp, what is the benefit of ever setting the WriteTooOld flag on a transaction and then continuing to lay down intents at the older timestamp? Why don't we always do what we're doing here and let WriteTooOldErrors fall back to the TxnCoordSender?


Review status: 0 of 43 files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@spencerkimball
Copy link
Copy Markdown
Member Author

Because you end up with O(n^2) behavior on big transactions that encounter a lot of WriteTooOldErrors on Puts. Each one has to refresh all of the spans which came before. Laying down the intent and refreshing at the end is the better algorithm.


Review status: 0 of 43 files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@spencerkimball spencerkimball force-pushed the avoid-client-retries-on-cput branch from de625fc to 3e00821 Compare February 1, 2018 16:09
@spencerkimball spencerkimball changed the title storage: avoid client-side retries on CPut write-too-old errors storage: avoid client-side retries on CPut/Inc write-too-old errors Feb 1, 2018
@spencerkimball spencerkimball force-pushed the avoid-client-retries-on-cput branch from 3e00821 to 6f0379f Compare February 1, 2018 18:48
@spencerkimball spencerkimball requested review from a team February 1, 2018 18:48
@spencerkimball spencerkimball force-pushed the avoid-client-retries-on-cput branch from 6f0379f to 05a3800 Compare February 1, 2018 21:01
@spencerkimball
Copy link
Copy Markdown
Member Author

OK, this is ready. I updated it to also include Increment requests, which fall into the same category.

@bdarnell
Copy link
Copy Markdown
Contributor

bdarnell commented Feb 1, 2018

:lgtm:


Review status: 0 of 2 files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@nvb
Copy link
Copy Markdown
Contributor

nvb commented Feb 1, 2018

yep :lgtm:, thought I gave that here already but I guess not.


Review status: 0 of 2 files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

Previously, a conditional put op that experienced a write-too-old error
would not immediately return an error. Instead, it would proceed to lay
down the intent, set the `WriteTooOld` bool on the `Transaction`, and
continue so that intents might be laid down to assure succes on the
eventual retry. The `EndTransaction` request triggers restart at commit
time in the event that `WriteTooOld` is set.

The problem with this is that refreshing the conditional put key is
guaranteed to fail because there is a known, newer version of the key
written. This implies a client-side retry.

This change makes conditional puts immediately return a `WriteTooOldError`
instead of just swallowing the error and setting the `WriteTooOld`
flag. The returned error allows the `TxnCoordSender` to refresh all
spans mid-transaction, and hopefully retry the conditional put at the
advanced timestamp, to either succeed or fail on the conditional put.
This allows the transaction to continue on success, or return a
`ConditionFailedError` on failure.

Release note: None
@spencerkimball spencerkimball force-pushed the avoid-client-retries-on-cput branch from 05a3800 to 6e1ae41 Compare February 2, 2018 00:01
@spencerkimball
Copy link
Copy Markdown
Member Author

Added fixes for a test in pkg/sql/ which had become flaky from the original serializable transaction improvements change.

@spencerkimball spencerkimball merged commit 7ba7f85 into cockroachdb:master Feb 2, 2018
@spencerkimball spencerkimball deleted the avoid-client-retries-on-cput branch February 2, 2018 15:55
@andreimatei
Copy link
Copy Markdown
Contributor

Spencer what was the test fix?


Review status: 0 of 3 files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

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.

5 participants