閱讀筆記(二十二)鏈複製擴展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和普通的鏈複製最大的區別在於將讀請求分散到了各個節點之上。這就會產生一個問題:鏈複製要解決的是一致性問題,而解決的方案是僅使用尾結點來完成讀請求。如果分散到各個節點,如何保證一致性?

  爲了解決該問題,CRAQ採取了以下機制:

  • 每一個非尾結點可以保存多版本的數據,版本號單調自增。每個版本可能是clean或者dirty,在開始時所有的均爲clean
  • 當頭部節點收到寫請求,則將自身設置爲dirty,傳遞新版本號給下一個節點。到達尾部節點時,尾部節點設置爲clean,依次回傳,收到ack之後各自設置爲clean。
  • 當節點收到讀請求的時候,如果最終版本號爲clean則回覆該版本號對應數據,否則問詢尾部節點上次提交爲clean的版本,並回復該版本對應的數據。

在這裏插入圖片描述

  不難看出,該機制的確可以實現數據的一致性,但是不能保證數據一定是最新的,這是該模型所存在的一個缺陷。但是在多數讀的場景下,該模型依然可以保持良好的表現。尤其是因爲各個節點分擔了請求,因此隨着規模擴大,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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章