Tarantool中的冲突解决(在发生冲突时如何在主-主模式下修复复制) [英] Conflict resolution in Tarantool (how to fix replication in master-master mode in case of conflicts)

查看:80
本文介绍了Tarantool中的冲突解决(在发生冲突时如何在主-主模式下修复复制)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多主场景中使用Tarantool时如何解决冲突?

How can I implement resolution of conflicts when I use Tarantool in multi master scenario?

我正在开发一项服务,该服务应具有很高的可用性,因此决定将nginx用作tarantool的两个节点(禁用了只读选项)的负载平衡器(带有备份指令).它会重试对其他节点的失败请求,但是如果出现网络问题(例如,tarantool的节点之间),则可能会发生冲突.

I'm developing a service which should be highly available, so decided to use nginx as a load balancer (with backup directive) for two nodes of tarantool (with disabled read only option). It retries failed requests to other node, but in case of network issues (for instance, between nodes of tarantool) conflicts may occur.

如何实现以下方案之一:

How can I implement one of the following scenarios:

  1. 在每个节点上选择一个新的元组
  2. 自定义逻辑(可能是冲突的另一个空间,等等)

另一个问题是如何定义唯一的可为空的复合索引(null是可以多次出现的值)

Another question is how can I define unique nullable compound index (null is a value which can occur multiple times)

| id | user_id | type | {some data} |

索引:

id - PK
user_id + type - unique nullable tree index (type is nullable)
user_id has non unique tree index

推荐答案

关于Kostja答案的第二点(on_ctl_init + _space:on_replace的组合),还有另外一招:您需要使用box.on_commit来获取进入正在创建的空间.结果片段如下:

Regarding second point from Kostja's answer (combination of on_ctl_init+_space:on_replace), there is one more trick: you'll need to utilize box.on_commit to get acces to the space being created. Resulting snippet would be the following:

local my_space_name = 'ny_space'
local my_trigger = function(old, new) ... end
box.schema.on_schema_init(function()
    box.space._space:on_replace(function(_, new_space)
        if new_space.name == my_space_name then
            box.on_commit(function()
                box.space[my_space_name]:before_replace(my_trigger)
            end
        end
    end)
end)

这篇关于Tarantool中的冲突解决(在发生冲突时如何在主-主模式下修复复制)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆