github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/logictest/testdata/logic_test/serializable_eager_restart (about) 1 # Demonstrates late restarting of a serializable transaction when its 2 # commit timestamp has moved forward. 3 # TODO(tschottdorf): implement eager restart for CLI. 4 5 statement ok 6 CREATE TABLE t (a INT) 7 8 statement ok 9 GRANT ALL on t TO testuser 10 11 statement ok 12 BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE 13 14 # Without client-directed retries, the serializability violation would be detected early. 15 statement ok 16 SAVEPOINT cockroach_restart 17 18 # The SELECT forces the timestamp to be chosen. 19 query I 20 SELECT * FROM t 21 ---- 22 23 user testuser 24 25 # A select alone would not be enough to cause a restart; we also write 26 # a key at a later timestamp than the transaction's, which will cause 27 # the transaction to retry at the clint level, after trying to update 28 # previously read spans. 29 statement ok 30 INSERT INTO t(a) VALUES (2) 31 32 # Touch all (relevant) keys with a timestamp ahead of the Transaction. This 33 # means that its future attempts to write will increase its timestamp. 34 query I 35 SELECT * FROM t 36 ---- 37 2 38 39 user root 40 41 # The insert increases the candidate timestamp, but a restart won't occur 42 # until an EndTxn. 43 statement ok 44 INSERT INTO t(a) VALUES (1) 45 46 # RELEASE will send an EndTxn which will result in a retriable error. 47 statement error pgcode 40001 retry txn.* 48 RELEASE SAVEPOINT cockroach_restart 49 50 #ROLLBACK TO SAVEPOINT 51 statement OK 52 ROLLBACK TO SAVEPOINT cockroach_restart 53 54 # Check that the connection is usable after the failed COMMIT. 55 query I 56 SELECT * FROM t 57 ---- 58 2