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

     1  subtest automatic_retry
     2  
     3  statement ok
     4  CREATE SEQUENCE s
     5  
     6  # On an implicit transaction, we retry automatically and the function
     7  # eventually returns a result.
     8  query I
     9  SELECT IF(nextval('s')<3, crdb_internal.force_retry('1h':::INTERVAL), 0)
    10  ----
    11  0
    12  
    13  # Demonstrate that the txn was indeed retried.
    14  query I
    15  SELECT currval('s')
    16  ----
    17  3
    18  
    19  statement ok
    20  DROP SEQUENCE s
    21  
    22  subtest automatic_retry
    23  
    24  statement ok
    25  CREATE SEQUENCE s;
    26    BEGIN TRANSACTION;
    27    SAVEPOINT cockroach_restart
    28  
    29  # The SELECT 1 is necessary to take the session out of the AutoRetry state,
    30  # otherwise the statement below would be retries automatically.
    31  statement ok
    32  SELECT 1
    33  
    34  query error restart transaction: crdb_internal.force_retry\(\): TransactionRetryWithProtoRefreshError: forced by crdb_internal.force_retry\(\)
    35  SELECT crdb_internal.force_retry('1h':::INTERVAL)
    36  
    37  statement ok
    38  ROLLBACK TO SAVEPOINT cockroach_restart
    39  
    40  query I
    41  SELECT IF(nextval('s')<3, crdb_internal.force_retry('1h':::INTERVAL), 0)
    42  ----
    43  0
    44  
    45  # Demonstrate that the txn was indeed retried.
    46  query I
    47  SELECT currval('s')
    48  ----
    49  3
    50  
    51  statement ok
    52  COMMIT
    53  
    54  # subtest savepoint_name
    55  
    56  # Check that releasing the special cockroach_restart savepoint moves us to CommitWait.
    57  
    58  statement ok
    59  BEGIN
    60  
    61  statement ok
    62  SAVEPOINT cockroach_restart
    63  
    64  query T
    65  SHOW TRANSACTION STATUS
    66  ----
    67  Open
    68  
    69  statement ok
    70  RELEASE SAVEPOINT cockroach_restart
    71  
    72  query T
    73  SHOW TRANSACTION STATUS
    74  ----
    75  CommitWait
    76  
    77  statement ok
    78  ROLLBACK
    79  
    80  # Ensure that ident case rules are used.
    81  statement ok
    82  BEGIN
    83  
    84  statement ok
    85  SAVEPOINT "COCKROACH_RESTART"
    86  
    87  query T
    88  SHOW TRANSACTION STATUS
    89  ----
    90  Open
    91  
    92  statement ok
    93  RELEASE SAVEPOINT "COCKROACH_RESTART"
    94  
    95  query T
    96  SHOW TRANSACTION STATUS
    97  ----
    98  Open
    99  
   100  statement ok
   101  ROLLBACK
   102  
   103  subtest schema_change_with_rollback
   104  
   105  # Test that creating a table repeatedly across restarts doesn't leave dangling
   106  # rows behind (the rows are  associated with the correct descriptor).
   107  # See #24785.
   108  
   109  statement ok
   110  BEGIN
   111  
   112  statement ok
   113  SAVEPOINT cockroach_restart
   114  
   115  statement ok
   116  CREATE TABLE t (
   117  id INT PRIMARY KEY
   118  )
   119  
   120  statement ok
   121  ROLLBACK TO SAVEPOINT cockroach_restart
   122  
   123  # The following CREATE shouldn't be necessary. This test would like to just run
   124  # the next insert (or a select) and check that it fails to resolve the table
   125  # name. However, that doesn't currently work because of #24885.
   126  statement ok
   127  CREATE TABLE t (
   128  id INT PRIMARY KEY
   129  )
   130  
   131  statement ok
   132  INSERT INTO t (id) VALUES (1);
   133  
   134  statement ok
   135  COMMIT
   136  
   137  query I
   138  SELECT id FROM t
   139  ----
   140  1
   141  
   142  subtest rename_savepoint
   143  
   144  query T
   145  show session force_savepoint_restart
   146  ----
   147  off
   148  
   149  statement ok
   150  SET force_savepoint_restart = true
   151  
   152  query T
   153  show session force_savepoint_restart
   154  ----
   155  on
   156  
   157  # We can now use anything that we want.
   158  statement ok
   159  BEGIN TRANSACTION; SAVEPOINT something_else; COMMIT
   160  
   161  # Ensure that we can't mix-and-match names.
   162  statement ok
   163  BEGIN TRANSACTION; SAVEPOINT foo
   164  
   165  statement error pq: savepoint "bar" does not exist
   166  ROLLBACK TO SAVEPOINT bar
   167  
   168  # Verify we're doing the right thing for non-quoted idents.
   169  statement ok
   170  ROLLBACK TO SAVEPOINT FOO
   171  
   172  statement ok
   173  ABORT; BEGIN TRANSACTION
   174  
   175  # Verify use of quoted idents.
   176  statement ok
   177  SAVEPOINT "Foo Bar"
   178  
   179  statement error pq: savepoint "foobar" does not exist
   180  ROLLBACK TO SAVEPOINT FooBar
   181  
   182  # Verify case-sensitivity of quoted idents.
   183  statement error pq: savepoint "foo bar" does not exist
   184  ROLLBACK TO SAVEPOINT "foo bar"
   185  
   186  statement ok
   187  ROLLBACK TO SAVEPOINT "Foo Bar"
   188  
   189  query TB colnames
   190  SHOW SAVEPOINT STATUS
   191  ----
   192  savepoint_name is_initial_savepoint
   193  Foo Bar  true
   194  
   195  statement ok
   196  ABORT; BEGIN TRANSACTION
   197  
   198  # Verify case-sensitivity of quoted vs. unquoted idents.
   199  statement ok
   200  SAVEPOINT "UpperCase"
   201  
   202  statement error pq: savepoint "uppercase" does not exist
   203  ROLLBACK TO SAVEPOINT UpperCase
   204  
   205  query TB colnames
   206  SHOW SAVEPOINT STATUS
   207  ----
   208  savepoint_name is_initial_savepoint
   209  UpperCase  true
   210  
   211  statement ok
   212  ABORT
   213  
   214  statement ok
   215  RESET force_savepoint_restart
   216  
   217  query T
   218  show session force_savepoint_restart
   219  ----
   220  off