Skip to content

Commit 20fc849

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 for all orphan instances on the init stage of the queue. Closes #226
1 parent 5f2b145 commit 20fc849

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ local function cfg_call_wrapper(cfg, ...)
7373
return wrapper_impl(...)
7474
end
7575

76+
local function orphan_waiter()
77+
local fiber = require('fiber')
78+
local wait_for_orphan = fiber.new(function()
79+
while true do
80+
if box.info.status ~= 'orphan' then
81+
break
82+
end
83+
fiber.sleep(0.1)
84+
end
85+
end)
86+
wait_for_orphan:set_joinable(true)
87+
wait_for_orphan:join()
88+
end
89+
7690
local function wrap_box_cfg()
7791
if type(box.cfg) == 'function' then
7892
-- box.cfg before the first box.cfg call
@@ -97,6 +111,11 @@ function wrapper_impl(...)
97111
error(result[2])
98112
end
99113

114+
if box.info.ro_reason == 'orphan' then
115+
-- Wait for the orphan instance.
116+
orphan_waiter()
117+
end
118+
100119
if box.info.ro == false then
101120
local abstract = require 'queue.abstract'
102121
for name, val in pairs(abstract) do
@@ -121,6 +140,10 @@ end
121140
-- configured with read_only = false. Otherwise, a start is
122141
-- delayed until the instance will be configured with read_only = false.
123142
local function queue_init()
143+
if rawget(box, 'space') ~= nil and box.info.ro_reason == 'orphan' then
144+
-- Wait for the orphan instance.
145+
orphan_waiter()
146+
end
124147
if rawget(box, 'space') ~= nil and box.info.ro == false then
125148
-- The box was configured with read_only = false
126149
queue = require('queue.abstract')

0 commit comments

Comments
 (0)