Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lhsoft committed May 16, 2024
1 parent d4ce056 commit 5317991
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/braft/fsm_caller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ void FSMCaller::do_stop_following(const LeaderChangeContext& stop_following_cont
_fsm->on_stop_following(stop_following_context);
}

void FSMCaller::on_install_snapshot_start(const PeerId& peer_id) {
_fsm->on_install_snapshot_start(peer_id);
void FSMCaller::on_pre_send_snapshot(const PeerId& peer_id) {
_fsm->on_pre_send_snapshot(peer_id);
}

void FSMCaller::describe(std::ostream &os, bool use_html) {
Expand Down
2 changes: 1 addition & 1 deletion src/braft/fsm_caller.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BAIDU_CACHELINE_ALIGNMENT FSMCaller {
int on_leader_start(int64_t term, int64_t lease_epoch);
int on_start_following(const LeaderChangeContext& start_following_context);
int on_stop_following(const LeaderChangeContext& stop_following_context);
void on_install_snapshot_start(const PeerId& peer_id);
void on_pre_send_snapshot(const PeerId& peer_id);
BRAFT_MOCK int on_error(const Error& e);
int64_t last_applied_index() const {
return _last_applied_index.load(butil::memory_order_relaxed);
Expand Down
4 changes: 4 additions & 0 deletions src/braft/log_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ void LogManager::set_snapshot(const SnapshotMeta* meta) {
// We have last snapshot index
_virtual_first_log_id = last_but_one_snapshot_id;
truncate_prefix(last_but_one_snapshot_id.index + 1, lck);
} else {
// after restart, no followers, we can truncate log safely
_virtual_first_log_id = _last_snapshot_id;
truncate_prefix(meta->last_included_index() + 1, lck);
}
return;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/braft/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,8 @@ void NodeImpl::on_error(const Error& e) {
lck.unlock();
}

void NodeImpl::install_snapshot_start(const PeerId& peer_id) {
_fsm_caller->on_install_snapshot_start(peer_id);
void NodeImpl::pre_send_snapshot(const PeerId& peer_id) {
_fsm_caller->on_pre_send_snapshot(peer_id);
}


Expand Down
4 changes: 2 additions & 2 deletions src/braft/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ friend class VoteBallotCtx;
bool disable_cli() const { return _options.disable_cli; }
bool is_witness() const { return _options.witness; }

// Called when leader start to install snapshot to remote peer
void install_snapshot_start(const PeerId& peer_id);
// Called when leader start to send snapshot to remote peer
void pre_send_snapshot(const PeerId& peer_id);
private:
friend class butil::RefCountedThreadSafe<NodeImpl>;

Expand Down
2 changes: 1 addition & 1 deletion src/braft/raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void StateMachine::on_configuration_committed(const Configuration& conf, int64_t

void StateMachine::on_stop_following(const LeaderChangeContext&) {}
void StateMachine::on_start_following(const LeaderChangeContext&) {}
void StateMachine::on_install_snapshot_start(const PeerId& peer_id) {}
void StateMachine::on_pre_send_snapshot(const PeerId& peer_id) {}

BootstrapOptions::BootstrapOptions()
: last_log_index(0)
Expand Down
2 changes: 1 addition & 1 deletion src/braft/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class StateMachine {

// Invoked when the leader start to send snapshot to |peer_id|
// Default: Do nothing
virtual void on_install_snapshot_start(const PeerId& peer_id);
virtual void on_pre_send_snapshot(const PeerId& peer_id);

};

Expand Down
2 changes: 1 addition & 1 deletion src/braft/replicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void Replicator::_install_snapshot() {
return _block(butil::gettimeofday_us(), EBUSY);
}

node_impl->install_snapshot_start(_options.peer_id);
node_impl->pre_send_snapshot(_options.peer_id);

// pre-set replicator state to INSTALLING_SNAPSHOT, so replicator could be
// blocked if something is wrong, such as throttled for a period of time
Expand Down

0 comments on commit 5317991

Please sign in to comment.