Skip to content

Commit

Permalink
chore(all): format codes
Browse files Browse the repository at this point in the history
Signed-off-by: NaturalSelect <[email protected]>
  • Loading branch information
NaturalSelect committed Sep 15, 2023
1 parent 79bb8da commit 6d3cf1d
Show file tree
Hide file tree
Showing 32 changed files with 631 additions and 751 deletions.
43 changes: 21 additions & 22 deletions curvefs/src/metaserver/copyset/copyset_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ void CopysetNode::on_apply(braft::Iterator& iter) {
auto type = metaOperator->GetOperatorType();
auto task =
std::bind(&MetaOperator::OnApplyFromLog, metaOperator.release(),
iter.index(),
TimeUtility::GetTimeofDayUs());
iter.index(), TimeUtility::GetTimeofDayUs());
applyQueue_->Push(hashcode, type, std::move(task));
timer.stop();
g_concurrent_apply_from_log_wait_latency << timer.u_elapsed();
Expand Down Expand Up @@ -372,7 +371,7 @@ void CopysetNode::DoSnapshot(OnSnapshotSaveDoneClosure* done) {
// raft snapshot metadata
std::vector<std::string> files;
brpc::ClosureGuard doneGuard(done);
auto *writer = done->GetSnapshotWriter();
auto* writer = done->GetSnapshotWriter();
if (!metaStore_->SaveMeta(writer->get_path(), &files)) {
done->SetError(MetaStatusCode::SAVE_META_FAIL);
LOG(ERROR) << "Save meta store metadata failed";
Expand All @@ -381,23 +380,23 @@ void CopysetNode::DoSnapshot(OnSnapshotSaveDoneClosure* done) {
// asynchronous save data
{
std::lock_guard<std::mutex> lock(snapshotLock_);
snapshotTask_ = std::async(std::launch::async,
[files, done, this]() mutable {
brpc::ClosureGuard doneGuard(done);
auto *writer = done->GetSnapshotWriter();
// save data files
if (!metaStore_->SaveData(writer->get_path(), &files)) {
done->SetError(MetaStatusCode::SAVE_META_FAIL);
LOG(ERROR) << "Save meta store data failed";
return;
}
// add files to snapshot writer
// file is a relative path under the given directory
for (const auto &f : files) {
writer->add_file(f);
}
done->SetSuccess();
});
snapshotTask_ =
std::async(std::launch::async, [files, done, this]() mutable {
brpc::ClosureGuard doneGuard(done);
auto* writer = done->GetSnapshotWriter();
// save data files
if (!metaStore_->SaveData(writer->get_path(), &files)) {
done->SetError(MetaStatusCode::SAVE_META_FAIL);
LOG(ERROR) << "Save meta store data failed";
return;
}
// add files to snapshot writer
// file is a relative path under the given directory
for (const auto& f : files) {
writer->add_file(f);
}
done->SetSuccess();
});
}
doneGuard.release();
}
Expand Down Expand Up @@ -430,8 +429,8 @@ void CopysetNode::on_snapshot_save(braft::SnapshotWriter* writer,

writer->add_file(kConfEpochFilename);

DoSnapshot(new OnSnapshotSaveDoneClosureImpl(
this, writer, done, metricCtx));
DoSnapshot(
new OnSnapshotSaveDoneClosureImpl(this, writer, done, metricCtx));
doneGuard.release();

// `Cancel` only available for rvalue
Expand Down
6 changes: 3 additions & 3 deletions curvefs/src/metaserver/copyset/copyset_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
#include <braft/raft.h>
#include <gtest/gtest_prod.h>

#include <condition_variable>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <condition_variable>

#include "curvefs/proto/heartbeat.pb.h"
#include "curvefs/src/metaserver/common/types.h"
#include "curvefs/src/metaserver/copyset/concurrent_apply_queue.h"
#include "curvefs/src/metaserver/copyset/conf_epoch_file.h"
Expand All @@ -41,7 +42,6 @@
#include "curvefs/src/metaserver/copyset/metric.h"
#include "curvefs/src/metaserver/copyset/raft_node.h"
#include "curvefs/src/metaserver/metastore.h"
#include "curvefs/proto/heartbeat.pb.h"

namespace curvefs {
namespace metaserver {
Expand Down
54 changes: 27 additions & 27 deletions curvefs/src/metaserver/copyset/meta_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void MetaOperator::FastApplyTask() {
g_concurrent_fast_apply_wait_latency << timer.u_elapsed();
}

#define OPERATOR_CAN_BY_PASS_PROPOSE(TYPE) \
#define OPERATOR_CAN_BY_PASS_PROPOSE(TYPE) \
bool TYPE##Operator::CanBypassPropose() const { return true; }

// below operator are readonly, so can enable lease read
Expand All @@ -142,31 +142,31 @@ OPERATOR_CAN_BY_PASS_PROPOSE(GetVolumeExtent);

#undef OPERATOR_CAN_BY_PASS_PROPOSE

#define OPERATOR_ON_APPLY(TYPE) \
void TYPE##Operator::OnApply(int64_t index, \
google::protobuf::Closure *done, \
uint64_t startTimeUs) { \
brpc::ClosureGuard doneGuard(done); \
uint64_t timeUs = TimeUtility::GetTimeofDayUs(); \
node_->GetMetric()->WaitInQueueLatency(OperatorType::TYPE, \
timeUs - startTimeUs); \
auto status = node_->GetMetaStore()->TYPE( \
static_cast<const TYPE##Request *>(request_), \
static_cast<TYPE##Response *>(response_), index); \
uint64_t executeTime = TimeUtility::GetTimeofDayUs() - timeUs; \
node_->GetMetric()->ExecuteLatency(OperatorType::TYPE, executeTime); \
if (status == MetaStatusCode::OK) { \
node_->UpdateAppliedIndex(index); \
static_cast<TYPE##Response *>(response_)->set_appliedindex( \
std::max<uint64_t>(index, node_->GetAppliedIndex())); \
node_->GetMetric()->OnOperatorComplete( \
OperatorType::TYPE, \
TimeUtility::GetTimeofDayUs() - startTimeUs, true); \
} else { \
node_->GetMetric()->OnOperatorComplete( \
OperatorType::TYPE, \
TimeUtility::GetTimeofDayUs() - startTimeUs, false); \
} \
#define OPERATOR_ON_APPLY(TYPE) \
void TYPE##Operator::OnApply(int64_t index, \
google::protobuf::Closure* done, \
uint64_t startTimeUs) { \
brpc::ClosureGuard doneGuard(done); \
uint64_t timeUs = TimeUtility::GetTimeofDayUs(); \
node_->GetMetric()->WaitInQueueLatency(OperatorType::TYPE, \
timeUs - startTimeUs); \
auto status = node_->GetMetaStore()->TYPE( \
static_cast<const TYPE##Request*>(request_), \
static_cast<TYPE##Response*>(response_), index); \
uint64_t executeTime = TimeUtility::GetTimeofDayUs() - timeUs; \
node_->GetMetric()->ExecuteLatency(OperatorType::TYPE, executeTime); \
if (status == MetaStatusCode::OK) { \
node_->UpdateAppliedIndex(index); \
static_cast<TYPE##Response*>(response_)->set_appliedindex( \
std::max<uint64_t>(index, node_->GetAppliedIndex())); \
node_->GetMetric()->OnOperatorComplete( \
OperatorType::TYPE, \
TimeUtility::GetTimeofDayUs() - startTimeUs, true); \
} else { \
node_->GetMetric()->OnOperatorComplete( \
OperatorType::TYPE, \
TimeUtility::GetTimeofDayUs() - startTimeUs, false); \
} \
}

OPERATOR_ON_APPLY(GetDentry);
Expand Down Expand Up @@ -295,7 +295,7 @@ void GetVolumeExtentOperator::OnApply(int64_t index,
std::unique_ptr<TYPE##Operator> selfGuard(this); \
TYPE##Response response; \
auto status = node_->GetMetaStore()->TYPE( \
static_cast<const TYPE##Request *>(request_), &response, index); \
static_cast<const TYPE##Request*>(request_), &response, index); \
node_->GetMetric()->OnOperatorCompleteFromLog( \
OperatorType::TYPE, TimeUtility::GetTimeofDayUs() - startTimeUs, \
status == MetaStatusCode::OK); \
Expand Down
8 changes: 2 additions & 6 deletions curvefs/src/metaserver/copyset/meta_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class MetaOperator {
/**
* @brief Return internal closure
*/
google::protobuf::Closure* Closure() const {
return done_;
}
google::protobuf::Closure* Closure() const { return done_; }

void RedirectRequest();

Expand Down Expand Up @@ -109,9 +107,7 @@ class MetaOperator {
/**
* @brief Check whether current copyset node is leader
*/
bool IsLeaderTerm() const {
return node_->IsLeaderTerm();
}
bool IsLeaderTerm() const { return node_->IsLeaderTerm(); }

/**
* @brief Propose current operator to braft::Task
Expand Down
25 changes: 12 additions & 13 deletions curvefs/src/metaserver/dentry_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@

#include "curvefs/src/metaserver/dentry_manager.h"

#define CHECK_APPLIED() \
do { \
if (logIndex <= appliedIndex_) { \
VLOG(3) << __func__ \
<< "Log entry already be applied, index = " \
<< logIndex \
<< "applied index = " << appliedIndex_; \
return MetaStatusCode::IDEMPOTENCE_OK; \
} \
#define CHECK_APPLIED() \
do { \
if (logIndex <= appliedIndex_) { \
VLOG(3) << __func__ \
<< "Log entry already be applied, index = " << logIndex \
<< "applied index = " << appliedIndex_; \
return MetaStatusCode::IDEMPOTENCE_OK; \
} \
} while (false)

namespace curvefs {
Expand All @@ -61,10 +60,10 @@ void DentryManager::Log4Dentry(const std::string& request,
}

void DentryManager::Log4Code(const std::string& request, MetaStatusCode rc) {
auto succ = (rc == MetaStatusCode::OK ||
rc == MetaStatusCode::IDEMPOTENCE_OK ||
(rc == MetaStatusCode::NOT_FOUND &&
(request == "ListDentry" || request == "GetDentry")));
auto succ =
(rc == MetaStatusCode::OK || rc == MetaStatusCode::IDEMPOTENCE_OK ||
(rc == MetaStatusCode::NOT_FOUND &&
(request == "ListDentry" || request == "GetDentry")));
std::ostringstream message;
message << request << " " << (succ ? "success" : "fail")
<< ", retCode = " << MetaStatusCode_Name(rc);
Expand Down
Loading

0 comments on commit 6d3cf1d

Please sign in to comment.