github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/logictest/testdata/logic_test/poison_after_push (about)

     1  # This example session documents that a SERIALIZABLE transaction is
     2  # not immediately poisoned when it revisits a Range on which one of
     3  # its intents has had its timestamp pushed. This allows it to continue
     4  # laying down intents in a single pass, despite the possibility that it
     5  # will restart on commit. A SNAPSHOT transaction can always proceed and
     6  # commit with its new timestamp.
     7  #
     8  # Note that ORDER BY id is done on selects which expect more than a
     9  # single result, to account for the distsql config, which randomly
    10  # splits ranges. This can cause table scans to return tuples in any
    11  # arbitrary order.
    12  
    13  statement ok
    14  CREATE TABLE t (id INT PRIMARY KEY)
    15  
    16  statement ok
    17  INSERT INTO t VALUES (1)
    18  
    19  statement ok
    20  GRANT ALL ON t TO testuser
    21  
    22  statement ok
    23  BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE, PRIORITY LOW
    24  
    25  statement ok
    26  INSERT INTO t VALUES (2)
    27  
    28  # Switch users and push the above insert to a higher timestamp.
    29  user testuser
    30  
    31  statement ok
    32  BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE, PRIORITY HIGH
    33  
    34  # This pushes the intent.
    35  query I
    36  SELECT * FROM t
    37  ----
    38  1
    39  
    40  statement ok
    41  COMMIT
    42  
    43  # Switch back and observe that we can still read our data - the txn is still
    44  # operational and will continue to lay down its intents in the first pass.
    45  user root
    46  
    47  query I
    48  SELECT * FROM t ORDER BY id
    49  ----
    50  1
    51  2
    52  
    53  # On commit, there were no key spans that require updating, so the txn
    54  # coordinator should handle the retry automatically and succeed.
    55  statement ok
    56  COMMIT
    57  
    58  # The same type of session for a SNAPSHOT transaction shouldn't be poisoned.
    59  statement ok
    60  BEGIN TRANSACTION ISOLATION LEVEL SNAPSHOT, PRIORITY LOW
    61  
    62  statement ok
    63  INSERT INTO t VALUES (3)
    64  
    65  user testuser
    66  
    67  statement ok
    68  BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE, PRIORITY HIGH
    69  
    70  # This pushes the intent.
    71  query I
    72  SELECT * FROM t ORDER BY id
    73  ----
    74  1
    75  2
    76  
    77  statement ok
    78  COMMIT
    79  
    80  user root
    81  
    82  query I
    83  SELECT * FROM t ORDER BY id
    84  ----
    85  1
    86  2
    87  3
    88  
    89  statement ok
    90  COMMIT