/
manual_retry
146 lines (107 loc) · 2.97 KB
/
manual_retry
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# LogicTest: local local-opt local-parallel-stmts fakedist fakedist-opt fakedist-metadata
subtest automatic_retry
# On an implicit transaction, we retry automatically and the function
# eventually returns a result.
query I
SELECT crdb_internal.force_retry('50ms':::INTERVAL)
----
0
subtest automatic_retry
statement ok
BEGIN TRANSACTION; SAVEPOINT cockroach_restart
# The SELECT 1 is necessary to take the session out of the AutoRetry state,
# otherwise the statement below would be retries automatically.
statement ok
SELECT 1
query error restart transaction: HandledRetryableTxnError: forced by crdb_internal.force_retry()
SELECT crdb_internal.force_retry('500ms':::INTERVAL)
statement ok
ROLLBACK TO SAVEPOINT cockroach_restart
# wait until the transaction is at least 1 second
sleep 1s
# Ensure that ident case rules are used.
statement error pq: unimplemented: SAVEPOINT not supported except for cockroach_restart
SAVEPOINT "COCKROACH_RESTART"
# Ensure that ident case rules are used.
statement ok
SAVEPOINT COCKROACH_RESTART
query I
SELECT crdb_internal.force_retry('500ms':::INTERVAL)
----
0
statement ok
COMMIT
subtest schema_chage_with_rollback
# Test that creating a table repeatedly across restarts doesn't leave dangling
# rows behind (the rows are associated with the correct descriptor).
# See #24785.
statement ok
BEGIN
statement ok
SAVEPOINT cockroach_restart
statement ok
CREATE TABLE t (
id INT PRIMARY KEY
)
statement ok
ROLLBACK TO SAVEPOINT cockroach_restart
# The following CREATE shouldn't be necessary. This test would like to just run
# the next insert (or a select) and check that it fails to resolve the table
# name. However, that doesn't currently work because of #24885.
statement ok
CREATE TABLE t (
id INT PRIMARY KEY
)
statement ok
INSERT INTO t (id) VALUES (1);
statement ok
COMMIT
query I
SELECT id FROM t
----
1
subtest rename_savepoint
query T
show session force_savepoint_restart
----
off
statement ok
SET force_savepoint_restart = true
query T
show session force_savepoint_restart
----
on
# We can now use anything that we want.
statement ok
BEGIN TRANSACTION; SAVEPOINT something_else; COMMIT
# Ensure that we can't mix-and-match names.
statement ok
BEGIN TRANSACTION; SAVEPOINT foo
statement error pq: SAVEPOINT "foo" is in use
ROLLBACK TO SAVEPOINT bar
# Verify we're doing the right thing for non-quoted idents.
statement ok
ROLLBACK TO SAVEPOINT FOO
# Verify use of quoted idents.
statement ok
SAVEPOINT "Foo Bar"
statement error pq: SAVEPOINT "Foo Bar" is in use
ROLLBACK TO SAVEPOINT FooBar
# Verify case-sensitivity of quoted idents.
statement error pq: SAVEPOINT "Foo Bar" is in use
ROLLBACK TO SAVEPOINT "foo bar"
statement ok
ROLLBACK TO SAVEPOINT "Foo Bar"
# Verify case-sensitivity of quoted vs. unquoted idents.
statement ok
SAVEPOINT "UpperCase"
statement error pq: SAVEPOINT "UpperCase" is in use
ROLLBACK TO SAVEPOINT UpperCase
statement ok
ABORT
statement ok
RESET force_savepoint_restart
query T
show session force_savepoint_restart
----
off