braft 快照拉取流程

整體過程

快照的拉取分為主從兩端娇哆『课溃快照都是通過主節(jié)點主動發(fā)起的。

  • 主(Leader):負(fù)責(zé)快照的生成迈套,并負(fù)責(zé)觸發(fā)快照發(fā)送任務(wù)捐祠。
  • 從(Follower):負(fù)責(zé)接收快照數(shù)據(jù),并加載快照到本地

生成快照

快照生成時序圖

傳輸快照

傳輸快照時序圖

附錄

快照生成時序圖

@startuml

NodeImpl ->> SnapshotExecutor : do_snapshot() <<async>>
activate SnapshotExecutor

SnapshotExecutor -> SnapshotStorage: create()
activate SnapshotStorage

create SnapshotWriter
SnapshotStorage->SnapshotWriter: new

return create writer finish

create SaveSnapshotDone

SnapshotExecutor -> SaveSnapshotDone: new with SnapshotWriter
SnapshotExecutor ->> StateMachine: on_snapshot_save<<async with SaveSnapshotDone>>
activate StateMachine
StateMachine -->> SnapshotExecutor: async call return 

deactivate SnapshotExecutor

StateMachine -> SaveSnapshotDone: access
activate SaveSnapshotDone
return get writer finish

StateMachine -> SnapshotWriter: add_file()
activate SnapshotWriter
return add file finish

StateMachine -> SaveSnapshotDone: run()
activate SaveSnapshotDone

SaveSnapshotDone -> SnapshotExecutor: on_snapshot_save_done()
activate SnapshotExecutor
SnapshotExecutor -> SnapshotWriter: save_meta()
activate SnapshotWriter
return
SnapshotExecutor -> SnapshotStorage: close()
activate SnapshotStorage
return
SnapshotExecutor -> LogManager: set_snapshot()
activate LogManager
return

return on_snapshot_save_done finish
deactivate SaveSnapshotDone

@enduml

快照傳輸時序圖

@startuml
scale 4000 width
box Leader #LightBlue

control Replicator_Entry_RPC
participant Replicator as l_replicator
participant LocalSnapshotStorage as l_storage

Replicator_Entry_RPC -> l_replicator: _install_snapshot()
activate l_replicator
l_replicator -> l_storage: open()
activate l_storage
create LocalSnapshotReader as l_s_reader
l_storage -> l_s_reader: new()

return get snapshot reader
l_replicator -> l_s_reader: generate_uri_for_copy()
activate l_s_reader
create SnapshotFileReader as l_s_file_reader
l_s_reader -> l_s_file_reader: new()
l_s_reader -> l_s_file_reader: set_meta_table()
activate l_s_file_reader
return
l_s_reader -> l_s_reader: file_service_add()
activate l_s_reader
participant FileSystemAdaptor as l_fs_adaptor
participant FileAdaptor as l_file_adaptor
l_s_reader -> "FileServiceImpl Singleton" as FileServiceImpl: add_reader(SnapshotFileReader)

activate FileServiceImpl
return add file to FileServiceImpl finish
return add file into service finish
l_s_file_reader o<-[#red]->o FileServiceImpl : channel to read snapshot file

return generatre uri finish
l_replicator -> l_s_reader: load_meta(), meta table\nwill be sent to follower later
activate l_s_reader
return

end box

box Follower #LightYellow
l_replicator ->> NodeImpl: handle_install_snapshot_request(async rpc)
Activate NodeImpl
l_replicator -> Replicator_Entry_RPC: launch install snapshot finish

deactivate l_replicator

NodeImpl -> SnapshotExecutor: install_snapshot(done)
activate SnapshotExecutor

SnapshotExecutor -> SnapshotExecutor: register_downloading_snapshot()
activate SnapshotExecutor
participant LocalSnapshotStorage as f_storage
SnapshotExecutor -> f_storage : start_to_copy_from()
activate f_storage
create LocalSnapshotCopier
f_storage -> LocalSnapshotCopier : new()

create RemoteFileCopier
LocalSnapshotCopier -> RemoteFileCopier : create
note right : copy file from leader by rpc
RemoteFileCopier o<-[#red]->o FileServiceImpl : channel of file transfer

create LocalSnapshot

LocalSnapshotCopier -> LocalSnapshot : create
note right : Describe the Snapshot on another machine

f_storage -> LocalSnapshotCopier : init()
activate LocalSnapshotCopier

LocalSnapshotCopier -> RemoteFileCopier: init()
activate RemoteFileCopier
return RemoteFileCopier\ninit finish

return init finish

f_storage ->> LocalSnapshotCopier : copy(), trigger async copy
activate LocalSnapshotCopier
f_storage -->> SnapshotExecutor: start copier finish
deactivate f_storage

SnapshotExecutor -->> SnapshotExecutor: register_downloading_snapshot finish
deactivate SnapshotExecutor

LocalSnapshotCopier -> LocalSnapshotCopier: load_meta_table()
activate LocalSnapshotCopier
LocalSnapshotCopier -> RemoteFileCopier: start_to_copy_to_iobuf()
activate RemoteFileCopier
create "RemoteFileCopier::session" as f_session1
RemoteFileCopier -> f_session1: new()
return start_to_copy_to_iobuf finish, return one session
LocalSnapshotCopier -> f_session1: join(), wait for meta table read by rpc
activate f_session1
return read meta table finish
LocalSnapshotCopier -> LocalSnapshot: set meta table
activate LocalSnapshot 
return
return load_meta_table() finish
LocalSnapshotCopier -> LocalSnapshotCopier: filter()
activate LocalSnapshotCopier
LocalSnapshotCopier -> f_storage : create()
activate f_storage
create LocalSnapshotWriter as f_s_writer
f_storage -> f_s_writer : new()

f_storage -> LocalSnapshotCopier : create LocalSnapshotWriter
deactivate f_storage
LocalSnapshotCopier -> f_s_writer : save_meta(meta_table)
activate f_s_writer
return save meta which is acquired by rpc
LocalSnapshotCopier -> f_s_writer : sync()
activate f_s_writer
return sync meta table to disk
LocalSnapshotCopier -> LocalSnapshotCopier : filter() finish, with LocalSnapshotWriter created
deactivate LocalSnapshotCopier
LocalSnapshotCopier -> LocalSnapshot: list_files()
note right: list files\nto copy
activate LocalSnapshot
return

loop "loop all files to copy"

LocalSnapshotCopier -> LocalSnapshotCopier: copy_file(file_name)
activate LocalSnapshotCopier

LocalSnapshotCopier -> LocalSnapshot : get_file_meta
activate LocalSnapshot
return

LocalSnapshotCopier -> RemoteFileCopier: start_to_copy_to_file() async
activate RemoteFileCopier
participant FileSystemAdaptor as f_fs_adaptor
RemoteFileCopier -> f_fs_adaptor: open()
activate f_fs_adaptor
create FileAdaptor as f_file_adaptor
f_fs_adaptor ->  f_file_adaptor: new()
return get FileAdaptor
create "RemoteFileCopier::session" as f_session2
RemoteFileCopier -> f_session2: new()
return start copy file finish, return one session

loop get file by segment using rpc
f_session2 -> FileServiceImpl: get_file by segment
activate FileServiceImpl
FileServiceImpl -> l_s_file_reader: read_file()
activate l_s_file_reader
l_s_file_reader -> l_s_file_reader: get file meta from meta_table
activate l_s_file_reader
return get file meta
l_s_file_reader -> l_s_file_reader: read_file_with_meta()
activate l_s_file_reader

l_s_file_reader -> l_fs_adaptor: open()
activate l_fs_adaptor
l_fs_adaptor -> l_file_adaptor: new()
return new FileAdaptor

l_s_file_reader -> l_file_adaptor: read()
activate l_file_adaptor
return read data segment from file

return
return read_file() finish, only a segment
return get one segment of file
f_session2 -> f_file_adaptor: write(seg_data)
activate f_file_adaptor
return
end

LocalSnapshotCopier -> f_session2 : join(), wait to copy one file
activate f_session2
f_session2 -> f_file_adaptor !!: destruct
return copy one file finish
LocalSnapshotCopier -> f_s_writer: add_file(file_name)
activate f_s_writer
return add one file into meta table
LocalSnapshotCopier -> f_s_writer: sync
activate f_s_writer
return sync meta table to disk
LocalSnapshotCopier -> f_session2 !! :destruct 

LocalSnapshotCopier -> LocalSnapshotCopier : copy file finish
deactivate LocalSnapshotCopier

end

LocalSnapshotCopier -> f_storage: close(writer) << writer realease >>
activate f_storage
f_storage -> f_s_writer !! : destruct
return

LocalSnapshotCopier -> f_storage: open() << create reader >>
activate f_storage

create LocalSnapshotReader as f_s_reader

f_storage -> f_s_reader: new

return 
deactivate LocalSnapshotCopier

SnapshotExecutor ->> LocalSnapshotCopier:join(), wait for snapshot copy
activate LocalSnapshotCopier

LocalSnapshotCopier -->> SnapshotExecutor: copy() done
deactivate LocalSnapshotCopier

SnapshotExecutor -> SnapshotExecutor : load_downloading_snapshot()
activate SnapshotExecutor
SnapshotExecutor -> LocalSnapshotCopier: get_reader()
activate LocalSnapshotCopier
return get reader

SnapshotExecutor -> f_storage: close(copier)
activate f_storage
f_storage -> LocalSnapshotCopier !! : destruct
return close snapshot storage and copier

create InstallSnapshotDone
SnapshotExecutor -> InstallSnapshotDone: new (with reader)
participant SMCaller as f_sm_caller
SnapshotExecutor ->> f_sm_caller : on_snapshot_load(InstallSnapshotDone)
activate f_sm_caller

SnapshotExecutor -> SnapshotExecutor: launch load_downloading_snapshot() finish
deactivate SnapshotExecutor
SnapshotExecutor -> NodeImpl: copy snapshot and\nlaunch load snapshot finish 
deactivate NodeImpl
deactivate SnapshotExecutor
f_sm_caller -> InstallSnapshotDone: start()
activate InstallSnapshotDone
return get reader

f_sm_caller -> f_s_reader: load_meta()
activate f_s_reader
return
participant StateMachine as f_sm
f_sm_caller -> f_sm: on_snapshot\n_load(reader) 
activate f_sm
return
f_sm_caller -> InstallSnapshotDone: run(done)

deactivate f_sm_caller
activate InstallSnapshotDone
InstallSnapshotDone -->> SnapshotExecutor: on_snapshot_load_done()
activate SnapshotExecutor
SnapshotExecutor -->> l_replicator: _on_install_snapshot_returned(async rpc finish)
deactivate SnapshotExecutor

activate l_replicator
deactivate l_replicator
InstallSnapshotDone -> f_storage: close(reader) on destruct
activate f_storage
f_storage -> f_s_reader !! : destruct
return
deactivate InstallSnapshotDone

end box
@enduml
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末桑李,一起剝皮案震驚了整個濱河市踱蛀,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌贵白,老刑警劉巖率拒,帶你破解...
    沈念sama閱讀 206,839評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異禁荒,居然都是意外死亡猬膨,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,543評論 2 382
  • 文/潘曉璐 我一進店門呛伴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來勃痴,“玉大人谒所,你說我怎么就攤上這事≌僭牛” “怎么了?”我有些...
    開封第一講書人閱讀 153,116評論 0 344
  • 文/不壞的土叔 我叫張陵褐隆,是天一觀的道長污它。 經(jīng)常有香客問我,道長庶弃,這世上最難降的妖魔是什么衫贬? 我笑而不...
    開封第一講書人閱讀 55,371評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮歇攻,結(jié)果婚禮上固惯,老公的妹妹穿的比我還像新娘。我一直安慰自己缴守,他們只是感情好葬毫,可當(dāng)我...
    茶點故事閱讀 64,384評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著屡穗,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上芥被,一...
    開封第一講書人閱讀 49,111評論 1 285
  • 那天葫笼,我揣著相機與錄音,去河邊找鬼础废。 笑死汛骂,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的评腺。 我是一名探鬼主播帘瞭,決...
    沈念sama閱讀 38,416評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼蒿讥!你這毒婦竟也來了图张?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,053評論 0 259
  • 序言:老撾萬榮一對情侶失蹤诈悍,失蹤者是張志新(化名)和其女友劉穎祸轮,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體侥钳,經(jīng)...
    沈念sama閱讀 43,558評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡适袜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,007評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了舷夺。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片苦酱。...
    茶點故事閱讀 38,117評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡售貌,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出疫萤,到底是詐尸還是另有隱情颂跨,我是刑警寧澤,帶...
    沈念sama閱讀 33,756評論 4 324
  • 正文 年R本政府宣布扯饶,位于F島的核電站恒削,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏尾序。R本人自食惡果不足惜钓丰,卻給世界環(huán)境...
    茶點故事閱讀 39,324評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望每币。 院中可真熱鬧携丁,春花似錦、人聲如沸兰怠。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,315評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽揭保。三九已至尚揣,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間掖举,已是汗流浹背快骗。 一陣腳步聲響...
    開封第一講書人閱讀 31,539評論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留塔次,地道東北人方篮。 一個月前我還...
    沈念sama閱讀 45,578評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像励负,于是被迫代替她去往敵國和親藕溅。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,877評論 2 345

推薦閱讀更多精彩內(nèi)容