From 4e9ae641a3974817f03519ae3f8adb41f494ecd1 Mon Sep 17 00:00:00 2001 From: sduzh Date: Thu, 25 Apr 2019 15:25:58 +0800 Subject: [PATCH 1/4] Fix code style --- src/braft/node.cpp | 4 ++-- src/braft/replicator.cpp | 8 ++++---- src/braft/snapshot_executor.cpp | 2 +- test/memory_file_system_adaptor.h | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/braft/node.cpp b/src/braft/node.cpp index 6a8ed5ac..8a26a630 100644 --- a/src/braft/node.cpp +++ b/src/braft/node.cpp @@ -2265,11 +2265,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 d2f9839f..c66b7e45 100644 --- a/src/braft/replicator.cpp +++ b/src/braft/replicator.cpp @@ -313,7 +313,7 @@ void Replicator::_on_heartbeat_returned( return; } BRAFT_VLOG << " success"; - 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); @@ -696,10 +696,10 @@ void Replicator::_install_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; @@ -713,7 +713,7 @@ void Replicator::_install_snapshot() { std::string uri = _reader->generate_uri_for_copy(); 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 177d7229..981f5081 100644 --- a/src/braft/snapshot_executor.cpp +++ b/src/braft/snapshot_executor.cpp @@ -386,7 +386,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; diff --git a/test/memory_file_system_adaptor.h b/test/memory_file_system_adaptor.h index 1bce5bfa..8450e7c1 100644 --- a/test/memory_file_system_adaptor.h +++ b/test/memory_file_system_adaptor.h @@ -271,7 +271,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()); @@ -353,7 +353,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()); From b69ef60ce9c41eaa0b9cc41be134625f9ced9621 Mon Sep 17 00:00:00 2001 From: sduzh Date: Thu, 25 Apr 2019 17:31:12 +0800 Subject: [PATCH 2/4] Fix typo --- src/braft/node.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/braft/node.cpp b/src/braft/node.cpp index 8a26a630..2b5cc8fc 100644 --- a/src/braft/node.cpp +++ b/src/braft/node.cpp @@ -2178,12 +2178,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"); @@ -2212,7 +2211,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); From e539db4da1b1a15536565a30e91ea3fdb89c86bc Mon Sep 17 00:00:00 2001 From: sduzh Date: Thu, 25 Apr 2019 19:24:25 +0800 Subject: [PATCH 3/4] coping -> copying --- src/braft/snapshot_executor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/braft/snapshot_executor.cpp b/src/braft/snapshot_executor.cpp index 981f5081..25da9107 100644 --- a/src/braft/snapshot_executor.cpp +++ b/src/braft/snapshot_executor.cpp @@ -418,7 +418,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); } From dcc204ef0510d4fed595bbf0ec2f6b637799e4eb Mon Sep 17 00:00:00 2001 From: sduzh Date: Thu, 25 Apr 2019 19:47:51 +0800 Subject: [PATCH 4/4] is -> ds --- src/braft/snapshot_executor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/braft/snapshot_executor.cpp b/src/braft/snapshot_executor.cpp index 25da9107..d1fe2bb1 100644 --- a/src/braft/snapshot_executor.cpp +++ b/src/braft/snapshot_executor.cpp @@ -542,12 +542,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.";