Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/lintanghui/braft
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 24, 2023
2 parents 2e34921 + d260d29 commit 91ac60a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/braft/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ int NodeImpl::init(const NodeOptions& options) {
CHECK_EQ(0, _election_timer.init(this, options.election_timeout_ms * 2));
CHECK_EQ(0, _vote_timer.init(this, options.election_timeout_ms * 2 + options.max_clock_drift_ms));
}
}else {
} else {
CHECK_EQ(0, _election_timer.init(this, options.election_timeout_ms));
CHECK_EQ(0, _vote_timer.init(this, options.election_timeout_ms + options.max_clock_drift_ms));
}
Expand Down
16 changes: 12 additions & 4 deletions src/braft/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,18 @@ struct NodeOptions {
// Default: false
bool disable_cli;

// if true, this node is a witness, when FLAGS_raft_enable_witness_to_leader is false,
// it will never be elected as leader. so we don't need to init _vote_timer and _election_timer.
// if FLAGS_raft_enable_witness_to_leader is true, it can be electd as leader,
// but should transfer leader to normal replica as soon as possible.
// If true, this node is a witness.
// 1. FLAGS_raft_enable_witness_to_leader = false
// It will never be elected as leader. So we don't need to init _vote_timer and _election_timer.
// 2. FLAGS_raft_enable_witness_to_leader = true
// It can be electd as leader, but should transfer leader to normal replica as soon as possible.
//
// Warning:
// 1. FLAGS_raft_enable_witness_to_leader = false
// When leader down and witness had newer log entry, it may cause leader election fail.
// 2. FLAGS_raft_enable_witness_to_leader = true
// When leader shutdown and witness was elected as leader, if follower delay over one snapshot,
// it may cause data lost because witness had truncated log entry before snapshot.
// Default: false
bool witness = false;
// Construct a default instance
Expand Down
7 changes: 7 additions & 0 deletions src/braft/replicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ void Replicator::wait_for_caught_up(ReplicatorId id,
}

void* Replicator::_on_block_timedout_in_new_thread(void* arg) {
Replicator* r = NULL;
bthread_id_t id = { (uint64_t)arg };
if (bthread_id_lock(id, (void**)&r) != 0) {
return NULL;
}
r->_st.st = IDLE;
bthread_id_unlock(id);
Replicator::_continue_sending(arg, ETIMEDOUT);
return NULL;
}
Expand Down

0 comments on commit 91ac60a

Please sign in to comment.