Raft瀹炴垬鈥斺€旈泦缇ゆ垚鍛樺彉鏇翠笌鏃ュ織鍘嬬缉

Posted Q鐨勫崥瀹?/a> Raft

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Raft瀹炴垬鈥斺€旈泦缇ゆ垚鍛樺彉鏇翠笌鏃ュ織鍘嬬缉相关的知识,希望对你有一定的参考价值。

鏈?/span>鏂囦负銆奟aft瀹炴垬銆嬬郴鍒楃5绡囷紝浠嬬粛 Raft 宸ョ▼瀹炶返鐨勫繀澶囨妧鏈€斺€旈泦缇ゆ垚鍛樺彉鏇翠笌鏃ュ織鍘嬬缉銆?span>鏈枃閲嶇偣璁茶В raft 闆嗙兢濡備綍鍔ㄦ€佸鍒犺妭鐐广€侀泦缇ゅ彉鏇存椂鑴戣鐨勮鍥犲強搴斿鏂规銆佺姸鎬佹満鏃ュ織鑶ㄨ儉鐨勫簲瀵规柟妗堬紝涔熶細璁ㄨ鏇存鐭ヤ箮鏌愬ぇ绁炪€奟aft鍗忚璇﹁В銆嬫枃绔犱腑蹇界暐鐨勫皬璇尯銆?/strong>


绗旇€呮湡鏈涘府鍔╄鑰呮繁鍏ョ悊瑙?Raft 鍗忚锛屽苟鑳戒粯璇镐簬宸ョ▼瀹炶返涓紝鍚屾椂瑙h涓嶆槗鐞嗚В鎴栨槗璇В鐨勫叧閿偣锛岀湅瀹屼笉鎳備綘鏉ユ媿鎴戰煒?銆傝绯诲垪浠?span class="mq-7">鍘熺悊銆佹簮鐮併€佸疄璺?/strong>涓変釜閮ㄥ垎璁茶В Raft 鍘熺悊鍙婄畻娉曪細

  • 鍘熺悊閮ㄥ垎缁撳悎 Raft 璁烘枃璁茶В Raft 绠楁硶鍘熺悊锛屽垎绡囬伒寰?Raft 鐨勬ā鍧楀寲鎬濇兂锛屽垎鍒瑙?Leader election銆丩og replication銆丼afety銆丆luster membership change銆丩og compaction 绛夈€?/span>

  • 婧愮爜閮ㄥ垎鍒嗘瀽 hashicorp/raft 鏉ュ涔犱竴涓伐涓氱晫鐨?Raft 瀹炵幇锛坔ashicorp/raft 鏄?Consul 鐨勫簳灞備緷璧栵級銆?/span>

  • 瀹炶返閮ㄥ垎鍩轰簬 hashicorp/raft 瀹炵幇涓€涓畝鍗曠殑鍒嗗竷寮?kv 瀛樺偍锛屼綔涓烘敹灏俱€?/span>


绯诲垪鍘嗗彶鏂囩珷閾炬帴锛?/span>





------------


灏界鎴戜滑宸茬粡閫氳繃鍓嶅嚑绡囨枃绔犱簡瑙d簡 Raft 绠楁硶鐨勬牳蹇冮儴鍒嗭紝浣嗙浉杈冧簬绠楁硶鐞嗚鏉ヨ锛屽湪宸ョ▼瀹炶返涓粛鏈変竴浜涚幇瀹為棶棰橀渶瑕佹垜浠幓闈㈠銆俁aft 闈炲父璐村績鐨勫湪璁烘枃涓粰鍑轰簡涓や釜甯歌闂鐨勮В鍐虫柟妗堬紝瀹冧滑鍒嗗埆鏄細


  1. 闆嗙兢鎴愬憳鍙樻洿锛氬浣曞畨鍏ㄥ湴鏀瑰彉闆嗙兢鐨勮妭鐐规垚鍛樸€?/p>

  2. 鏃ュ織鍘?/span>缂?/span>锛?/span>濡備綍瑙e喅鏃ュ織闆嗗悎鏃犻檺鍒跺闀垮甫鏉ョ殑闂銆?/span>


鏈枃鎴戜滑灏嗗垎鍒瑙h繖涓ょ鎶€鏈€?/p>


1. 闆嗙兢鎴愬憳鍙樻洿


鍦ㄥ墠鏂囩殑鐞嗚鎻忚堪涓垜浠兘鍋囪浜嗛泦缇ゆ垚鍛樻槸涓嶅彉鐨勶紝鐒惰€屽湪瀹炶返涓湁鏃朵細闇€瑕佹浛鎹㈠畷鏈烘満鍣ㄦ垨鑰呮敼鍙樺鍒剁骇鍒紙鍗冲鍑忚妭鐐癸級銆備竴绉嶆渶绠€鍗曟毚鍔涜揪鎴愮洰鐨勭殑鏂瑰紡灏辨槸锛氬仠姝㈤泦缇ゃ€佹敼鍙樻垚鍛樸€佸惎鍔ㄩ泦缇ゃ€傝繖绉嶆柟寮忓湪鎵ц鏃朵細瀵艰嚧闆嗙兢鏁翠綋涓嶅彲鐢紝姝ゅ杩樺瓨鍦ㄦ墜宸ユ搷浣滃甫鏉ョ殑椋庨櫓銆?/p>


涓轰簡閬垮厤杩欐牱鐨勯棶棰橈紝Raft 璁烘枃涓粰鍑轰簡涓€绉嶆棤闇€鍋滄満鐨勩€佽嚜鍔ㄥ寲鐨勬敼鍙橀泦缇ゆ垚鍛樼殑鏂瑰紡锛屽叾瀹炴湰璐ㄤ笂杩樻槸鍒╃敤浜?Raft 鐨勬牳蹇冪畻娉曪紝灏嗛泦缇ゆ垚鍛橀厤缃綔涓轰竴涓壒娈婃棩蹇椾粠 leader 鑺傜偣鍚屾鍒板叾瀹冭妭鐐瑰幓銆?/p>


1.1 鐩存帴鍒囨崲闆嗙兢鎴愬憳閰嶇疆


鍏堣缁撹锛?span>鎵€鏈夊皢闆嗙兢浠庢棫閰嶇疆鐩存帴瀹屽叏鍒囨崲鍒版柊閰嶇疆鐨勬柟妗堥兘鏄笉瀹夊叏鐨?/strong>銆?/p>


鎴戜滑涓嶈兘鎯冲綋鐒剁殑灏嗘柊閰嶇疆鐩存帴浣滀负鏃ュ織鍚屾缁欓泦缇ゅ苟 apply銆傚洜涓烘垜浠笉鍙兘璁╅泦缇や腑鐨勫叏閮ㄨ妭鐐瑰湪鈥?span>鍚屼竴鏃跺埢鈥?span>鍘熷瓙鍦?/strong>鍒囨崲鍏堕泦缇ゆ垚鍛橀厤缃紝鎵€浠ュ湪鍒囨崲鏈熼棿涓嶅悓鐨勮妭鐐圭湅鍒扮殑闆嗙兢瑙嗗浘鍙兘瀛樺湪涓嶅悓锛屾渶缁堝彲鑳藉鑷撮泦缇ゅ瓨鍦ㄥ涓?leader銆?/p>


涓轰簡鐞嗚В涓婅堪缁撹锛屾垜浠潵鐪嬩竴涓疄闄呭嚭鐜伴棶棰樼殑鍦烘櫙锛屼笅鍥惧鍏惰繘琛屼簡灞曠幇銆?/p>


鍥?


闃舵a. 闆嗙兢瀛樺湪 S1 ~ S3 涓変釜鑺傜偣锛屾垜浠皢璇ユ垚鍛橀厤缃〃绀轰负 C-old锛岀豢鑹茶〃绀鸿鑺傜偣褰撳墠瑙嗗浘锛堟垚鍛橀厤缃級涓?C-old锛屽叾涓孩杈圭殑 S3 涓?leader銆?/p>


闃舵b. 闆嗙兢鏂板浜?S4銆丼5 涓や釜鑺傜偣锛岃鍙樻洿浠?leader 鍐欏叆锛屾垜浠皢 S1 ~ S5 鐨勪簲鑺傜偣鏂版垚鍛橀厤缃〃绀轰负 C-new锛岃摑鑹茶〃绀鸿鑺傜偣褰撳墠瑙嗗浘涓?C-new銆?/p>


闃舵c. 鍋囪 S3 鐭殏瀹曟満瑙﹀彂浜?S1 涓?S5 鐨勮秴鏃堕€変富銆?/p>


闃舵d. S1 鍚?S2銆丼3 鎷夌エ锛孲5 鍚戝叾瀹冨叏閮ㄥ洓涓妭鐐规媺绁ㄣ€傜敱浜?S2 鐨勬棩蹇楀苟娌℃湁姣?S1 鏇存柊锛屽洜姝?S2 鍙兘浼氬皢閫夌エ鎶曠粰 S1锛孲1 涓ょエ褰撻€夛紙鍥犱负 S1 璁や负闆嗙兢鍙湁涓変釜鑺傜偣锛夈€傝€?S5 鑲畾浼氬緱鍒?S3銆丼4 鐨勯€夌エ锛屽洜涓?S1 鎰熺煡涓嶅埌 S4锛屾病鏈夊悜瀹冨彂閫?RequestVote RPC锛屽苟涓?S1 鐨勬棩蹇楄惤鍚庝簬 S3锛孲3 涔熶竴瀹氫笉浼氭姇缁?S1锛岀粨鏋?S5 涓夌エ褰撻€夈€傛渶缁堥泦缇ゅ嚭鐜颁簡澶氫釜涓昏妭鐐圭殑鑷村懡閿欒锛屼篃灏辨槸鎵€璋撶殑鑴戣銆?/p>


Raft瀹炴垬鈥斺€旈泦缇ゆ垚鍛樺彉鏇翠笌鏃ュ織鍘嬬缉

鍥?


鍥?鏉ヨ嚜璁烘枃锛岀敤涓嶅悓鐨勫舰寮忓睍鐜颁簡鍜屽浘1鐩稿悓鐨勯棶棰樸€傞鑹蹭唬琛ㄧ殑鍚箟涓庡浘1鏄竴鑷寸殑锛屽湪 problem: two disjoint majorities 鎵€鎸囩殑鏃堕棿鐐癸紝闆嗙兢鍙兘浼氬嚭鐜颁袱涓?leader銆?/p>


浣嗘槸锛屽涓婚棶棰樺苟涓嶆槸鍦ㄤ换浣曟柊鑰佽妭鐐瑰悓鏃堕€変妇鏃堕兘涓€瀹氬彲鑳藉嚭鐜扮殑锛岀ぞ鍖轰竴浜涙枃绔犲湪涓惧涓荤殑渚嬪瓙鏃跺彲鑳藉瓨鍦ㄩ敊璇紝涓嬮潰鏄竴涓渚嬶紙绗旇€呭涔?Raft 鍗忚涔熶粠杩欑瘒鏂囩珷涓彈鐩婂尓娴咃紝搴旇鏄綔鑰呰鏂囨椂蹇界暐浜嗐€傛枃绔犲緢璧烇紝寤鸿澶у鍙傝€冨涔狅級锛?br>

鏉ユ簮锛氥€奟aft 鍗忚璇﹁В銆嬬煡涔庢煇澶х
https://zhuanlan.zhihu.com/p/27207160


Raft瀹炴垬鈥斺€旈泦缇ゆ垚鍛樺彉鏇翠笌鏃ュ織鍘嬬缉

鍥?


璇ュ亣鎯冲満鏅被浼煎浘1鐨勯樁娈礵锛屾ā鎷熻繃绋嬪涓嬶細


  1. S1 涓洪泦缇ゅ師 leader锛岄泦缇ゆ柊澧?S4銆丼5锛岃閰嶇疆琚帹缁欎簡 S3锛孲2 灏氭湭鏀跺埌銆?/p>

  2. 姝ゆ椂 S1 鍙戠敓鐭殏瀹曟満锛孲2銆丼3 鍒嗗埆瑙﹀彂閫変富銆?/p>

  3. 鏈€缁?S2 鑾峰緱浜?S1 鍜岃嚜宸辩殑閫夌エ锛孲3 鑾峰緱浜?S4銆丼5 鍜岃嚜宸辩殑閫夌エ锛岄泦缇ゅ嚭鐜颁袱涓?leader銆?br>


鍥?杩囩▼鐪嬭捣鏉ュソ鍍忓拰鍥?娌℃湁浠€涔堝ぇ鐨勪笉鍚岋紝鍙槸鍙備笌閫変富鐨勮妭鐐瑰瓨鍦ㄥ尯鍒紝鐒惰€屼簨瀹炴槸鍥?鐨勬儏鍐垫槸涓嶅彲鑳藉嚭鐜扮殑銆?br>


娉ㄦ剰锛歊aft 璁烘枃涓紶閫掗泦缇ゅ彉鏇翠俊鎭篃鏄€氳繃鏃ュ織杩藉姞瀹炵幇鐨勶紝鎵€浠ヤ篃鍙楀埌閫変富鐨勯檺鍒躲€?span class="mq-58">寰堝璇昏€呭閫変富闄愬埗涓瘮杈冪殑鏃ュ織鏄惁蹇呴』鏄?nbsp;committed 浜х敓鐤戞儜锛屽洖鐪嬩笅鍦ㄣ€婂畨鍏ㄦ€?/span>銆嬩竴鏂囦腑鐨勬弿杩帮細

姣忎釜 candidate 蹇呴』鍦?RequestVote RPC 涓惡甯﹁嚜宸辨湰鍦版棩蹇楃殑鏈€鏂?(term, index)锛屽鏋?follower 鍙戠幇杩欎釜 candidate 鐨勬棩蹇楄繕娌℃湁鑷繁鐨勬柊锛屽垯鎷掔粷鎶曠エ缁欒 candidate銆?/span>
Q鐨勫崥瀹紝鍏紬鍙凤細Q鐨勫崥瀹?/span>


杩欓噷鍐嶅府澶у鏄庣‘涓嬶紝璁烘枃閲岀‘瀹為棿鎺ヨ〃鏄庝簡锛?/span>閫変富鏃舵瘮杈冪殑鏃ュ織鏄笉瑕佹眰 committed 鐨勶紝鍙渶姣旇緝鏈湴鐨勬渶鏂版棩蹇楀氨琛岋紒


鍥炲埌鍥?锛屼笉鍙兘鍑虹幇鐨?span class="mq-72">鍘熷洜鍦ㄤ簬锛孲1 浣滀负鍘?leader 宸茬粡绗竴涓繚瀛樹簡鏂伴厤缃殑鏃ュ織锛岃€?S2 灏氭湭琚悓姝ヨ繖鏉℃棩蹇楋紝鏍规嵁涓婁竴绡囥€婂畨鍏ㄦ€с€嬫垜浠鍒扮殑閫変富闄愬埗锛?/span>S1 涓嶅彲鑳藉皢閫夌エ鎶曠粰 S2锛屽洜姝?S2 涓嶅彲鑳芥垚涓?leader銆?/span>


1.2 涓ら樁娈靛垏鎹㈤泦缇ゆ垚鍛橀厤缃?/strong>


Raft 浣跨敤涓€绉嶄袱闃舵鏂规硶骞虫粦鍒囨崲闆嗙兢鎴愬憳閰嶇疆鏉ラ伩鍏嶉亣鍒板墠涓€鑺傛弿杩扮殑闂锛屽叿浣撴祦绋嬪涓嬶細


闃舵涓€

  1. 瀹㈡埛绔皢 C-new 鍙戦€佺粰 leader锛宭eader 灏?C-old 涓?C-new 鍙?span>骞堕泦骞剁珛鍗砤pply锛屾垜浠〃绀轰负 C-old,new銆?/p>

  2. Leader 灏?C-old,new 鍖呰涓烘棩蹇楀悓姝ョ粰鍏跺畠鑺傜偣銆?/span>

  3. Follower 鏀跺埌 C-old,new 鍚庣珛鍗?apply锛屽綋 C-old,new 鐨勫ぇ澶氭暟鑺傜偣锛堝嵆 C-old 鐨勫ぇ澶氭暟鑺傜偣鍜?C-new 鐨勫ぇ澶氭暟鑺傜偣锛?/strong>閮藉垏鎹㈠悗锛宭eader 灏嗚鏃ュ織 commit銆?/span>

闃舵浜?/strong>

  1. Leader 鎺ョ潃灏?C-new 鍖呰涓烘棩蹇楀悓姝ョ粰鍏跺畠鑺傜偣銆?/p>

  2. Follower 鏀跺埌 C-new 鍚庣珛鍗?apply锛屽鏋滄鏃跺彂鐜拌嚜宸变笉鍦?C-new 鍒楄〃锛屽垯涓诲姩閫€鍑洪泦缇ゃ€?/span>

  3. Leader 纭 C-new 鐨勫ぇ澶氭暟鑺傜偣閮藉垏鎹㈡垚鍔熷悗锛岀粰瀹㈡埛绔彂閫佹墽琛屾垚鍔熺殑鍝嶅簲銆?/span>


鍥?


鍥?灞曠ず浜嗚娴佺▼鐨勬椂闂寸嚎銆傝櫄绾胯〃绀哄凡缁忓垱寤轰絾灏氭湭 commit 鐨勬垚鍛橀厤缃棩蹇楋紝瀹炵嚎琛ㄧず committed 鐨勬垚鍛橀厤缃棩蹇椼€?/p>


涓轰粈涔堣鏂规鍙互淇濊瘉涓嶄細鍑虹幇澶氫釜 leader锛熸垜浠潵鎸夋祦绋嬮€愰樁娈靛垎鏋愩€?/p>


闃舵1. C-old,new 灏氭湭 commit


璇ラ樁娈垫墍鏈夎妭鐐圭殑閰嶇疆瑕佷箞鏄?C-old锛岃涔堟槸 C-old,new锛屼絾鏃犺鏄簩鑰呭摢绉嶏紝鍙鍘?leader 鍙戠敓瀹曟満锛屾柊 leader 閮?span>蹇呴』寰楀埌澶у鏁?C-old 闆嗗悎鍐呰妭鐐圭殑鎶曠エ銆?/p>


浠ュ浘1鍦烘櫙涓轰緥锛孲5 鍦ㄩ樁娈礵鏍规湰娌℃湁鏈轰細鎴愪负 leader锛屽洜涓?C-old 涓彧鏈?S3 缁欏畠鎶曠エ浜嗭紝涓嶆弧瓒冲ぇ澶氭暟銆?/p>


闃舵2. C-old,new 宸茬粡 commit锛孋-new 灏氭湭涓嬪彂


璇ラ樁娈?C-old,new 宸茬粡 commit锛屽彲浠ョ‘淇濆凡缁忚 C-old,new 鐨勫ぇ澶氭暟鑺傜偣锛?span>鍐嶆寮鸿皟锛欳-old 鐨勫ぇ澶氭暟鑺傜偣鍜?C-new 鐨勫ぇ澶氭暟鑺傜偣锛夊鍒躲€?/p>


鍥犳褰?leader 瀹曟満鏃讹紝鏂伴€夊嚭鐨?leader 涓€瀹氭槸宸茬粡鎷ユ湁 C-old,new 鐨勮妭鐐癸紝涓嶅彲鑳藉嚭鐜颁袱涓?leader銆?/p>


闃舵3. C-new 宸茬粡涓嬪彂浣嗗皻鏈?commit


璇ラ樁娈甸泦缇や腑鍙兘鏈変笁绉嶈妭鐐?C-old銆丆-old,new銆丆-new锛屼絾鐢变簬宸茬粡缁忓巻浜嗛樁娈?锛屽洜姝?C-old 鑺傜偣涓嶅彲鑳藉啀鎴愪负 leader銆傝€屾棤璁烘槸 C-old,new 杩樻槸 C-new 鑺傜偣鍙戣捣閫変妇锛岄兘闇€瑕佺粡杩囧ぇ澶氭暟 C-new 鑺傜偣鐨勫悓鎰忥紝鍥犳涔熶笉鍙兘鍑虹幇涓や釜 leader銆?/p>


闃舵4. C-new 宸茬粡 commit


璇ラ樁娈?C-new 宸茬粡琚?commit锛屽洜姝ゅ彧鏈?C-new 鑺傜偣鍙互寰楀埌澶у鏁伴€夌エ鎴愪负 leader銆傛鏃堕泦缇ゅ凡缁忓畨鍏ㄥ湴瀹屾垚浜嗚繖杞彉鏇达紝鍙互缁х画寮€鍚笅涓€杞彉鏇翠簡銆?/p>


浠ヤ笂渚挎槸瀵硅涓ら樁娈垫柟娉曞彲琛屾€х殑鍒嗘楠岃瘉锛孯aft 璁烘枃灏嗚鏂规硶绉颁箣涓?span>鍏卞悓涓€鑷达紙Joint Consensus锛?/strong>銆?/p>


鍏充簬闆嗙兢鎴愬憳鍙樻洿鍙︿竴绡囨洿璇︾粏鐨勮鏂囪繕缁欏嚭浜嗗叾瀹冩柟娉曪紝绠€鍗曟潵璇村氨鏄璇?span>涓€娆″彧鍙樻洿涓€涓妭鐐圭殑鐨勬纭€э紝骞剁粰鍑鸿В鍐冲彲鐢ㄦ€ч棶棰樼殑浼樺寲鏂规銆傛劅鍏磋叮鐨勫悓瀛﹀彲浠ュ弬鑰冦€奀onsensus: Bridging Theory and Practice銆?鏂囨湯閾炬帴)銆?/p>


2. 鏃ュ織鍘嬬缉


鎴戜滑鐭ラ亾 Raft 鏍稿績绠楁硶缁存姢浜嗘棩蹇楃殑涓€鑷存€э紝閫氳繃 apply 鏃ュ織鎴戜滑涔熷氨寰楀埌浜嗕竴鑷寸殑鐘舵€佹満锛屽鎴风鐨勬搷浣滃懡浠や細琚寘瑁呮垚鏃ュ織浜ょ粰 Raft 澶勭悊銆傜劧鑰屽湪瀹為檯绯荤粺涓紝瀹㈡埛绔搷浣滄槸杩炵坏涓嶆柇鐨勶紝浣嗘棩蹇楀嵈涓嶈兘鏃犻檺澧為暱锛岄鍏堝畠浼氬崰鐢ㄥ緢楂樼殑瀛樺偍绌洪棿锛屽叾娆℃瘡娆$郴缁熼噸鍚椂閮介渶瑕佸畬鏁村洖鏀句竴閬嶆墍鏈夋棩蹇楁墠鑳藉緱鍒版渶鏂扮殑鐘舵€佹満銆?/p>


鍥犳 Raft 鎻愪緵浜嗕竴绉嶆満鍒跺幓娓呴櫎鏃ュ織閲岀Н绱殑闄堟棫淇℃伅锛屽彨鍋?span>鏃ュ織鍘嬬缉銆?/p>


蹇収锛圫napshot锛?/strong>鏄竴绉嶅父鐢ㄧ殑銆佺畝鍗曠殑鏃ュ織鍘嬬缉鏂瑰紡锛孼ooKeeper銆丆hubby 绛夌郴缁熼兘鍦ㄧ敤銆傜畝鍗曟潵璇达紝灏辨槸灏嗘煇涓€鏃跺埢绯荤粺鐨勭姸鎬?dump 涓嬫潵骞惰惤鍦板瓨鍌紝杩欐牱璇ユ椂鍒讳箣鍓嶇殑鎵€鏈夋棩蹇楀氨閮藉彲浠ヤ涪寮冧簡銆傛墍浠ュぇ瀹跺鈥滃帇缂┾€濅竴璇嶄笉瑕佷骇鐢熼敊璇悊瑙o紝鎴戜滑骞舵病鏈夊姙娉曞皢鐘舵€佹満蹇収鈥滆В鍘嬬缉鈥濆洖鏃ュ織搴忓垪銆?/p>


娉ㄦ剰锛?span>鍦?Raft 涓垜浠彧鑳戒负 committed 鏃ュ織鍋?snapshot锛屽洜涓哄彧鏈?committed 鏃ュ織鎵嶆槸纭繚鏈€缁堜細搴旂敤鍒扮姸鎬佹満鐨勩€?/p>


鍥?


鍥?灞曠ず浜嗕竴涓妭鐐圭敤蹇収鏇挎崲浜?(term1, index1) ~ (term3, index5) 鐨勬棩蹇椼€?/p>


蹇収涓€鑸寘鍚互涓嬪唴瀹癸細


1. 鏃ュ織鐨勫厓鏁版嵁锛氭渶鍚庝竴鏉¤璇ュ揩鐓?apply 鐨勬棩蹇?term 鍙?index

2. 鐘舵€佹満锛氬墠杈瑰叏閮ㄦ棩蹇?apply 鍚庢渶缁堝緱鍒扮殑鐘舵€佹満


褰?leader 闇€瑕佺粰鏌愪釜 follower 鍚屾涓€浜涙棫鏃ュ織锛屼絾杩欎簺鏃ュ織宸茬粡琚?leader 鍋氫簡蹇収骞跺垹闄ゆ帀浜嗘椂锛宭eader 灏遍渶瑕佹妸璇ュ揩鐓у彂閫佺粰 follower銆?/p>


鍚屾牱锛屽綋闆嗙兢涓湁鏂拌妭鐐瑰姞鍏ワ紝鎴栬€呮煇涓妭鐐瑰畷鏈哄お涔呰惤鍚庝簡澶鏃ュ織鏃讹紝leader 涔熷彲浠ョ洿鎺ュ彂閫佸揩鐓э紝澶ч噺鑺傜害鏃ュ織浼犺緭鍜屽洖鏀炬椂闂淬€?/p>


鍚屾蹇収浣跨敤涓€涓柊鐨?RPC 鏂规硶锛屽彨鍋?InstallSnapshot RPC銆?/strong>



鑷虫鎴戜滑宸茬粡灏?Raft 璁烘枃涓殑鍐呭鍩烘湰璁茶В瀹屾瘯浜嗐€傘€奍n Search of an Understandable Consensus Algorithm (Extended Version)銆嬫瘯绔熷彧鏈?8椤碉紝鏇村姞渚ч噸浜庣悊璁烘弿杩拌€岄潪宸ョ▼瀹炶返銆傚鏋滀綘鎯虫繁鍏ュ涔?Raft锛屾垨鑷繁鍔ㄦ墜鍐欎竴涓潬璋辩殑 Raft 瀹炵幇锛屻€奀onsensus: Bridging Theory and Practice銆嬫槸浣犲弬鑰冪殑涓嶄簩涔嬮€夈€?/p>


鎺ヤ笅鏉ユ垜浠細鍐嶆彁渚涗竴绡囧叧浜庣嚎鎬т竴鑷存€у拰 Raft 鎬ц兘浼樺寲鐨勮璁猴紝鏉ュ~琛ヤ竴浜涗粠鐞嗚鍒板伐涓氬疄璺电殑楦挎矡锛岀劧鍚庝究寮€鍚?span>婧愮爜鍒嗘瀽鏂扮瘒绔爚




闄勶細

[In Search of an Understandable Consensus Algorithm (Extended Version)]

(https://raft.github.io/raft.pdf)


[Consensus: Bridging Theory and Practice]

(https://github.com/ongardie/dissertation)

以上是关于Raft瀹炴垬鈥斺€旈泦缇ゆ垚鍛樺彉鏇翠笌鏃ュ織鍘嬬缉的主要内容,如果未能解决你的问题,请参考以下文章

鐧藉珫鐗?2019Java寮€鍙戝叏缁堢瀹炴垬绉熸埧椤圭洰瑙嗛鏁欑▼

Java鈥斺€旈泦鍚堢粡鍏搁潰璇曢

logging鏃ュ織妯″潡

mysql 鏃ュ織log