Skip to content

Commit a82ec30

Browse files
cyrilloskyukhin
authored andcommitted
test: add replication/gh-4730-applier-rollback
Test that diag_raise doesn't happen if async transaction fails inside replication procedure. Side note: I don't like merging tests with patches in general and I hate doing so for big tests with a passion because it hides the patch code itself. So here is a separate patch on top of the fix. Test-of #4730 Acked-by: Serge Petrenko <sergepetrenko@tarantool.org> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
1 parent 73b9798 commit a82ec30

File tree

8 files changed

+251
-1
lines changed

8 files changed

+251
-1
lines changed

src/box/txn.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "journal.h"
3535
#include <fiber.h>
3636
#include "xrow.h"
37+
#include "errinj.h"
3738

3839
double too_long_threshold;
3940

@@ -576,6 +577,18 @@ txn_commit_async(struct txn *txn)
576577
{
577578
struct journal_entry *req;
578579

580+
ERROR_INJECT(ERRINJ_TXN_COMMIT_ASYNC, {
581+
diag_set(ClientError, ER_INJECTION,
582+
"txn commit async injection");
583+
/*
584+
* Log it for the testing sake: we grep
585+
* output to mark this event.
586+
*/
587+
diag_log();
588+
txn_rollback(txn);
589+
return -1;
590+
});
591+
579592
if (txn_prepare(txn) != 0) {
580593
txn_rollback(txn);
581594
return -1;

src/lib/core/errinj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct errinj {
139139
_(ERRINJ_FIBER_MPROTECT, ERRINJ_INT, {.iparam = -1}) \
140140
_(ERRINJ_RELAY_FASTER_THAN_TX, ERRINJ_BOOL, {.bparam = false}) \
141141
_(ERRINJ_INDEX_RESERVE, ERRINJ_BOOL, {.bparam = false})\
142+
_(ERRINJ_TXN_COMMIT_ASYNC, ERRINJ_BOOL, {.bparam = false})\
142143

143144
ENUM0(errinj_id, ERRINJ_LIST);
144145
extern struct errinj errinjs[];

test/box/errinj.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ evals
7676
- ERRINJ_TUPLE_ALLOC: false
7777
- ERRINJ_TUPLE_FIELD: false
7878
- ERRINJ_TUPLE_FORMAT_COUNT: -1
79+
- ERRINJ_TXN_COMMIT_ASYNC: false
7980
- ERRINJ_VYRUN_DATA_READ: false
8081
- ERRINJ_VY_COMPACTION_DELAY: false
8182
- ERRINJ_VY_DELAY_PK_LOOKUP: false
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
-- test-run result file version 2
2+
#!/usr/bin/env tarantool
3+
| ---
4+
| ...
5+
--
6+
-- vim: ts=4 sw=4 et
7+
--
8+
9+
test_run = require('test_run').new()
10+
| ---
11+
| ...
12+
13+
--
14+
-- Allow replica to connect to us
15+
box.schema.user.grant('guest', 'replication')
16+
| ---
17+
| ...
18+
19+
--
20+
-- Create replica instance, we're the master and
21+
-- start it, no data to sync yet though
22+
test_run:cmd("create server replica_slave with rpl_master=default, script='replication/replica-applier-rollback.lua'")
23+
| ---
24+
| - true
25+
| ...
26+
test_run:cmd("start server replica_slave")
27+
| ---
28+
| - true
29+
| ...
30+
31+
--
32+
-- Fill initial data on the master instance
33+
test_run:cmd('switch default')
34+
| ---
35+
| - true
36+
| ...
37+
38+
_ = box.schema.space.create('test')
39+
| ---
40+
| ...
41+
s = box.space.test
42+
| ---
43+
| ...
44+
45+
s:format({{name = 'id', type = 'unsigned'}, {name = 'band_name', type = 'string'}})
46+
| ---
47+
| ...
48+
49+
_ = s:create_index('primary', {type = 'tree', parts = {'id'}})
50+
| ---
51+
| ...
52+
s:insert({1, '1'})
53+
| ---
54+
| - [1, '1']
55+
| ...
56+
s:insert({2, '2'})
57+
| ---
58+
| - [2, '2']
59+
| ...
60+
s:insert({3, '3'})
61+
| ---
62+
| - [3, '3']
63+
| ...
64+
65+
--
66+
-- Wait for data from master get propagated
67+
test_run:wait_lsn('replica_slave', 'default')
68+
| ---
69+
| ...
70+
71+
--
72+
-- Now inject error into slave instance
73+
test_run:cmd('switch replica_slave')
74+
| ---
75+
| - true
76+
| ...
77+
78+
--
79+
-- To make sure we're running
80+
box.info.status
81+
| ---
82+
| - running
83+
| ...
84+
85+
--
86+
-- To fail inserting new record.
87+
errinj = box.error.injection
88+
| ---
89+
| ...
90+
errinj.set('ERRINJ_TXN_COMMIT_ASYNC', true)
91+
| ---
92+
| - ok
93+
| ...
94+
95+
--
96+
-- Jump back to master node and write new
97+
-- entry which should cause error to happen
98+
-- on slave instance
99+
test_run:cmd('switch default')
100+
| ---
101+
| - true
102+
| ...
103+
s:insert({4, '4'})
104+
| ---
105+
| - [4, '4']
106+
| ...
107+
108+
--
109+
-- Wait for error to trigger
110+
test_run:cmd('switch replica_slave')
111+
| ---
112+
| - true
113+
| ...
114+
fiber = require('fiber')
115+
| ---
116+
| ...
117+
while test_run:grep_log('replica_slave', 'ER_INJECTION:[^\n]*') == nil do fiber.sleep(0.1) end
118+
| ---
119+
| ...
120+
121+
----
122+
---- Such error cause the applier to be
123+
---- cancelled and reaped, thus stop the
124+
---- slave node and cleanup
125+
test_run:cmd('switch default')
126+
| ---
127+
| - true
128+
| ...
129+
130+
--
131+
-- Cleanup
132+
test_run:cmd("stop server replica_slave")
133+
| ---
134+
| - true
135+
| ...
136+
test_run:cmd("delete server replica_slave")
137+
| ---
138+
| - true
139+
| ...
140+
box.space.test:drop()
141+
| ---
142+
| ...
143+
box.schema.user.revoke('guest', 'replication')
144+
| ---
145+
| ...
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env tarantool
2+
--
3+
-- vim: ts=4 sw=4 et
4+
--
5+
6+
test_run = require('test_run').new()
7+
8+
--
9+
-- Allow replica to connect to us
10+
box.schema.user.grant('guest', 'replication')
11+
12+
--
13+
-- Create replica instance, we're the master and
14+
-- start it, no data to sync yet though
15+
test_run:cmd("create server replica_slave with rpl_master=default, script='replication/replica-applier-rollback.lua'")
16+
test_run:cmd("start server replica_slave")
17+
18+
--
19+
-- Fill initial data on the master instance
20+
test_run:cmd('switch default')
21+
22+
_ = box.schema.space.create('test')
23+
s = box.space.test
24+
25+
s:format({{name = 'id', type = 'unsigned'}, {name = 'band_name', type = 'string'}})
26+
27+
_ = s:create_index('primary', {type = 'tree', parts = {'id'}})
28+
s:insert({1, '1'})
29+
s:insert({2, '2'})
30+
s:insert({3, '3'})
31+
32+
--
33+
-- Wait for data from master get propagated
34+
test_run:wait_lsn('replica_slave', 'default')
35+
36+
--
37+
-- Now inject error into slave instance
38+
test_run:cmd('switch replica_slave')
39+
40+
--
41+
-- To make sure we're running
42+
box.info.status
43+
44+
--
45+
-- To fail inserting new record.
46+
errinj = box.error.injection
47+
errinj.set('ERRINJ_TXN_COMMIT_ASYNC', true)
48+
49+
--
50+
-- Jump back to master node and write new
51+
-- entry which should cause error to happen
52+
-- on slave instance
53+
test_run:cmd('switch default')
54+
s:insert({4, '4'})
55+
56+
--
57+
-- Wait for error to trigger
58+
test_run:cmd('switch replica_slave')
59+
fiber = require('fiber')
60+
while test_run:grep_log('replica_slave', 'ER_INJECTION:[^\n]*') == nil do fiber.sleep(0.1) end
61+
62+
----
63+
---- Such error cause the applier to be
64+
---- cancelled and reaped, thus stop the
65+
---- slave node and cleanup
66+
test_run:cmd('switch default')
67+
68+
--
69+
-- Cleanup
70+
test_run:cmd("stop server replica_slave")
71+
test_run:cmd("delete server replica_slave")
72+
box.space.test:drop()
73+
box.schema.user.revoke('guest', 'replication')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--
2+
-- vim: ts=4 sw=4 et
3+
--
4+
5+
print('arg', arg)
6+
7+
box.cfg({
8+
replication = os.getenv("MASTER"),
9+
listen = os.getenv("LISTEN"),
10+
memtx_memory = 107374182,
11+
replication_timeout = 0.1,
12+
replication_connect_timeout = 0.5,
13+
read_only = true,
14+
})
15+
16+
require('console').listen(os.getenv('ADMIN'))

test/replication/suite.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"gh-4605-empty-password.test.lua": {},
1717
"gh-4606-admin-creds.test.lua": {},
1818
"gh-4739-vclock-assert.test.lua": {},
19+
"gh-4730-applier-rollback.test.lua": {},
1920
"*": {
2021
"memtx": {"engine": "memtx"},
2122
"vinyl": {"engine": "vinyl"}

test/replication/suite.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ core = tarantool
33
script = master.lua
44
description = tarantool/box, replication
55
disabled = consistent.test.lua
6-
release_disabled = catch.test.lua errinj.test.lua gc.test.lua gc_no_space.test.lua before_replace.test.lua quorum.test.lua recover_missing_xlog.test.lua sync.test.lua long_row_timeout.test.lua gh-4739-vclock-assert.test.lua
6+
release_disabled = catch.test.lua errinj.test.lua gc.test.lua gc_no_space.test.lua before_replace.test.lua quorum.test.lua recover_missing_xlog.test.lua sync.test.lua long_row_timeout.test.lua gh-4739-vclock-assert.test.lua gh-4730-applier-rollback.test.lua
77
config = suite.cfg
88
lua_libs = lua/fast_replica.lua lua/rlimit.lua
99
use_unix_sockets = True

0 commit comments

Comments
 (0)