-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathmanual_retry
194 lines (150 loc) · 3.54 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
subtest automatic_retry
statement ok
CREATE SEQUENCE s
# On an implicit transaction, we retry automatically and the function
# eventually returns a result.
query I
SELECT IF(nextval('s')<3, crdb_internal.force_retry('1h':::INTERVAL), 0)
----
0
# Demonstrate that the txn was indeed retried.
query I
SELECT currval('s')
----
3
statement ok
DROP SEQUENCE s
subtest automatic_retry
statement ok
CREATE SEQUENCE s;
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: crdb_internal.force_retry\(\): TransactionRetryWithProtoRefreshError: forced by crdb_internal.force_retry\(\)
SELECT crdb_internal.force_retry('1h':::INTERVAL)
statement ok
ROLLBACK TO SAVEPOINT cockroach_restart
query I
SELECT IF(nextval('s')<3, crdb_internal.force_retry('1h':::INTERVAL), 0)
----
0
# Demonstrate that the txn was indeed retried.
query I
SELECT currval('s')
----
3
statement ok
COMMIT
# subtest savepoint_name
#
# statement ok
# BEGIN
#
# !!! rewrite this test somehow to assert the release behavior, not the initial status
# # Ensure that ident case rules are used.
# statement ok
# SAVEPOINT "COCKROACH_RESTART"
#
# query TB
# SHOW SAVEPOINT STATUS
# ----
# COCKROACH_RESTART false
#
# statement ok
# ROLLBACK; BEGIN
#
# # Ensure that ident case rules are used.
# statement ok
# SAVEPOINT COCKROACH_RESTART
#
# statement ok
# ROLLBACK
subtest schema_change_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 bar does not exist
ROLLBACK TO SAVEPOINT bar
# Verify we're doing the right thing for non-quoted idents.
statement ok
ROLLBACK TO SAVEPOINT FOO
statement ok
ABORT; BEGIN TRANSACTION
# Verify use of quoted idents.
statement ok
SAVEPOINT "Foo Bar"
statement error pq: savepoint foobar does not exist
ROLLBACK TO SAVEPOINT FooBar
# Verify case-sensitivity of quoted idents.
statement error pq: savepoint foo bar does not exist
ROLLBACK TO SAVEPOINT "foo bar"
statement ok
ROLLBACK TO SAVEPOINT "Foo Bar"
query TB
SHOW SAVEPOINT STATUS
----
Foo Bar true
statement ok
ABORT; BEGIN TRANSACTION
# Verify case-sensitivity of quoted vs. unquoted idents.
statement ok
SAVEPOINT "UpperCase"
statement error pq: savepoint uppercase does not exist
ROLLBACK TO SAVEPOINT UpperCase
query TB
SHOW SAVEPOINT STATUS
----
UpperCase true
statement ok
ABORT
statement ok
RESET force_savepoint_restart
query T
show session force_savepoint_restart
----
off