diff --git a/src/braft/node.cpp b/src/braft/node.cpp index afe57084..67dd6d19 100644 --- a/src/braft/node.cpp +++ b/src/braft/node.cpp @@ -2237,12 +2237,11 @@ void NodeImpl::after_shutdown() { } } -void NodeImpl::handle_install_snapshot_request(brpc::Controller* controller, +void NodeImpl::handle_install_snapshot_request(brpc::Controller* cntl, const InstallSnapshotRequest* request, InstallSnapshotResponse* response, google::protobuf::Closure* done) { brpc::ClosureGuard done_guard(done); - brpc::Controller* cntl = (brpc::Controller*)controller; if (_snapshot_executor == NULL) { cntl->SetFailed(EINVAL, "Not support snapshot"); @@ -2271,7 +2270,7 @@ void NodeImpl::handle_install_snapshot_request(brpc::Controller* controller, // check stale term if (request->term() < _current_term) { LOG(WARNING) << "node " << _group_id << ":" << _server_id - << " ignore stale AppendEntries from " << request->server_id() + << " ignore stale InstallSnapshot from " << request->server_id() << " in term " << request->term() << " current_term " << _current_term; response->set_term(_current_term); @@ -2324,11 +2323,11 @@ butil::Status NodeImpl::read_committed_user_log(const int64_t index, UserLog* us } int64_t cur_index = index; LogEntry* entry = _log_manager->get_entry(cur_index); - if (entry == NULL){ + if (entry == NULL) { return butil::Status(ELOGDELETED, "user log is deleted at index:%" PRId64, index); } do { - if (entry->type == ENTRY_TYPE_DATA){ + if (entry->type == ENTRY_TYPE_DATA) { user_log->set_log_index(cur_index); user_log->set_log_data(entry->data); entry->Release(); diff --git a/src/braft/replicator.cpp b/src/braft/replicator.cpp index a0272d73..f63a3083 100644 --- a/src/braft/replicator.cpp +++ b/src/braft/replicator.cpp @@ -326,9 +326,10 @@ void Replicator::_on_heartbeat_returned( node_impl->Release(); return; } + bool readonly = response->has_readonly() && response->readonly(); BRAFT_VLOG << ss.str() << " readonly " << readonly; - if (rpc_send_time > r->_last_rpc_send_timestamp){ + if (rpc_send_time > r->_last_rpc_send_timestamp) { r->_last_rpc_send_timestamp = rpc_send_time; } r->_start_heartbeat_timer(start_time_us); @@ -775,10 +776,10 @@ void Replicator::_install_snapshot() { _st.st = INSTALLING_SNAPSHOT; _reader = _options.snapshot_storage->open(); - if (!_reader){ + if (!_reader) { if (_options.snapshot_throttle) { _options.snapshot_throttle->finish_one_task(true); - } + } NodeImpl *node_impl = _options.node; node_impl->AddRef(); CHECK_EQ(0, bthread_id_unlock(_id)) << "Fail to unlock " << _id; @@ -802,7 +803,7 @@ void Replicator::_install_snapshot() { } SnapshotMeta meta; // report error on failure - if (_reader->load_meta(&meta) != 0){ + if (_reader->load_meta(&meta) != 0) { std::string snapshot_path = _reader->get_path(); NodeImpl *node_impl = _options.node; node_impl->AddRef(); diff --git a/src/braft/snapshot_executor.cpp b/src/braft/snapshot_executor.cpp index 1aba640e..1971affd 100644 --- a/src/braft/snapshot_executor.cpp +++ b/src/braft/snapshot_executor.cpp @@ -395,7 +395,7 @@ void SnapshotExecutor::install_snapshot(brpc::Controller* cntl, SnapshotMeta meta = request->meta(); // check if install_snapshot tasks num exceeds threshold - if (_snapshot_throttle && !_snapshot_throttle->add_one_more_task(false)){ + if (_snapshot_throttle && !_snapshot_throttle->add_one_more_task(false)) { LOG(WARNING) << "Fail to install snapshot"; cntl->SetFailed(EBUSY, "Fail to add install_snapshot tasks now"); return; @@ -429,7 +429,7 @@ void SnapshotExecutor::install_snapshot(brpc::Controller* cntl, done_guard.release(); CHECK(_cur_copier); _cur_copier->join(); - // when coping finished or canceled, more install_snapshot tasks are allowed + // when copying finished or canceled, more install_snapshot tasks are allowed if (_snapshot_throttle) { _snapshot_throttle->finish_one_task(false); } @@ -553,12 +553,12 @@ int SnapshotExecutor::register_downloading_snapshot(DownloadingSnapshot* ds) { rc = 1; } else if (m->request->meta().last_included_index() > ds->request->meta().last_included_index()) { - // |is| is older + // |ds| is older LOG(WARNING) << "Register failed: is installing a newer one."; ds->cntl->SetFailed(EINVAL, "A newer snapshot is under installing"); return -1; } else { - // |is| is newer + // |ds| is newer if (_loading_snapshot) { // We can't interrupt the loading one LOG(WARNING) << "Register failed: is loading an older snapshot."; diff --git a/test/memory_file_system_adaptor.h b/test/memory_file_system_adaptor.h index 8706d8d7..deec27cd 100644 --- a/test/memory_file_system_adaptor.h +++ b/test/memory_file_system_adaptor.h @@ -276,7 +276,7 @@ class MemoryFileSystemAdaptor : public braft::FileSystemAdaptor { continue; } else if (sub_path.BaseName().value() == "..") { ++ignore; - } else if (ignore > 0){ + } else if (ignore > 0) { --ignore; } else { subpaths.push_back(sub_path.BaseName()); @@ -358,7 +358,7 @@ class MemoryFileSystemAdaptor : public braft::FileSystemAdaptor { continue; } else if (sub_path.BaseName().value() == "..") { ++ignore; - } else if (ignore > 0){ + } else if (ignore > 0) { --ignore; } else { subpaths.push_back(sub_path.BaseName());