美文网首页
braft 快照拉取流程

braft 快照拉取流程

作者: GOGOYAO | 来源:发表于2022-05-10 20:09 被阅读0次

整体过程

快照的拉取分为主从两端。快照都是通过主节点主动发起的。

  • 主(Leader):负责快照的生成,并负责触发快照发送任务。
  • 从(Follower):负责接收快照数据,并加载快照到本地

生成快照

快照生成时序图

传输快照

传输快照时序图

附录

快照生成时序图

@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

相关文章

  • braft 快照拉取流程

    整体过程 快照的拉取分为主从两端。快照都是通过主节点主动发起的。 主(Leader):负责快照的生成,并负责触发快...

  • Glide源码分析

    它支持拉取、解码、展示,视频快照、图片和GIF动画。提供了易用的API,高性能、可扩展的图片解码管道(decode...

  • Maven 开启SNAPSHOT

    Maven默认不拉取快照包,需要添加以下配置: 注意: 必须在 中添加profile.id ,而且一定要对应上

  • 模拟公司中使用的Git

    通过Git地址克隆项目 基本提交流程: 拉取流程: 冲突解决: git pull 与 git fetch的区...

  • Git

    ——— 可能理解有误,记下笔记加深理解吧~ TortoiseGit 基本流程: 提交 → 拉取 → (解决...

  • 关于Git的基础操作流程(参考)

    一、基础操作: 克隆/签出 远程代码到本地的流程: 1.签出、拉取、提交代码流程 git clone https:...

  • Sqoop 拉取数据流程

    考虑离线数据定时从SQL Server 数据库,批量导入到hive数据表。具体执行流程如下: 根据以上执行流程分别...

  • braft-editor使用

    本文的示例代码参考braft-editor 目录 DvaJS braft-editor 七牛云 DvaJS bra...

  • Ceph块存储-2·镜像快照创建&回滚流程

    一、创建和回滚的思路及流程: 创建快照: 创建镜像 映射镜像 格式化后挂载 创建快照 快照回滚: 删除数据 卸载挂...

  • Git使用中的点点滴滴

    1、push提交流程 git clone xxx #克隆工程 git pull #拉取/对齐 git add xx...

网友评论

      本文标题:braft 快照拉取流程

      本文链接:https://www.haomeiwen.com/subject/jtipyrtx.html