Skip to content

Commit

Permalink
Handle abrupt shutdown better.
Browse files Browse the repository at this point in the history
  • Loading branch information
kishorenc committed Feb 14, 2021
1 parent 6eae4c9 commit b59b01a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/raft_server.cpp
Expand Up @@ -146,7 +146,7 @@ void ReplicationState::write(http_req* request, http_res* response) {
}

void ReplicationState::write_to_leader(http_req *request, http_res *response) const {
if(node->leader_id().is_empty()) {
if(!node || node->leader_id().is_empty()) {
// Handle no leader scenario
LOG(ERROR) << "Rejecting write: could not find a leader.";

Expand Down Expand Up @@ -302,11 +302,6 @@ void ReplicationState::on_apply(braft::Iterator& iter) {
delete request;
delete response;
}

if(shut_down) {
iter.set_error_and_rollback();
return;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/typesense_server_utils.cpp
Expand Up @@ -263,7 +263,7 @@ int start_raft_server(ReplicationState& replication_state, const std::string& st

// Wait until 'CTRL-C' is pressed. then Stop() and Join() the service
size_t raft_counter = 0;
while (!brpc::IsAskedToQuit() && !quit_raft_service.load()) {
while (!quit_raft_service.load()) {
// post-increment to ensure that we refresh right away on a fresh boot
if(raft_counter++ % 10 == 0) {
// reset peer configuration periodically to identify change in cluster membership
Expand Down

0 comments on commit b59b01a

Please sign in to comment.