Redis Sharding集羣跟一致性哈希有什麼瓜葛?

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"一、前言"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最近在所負責的某些系統上遇到了一些Redis相關的問題,剛好在朋友圈聊到Cluster和Sharding這方面的東西,發現有些地方比較模糊,考慮到之前也整理了關於Sentinel集羣模式,趁着有點力氣整理一下Sharding的一些相關資料。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Cluster模式後面有時間再補充吧。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"二、Redis sharding集羣"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1、概念及優劣:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"客戶端分片技術,即客戶端自己計算每個key應該要放到哪個Redis實例,其主要原理還是使用哈希算法對某個Key進行哈希後映射存儲到對應的Redis實例上。(這裏提前透露簡單的哈希算法可以是通過簡單的取餘,但是這種辦法有致命的弱點,稍後再講。)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此方法的好處是1)降低服務器集羣的複雜度,且2)每個實例都是獨立沒有關聯的。缺點就是1)擴容問題,目前客戶端實現在支持動態增刪實例方面沒有解決方案;2)單點故障:即如果某個分片宕機後,那個分片的數據就不能提供服務,每個實例本身的高可用需要自己想辦法。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"針對以上兩個問題,一般有以下的解決方案:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"單點故障"},{"type":"text","text":":一般的做法是通過一主N從的哨兵模式實現該分片的自動故障轉移,具體的方案原理及搭建請參考我的另外一篇文章:"},{"type":"link","attrs":{"href":"https://blog.csdn.net/justyman/article/details/106582868","title":null},"content":[{"type":"text","text":"Redis哨兵(Sentinel)模式"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"擴容問題"},{"type":"text","text":":一般只能通過重啓的方法進行擴容,但這種辦法在鍵值對數據遷移方面加大了運維側的難度,且應用層需要做配置改動去支持新的實例。還有另外一種辦法,Redis作者推薦可以使用一種PreSharding的辦法,這裏暫不做介紹,後面再補充。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2、數據傾斜問題"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"後面會提到Jedis的用法(因爲Jedis就是客戶端分片的其中一種實現方案),這裏也先簡單介紹一下一致性哈希可以解決的問題吧。但在開始介紹之前一定要接受一個前提,一致性哈希算法可以做到:"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}},{"type":"strong"}],"text":"均衡性:不同對象經哈希後的哈希值在哈希環內(即hash family)能保證儘量均勻分佈確保均衡落入到不同節點;"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}},{"type":"strong"}],"text":"單調性:對於部分已經分配到具體節點的鍵值對,即使有新節點加入也能保證該部分鍵值對要麼映射在原節點要麼映射到新節點(即不會映射到其他舊有節點上);"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}},{"type":"strong"}],"text":"分散性:暫時還不是特別懂,翻譯不了"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}},{"type":"strong"}],"text":"負載性:暫時還不是特別懂,翻譯不了"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"具體上述4種特性的英文描述可以在下面的原始論文中的第6頁可以找到,這裏就不做展示了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"另:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1、關於緩存系統對於該算法運用的相關論文有興趣的朋友可以參考哥倫比亞大學網站的資料: "},{"type":"link","attrs":{"href":"http://www.cs.columbia.edu/~asherman/papers/cachePaper.pdf","title":null},"content":[{"type":"text","text":"http://www.cs.columbia.edu/~asherman/papers/cachePaper.pdf"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2、關於算法原始論文有興趣的可以參考普林斯頓大學資料:"},{"type":"link","attrs":{"href":"https://www.cs.princeton.edu/courses/archive/fall09/cos518/papers/chash.pdf","title":null},"content":[{"type":"text","text":"https://www.cs.princeton.edu/courses/archive/fall09/cos518/papers/chash.pdf"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果Redis平時放些用戶session、參數這類偏靜態數據問題不大,如果我們是存儲千萬或億級級別的交易數據、埋點數據(且需要頻發讀寫)的話,在Redis Sharding的方案中,例如我們上例因爲資源成本的問題我不可能配幾十或百臺實例,因此只配了兩個實例,但是兩個實例會帶來什麼樣的問題?對,也會因爲物理實例節點(這裏簡稱Node)的偏少而帶來數據傾斜的問題。怎麼辦呢?如果使用一致性哈希算法的話(我這裏畫了個概念圖方便理解),算法會針對每個物理節點(Node)虛擬出多個虛擬節點(這裏簡稱Virtual Node或者VNode),這樣在整個哈希環空間內就有多個互相交錯的虛擬節點,那數據分佈得更均衡了而避免對於某臺服務器的讀寫壓力,一般來說虛擬節點越多數據分佈得約均勻(曾經在某個文章看過壓測數據,當虛擬節點數達到"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":" "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"1000級別"},{"type":"text","text":"的時候,每個節點存儲的數據基本上接近"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":" "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"“平均數”"},{"type":"text","text":")。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"具體請看下圖。在沒有虛擬的情況下,差不多所有數據(K1/K2/K3/K4/K5)全在Node1,只有K6在Node2;在使用了一致性哈希算法後(虛擬化後),K1/K3/K5實際上在Node1對應的那些虛擬節點中,K2/K4/K6則在Node2裏,這樣數據就均衡的分佈在兩個物理節點。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/92/9289ae108d8425ebb5e0d48e536875cc.png","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"實際上,大家可以看看一下Jedis的源碼,在Node的初始化的時候Jedis會自動將每個Node虛擬出160個VNode,這樣的話上例中的2個實例實際上就有"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"2*160=320個虛擬節點"},{"type":"text","text":",而且可以從上圖類推出來,這320個節點是"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"縱橫交錯的而非順序排列"},{"type":"text","text":"。另外,具體鍵值對(K,V)存儲的時候Jedis怎麼選擇對應的虛擬節點的話,大家有興趣可以看看相應源碼,這裏不做具體展示。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4d/4dab0e154eec7b08d226c8bb8ad133a5.png","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"3、數據丟失問題"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用了一致性哈希算法後還有一個好處,就是在沒有足夠時間做數據遷移的前提下,動態擴容或突發宕機時候導致數據丟失或者打到後面數據庫的流量減少,最大程度避免雪崩的發生,是高容錯性的一個體現。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以下圖的哈希環爲例,在沒有插入Node3節點前,如果我們通過客戶端去讀取這幾個K1/K2/K3的鍵值對的時候會根據算法自動識別是存儲在Node1並可以獲取到;但是如果在服務器壓力暴增情況下臨時新增一臺服務器的話(潛臺詞就是沒有做數據遷移,因爲一旦上量了遷移也需要很多時間),客戶端再去獲取K1/K2/K3的時候,通過算法計算認爲它們應該存儲在Node3的,但實際Node3是肯定沒有啦(因爲沒做數據遷移),所以對客戶端來說50%的數據是憑空消失了( "},{"type":"text","marks":[{"type":"italic"},{"type":"bgcolor","attrs":{"color":"#FDED8A","name":"yellow"}}],"text":"被黃圈圈起來部分,這裏思考一下是不是跟該算法的單調性有點吻合,細品一下"},{"type":"text","text":"),這是何等悲壯啊,等着跑路吧兄dei。但是,如果是有良心的程序猿,在系統設計時候會做好容錯性設計的(不知道在讀的你有沒有做到),一般在應用層邏輯上會兜底,就是允許把請求穿透到服務端通過查庫獲取並同步更新到最新的Node3上,那下次再有請求過來的時候直接從Node3獲取即可而不需要打到數據庫。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"針對上面提到的問題,"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"首先,如果採用了一致性哈希後,因爲上面提到虛擬化節點很多,這樣的話呢就算髮生上面情況,所影響的數據範圍也是相對較小的,起碼不是整個物理節點的數據都得查庫;"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其次,如果我們在應用層做了相應兜底處理(即穿透到數據庫獲取並同步到Redis節點),因爲相應的數據範圍較小,因此打到服務端的流量壓力也沒有那麼大。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c8/c864265947acc7dd0fb314e298b86524.png","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"4、應用"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前客戶端Jedis能夠支持Redis Sharding,即ShardedJedis 以及結合緩存池的ShardedJedisPool組合使用。而且,Jedis的Redis Sharding實現是採用一致性哈希算法(具體請參考以上第二點)。 具體客戶端使用方法請參考以下(整個工程爲"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"springboot工程"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":" "},{"type":"text","text":")。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"pom.xml"}]},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"\n \t\n \tredis.clients\t\n jedis\t\n 2.8.0\n "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"application.properties"}]},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"#redis sharding instance config\nredis_client_timeout=500\nredis_one_host=192.168.32.101\nredis_one_port=6379\nredis_one_password=123\nredis_two_host=192.168.32.102\nredis_two_port=6380\nredis_two_password=123"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"RedisConfiguration.java"}]},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"@Configuration\npublic class RedisConfiguration {\n\n //redis one host\n @Value(\"${redis_one_host}\")\n private String redisOneHost;\n\n //redis one port\n @Value(\"${redis_one_port}\")\n private int redisOnePort;\n\n //redis one password\n @Value(\"${redis_one_password}\")\n private String redisOnePassword;\n\n //redis two host\n @Value(\"${redis_one_host}\")\n private String redisTwoHost;\n\n //redis two port\n @Value(\"${redis_one_port}\")\n private int redisTwoPort;\n\n //redis two password\n @Value(\"${redis_two_password}\")\n private String redisTwoPassword;\n\n //redis client timeout\n @Value(\"${redis_client_timeout}\")\n private int redisClientTimeout;\n\n @Bean(name=\"redisPool\")\n public ShardedJedisPool createRedisPool() throws Exception {\n\n //設置連接池的相關配置\n JedisPoolConfig poolConfig = new JedisPoolConfig();\n poolConfig.setMaxTotal(5);\n poolConfig.setMaxIdle(2);\n poolConfig.setMaxWaitMillis(5000);\n poolConfig.setTestOnBorrow(false);\n poolConfig.setTestOnReturn(false);\n\n //設置Redis信息\n JedisShardInfo shardInfo1 = new JedisShardInfo(redisOneHost,redisOnePort, redisClientTimeout);\n shardInfo1.setPassword(redisOnePassword);\n JedisShardInfo shardInfo2 = new JedisShardInfo(redisTwoHost, redisTwoPort, redisClientTimeout);\n shardInfo2.setPassword(redisTwoPassword);\n\n //初始化ShardedJedisPool\n List infoList = Arrays.asList(shardInfo1, shardInfo2);\n ShardedJedisPool jedisPool = new ShardedJedisPool(poolConfig, infoList);\n\n return jedisPool;\n\n }\n\n public static void main(String[] args){\n\n ShardedJedis shardedJedis = null;\n\n try{\n\n RedisConfiguration redisConfiguration = new RedisConfiguration();\n ShardedJedisPool shardedJedisPool = redisConfiguration.createRedisPool();\n shardedJedis = shardedJedisPool.getResource();\n\n shardedJedis.set(\"CSDN\", \"56\");\n shardedJedis.set(\"InfoQ\",\"44\");\n shardedJedis.set(\"CNBlog\",\"13\");\n shardedJedis.set(\"SegmentFault\",\"22\");\n\n Client client1 = shardedJedis.getShard(\"CSDN\").getClient();\n Client client2 = shardedJedis.getShard(\"InfoQ\").getClient();\n Client client3 = shardedJedis.getShard(\"CNBlog\").getClient();\n Client client4 = shardedJedis.getShard(\"SegmentFault\").getClient();\n\n System.out.println(\"CSDN 位於實例:\" + client1.getHost() + \"|\" + client1.getPort());\n System.out.println(\"InfoQ 位於實例:\" + client1.getHost() + \"|\" + client1.getPort());\n System.out.println(\"CNBlog 位於實例:\" + client1.getHost() + \"|\" + client1.getPort());\n System.out.println(\"SegmentFault 位於實例:\" + client1.getHost() + \"|\" + client1.getPort());\n\n }catch(Exception e){\n e.printStackTrace();\n }finally {\n shardedJedis.close();\n }\n }\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"運行後打印出來的日誌看,這幾個值是存放到"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"不同的Redis實例"},{"type":"text","text":"中,但是在客戶端使用的時候究竟如何分配到不同的分片具體有Jedis實現的一致性哈希算法所決定的;當然,它所支持的默認算法是64位的MURMUR_HASH算法,另外也支持MD5哈希算法。"}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"\"C:\\Program Files\\Java\\jdk1.8.0_102\\bin\\java\"..."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}}],"text":"CSDN 位於實例:192.168.32.101|6379"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}}],"text":"InfoQ 位於實例:192.168.32.102|6380"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}}],"text":"CNBlog 位於實例:192.168.32.101|6379"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}}],"text":"SegmentFault 位於實例:192.168.32.102|6380"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"三、後話"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"區別於Redis Sharding這種輕量方案,Redis Cluster是Redis官方於Redis 3.0發佈後推出的一種服務端分片的解決方案,它解決了多Redis實例下的協同問題。這裏的協同包含數據自動分片、不同哈希槽(slot)的故障自動轉移、新節點擴容等功能。你看,數據分片以前是靠客戶端自己解決的,哈希槽故障自動轉移以前是靠額外的哨兵機制解決的,現在官方搞個整體解決方案以幫助客戶端輕量化以便客戶端能夠更聚焦於業務邏輯的開發工作。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我的理解是Redis Cluster是一個去中心化的集羣解決方案,集羣中的每個節點都是平等的(因爲每個節點都知道整個集羣其他節點的信息,如IP、端口、狀態等,每個節點間都是相互通過長鏈保持通訊的),它跟Sentinel的本質上的差異也在於這裏。一個去中心化模式,另一個集中式的主從模式。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"具體cluster如何做"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"數據自動分片、故障自動轉移、節點擴縮容"},{"type":"text","text":"等細節,後面通過另外一篇博客中整理再發布吧,今天先到這裏。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"四、參考"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.cs.princeton.edu/courses/archive/fall09/cos518/papers/chash.pdf","title":null},"content":[{"type":"text","text":"https://www.cs.princeton.edu/courses/archive/fall09/cos518/papers/chash.pdf"}]},{"type":"link","attrs":{"href":"http://www.cs.columbia.edu/~asherman/papers/cachePaper.pdf","title":null},"content":[{"type":"text","text":"http://www.cs.columbia.edu/~asherman/papers/cachePaper.pdf"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章