A C++ Raft implementation, project moved
C++
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
.gitignore
LICENSE
LICENSE_1_0.txt
Makefile.bsd
Makefile.lx
Makefile.win
README.md
asio_service.cxx
asio_service.hxx
async.hxx
basic_types.hxx
buffer.cxx
buffer.hxx
cluster_config.cxx
cluster_config.hxx
context.hxx
cornerstone.hxx
cornerstone.vcxproj
cornerstone.vcxproj.filters
delayed_task.hxx
delayed_task_scheduler.hxx
fs_log_store.cxx
fs_log_store.hxx
log_entry.hxx
log_store.hxx
log_val_type.hxx
logger.hxx
msg_base.hxx
msg_type.hxx
peer.cxx
peer.hxx
pp_util.hxx
ptr.hxx
raft_params.hxx
raft_server.cxx
raft_server.hxx
req_msg.hxx
resp_msg.hxx
rpc_cli.hxx
rpc_cli_factory.hxx
rpc_exception.hxx
rpc_listener.hxx
snapshot.cxx
snapshot.hxx
snapshot_sync_ctx.hxx
snapshot_sync_req.cxx
snapshot_sync_req.hxx
sources
srv_config.cxx
srv_config.hxx
srv_role.hxx
srv_state.hxx
state_machine.hxx
state_mgr.hxx
strfmt.hxx
timer_task.hxx

README.md

cornerstone

Another Raft C++ Implementation

Project moved

Please be noted that this project is no longer maintained, I will not fix any bugs, neither have new features in this project anymore, however, I have found a team to take over this for me, the code has been re-organized and published at cornerstone, the team will start from there and make it under Apache 2, nothing is changed, but better support and more features on it

The core algorithm is implemented based on the TLA+ spec, whose safety and liveness are proven, this implementation is copied from jraft but replace java code with C++

Updates and Plan

  • As memory goes big, GC may not be as efficient as memory tracking, introduced ptr<T> to this project to manage pointers
  • having a memory pool to improve the performance, this may not be done in this project, another project called jitl is on going to lead a new life style for c++ coders
  • started working on file based log store, as raft's store accessing pattern is very special, file based would be the fastest one (not prove yet)
  • update fs_log_store to make the test pass and add more test cases for it
  • asio based rpc client and rpc servers
  • go real (have this into a product)

Supported Features,

  • Core Algorithm, safety, liveness are proven
  • Configuration Change Support, add or remove servers one by one without limitation
  • Client Request Support, to be enhanced, but is working now.
  • Urgent commit, see below
  • log compaction

Urgent Commit, is a new feature introduced by this implementation, which enables the leader asks all other servers to commit one or more logs if commit index is advanced. With Urgent Commit, the system's performance is highly improved and the heartbeat interval could be increased to seconds,depends on how long your application can abide when a leader goes down, usually, one or two seconds is fine.

About this implementation

it's always safer to implement such kind of algorithm based on Math description other than natural languge description. there should be an auto conversion from TLA+ to programming languages, even they are talking things in different ways, but they are identical

Code Structure

I know it's lack of documentations, I will try my best, but if you can help, let me know. This project has core algorithm implementation only for now, we also rely on asio library for timer and in future for tcp based cli/srv communications

For how to use the code, please refer to tests/test_impls.cxx for interfaces that you need to implement, for log_store and state_machine implementations, it's your own resposibility to take care of locking.

It could be built on Windows (Makefile.win, nmake), Linux (Makefile.lx, gnu make) and FreeBSD (Makefile.bsd, pmake)

Coding Hints

Now, I resolve all pointer issues with ptr, which is better than shared_ptr, ptr is pretty customized for cornerstone project only, however, it should meet most of your requirements, use cs_new to create ptr

please write me if you have any question about using this