-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document nested transactions with SAVEPOINTs
Fixes #5953. Summary of changes: - Update SAVEPOINT page with more examples of "generalized" aka "nested" savepoints adapted from the RFC, in addition to the existing "retry" savepoints info - Add a new SHOW SAVEPOINT STATUS statement page (with syntax diagram), and add it to the sidebar - Update RELEASE SAVEPOINT docs to clarify "retry" savepoints vs. "generalized/nested" savepoints, and update the examples as well - Update the ROLLBACK docs to mention rollbacks to savepoints more explicitly. Also, update the diagram to reflect that 'cockroach_restart' is no longer the only allowed savepoint name. - Add information on how CockroachDB handles savepoints and locking vs. Postgres - Add a new "nested transactions" section to the 'Transactions' page, including descriptions of how COMMIT, ROLLBACK, RELEASE SAVEPOINT, and ROLLBACK TO SAVEPOINT relate to each other - Draw distinctions in several places between "retry" savepoints and "nested" or "generalized" savepoints, since they are different - Update mentions of savepoints on 'SQL Statements' and 'Postgres Compatibility' to note that they are supported now
- Loading branch information
1 parent
a0d4629
commit 1dec38d
Showing
21 changed files
with
493 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
Set the `force_savepoint_restart` [session variable](set-vars.html#supported-variables) to `true` to enable using a custom name for the restart savepoint (for example, because you are using an ORM that wants to use its own names for savepoints). | ||
Set the `force_savepoint_restart` [session variable](set-vars.html#supported-variables) to `true` to enable using a custom name for the [retry savepoint](advanced-client-side-transaction-retries.html#retry-savepoints) (for example, because you are using an ORM that wants to use its own names for savepoints). | ||
|
||
Once this variable is set, the [`SAVEPOINT`](savepoint.html) statement will accept any name for the savepoint, not just `cockroach_restart`. This allows compatibility with existing code that uses a single savepoint per transaction as long as that savepoint occurs before any statements that access data stored in non-virtual tables. | ||
Once this variable is set, the [`SAVEPOINT`](savepoint.html) statement will accept any name for the retry savepoint, not just `cockroach_restart`. In addition, it causes every savepoint name to be equivalent to `cockroach_restart`, therefore disallowing the use of [nested transactions](transactions.html#nested-transactions). | ||
|
||
{{site.data.alerts.callout_danger}} | ||
The `force_savepoint_restart` variable changes the semantics of CockroachDB savepoints so that `RELEASE SAVEPOINT <your-custom-name>` functions as a real commit. Note that the existence of this variable and its behavior does not change the fact that CockroachDB savepoints can only be used as a part of the transaction retry protocol. | ||
{{site.data.alerts.end}} | ||
This feature exists to support applications that want to use the [advanced client-side transaction retry protocol](advanced-client-side-transaction-retries.html), but cannot customize the name of savepoints to be `cockroach_restart`. |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
<div><svg width="518" height="68"> | ||
|
||
<polygon points="9 17 1 13 1 21"></polygon> | ||
<polygon points="17 17 9 13 9 21"></polygon> | ||
<rect x="31" y="3" width="92" height="32" rx="10"></rect> | ||
<rect x="29" y="1" width="92" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="39" y="21">ROLLBACK</text> | ||
<rect x="163" y="35" width="38" height="32" rx="10"></rect> | ||
<rect x="161" y="33" width="38" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="171" y="53">TO</text> | ||
<rect x="221" y="35" width="98" height="32" rx="10"></rect> | ||
<rect x="219" y="33" width="98" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="229" y="53">SAVEPOINT</text> | ||
|
||
<rect x="339" y="35" width="132" height="32"></rect> | ||
<rect x="337" y="33" width="132" height="32" class="nonterminal"></rect> | ||
<text class="nonterminal" x="347" y="53">cockroach_restart</text> | ||
|
||
<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> | ||
<polygon points="509 17 517 13 517 21"></polygon> | ||
<polygon points="509 17 501 13 501 21"></polygon> | ||
</svg></div> | ||
<div><svg width="515" height="69"> | ||
<polygon points="9 17 1 13 1 21"></polygon> | ||
<polygon points="17 17 9 13 9 21"></polygon> | ||
<rect x="31" y="3" width="92" height="32" rx="10"></rect> | ||
<rect x="29" y="1" width="92" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="39" y="21">ROLLBACK</text> | ||
<rect x="163" y="35" width="38" height="32" rx="10"></rect> | ||
<rect x="161" y="33" width="38" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="171" y="53">TO</text> | ||
<rect x="221" y="35" width="100" height="32" rx="10"></rect> | ||
<rect x="219" y="33" width="100" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="229" y="53">SAVEPOINT</text><a xlink:href="sql-grammar.html#savepoint_name" xlink:title="savepoint_name"> | ||
<rect x="341" y="35" width="126" height="32"></rect> | ||
<rect x="339" y="33" width="126" height="32" class="nonterminal"></rect> | ||
<text class="nonterminal" x="349" y="53">savepoint_name</text></a><path class="line" d="m17 17 h2 m0 0 h10 m92 0 h10 m20 0 h10 m0 0 h314 m-344 0 h20 m324 0 h20 m-364 0 q10 0 10 10 m344 0 q0 -10 10 -10 m-354 10 v12 m344 0 v-12 m-344 12 q0 10 10 10 m324 0 q10 0 10 -10 m-334 10 h10 m38 0 h10 m0 0 h10 m100 0 h10 m0 0 h10 m126 0 h10 m23 -32 h-3"></path> | ||
<polygon points="505 17 513 13 513 21"></polygon> | ||
<polygon points="505 17 497 13 497 21"></polygon></svg></div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div><svg width="335" height="37"> | ||
<polygon points="9 17 1 13 1 21"></polygon> | ||
<polygon points="17 17 9 13 9 21"></polygon> | ||
<rect x="31" y="3" width="64" height="32" rx="10"></rect> | ||
<rect x="29" y="1" width="64" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="39" y="21">SHOW</text> | ||
<rect x="115" y="3" width="100" height="32" rx="10"></rect> | ||
<rect x="113" y="1" width="100" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="123" y="21">SAVEPOINT</text> | ||
<rect x="235" y="3" width="72" height="32" rx="10"></rect> | ||
<rect x="233" y="1" width="72" height="32" class="terminal" rx="10"></rect> | ||
<text class="terminal" x="243" y="21">STATUS</text> | ||
<path class="line" d="m17 17 h2 m0 0 h10 m64 0 h10 m0 0 h10 m100 0 h10 m0 0 h10 m72 0 h10 m3 0 h-3"></path> | ||
<polygon points="325 17 333 13 333 21"></polygon> | ||
<polygon points="325 17 317 13 317 21"></polygon></svg></div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A savepoint defined with the name `cockroach_restart` is a "retry savepoint" and is used to implement [advanced client-side transaction retries](advanced-client-side-transaction-retries.html). For more information, see [Retry savepoints](advanced-client-side-transaction-retries.html#retry-savepoints). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{site.data.alerts.callout_danger}} | ||
Rollbacks to savepoints over [DDL](https://en.wikipedia.org/wiki/Data_definition_language) statements are only supported if you're rolling back to a savepoint created at the beginning of the transaction. | ||
{{site.data.alerts.end}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CockroachDB supports exclusive row locks. | ||
|
||
- In PostgreSQL, row locks are released/cancelled upon [`ROLLBACK TO SAVEPOINT`][rts]. | ||
- In CockroachDB, row locks are preserved upon [`ROLLBACK TO SAVEPOINT`][rts]. | ||
|
||
This is an architectural difference in v20.1 that may or may not be lifted in a later CockroachDB version. | ||
|
||
The code of client applications that rely on row locks must be reviewed and possibly modified to account for this difference. In particular, if an application is relying on [`ROLLBACK TO SAVEPOINT`][rts] to release row locks and allow a concurrent transaction touching the same rows to proceed, this behavior will not work with CockroachDB. | ||
|
||
<!-- Reference Links --> | ||
|
||
[rts]: rollback-transaction.html |
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.