V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JasonLaw
V2EX  ›  数据库

为什么 Redlock 算法说“It tries to acquire the lock in all the N instances sequentially”

  •  
  •   JasonLaw · 48 天前 · 365 次点击
    这是一个创建于 48 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Distributed locks with Redis – Redis - The Redlock algorithm中,它说

    It tries to acquire the lock in all the N instances sequentially, using the same key name and random value in all the instances. During step 2, when setting the lock in each instance, the client uses a timeout which is small compared to the total lock auto-release time in order to acquire it. For example if the auto-release time is 10 seconds, the timeout could be in the ~ 5-50 milliseconds range. This prevents the client from remaining blocked for a long time trying to talk with a Redis node which is down: if an instance is not available, we should try to talk with the next instance ASAP.

    sequentially 是什么含义?为什么要 sequentially 呢?

    然后在Distributed locks with Redis – Redis - Retry on failure中,它又说

    When a client is unable to acquire the lock, it should try again after a random delay in order to try to desynchronize multiple clients trying to acquire the lock for the same resource at the same time (this may result in a split brain condition where nobody wins). Also the faster a client tries to acquire the lock in the majority of Redis instances, the smaller the window for a split brain condition (and the need for a retry), so ideally the client should try to send the SET commands to the N instances at the same time using multiplexing.

    这不是互相矛盾吗?还是我哪里理解错了?

    1 条回复    2021-10-22 18:08:25 +08:00
    lance6716
        1
    lance6716  
       47 天前 via iPhone
    一上来并发请求锁,在并发高的时候冲突会很大吧。重试的时候由于随机 delay 冲突就变小了
    关于   ·   帮助文档   ·   API   ·   FAQ   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   3487 人在线   最高记录 5497   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 18ms · UTC 01:24 · PVG 09:24 · LAX 17:24 · JFK 20:24
    ♥ Do have faith in what you're doing.