@@ -41,12 +41,13 @@ namespace nuraft {
41
41
42
42
void raft_server::commit (ulong target_idx) {
43
43
bool track_peers_sm_commit_idx = ctx_->get_params ()->track_peers_sm_commit_idx_ ;
44
+ bool same_target_idx = (target_idx == quick_commit_index_);
44
45
if (target_idx > quick_commit_index_ ||
45
- (track_peers_sm_commit_idx &&
46
- target_idx >= quick_commit_index_)) {
46
+ (track_peers_sm_commit_idx && same_target_idx)) {
47
+ p_db ( " trigger commit upto %" PRIu64 " , current quick commit index %" PRIu64,
48
+ target_idx, quick_commit_index_.load () );
47
49
quick_commit_index_ = target_idx;
48
50
lagging_sm_target_index_ = target_idx;
49
- p_db ( " trigger commit upto %" PRIu64 " " , quick_commit_index_.load () );
50
51
51
52
// if this is a leader notify peers to commit as well
52
53
// for peers that are free, send the request, otherwise,
@@ -60,6 +61,11 @@ void raft_server::commit(ulong target_idx) {
60
61
// upto the target index. No need to send AE.
61
62
continue ;
62
63
}
64
+ if (track_peers_sm_commit_idx &&
65
+ same_target_idx &&
66
+ pp->get_sm_committed_idx () == 0 ) {
67
+ continue ;
68
+ }
63
69
if (!request_append_entries (pp)) {
64
70
pp->set_pending_commit ();
65
71
}
@@ -316,7 +322,8 @@ bool raft_server::commit_in_bg_exec(size_t timeout_ms) {
316
322
}
317
323
}
318
324
319
- if (check_sm_commit_notify_ready (index_to_commit)) {
325
+ if (ctx_->get_params ()->track_peers_sm_commit_idx_ &&
326
+ check_sm_commit_notify_ready (index_to_commit)) {
320
327
uint64_t target_idx = update_sm_commit_notifier_target_idx (index_to_commit);
321
328
p_tr (" sm commit notify ready: %" PRIu64 " , target: %" PRIu64,
322
329
index_to_commit, target_idx);
@@ -510,9 +517,13 @@ void raft_server::commit_conf(ulong idx_to_commit,
510
517
}
511
518
512
519
void raft_server::scan_sm_commit_and_notify (uint64_t idx_upto) {
520
+ auto params = ctx_->get_params ();
521
+ if (params->track_peers_sm_commit_idx_ == false ) {
522
+ return ;
523
+ }
524
+
513
525
p_tr (" sm commit notifier scan start, upto %" PRIu64, idx_upto);
514
526
515
- auto params = ctx_->get_params ();
516
527
std::list< ptr<commit_ret_elem> > async_elems;
517
528
518
529
std::unique_lock<std::mutex> cre_lock (commit_ret_elems_lock_);
@@ -572,8 +583,12 @@ bool raft_server::check_sm_commit_notify_ready(uint64_t idx) {
572
583
// that means it is excluded from the quorum.
573
584
continue ;
574
585
}
575
- if (pp.second ->get_sm_committed_idx () < idx) {
586
+ if (pp.second ->get_sm_committed_idx () &&
587
+ pp.second ->get_sm_committed_idx () < idx) {
576
588
// At least one peer's lag is enough to return false.
589
+ //
590
+ // WARNING: We should exclude 0, in case that there are member
591
+ // without tracking peer sm mode.
577
592
return false ;
578
593
}
579
594
}
0 commit comments