2

我需要将 box.info.status 从“正在加载”更改为“准备就绪”。所以我可以在 WAL 读取之后,但在复制同步之前启用我的触发器。

我的触发功能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
  • 如果我在架构初始化时设置触发器,它会因 read_only 错误而失败。在尝试 upsert read_onlystat空间时。
  • 如果我将其设置为它box.info.ro == False会跳过replication_sync。

我发现最适合设置触发器的时间是片刻,然后box.info.status从 更改loadingrunning。我这样解决我的问题。但我想知道是否有更好的方法?

我想过在box.info.status字段更改时设置回调函数。我怎样才能做到这一点?

4

2 回答 2

1

你这样做是错的。box.ctl.wait_ro() 如果您想等到实例离开只读模式,可以使用 box.ctl.wait_ro()。如果您想等待引导程序结束,请将您的代码放在 box.cfg 之后。最后,如果要捕获模式初始化的事件,则设置 box.ctl.on_schema_init 触发器。请描述你究竟想要完成什么,并且会有一个合适的工具来完成它。

于 2019-08-07T15:06:14.617 回答
0

我能想到的最简单的破解方法是生成一个纤程,它会定期检查更改并在检测到更改时运行回调。

于 2019-08-07T14:53:02.857 回答