Skip to content

Commit ee6e373

Browse files
author
jseldess
authored
Merge pull request #1296 from cockroachdb/rollback
Updates to ROLLBACK docs
2 parents eba67fb + fcfe9e0 commit ee6e373

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
<svg width="302" height="36">
1+
<svg width="518" height="68">
22

33
<polygon points="9 17 1 13 1 21"></polygon>
44
<polygon points="17 17 9 13 9 21"></polygon>
55
<rect x="31" y="3" width="92" height="32" rx="10"></rect>
66
<rect x="29" y="1" width="92" height="32" class="terminal" rx="10"></rect>
77
<text class="terminal" x="39" y="21">ROLLBACK</text>
8-
<a xlink:href="sql-grammar.html#opt_to_savepoint" xlink:title="opt_to_savepoint">
9-
<rect x="143" y="3" width="132" height="32"></rect>
10-
<rect x="141" y="1" width="132" height="32" class="nonterminal"></rect>
11-
<text class="nonterminal" x="151" y="21">opt_to_savepoint</text>
12-
</a>
13-
<path class="line" d="m17 17 h2 m0 0 h10 m92 0 h10 m0 0 h10 m132 0 h10 m3 0 h-3"></path>
14-
<polygon points="293 17 301 13 301 21"></polygon>
15-
<polygon points="293 17 285 13 285 21"></polygon>
8+
<rect x="163" y="35" width="38" height="32" rx="10"></rect>
9+
<rect x="161" y="33" width="38" height="32" class="terminal" rx="10"></rect>
10+
<text class="terminal" x="171" y="53">TO</text>
11+
<rect x="221" y="35" width="98" height="32" rx="10"></rect>
12+
<rect x="219" y="33" width="98" height="32" class="terminal" rx="10"></rect>
13+
<text class="terminal" x="229" y="53">SAVEPOINT</text>
14+
15+
<rect x="339" y="35" width="132" height="32"></rect>
16+
<rect x="337" y="33" width="132" height="32" class="nonterminal"></rect>
17+
<text class="nonterminal" x="347" y="53">cockroach_restart</text>
18+
19+
<path class="line" d="m17 17 h2 m0 0 h10 m92 0 h10 m20 0 h10 m0 0 h318 m-348 0 h20 m328 0 h20 m-368 0 q10 0 10 10 m348 0 q0 -10 10 -10 m-358 10 v12 m348 0 v-12 m-348 12 q0 10 10 10 m328 0 q10 0 10 -10 m-338 10 h10 m38 0 h10 m0 0 h10 m98 0 h10 m0 0 h10 m132 0 h10 m23 -32 h-3"></path>
20+
<polygon points="509 17 517 13 517 21"></polygon>
21+
<polygon points="509 17 501 13 501 21"></polygon>
1622
</svg>

generate/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,14 @@ func main() {
397397
{name: "rename_index", stmt: "rename_stmt", match: []*regexp.Regexp{regexp.MustCompile("'ALTER' 'INDEX'")}, inline: []string{"table_name_with_index"}, replace: map[string]string{"qualified_name": "table_name", "'@' name": "'@' index_name"}, unlink: []string{"table_name", "index_name"}},
398398
{name: "rename_table", stmt: "rename_stmt", match: []*regexp.Regexp{regexp.MustCompile("'ALTER' 'TABLE' .* 'RENAME' 'TO'")}},
399399
{name: "revoke_stmt", inline: []string{"privileges", "privilege_list", "privilege", "targets", "grantee_list"}},
400-
{name: "rollback_transaction", stmt: "transaction_stmt", inline: []string{"opt_transaction"}, match: []*regexp.Regexp{regexp.MustCompile("'ROLLBACK'")}},
400+
{
401+
name: "rollback_transaction",
402+
stmt: "transaction_stmt",
403+
inline: []string{"opt_to_savepoint"},
404+
match: []*regexp.Regexp{regexp.MustCompile("'ROLLBACK'")},
405+
replace: map[string]string{"'TRANSACTION'": "", "'TO'": "'TO' 'SAVEPOINT'","savepoint_name": "cockroach_restart"},
406+
unlink: []string{"cockroach_restart"},
407+
},
401408
{name: "savepoint_stmt", inline: []string{"savepoint_name"}},
402409
{
403410
name: "select_stmt",

rollback-transaction.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toc: false
66

77
The `ROLLBACK` [statement](sql-statements.html) aborts the current [transaction](transactions.html), discarding all updates made by statements included in the transaction.
88

9-
When using [client-side transaction retries](transactions.html#client-side-transaction-retries), use `ROLLBACK TO SAVEPOINT cockroach_restart` to handle transaction that need to be retried (identified via the `40001` error code or `retry transaction` string in the error message), and then re-execute the statements in the transaction.
9+
When using [client-side transaction retries](transactions.html#client-side-transaction-retries), use `ROLLBACK TO SAVEPOINT cockroach_restart` to handle a transaction that needs to be retried (identified via the `40001` error code or `retry transaction` string in the error message), and then re-execute the statements you want the transaction to contain.
1010

1111
<div id="toc"></div>
1212

@@ -22,13 +22,13 @@ No [privileges](privileges.html) are required to rollback a transaction. However
2222

2323
| Parameter | Description |
2424
|-----------|-------------|
25-
| `TO cockroach_restart` | If using [client-side transaction retries](transactions.html#client-side-transaction-retries), retry the transaction. You should execute this statement when a transaction returns a `40001` / `retry transaction` error. |
25+
| `TO SAVEPOINT cockroach_restart` | If using [client-side transaction retries](transactions.html#client-side-transaction-retries), retry the transaction. You should execute this statement when a transaction returns a `40001` / `retry transaction` error. |
2626

2727
## Example
2828

2929
### Rollback a Transaction
3030

31-
Typically, your application conditionally executes rollbacks but you can see their behavior by using `ROLLBACK` instead of `COMMIT` directly through SQL.
31+
Typically, your application conditionally executes rollbacks, but you can see their behavior by using `ROLLBACK` instead of `COMMIT` directly through SQL.
3232

3333
~~~ sql
3434
> SELECT * FROM accounts;
@@ -59,10 +59,10 @@ Typically, your application conditionally executes rollbacks but you can see the
5959

6060
### Retry a Transaction
6161

62-
To use [client-side transaction retries](transactions.html#client-side-transaction-retries), your application must execute `ROLLBACK TO cockroach_restart` after detecting a `40001` / `retry transaction` error.
62+
To use [client-side transaction retries](transactions.html#client-side-transaction-retries), your application must execute `ROLLBACK TO SAVEPOINT cockroach_restart` after detecting a `40001` / `retry transaction` error.
6363

6464
~~~ sql
65-
> ROLLBACK TO cockroach_restart;
65+
> ROLLBACK TO SAVEPOINT cockroach_restart;
6666
~~~
6767

6868
For examples of retrying transactions in your application, check out the transaction code samples in our [Build an App with CockroachDB](build-an-app-with-cockroachdb.html) tutorials.

savepoint.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The `SAVEPOINT cockroach_restart` statement defines the intent to retry [transac
99
{{site.data.alerts.callout_danger}}CockroachDB’s <code>SAVEPOINT</code> implementation only supports the <code>cockroach_restart</code> savepoint and does not support all savepoint functionality, such as nested transactions.{{site.data.alerts.end}}
1010

1111
<div id="toc"></div>
12-
12+
1313
## Synopsis
1414

1515
{% include sql/diagrams/savepoint.html %}
@@ -38,7 +38,7 @@ After you `BEGIN` the transaction, you must create the savepoint to identify tha
3838
> COMMIT;
3939
~~~
4040

41-
When using `SAVEPOINT`, your application must also include functions to execute retries with [`ROLLBACK TO cockroach_restart`](rollback-transaction.html#retry-a-transaction).
41+
When using `SAVEPOINT`, your application must also include functions to execute retries with [`ROLLBACK TO SAVEPOINT cockroach_restart`](rollback-transaction.html#retry-a-transaction).
4242

4343
## See Also
4444

transactions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ Each of the following SQL statements control transactions in some way.
2121
| [`SAVEPOINT cockroach_restart`](savepoint.html) | Declare the transaction as [retryable](#client-side-transaction-retries). This lets you retry the transaction if it doesn't succeed because a higher priority transaction concurrently or recently accessed the same values. |
2222
| [`RELEASE SAVEPOINT cockroach_restart`](release-savepoint.html) | Commit a [retryable transaction](#client-side-transaction-retries). |
2323
| [`COMMIT`](commit-transaction.html) | Commit a non-retryable transaction or clear the connection after committing a retryable transaction. |
24-
| [`ROLLBACK cockroach_restart`](rollback-transaction.html) | Handle [retryable errors](#error-handling) by rolling back a transaction's changes and increasing its priority. |
24+
| [`ROLLBACK TO SAVEPOINT cockroach_restart`](rollback-transaction.html) | Handle [retryable errors](#error-handling) by rolling back a transaction's changes and increasing its priority. |
2525
| [`ROLLBACK`](rollback-transaction.html) | Abort a transaction and roll the database back to its state before the transaction began. |
2626
| [`SHOW TRANSACTION`](show-transaction.html) | Retrieve a transaction's [priority](#transaction-priorities) or [isolation level](#isolation-levels). |
2727

2828
## Syntax
2929

3030
In CockroachDB, a transaction is set up by surrounding SQL statements with the [`BEGIN`](begin-transaction.html) and [`COMMIT`](commit-transaction.html) statements.
3131

32-
To use [client-side transaction retries](#client-side-transaction-retries), you should also include the `SAVEPOINT cockroach_restart`, `ROLLBACK TO cockroach_restart` and `RELEASE SAVEPOINT` statements.
32+
To use [client-side transaction retries](#client-side-transaction-retries), you should also include the `SAVEPOINT cockroach_restart`, `ROLLBACK TO SAVEPOINT cockroach_restart` and `RELEASE SAVEPOINT` statements.
3333

3434
~~~ sql
3535
> BEGIN;
@@ -144,9 +144,9 @@ Implementing client-side retries requires three statements:
144144

145145
- [`SAVEPOINT cockroach_restart`](savepoint.html) declares the client's intent to retry the transaction if there are contention errors. It must be executed after `BEGIN` but before the first statement that manipulates a database.
146146

147-
- [`ROLLBACK TO cockroach_restart`](rollback-transaction.html#retry-a-transaction) is used when your application detects `40001` / `retry transaction` errors. It provides you a chance to "retry" the transaction by rolling the database's state back to the beginning of the transaction and increasing the transaction's priority.
147+
- [`ROLLBACK TO SAVEPOINT cockroach_restart`](rollback-transaction.html#retry-a-transaction) is used when your application detects `40001` / `retry transaction` errors. It provides you a chance to "retry" the transaction by rolling the database's state back to the beginning of the transaction and increasing the transaction's priority.
148148

149-
After issuing `ROLLBACK TO cockroach_restart`, you must issue any statements you want the transaction to contain. Typically, this means recalculating values and reissuing a similar set of statements to the previous attempt.
149+
After issuing `ROLLBACK TO SAVEPOINT cockroach_restart`, you must issue any statements you want the transaction to contain. Typically, this means recalculating values and reissuing a similar set of statements to the previous attempt.
150150

151151
- [`RELEASE SAVEPOINT cockroach_restart`](release-savepoint.html) commits the transaction. At this point, CockroachDB checks to see if the transaction contends with others for access to the same values; the highest priority transaction succeeds, and the others return `40001` / `retry transaction` errors.
152152

0 commit comments

Comments
 (0)