Skip to content

Commit 886f363

Browse files
oleg-jukovecLeonidVas
authored andcommitted
abstract: fix switch in_replicaset value
Execution of non-yielding DDL statements in transactions has been allowed only since Tarantool 2.2.1 [1]. We should avoid using DDL statements in transactions for older versions. 1. tarantool/tarantool@f266559 Closes #185
1 parent d3ec7c1 commit 886f363

File tree

4 files changed

+75
-18
lines changed

4 files changed

+75
-18
lines changed

queue/abstract.lua

+16-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ local qc = require('queue.compat')
1111
local num_type = qc.num_type
1212
local str_type = qc.str_type
1313

14+
-- since:
15+
-- https://github.com/tarantool/tarantool/commit/f266559b167b4643c377724eebde9651877d6cc9
16+
local ddl_txn_supported = qc.check_version({2, 2, 1})
17+
1418
-- The term "queue session" has been added to the queue. One "queue session"
1519
-- can include many connections (box.session). For clarity, the box.session
1620
-- will be referred to as connection below.
@@ -668,13 +672,23 @@ local function switch_in_replicaset(replicaset_mode)
668672
box.space._queue_taken_2_mgr:insert(tuple)
669673
end
670674

671-
box.space._queue_taken_2:drop()
672-
box.space._queue_taken_2_mgr:rename('_queue_taken_2')
675+
if ddl_txn_supported then
676+
-- We can do it inside a transaction.
677+
box.space._queue_taken_2:drop()
678+
box.space._queue_taken_2_mgr:rename('_queue_taken_2')
679+
end
673680

674681
local status, err = pcall(box.commit)
675682
if not status then
676683
error(('Error migrate _queue_taken_2: %s'):format(tostring(err)))
677684
end
685+
686+
if not ddl_txn_supported then
687+
-- Do it outside a transaction becase DDL does not support
688+
-- multi-statement transactions.
689+
box.space._queue_taken_2:drop()
690+
box.space._queue_taken_2_mgr:rename('_queue_taken_2')
691+
end
678692
end
679693

680694
-- create or join infrastructure

queue/abstract/queue_session.lua

+15-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ local qc = require('queue.compat')
77
local num_type = qc.num_type
88
local str_type = qc.str_type
99

10+
-- since:
11+
-- https://github.com/tarantool/tarantool/commit/f266559b167b4643c377724eebde9651877d6cc9
12+
local ddl_txn_supported = qc.check_version({2, 2, 1})
1013

1114
local queue_session = {}
1215

@@ -62,13 +65,23 @@ local function switch_in_replicaset(replicaset_mode)
6265
box.space._queue_shared_sessions_mgr:insert(tuple)
6366
end
6467

65-
box.space._queue_shared_sessions:drop()
66-
box.space._queue_shared_sessions_mgr:rename('_queue_shared_sessions')
68+
if ddl_txn_supported then
69+
-- We can do it inside a transaction.
70+
box.space._queue_shared_sessions:drop()
71+
box.space._queue_shared_sessions_mgr:rename('_queue_shared_sessions')
72+
end
6773

6874
local status, err = pcall(box.commit)
6975
if not status then
7076
error(('Error migrate _queue_shared_sessions: %s'):format(tostring(err)))
7177
end
78+
79+
if not ddl_txn_supported then
80+
-- Do it outside a transaction becase DDL does not support
81+
-- multi-statement transactions.
82+
box.space._queue_shared_sessions:drop()
83+
box.space._queue_shared_sessions_mgr:rename('_queue_shared_sessions')
84+
end
7285
end
7386

7487
--- Create everything that's needed to work with "shared" sessions.

t/200-master-replica.t

+1-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
-- Replica connection handler.
2222
local conn = {}
2323

24-
test:plan(8)
24+
test:plan(7)
2525

2626
test:test('Check master-replica setup', function(test)
2727
test:plan(8)
@@ -46,19 +46,6 @@ test:test('Check master-replica setup', function(test)
4646
test:ok(tube, 'test tube created')
4747
end)
4848

49-
test:test('Check error create temporary tube', function(test)
50-
test:plan(2)
51-
local engine = os.getenv('ENGINE') or 'memtx'
52-
53-
queue.cfg{ttr = 0.5, in_replicaset = true}
54-
local opts = {temporary = true, engine = engine}
55-
local status, err = pcall(queue.create_tube, 'test', 'fifo', opts)
56-
test:is(status, false, 'test tube should not be created')
57-
local founded = string.find(err,
58-
'Cannot create temporary tube in replicaset mode')
59-
test:ok(founded, 'unexpected error')
60-
end)
61-
6249
test:test('Check queue state switching', function(test)
6350
test:plan(4)
6451
box.cfg{read_only = true}

t/210-cfg-in-replicaset.t

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env tarantool
2+
3+
local test = require('tap').test('')
4+
local queue = require('queue')
5+
6+
rawset(_G, 'queue', require('queue'))
7+
8+
test:plan(2)
9+
10+
test:test('Check in_replicaset switches', function(test)
11+
test:plan(4)
12+
local engine = os.getenv('ENGINE') or 'memtx'
13+
14+
box.cfg({})
15+
16+
local status, err = pcall(queue.cfg, {in_replicaset = true})
17+
test:ok(status, 'in_replicaset = true switched')
18+
local status, _ = pcall(queue.cfg, {in_replicaset = false})
19+
test:ok(status, 'in_replicaset = false switched')
20+
local status, _ = pcall(queue.cfg, {in_replicaset = true})
21+
test:ok(status, 'in_replicaset = true switched')
22+
local status, _ = pcall(queue.cfg, {in_replicaset = false})
23+
test:ok(status, 'in_replicaset = false switched')
24+
end)
25+
26+
test:test('Check error create temporary tube', function(test)
27+
test:plan(2)
28+
local engine = os.getenv('ENGINE') or 'memtx'
29+
30+
box.cfg({})
31+
32+
queue.cfg{ttr = 0.5, in_replicaset = true}
33+
local opts = {temporary = true, engine = engine}
34+
local status, err = pcall(queue.create_tube, 'test', 'fifo', opts)
35+
test:is(status, false, 'test tube should not be created')
36+
local founded = string.find(err,
37+
'Cannot create temporary tube in replicaset mode')
38+
test:ok(founded, 'unexpected error')
39+
end)
40+
41+
rawset(_G, 'queue', nil)
42+
os.exit(test:check() and 0 or 1)
43+
-- vim: set ft=lua :

0 commit comments

Comments
 (0)