-
Notifications
You must be signed in to change notification settings - Fork 284
Add file-based persistent log store and state manager #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ | |
| add_executable(calc_server | ||
| calculator/calc_server.cxx | ||
| logger.cc | ||
| in_memory_log_store.cxx) | ||
| in_memory_log_store.cxx | ||
| file_based_log_store.cxx) | ||
|
|
||
| # add_dependencies(calc_server | ||
| # ${LIBRARY_NAME}) | ||
|
|
@@ -14,7 +15,8 @@ target_link_libraries(calc_server | |
| add_executable(echo_server | ||
| echo/echo_server.cxx | ||
| logger.cc | ||
| in_memory_log_store.cxx) | ||
| in_memory_log_store.cxx | ||
| file_based_log_store.cxx) | ||
| # add_dependencies(echo_server | ||
| # ${LIBRARY_NAME}) | ||
| target_link_libraries(echo_server | ||
|
|
@@ -24,7 +26,8 @@ target_link_libraries(echo_server | |
| add_executable(quick_start | ||
| quick_start.cxx | ||
| logger.cc | ||
| in_memory_log_store.cxx) | ||
| in_memory_log_store.cxx | ||
| file_based_log_store.cxx) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
| # add_dependencies(quick_start | ||
| # ${LIBRARY_NAME}) | ||
| target_link_libraries(quick_start | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,21 @@ using namespace nuraft; | |
|
|
||
| using raft_result = cmd_result< ptr<buffer> >; | ||
|
|
||
| // Global flag to enable persistent storage. | ||
| // If true, file-based storage will be used instead of in-memory. | ||
| static bool USE_PERSISTENT_STORAGE = false; | ||
|
|
||
| // Directory for persistent storage. | ||
| static std::string PERSISTENT_STORAGE_DIR = "./nuraft_data"; | ||
|
|
||
| // Helper to set persistent storage options. | ||
| inline void set_persistent_storage(bool enable, const std::string& dir = "./nuraft_data") { | ||
| USE_PERSISTENT_STORAGE = enable; | ||
| if (enable) { | ||
| PERSISTENT_STORAGE_DIR = dir; | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+24
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are used by
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +) |
||
| struct server_stuff { | ||
| server_stuff() | ||
| : server_id_(1) | ||
|
|
@@ -155,10 +170,18 @@ void init_raft(ptr<state_machine> sm_instance) { | |
| ptr<logger_wrapper> log_wrap = cs_new<logger_wrapper>( log_file_name, 4 ); | ||
| stuff.raft_logger_ = log_wrap; | ||
|
|
||
| // State manager: use persistent or in-memory based on flag. | ||
| if (USE_PERSISTENT_STORAGE) { | ||
| std::cout << "using persistent storage: " << PERSISTENT_STORAGE_DIR << std::endl; | ||
| stuff.smgr_ = cs_new<file_based_state_mgr>( stuff.server_id_, | ||
| stuff.endpoint_, | ||
| PERSISTENT_STORAGE_DIR ); | ||
| } else { | ||
| std::cout << "using in-memory storage" << std::endl; | ||
| stuff.smgr_ = cs_new<inmem_state_mgr>( stuff.server_id_, | ||
| stuff.endpoint_ ); | ||
| } | ||
|
Comment on lines
+173
to
+183
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, I suggest modifying |
||
| // State machine. | ||
| stuff.smgr_ = cs_new<inmem_state_mgr>( stuff.server_id_, | ||
| stuff.endpoint_ ); | ||
| // State manager. | ||
| stuff.sm_ = sm_instance; | ||
|
|
||
| // ASIO options. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo_serverwill not use it, after it is removed fromexample_common.hxx.