forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: automatically retry the first batch after a BEGIN
Before this patch, in case of retryable errors, the server (i.e. the Executor) would automatically retry a batch of statements if the batch was the prefix of a transaction (or if the batch contained the whole txn). For example, if the following SELECT would get an error, it'd be retried if all of the following statements arrived to the server in one batch: BEGIN; ...; SELECT foo; [... COMMIT]. The rationale in retrying these prefixes, but not otherwise, was that, in the case of a prefix batch, we know that the client had no conditional logic based on reads performed in the current txn. This patch extends this reasoning to statements executed in the first batch arriving after the batch with the BEGIN if the BEGIN had been trailing a previous batch (more realistically, if the BEGIN is sent alone as a batch). As a further optimization, the SAVEPOINT statement doesn't change the retryable character of the next range). So, if you do something like (different lines are different batches): BEGIN SELECT foo; or BEGIN; SAVEPOINT cockroach_restart; SELECT foo or BEGIN SAVEPOINT cockroach_restart [...;] SELECT FOO the SELECTs will be retried automatically. Besides being generally a good idea to hide retryable errors more, this change was motivated by ORMs getting retryable errors from a BEGIN; CREATE TABLE ...; COMMIT; sequence (with the BEGIN being a separate batch). This ORM code is not under our control and we can't teach it about user-directed retries. This is implemented by creating a new txnState.State - FirstBatch. Auto-retry is enabled for batches executed in this state. Fixes cockroachdb#16450 Fixes cockroachdb#16200 See also forum discussion about it: https://forum.cockroachlabs.com/t/automatically-retrying-the-first-batch-of-statements-after-a-begin/759
- Loading branch information
1 parent
7a31a9e
commit 488a1ec
Showing
10 changed files
with
245 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.