天天看點

閱讀筆記(二十二)鍊複制擴充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》