apache-zookeeper - Chubby Sequencer 的目的是什么

标签 apache-zookeeper distributed-system consensus paxos

阅读时article from google about chubby ,我并没有真正理解sequencer的用途

假设我们有 4 个实体:

  1. 胖乎乎的细胞
  2. 客户 1
  3. 客户 2
  4. 我们想要使用的服务以及我们将请求发送到哪里(我们需要锁)

据我了解,步骤是:

enter image description here

  1. Client 1 发送 lock_request()Chubby cell,Chubby 使用 Sequencer 响应(假设序列号 = 1)

  2. 客户端 1 向服务发送带有 Sequencer (SequenceNumber = 1) 的请求 modify_data()

  3. Service 询问 Chubby cell SequenceNumber 是否有效 (=1)
  4. Chubby 承认它,设置 LeasePeriod(锁定到期时间为(假设)60 秒) !在此期间没有人能够获得锁
  5. 确认后,服务缓存有关客户端 1 (SequenceNumber = 1) 的数据(假设)40 秒

现在: 如果 Client 2 在我们设置的这 60 秒内尝试获取锁,它将被 Chubby cell

拒绝

这意味着 Client 2 不可能在下一个 SequenceNumber = 2 时获取锁并向 Service

发送任何内容

据我了解,SequenceNumber 的所有目的仅适用于当 2 个请求到达 Service 并且 Service 可以只比较 2 个 SequenceNumbers 并拒绝较低的情况,而不需要问Chubby细胞

但是如果我们有缓存并且不可能由 Client 2 获得锁而 Client 1 持有此锁,这种情况会如何发生?

最佳答案

用实际时间(如秒)来考虑分布式系统的计时是错误的,但我会尝试使用相同的语义来回答。

如您所说,假设 client1 获取名为 foo1 的写锁, 这里的 foo 是锁名,1 是世代号。

现在假设,租期为 60 秒。第 58 秒现在 Client1 发送了一个写,比如 R1。

很快,Client1 就死了。

现在,问题来了。您在分析中假设 R1 将达到 服务器在 2 秒内,在另一个客户端之前,说 Client2 成为主服务器。

这还不确定。

在分布式系统中,一方面有几分之一毫秒的网络延迟,另一方面有网络分区, 你只是无法确定什么先到达主人,R1 或客户 2 请求成为主人。

这是序列号有用的地方。

Master,现在知道有 foo2,可以拒绝元数据中 foo1 附带的 R1。

阅读有关世代时钟/逻辑时钟的更多信息 here .

A logical clock is a mechanism for capturing chronological and causal relationships in a distributed system. Often, distributed systems may have no physically synchronous global clock. Fortunately, in many applications (such as distributed GNU make), if two processes never interact, the lack of synchronization is unobservable. Moreover, in these applications, it suffices for the processes to agree on the event ordering (i.e., logical clock) rather than the wall-clock time.[1]

关于apache-zookeeper - Chubby Sequencer 的目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58891266/

相关文章:

java - 使用 Java 套接字的基本分布式计数器

hadoop - 使用hbase中已有的zookeeper

java - 卡夫卡 : could not find or load main class installation Windows

apache-zookeeper - 共识服务与锁定服务?

networking - 为什么 Docker 覆盖网络需要共识?

algorithm - 如果有多个领导者,Raft 算法如何保证共识?

algorithm - 为什么使用空操作来填补 paxos 事件之间的空白是合法的?

java - 在 Spring Boot 中排除 BootstrapConfiguration 类进行测试

apache-zookeeper - 如何以编程方式检测集成客户端中连接到的服务器?

javascript - 不同语言生成的simpleflake id是否一致?