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

2021-10-21 12:36:03 +08:00
 JasonLaw

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.

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

869 次点击
所在节点    数据库
3 条回复
lance6716
2021-10-22 18:08:25 +08:00
一上来并发请求锁,在并发高的时候冲突会很大吧。重试的时候由于随机 delay 冲突就变小了
yibo2018
2022-03-23 17:39:32 +08:00
最近也在看,也不知道是不是英文,所以争议才会这么大。我也提供一个佐证楼主的证据
https://redis.io/topics/distlock#:~:text=In%20order%20to%20meet,each%20instance%20is%20similar).

In order to meet this requirement, the strategy to talk with the N Redis servers to reduce latency is definitely multiplexing (or poor man's multiplexing, which is, putting the socket in non-blocking mode, send all the commands, and read all the commands later, assuming that the RTT between the client and each instance is similar).

这里的 multiplexing 是不是也是同时发送的意思?而不是依次
JasonLaw
2022-03-23 18:26:37 +08:00
@yibo2018 #2 我也是这么理解的🤐

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/809481

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX