Skip to content

Commit 6bc1d63

Browse files
0x501DLeonidVas
authored andcommitted
replicaset_mode: allow api call in init state
In replicaset mode, the user can attempt to call public methods on the replica start. For example, a single script is used for master and replica. This patch allows you to call a public method in the INIT state without interrupting the script by exiting with an obscure error. It will only log an attempt to call a method from the check_state function, which is present at the beginning of each public method. Closes #216
1 parent c3cdc7b commit 6bc1d63

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
- In replicaset mode, the behavior of the public API is reduced to the same behavior
11+
in all queue states, including INIT. Previously, in the INIT state, an ambiguous
12+
error was thrown when trying to access a public method on a replica and the script
13+
was interrupted by an error.
14+
15+
Old behavior (call `create_tube` on replica, queue is in INIT state):
16+
```
17+
2023-09-04 14:01:11.000 [5990] main/103/replica.lua/box.load_cfg I> set 'read_only' configuration option to true
18+
stack traceback:
19+
/home/void/tmp/cluster/repl/queue/init.lua:44: in function '__index'
20+
replica.lua:13: in main chunk
21+
2023-09-04 14:01:11.004 [5990] main/105/checkpoint_daemon I> scheduled next checkpoint for Mon Sep 4 15:11:32 2023
22+
2023-09-04 14:01:11.004 [5990] main utils.c:610 E> LuajitError: /home/void/tmp/cluster/repl/queue/init.lua:45: Please configure box.cfg{} in read/write mode first
23+
```
24+
After this fix:
25+
```
26+
2023-09-11 10:24:31.463 [19773] main/103/replica.lua abstract.lua:93 E> create_tube: queue is in INIT state
27+
```
28+
829
## [1.3.2] - 2023-08-24
930

1031
### Fixed

queue/init.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local abstract = require('queue.abstract')
12
local queue_state = require('queue.abstract.queue_state')
23
local queue = nil
34

@@ -40,9 +41,18 @@ queue = setmetatable({
4041
state = queue_state.show,
4142
cfg = deferred_cfg,
4243
_VERSION = require('queue.version'),
43-
}, { __index = function()
44-
print(debug.traceback())
45-
error('Please configure box.cfg{} in read/write mode first')
44+
}, { __index = function(self, key)
45+
-- In replicaset mode, the user can attempt to call public methods on the replica start.
46+
-- For example, a single script is used for master and replica.
47+
-- Each public method has a check on the state of the queue, so this forwarding is safe.
48+
if deferred_opts['in_replicaset'] == true then
49+
if abstract[key] ~= nil then
50+
return abstract[key]
51+
end
52+
else
53+
print(debug.traceback())
54+
error('Please configure box.cfg{} in read/write mode first')
55+
end
4656
end
4757
})
4858

t/200-master-replica.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ local conn = {}
2424
test:plan(8)
2525

2626
test:test('Check master-replica setup', function(test)
27-
test:plan(8)
27+
test:plan(9)
2828
local engine = os.getenv('ENGINE') or 'memtx'
2929
tnt.cluster.cfg{}
3030

@@ -41,6 +41,8 @@ test:test('Check master-replica setup', function(test)
4141

4242
-- Setup tube. Set ttr = 0.5 for sessions expire testing.
4343
conn:call('queue.cfg', {{ttr = 0.5, in_replicaset = true}})
44+
test:isnil(conn:call('queue.create_tube', {'test', 'fifo'}),
45+
'check api call in INIT state')
4446
queue.cfg{ttr = 0.5, in_replicaset = true}
4547
local tube = queue.create_tube('test', 'fifo', {engine = engine})
4648
test:ok(tube, 'test tube created')

0 commit comments

Comments
 (0)