OpenAtomFoundation / pikiwidb

a high-performance, large-capacity, multi-tenant, data-persistent, strong data consistency based on raft, Redis-compatible elastic KV data storage system based on RocksDB
BSD 3-Clause "New" or "Revised" License
194 stars 63 forks source link

feat: overload the PosixFileSystemAdaptor interface to generate real snapshot when follower installs snapshot #279

Closed panlei-coder closed 4 months ago

panlei-coder commented 4 months ago

为了支持日常的快照仅仅只是推进日志的截断,避免raft日志过大,占用过多的磁盘空间,在braft代码中更改了Node::Snapshot接口,可以自定义设置快照的截断位置(参考pr:https://github.com/pikiwidb/braft/pull/2)。 同时,需要满足在follower节点需要进行快照安装时能够把leader的快照发送给follower,有两种解决方案: (1)直接在braft代码里修改(参考pr:https://github.com/pikiwidb/braft/pull/3),不过这种方式不是很优雅。 (2)直接重载PosixFileSystemAdaptor::open接口,这个函数在下面图中的FileServiceImpl::get_file接口中调用(file_service.cpp),我们只需要在follower真正读取快照数据之前,同步生成好需要的快照数据即可。此外,还可以根据min(所有Column Family已经持久化到磁盘上的数据的最大SequenceNum对应的log index)设置快照的截断位置,只需要在pikiwidb层修改代码即可,完全不需要修改braft的代码,比较优雅。 leader: image follower image

测试: 运行save_load.sh脚本,脚本中leader连续做了两次数据插入(每次10000条数据)和两次快照截断,第二次执行完成之后快照的截断点在20001,但快照数据是空的,follower节点加入集群之后,截断点为20001的快照被填充了真正的快照数据。 20099feedeb6616bca3ec96a99d4081

AlexStocks commented 4 months ago

有文件冲突,请处理

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


There is a file conflict, please deal with it

dingxiaoshuai123 commented 4 months ago

冲突有点多, 得修改一下

Issues-translate-bot commented 4 months ago

Bot detected the issue body's language is not English, translate it automatically.


There are a lot of conflicts and need to be modified.