天天看点

阅读笔记(二十二)链复制扩展CRAQ《High-throughput chain replication for read-mostly workloads》

一. 简介

  在前文中我们分析了链复制技术的细节和性能表现,而《High-throughput chain replication for read-mostly workloads》则对链复制模型进行了扩展和优化,即CRAQ。

二. CRAQ介绍

  链复制模型最大的缺陷在于尾结点:

  • 尾结点处理所有的读请求,作为热点在读数据过多时会出现阻塞
  • 尾结点出现问题会导致全部服务暂停,切换节点也会较为麻烦

  为了解决这些问题,就有了CRAQ(Chain Replication with Apportioned Queries)。

阅读笔记(二十二)链复制扩展CRAQ《High-throughput chain replication for read-mostly workloads》

  有图可见,CRAQ和普通的链复制最大的区别在于将读请求分散到了各个节点之上。这就会产生一个问题:链复制要解决的是一致性问题,而解决的方案是仅使用尾结点来完成读请求。如果分散到各个节点,如何保证一致性?

  为了解决该问题,CRAQ采取了以下机制:

  • 每一个非尾结点可以保存多版本的数据,版本号单调自增。每个版本可能是clean或者dirty,在开始时所有的均为clean
  • 当头部节点收到写请求,则将自身设置为dirty,传递新版本号给下一个节点。到达尾部节点时,尾部节点设置为clean,依次回传,收到ack之后各自设置为clean。
  • 当节点收到读请求的时候,如果最终版本号为clean则回复该版本号对应数据,否则问询尾部节点上次提交为clean的版本,并回复该版本对应的数据。
阅读笔记(二十二)链复制扩展CRAQ《High-throughput chain replication for read-mostly workloads》

  不难看出,该机制的确可以实现数据的一致性,但是不能保证数据一定是最新的,这是该模型所存在的一个缺陷。但是在多数读的场景下,该模型依然可以保持良好的表现。尤其是因为各个节点分担了请求,因此随着规模扩大,CRAQ的表现也会随着节点数线性增长,这是普通链复制不具有的优良特点。

三. CRAQ的一致性和可能的提升

3.2 Consistency in CRAQ

CRAQ provides strong consistency except for one case: when a node received the last committed version from the tail, tail might commit the newest version before the node sends the response to the client. In this scenario, CRAQ provides monotonic read (subsequent read requests don’t go in the past) on the whole chain.

It is also possible to provide other weaker consistencies in such cases to improve performance:

Eventual consistency: the node doesn’t request the latest committed version from the tail. This will still provide monotonic reads but only on one node. (subsequent read requests must hit the same node). Besides, this allows CRAQ to tolerate network partitioning.

Bounded Eventual Consistency: allow to return dirty version only under some conditions, like not older than N revisions or T minutes.

CRAQ has a very interesting feature — it is possible to send updates via multicast on write requests. When a write request hits head — head can multicast changes to all nodes and then send “fixation” event down the chain. Upon receiving the fixation event a node waits to receive the multicast update. The same way tail can multicast ACK and send fixation event back to the head via the chain.

欢迎关注本人公众号,公众号会更新一些不一样的内容,相信一定会有所收获。

阅读笔记(二十二)链复制扩展CRAQ《High-throughput chain replication for read-mostly workloads》