I need to catch changing box.info.status from "loading" to "ready". So i can enable my triggers after WAL read, but before replication sync.
My trigger function on box.space.myspace
:
local function before_replace(old, new)
-- collision resolving here
if box.session.type() ~= 'applier' then
box.space.stat:upsert(
{ "key", 0 },
{
{"+", stat.COUNT, 1}
})
end
return
end
- If i set trigger on schema initialization, it fails with read_only
error. While trying to upsert read_only
stat
space. - If i set it on
box.info.ro == False
it skips replication_sync.
I found that most suitable time to set up trigger is a moment then box.info.status
changed from loading
to running
. I solve my problem like this. But i'm wonder if where is a better way?
I thought about setting callback function on box.info.status
field changed. How can i achieve this?