2

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?

Vasil
  • 45
  • 5

2 Answers2

1

You're doing it wrong. There is box.ctl.wait_ro() if you want to wait until an instance leaves the read-only mode. If you want to wait bootstrap end, put your code right after box.cfg. Finally, if you want to catch the event of schema initialization, you set box.ctl.on_schema_init trigger. Please describe what exactly you are trying to accomplish and there will be an appropriate instrument for it.

Kostja
  • 1,607
  • 10
  • 17
0

The simplest hack I can think of is spawning a fiber that periodically checks for changes and runs the call back when it detects them.

DarkWiiPlayer
  • 6,871
  • 3
  • 23
  • 38