-
Notifications
You must be signed in to change notification settings - Fork 241
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
commit_ret_elems_ performance improvement and enclose basic types with namespace #142
Changes from all commits
2cafb41
dfdca71
5afc198
aeb70ea
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode/ | ||
build | ||
debug/ | ||
Debug/ | ||
.vs/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ if (BOOST_INCLUDE_PATH AND BOOST_LIBRARY_PATH) | |
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_ASIO") | ||
|
||
set(ASIO_INCLUDE_DIR ${BOOST_INCLUDE_PATH}) | ||
set(ASIO_INCLUDE_DIR ${BOOST_INCLUDE_PATH}/boost) | ||
set(LIBBOOST_SYSTEM "${BOOST_LIBRARY_PATH}/libboost_system.a") | ||
|
||
else () | ||
|
@@ -60,6 +60,10 @@ endif () | |
|
||
# === Includes === | ||
include_directories(BEFORE ./) | ||
if (BOOST_INCLUDE_PATH) | ||
message(STATUS "Boost include path: " ${BOOST_INCLUDE_PATH}) | ||
include_directories(BEFORE ${BOOST_INCLUDE_PATH}) | ||
endif () | ||
Comment on lines
+63
to
+66
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. Boost include path is already printed out at line 32 above. And also 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. As said this is my first PR, actually this cmake file change is for my own use only and I actually have no intention to make PR for this. Sorry for bother you. |
||
include_directories(BEFORE ${ASIO_INCLUDE_DIR}) | ||
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/include) | ||
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/include/libnuraft) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ limitations under the License. | |
|
||
#include <cstdint> | ||
|
||
namespace nuraft { | ||
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. Can you please make this change as a separate PR? Thanks. 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. ok |
||
|
||
typedef uint64_t ulong; | ||
typedef int64_t int64; | ||
typedef void* any_ptr; | ||
|
@@ -31,4 +33,6 @@ typedef uint16_t ushort; | |
typedef uint32_t uint; | ||
typedef int32_t int32; | ||
|
||
} | ||
|
||
#endif // _BASIC_TYPES_HXX_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ public: | |
* @param port_number Port number. | ||
* @param asio_options ASIO options. | ||
* @param params Raft parameters. | ||
* @param raft_callback Callback function for hooking the operation. | ||
* @return Raft server instance. | ||
* `nullptr` on any errors. | ||
*/ | ||
|
@@ -45,7 +46,8 @@ public: | |
ptr<logger> lg, | ||
int port_number, | ||
const asio_service::options& asio_options, | ||
const raft_params& params); | ||
const raft_params& params, | ||
cb_func::func_type raft_callback = nullptr); | ||
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. As I mentioned in the other comment, can you please replace this line with 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. understood and noted |
||
|
||
/** | ||
* Shutdown Raft server and ASIO service. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ struct raft_params { | |
, auto_adjust_quorum_for_small_cluster_(false) | ||
, locking_method_type_(dual_mutex) | ||
, return_method_(blocking) | ||
, skip_initial_election_timeout_(false) | ||
{} | ||
|
||
/** | ||
|
@@ -472,6 +473,17 @@ public: | |
* To choose blocking call or asynchronous call. | ||
*/ | ||
return_method_type return_method_; | ||
|
||
/** | ||
* If `true`, the election timer will not be initiated | ||
* automatically, so that this node will never trigger | ||
* leader election until it gets the first heartbeat | ||
* from any valid leader. | ||
* | ||
* Purpose: to avoid becoming leader when there is only one | ||
* node in the cluster. | ||
*/ | ||
bool skip_initial_election_timeout_; | ||
Comment on lines
+476
to
+486
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.
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. understood and noted |
||
}; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,12 +269,10 @@ void raft_server::commit_app_log(ulong idx_to_commit, | |
if (need_to_handle_commit_elem) { | ||
std::unique_lock<std::mutex> cre_lock(commit_ret_elems_lock_); | ||
bool match_found = false; | ||
auto entry = commit_ret_elems_.begin(); | ||
while (entry != commit_ret_elems_.end()) { | ||
auto entry = commit_ret_elems_.find(sm_idx); | ||
if (entry != commit_ret_elems_.end()) { | ||
ptr<commit_ret_elem> elem = entry->second; | ||
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. Changes regarding
Due to the racing between user and commit threads, Please note that, in most cases, there won't be notable performance degradation caused by 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. Actually the changes regarding And for Besides the lock, for |
||
if (elem->idx_ > sm_idx) { | ||
break; | ||
} else if (elem->idx_ == sm_idx) { | ||
if (elem->idx_ == sm_idx) { | ||
elem->result_code_ = cmd_result_code::OK; | ||
elem->ret_value_ = ret_value; | ||
match_found = true; | ||
|
@@ -284,21 +282,23 @@ void raft_server::commit_app_log(ulong idx_to_commit, | |
case raft_params::blocking: | ||
default: | ||
// Blocking mode: invoke waiting function. | ||
cre_lock.unlock(); | ||
elem->awaiter_.invoke(); | ||
entry++; | ||
break; | ||
|
||
case raft_params::async_handler: | ||
// Async handler: put into list. | ||
commit_ret_elems_.erase(entry); | ||
cre_lock.unlock(); | ||
async_elems.push_back(elem); | ||
entry = commit_ret_elems_.erase(entry); | ||
break; | ||
} | ||
|
||
} else { | ||
entry++; | ||
} | ||
} | ||
if (cre_lock.owns_lock()) | ||
{ | ||
cre_lock.unlock(); | ||
} | ||
|
||
if (!match_found) { | ||
// If not found, commit thread is invoked earlier than user thread. | ||
|
@@ -311,7 +311,9 @@ void raft_server::commit_app_log(ulong idx_to_commit, | |
case raft_params::blocking: | ||
default: | ||
elem->awaiter_.invoke(); // Callback will not sleep. | ||
cre_lock.lock(); | ||
commit_ret_elems_.insert( std::make_pair(sm_idx, elem) ); | ||
cre_lock.unlock(); | ||
break; | ||
case raft_params::async_handler: | ||
// Async handler: put into list. | ||
|
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.
This line is unnecessary, you can set the variable as
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.
As said this is my first PR, actually this cmake file change is for my own use only and I actually have no intention to make PR for this. Sorry for bother you.