# LogicTest: default parallel-stmts distsql

# Demonstrates late restarting of a serializable transaction when its
# commit timestamp has moved forward.
# TODO(tschottdorf): implement eager restart for CLI.

statement ok
CREATE TABLE t (a INT)

statement ok
GRANT ALL on t TO testuser

statement ok
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE

# The SELECT forces the timestamp to be chosen.
query I
SELECT * FROM t
----

user testuser

# Touch all (relevant) keys with a timestamp ahead of the Transaction. This
# means that its future attempts to write increase its timestamp.
query I
SELECT * FROM t
----

user root

# The insert increases the candidate timestamp, but a restart won't occur
# until an EndTransaction.
statement ok
INSERT INTO t(a) VALUES (1)

# Commit will send an EndTransaction which will result in a retry error.
statement error pgcode 40001 retry txn.*
COMMIT

# Check that the connection is usable after the failed COMMIT.
query I
SELECT * FROM t
----
