Skip to content

Commit 62e9416

Browse files
committed
api: fix INIT state stuck
Sometimes, instance could enter the queue initialization while still in the orphan mode. This resulted in "lazy start". But tarantool does not call `box.cfg {}` after leaving orphan mode, so queue was stuck in the `INIT` state. Now we wait in the background for all orphan instances. It is simular to lazy init for read-only instances. Closes #226
1 parent 5f2b145 commit 62e9416

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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+
### Fixed
11+
12+
- Stuck in `INIT` state if instance failed to leave `orphan` mode in time (#226).
13+
814
## [1.3.3] - 2023-09-13
915

1016
### Fixed

queue/init.lua

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local fiber = require('fiber')
2+
13
local abstract = require('queue.abstract')
24
local queue_state = require('queue.abstract.queue_state')
35
local queue = nil
@@ -62,6 +64,19 @@ local orig_call = nil
6264

6365
local wrapper_impl
6466

67+
local function orphan_waiter()
68+
local wait_cond = fiber.cond()
69+
local w = box.watch('box.status', function(_, new_status)
70+
fiber.yield()
71+
if new_status.status ~= 'orphan' then
72+
wait_cond:signal()
73+
end
74+
end)
75+
wait_cond:wait()
76+
w:unregister()
77+
return wrapper_impl()
78+
end
79+
6580
local function cfg_wrapper(...)
6681
box.cfg = orig_cfg
6782
return wrapper_impl(...)
@@ -79,10 +94,15 @@ local function wrap_box_cfg()
7994
orig_cfg = box.cfg
8095
box.cfg = cfg_wrapper
8196
elseif type(box.cfg) == 'table' then
82-
-- box.cfg after the first box.cfg call
83-
local cfg_mt = getmetatable(box.cfg)
84-
orig_call = cfg_mt.__call
85-
cfg_mt.__call = cfg_call_wrapper
97+
if box.info.ro_reason == 'orphan' then
98+
-- Wait for the orphan instance.
99+
fiber.new(orphan_waiter)
100+
else
101+
-- box.cfg after the first box.cfg call
102+
local cfg_mt = getmetatable(box.cfg)
103+
orig_call = cfg_mt.__call
104+
cfg_mt.__call = cfg_call_wrapper
105+
end
86106
else
87107
error('The box.cfg type is unexpected: ' .. type(box.cfg))
88108
end

0 commit comments

Comments
 (0)