From 6d3cf1d5cad4bfd8481446fab0a64e8094a18456 Mon Sep 17 00:00:00 2001 From: NaturalSelect <2145973003@qq.com> Date: Fri, 15 Sep 2023 14:55:45 +0800 Subject: [PATCH] chore(all): format codes Signed-off-by: NaturalSelect <2145973003@qq.com> --- .../src/metaserver/copyset/copyset_node.cpp | 43 ++++--- curvefs/src/metaserver/copyset/copyset_node.h | 6 +- .../src/metaserver/copyset/meta_operator.cpp | 54 ++++---- .../src/metaserver/copyset/meta_operator.h | 8 +- curvefs/src/metaserver/dentry_manager.cpp | 25 ++-- curvefs/src/metaserver/dentry_storage.cpp | 105 +++++++--------- curvefs/src/metaserver/dentry_storage.h | 13 +- curvefs/src/metaserver/inode_manager.cpp | 113 +++++++---------- curvefs/src/metaserver/inode_manager.h | 74 ++++++----- curvefs/src/metaserver/inode_storage.cpp | 118 ++++++++---------- curvefs/src/metaserver/inode_storage.h | 29 ++--- curvefs/src/metaserver/metastore.cpp | 116 ++++++++--------- curvefs/src/metaserver/metastore.h | 95 ++++++-------- curvefs/src/metaserver/metastore_fstream.cpp | 52 ++++---- curvefs/src/metaserver/partition.cpp | 85 ++++++------- curvefs/src/metaserver/partition.h | 13 +- curvefs/src/metaserver/storage/converter.cpp | 54 ++++---- curvefs/src/metaserver/transaction.cpp | 12 +- curvefs/src/metaserver/transaction.h | 11 +- .../metaserver/copyset/meta_operator_test.cpp | 103 ++++++++------- .../test/metaserver/dentry_manager_test.cpp | 8 +- .../test/metaserver/dentry_storage_test.cpp | 93 ++++++++------ .../test/metaserver/inode_manager_test.cpp | 48 ++++--- .../test/metaserver/inode_storage_test.cpp | 1 - curvefs/test/metaserver/metastore_test.cpp | 15 +-- curvefs/test/metaserver/mock/mock_metastore.h | 48 ++++--- .../test/metaserver/partition_clean_test.cpp | 6 +- .../test/metaserver/recycle_cleaner_test.cpp | 8 +- .../test/metaserver/recycle_manager_test.cpp | 8 +- .../metaserver/s3compact/s3compact_test.cpp | 6 +- curvefs/test/metaserver/space/utils.h | 4 +- curvefs/test/metaserver/transaction_test.cpp | 8 +- 32 files changed, 631 insertions(+), 751 deletions(-) diff --git a/curvefs/src/metaserver/copyset/copyset_node.cpp b/curvefs/src/metaserver/copyset/copyset_node.cpp index dde3884ede..449886204f 100644 --- a/curvefs/src/metaserver/copyset/copyset_node.cpp +++ b/curvefs/src/metaserver/copyset/copyset_node.cpp @@ -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(); @@ -372,7 +371,7 @@ void CopysetNode::DoSnapshot(OnSnapshotSaveDoneClosure* done) { // raft snapshot metadata std::vector 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"; @@ -381,23 +380,23 @@ void CopysetNode::DoSnapshot(OnSnapshotSaveDoneClosure* done) { // asynchronous save data { std::lock_guard 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(); } @@ -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 diff --git a/curvefs/src/metaserver/copyset/copyset_node.h b/curvefs/src/metaserver/copyset/copyset_node.h index d0d57e267f..b1a6f14760 100644 --- a/curvefs/src/metaserver/copyset/copyset_node.h +++ b/curvefs/src/metaserver/copyset/copyset_node.h @@ -26,13 +26,14 @@ #include #include +#include #include +#include #include #include #include -#include -#include +#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" @@ -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 { diff --git a/curvefs/src/metaserver/copyset/meta_operator.cpp b/curvefs/src/metaserver/copyset/meta_operator.cpp index 943b3bba99..456fd9c361 100644 --- a/curvefs/src/metaserver/copyset/meta_operator.cpp +++ b/curvefs/src/metaserver/copyset/meta_operator.cpp @@ -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 @@ -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(request_), \ - static_cast(response_), index); \ - uint64_t executeTime = TimeUtility::GetTimeofDayUs() - timeUs; \ - node_->GetMetric()->ExecuteLatency(OperatorType::TYPE, executeTime); \ - if (status == MetaStatusCode::OK) { \ - node_->UpdateAppliedIndex(index); \ - static_cast(response_)->set_appliedindex( \ - std::max(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(request_), \ + static_cast(response_), index); \ + uint64_t executeTime = TimeUtility::GetTimeofDayUs() - timeUs; \ + node_->GetMetric()->ExecuteLatency(OperatorType::TYPE, executeTime); \ + if (status == MetaStatusCode::OK) { \ + node_->UpdateAppliedIndex(index); \ + static_cast(response_)->set_appliedindex( \ + std::max(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); @@ -295,7 +295,7 @@ void GetVolumeExtentOperator::OnApply(int64_t index, std::unique_ptr selfGuard(this); \ TYPE##Response response; \ auto status = node_->GetMetaStore()->TYPE( \ - static_cast(request_), &response, index); \ + static_cast(request_), &response, index); \ node_->GetMetric()->OnOperatorCompleteFromLog( \ OperatorType::TYPE, TimeUtility::GetTimeofDayUs() - startTimeUs, \ status == MetaStatusCode::OK); \ diff --git a/curvefs/src/metaserver/copyset/meta_operator.h b/curvefs/src/metaserver/copyset/meta_operator.h index 12dd566184..b78aa3e78f 100644 --- a/curvefs/src/metaserver/copyset/meta_operator.h +++ b/curvefs/src/metaserver/copyset/meta_operator.h @@ -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(); @@ -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 diff --git a/curvefs/src/metaserver/dentry_manager.cpp b/curvefs/src/metaserver/dentry_manager.cpp index 552c4a1a09..46b0102369 100644 --- a/curvefs/src/metaserver/dentry_manager.cpp +++ b/curvefs/src/metaserver/dentry_manager.cpp @@ -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 { @@ -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); diff --git a/curvefs/src/metaserver/dentry_storage.cpp b/curvefs/src/metaserver/dentry_storage.cpp index aa4d83d023..57fc70c1cf 100644 --- a/curvefs/src/metaserver/dentry_storage.cpp +++ b/curvefs/src/metaserver/dentry_storage.cpp @@ -20,18 +20,20 @@ * Author: chenwei */ +#include "curvefs/src/metaserver/dentry_storage.h" + #include + +#include #include +#include #include #include -#include -#include #include "curvefs/src/metaserver/storage/status.h" #include "curvefs/src/metaserver/storage/storage.h" #include "curvefs/src/metaserver/transaction.h" #include "src/common/string_util.h" -#include "curvefs/src/metaserver/dentry_storage.h" namespace curvefs { namespace metaserver { @@ -45,20 +47,18 @@ using ::curvefs::metaserver::storage::Prefix4SameParentDentry; using ::curvefs::metaserver::storage::Status; bool operator==(const Dentry& lhs, const Dentry& rhs) { - return EQUAL(fsid) && EQUAL(parentinodeid) && EQUAL(name) && - EQUAL(txid) && EQUAL(inodeid) && EQUAL(flag); + return EQUAL(fsid) && EQUAL(parentinodeid) && EQUAL(name) && EQUAL(txid) && + EQUAL(inodeid) && EQUAL(flag); } bool operator<(const Dentry& lhs, const Dentry& rhs) { - return LESS(fsid) || - LESS2(fsid, parentinodeid) || + return LESS(fsid) || LESS2(fsid, parentinodeid) || LESS3(fsid, parentinodeid, name) || LESS4(fsid, parentinodeid, name, txid); } static bool BelongSomeOne(const Dentry& lhs, const Dentry& rhs) { - return EQUAL(fsid) && EQUAL(parentinodeid) && EQUAL(name) && - EQUAL(inodeid); + return EQUAL(fsid) && EQUAL(parentinodeid) && EQUAL(name) && EQUAL(inodeid); } static bool HasDeleteMarkFlag(const Dentry& dentry) { @@ -114,10 +114,8 @@ void DentryVector::Confirm(uint64_t* count) { *count = *count + nPendingAdd_ - nPendingDel_; } -DentryList::DentryList(std::vector* list, - uint32_t limit, - const std::string& exclude, - uint64_t maxTxId, +DentryList::DentryList(std::vector* list, uint32_t limit, + const std::string& exclude, uint64_t maxTxId, bool onlyDir) : list_(list), size_(0), @@ -154,13 +152,9 @@ void DentryList::PushBack(DentryVec* vec) { VLOG(9) << "Push dentry, dentry = (" << last->ShortDebugString() << ")"; } -uint32_t DentryList::Size() { - return size_; -} +uint32_t DentryList::Size() { return size_; } -bool DentryList::IsFull() { - return limit_ != 0 && size_ >= limit_; -} +bool DentryList::IsFull() { return limit_ != 0 && size_ >= limit_; } const char* DentryStorage::kDentryAppliedKey("dentry"); const char* DentryStorage::kDentryCountKey("count"); @@ -173,17 +167,20 @@ bool DentryStorage::Init() { s = GetHandleTxIndex(&handleTxIndex_); return s.ok() || s.IsNotFound(); } - return false; + return false; } DentryStorage::DentryStorage(std::shared_ptr kvStorage, std::shared_ptr nameGenerator, uint64_t nDentry) - : kvStorage_(kvStorage), table4Dentry_(nameGenerator->GetDentryTableName()), + : kvStorage_(kvStorage), + table4Dentry_(nameGenerator->GetDentryTableName()), table4AppliedIndex_(nameGenerator->GetAppliedIndexTableName()), table4Transaction_(nameGenerator->GetTransactionTableName()), table4DentryCount_(nameGenerator->GetDentryCountTableName()), - handleTxIndex_(-1), nDentry_(nDentry), conv_() { + handleTxIndex_(-1), + nDentry_(nDentry), + conv_() { // NOTE: for compatibility with older versions // we cannot ignore `nDentry` argument // try get dentry count for rocksdb @@ -231,9 +228,7 @@ bool DentryStorage::CompressDentry(storage::StorageTransaction* txn, *outCount = countCopy; return true; } while (false); - LOG(ERROR) << step - << " failed, status = " - << s.ToString(); + LOG(ERROR) << step << " failed, status = " << s.ToString(); return false; } @@ -278,8 +273,7 @@ MetaStatusCode DentryStorage::Find(const Dentry& in, Dentry* out, // with `nDentry_` MetaStatusCode DentryStorage::Find(storage::StorageTransaction* txn, const Dentry& in, Dentry* out, - DentryVec* vec, - uint64_t* compressOutCount) { + DentryVec* vec, uint64_t* compressOutCount) { std::string skey = DentryKey(in); Status s = txn->SGet(table4Dentry_, skey, vec); if (s.IsNotFound()) { @@ -328,34 +322,32 @@ MetaStatusCode DentryStorage::GetAppliedIndex(int64_t* index) { return MetaStatusCode::STORAGE_INTERNAL_ERROR; } -storage::Status -DentryStorage::SetAppliedIndex(storage::StorageTransaction* transaction, - int64_t index) { +storage::Status DentryStorage::SetAppliedIndex( + storage::StorageTransaction* transaction, int64_t index) { common::AppliedIndex val; val.set_index(index); return transaction->SSet(table4AppliedIndex_, kDentryAppliedKey, val); } -storage::Status -DentryStorage::DelAppliedIndex(storage::StorageTransaction* transaction) { +storage::Status DentryStorage::DelAppliedIndex( + storage::StorageTransaction* transaction) { return transaction->SDel(table4AppliedIndex_, kDentryAppliedKey); } -storage::Status -DentryStorage::SetHandleTxIndex(storage::StorageTransaction* transaction, - int64_t index) { +storage::Status DentryStorage::SetHandleTxIndex( + storage::StorageTransaction* transaction, int64_t index) { common::AppliedIndex val; val.set_index(index); return transaction->SSet(table4AppliedIndex_, kHandleTxKey, val); } -storage::Status -DentryStorage::DelHandleTxIndex(storage::StorageTransaction* transaction) { +storage::Status DentryStorage::DelHandleTxIndex( + storage::StorageTransaction* transaction) { return transaction->SDel(table4AppliedIndex_, kHandleTxKey); } -MetaStatusCode -DentryStorage::GetPendingTx(metaserver::TransactionRequest* request) { +MetaStatusCode DentryStorage::GetPendingTx( + metaserver::TransactionRequest* request) { auto s = kvStorage_->SGet(table4Transaction_, kPendingTxKey, request); if (s.ok()) { return MetaStatusCode::OK; @@ -366,9 +358,9 @@ DentryStorage::GetPendingTx(metaserver::TransactionRequest* request) { return MetaStatusCode::STORAGE_INTERNAL_ERROR; } -storage::Status -DentryStorage::SetPendingTx(storage::StorageTransaction* txn, - const metaserver::TransactionRequest& request) { +storage::Status DentryStorage::SetPendingTx( + storage::StorageTransaction* txn, + const metaserver::TransactionRequest& request) { return txn->SSet(table4Transaction_, kPendingTxKey, request); } @@ -376,8 +368,8 @@ storage::Status DentryStorage::DelPendingTx(storage::StorageTransaction* txn) { return txn->SDel(table4Transaction_, kPendingTxKey); } -storage::Status -DentryStorage::ClearPendingTx(storage::StorageTransaction* txn) { +storage::Status DentryStorage::ClearPendingTx( + storage::StorageTransaction* txn) { metaserver::TransactionRequest request; request.set_type(metaserver::TransactionRequest::None); request.set_rawpayload(""); @@ -391,8 +383,8 @@ storage::Status DentryStorage::SetDentryCount(storage::StorageTransaction* txn, return txn->SSet(table4DentryCount_, kDentryCountKey, val); } -storage::Status -DentryStorage::DelDentryCount(storage::StorageTransaction* txn) { +storage::Status DentryStorage::DelDentryCount( + storage::StorageTransaction* txn) { return txn->SDel(table4DentryCount_, kDentryCountKey); } @@ -414,8 +406,7 @@ storage::Status DentryStorage::GetHandleTxIndex(int64_t* index) { return s; } -MetaStatusCode DentryStorage::Insert(const Dentry& dentry, - int64_t logIndex) { +MetaStatusCode DentryStorage::Insert(const Dentry& dentry, int64_t logIndex) { WriteLockGuard lg(rwLock_); Dentry out; @@ -481,7 +472,7 @@ MetaStatusCode DentryStorage::Insert(const Dentry& dentry, LOG(ERROR) << step << " failed, status = " << s.ToString(); if (txn != nullptr && !txn->Rollback().ok()) { LOG(ERROR) << "Rollback insert dentry transaction failed, status = " - << s.ToString(); + << s.ToString(); } return MetaStatusCode::STORAGE_INTERNAL_ERROR; } @@ -539,13 +530,12 @@ MetaStatusCode DentryStorage::Insert(const DentryVec& vec, bool merge, LOG(ERROR) << step << " failed, status = " << s.ToString(); if (txn != nullptr && !txn->Rollback().ok()) { LOG(ERROR) << "Rollback insert dentry transaction failed, status = " - << s.ToString(); + << s.ToString(); } return MetaStatusCode::STORAGE_INTERNAL_ERROR; } -MetaStatusCode DentryStorage::Delete(const Dentry& dentry, - int64_t logIndex) { +MetaStatusCode DentryStorage::Delete(const Dentry& dentry, int64_t logIndex) { WriteLockGuard lg(rwLock_); Dentry out; @@ -692,10 +682,9 @@ MetaStatusCode DentryStorage::List(const Dentry& dentry, return MetaStatusCode::OK; } -MetaStatusCode -DentryStorage::PrepareTx(const std::vector& dentrys, - const metaserver::TransactionRequest& txRequest, - int64_t logIndex) { +MetaStatusCode DentryStorage::PrepareTx( + const std::vector& dentrys, + const metaserver::TransactionRequest& txRequest, int64_t logIndex) { WriteLockGuard lg(rwLock_); uint64_t count = nDentry_; Status s; @@ -981,9 +970,7 @@ MetaStatusCode DentryStorage::Clear() { if (txn != nullptr && !txn->Rollback().ok()) { LOG(ERROR) << "Rollback transaction failed"; } - LOG(ERROR) << step - << " failed, status = " - << s.ToString(); + LOG(ERROR) << step << " failed, status = " << s.ToString(); return MetaStatusCode::STORAGE_INTERNAL_ERROR; } diff --git a/curvefs/src/metaserver/dentry_storage.h b/curvefs/src/metaserver/dentry_storage.h index 1392ed71ed..102df6737a 100644 --- a/curvefs/src/metaserver/dentry_storage.h +++ b/curvefs/src/metaserver/dentry_storage.h @@ -23,18 +23,18 @@ #ifndef CURVEFS_SRC_METASERVER_DENTRY_STORAGE_H_ #define CURVEFS_SRC_METASERVER_DENTRY_STORAGE_H_ +#include #include +#include #include #include -#include -#include #include "absl/container/btree_set.h" -#include "curvefs/src/metaserver/storage/status.h" -#include "src/common/concurrent/rw_lock.h" #include "curvefs/proto/metaserver.pb.h" -#include "curvefs/src/metaserver/storage/storage.h" #include "curvefs/src/metaserver/storage/converter.h" +#include "curvefs/src/metaserver/storage/status.h" +#include "curvefs/src/metaserver/storage/storage.h" +#include "src/common/concurrent/rw_lock.h" namespace curvefs { namespace metaserver { @@ -107,8 +107,7 @@ class DentryStorage { MetaStatusCode Insert(const Dentry& dentry, int64_t logIndex); // only for loadding from snapshot - MetaStatusCode Insert(const DentryVec& vec, bool merge, - int64_t logIndex); + MetaStatusCode Insert(const DentryVec& vec, bool merge, int64_t logIndex); MetaStatusCode Delete(const Dentry& dentry, int64_t logIndex); diff --git a/curvefs/src/metaserver/inode_manager.cpp b/curvefs/src/metaserver/inode_manager.cpp index 78ad5d6f58..d5e4fce007 100644 --- a/curvefs/src/metaserver/inode_manager.cpp +++ b/curvefs/src/metaserver/inode_manager.cpp @@ -24,11 +24,12 @@ #include #include + +#include #include #include #include #include -#include #include "curvefs/proto/metaserver.pb.h" #include "curvefs/src/common/define.h" @@ -40,15 +41,14 @@ using ::curve::common::NameLockGuard; using ::curve::common::TimeUtility; using ::google::protobuf::util::MessageDifferencer; -#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 { @@ -63,9 +63,8 @@ bool InodeManager::Init() { } MetaStatusCode InodeManager::CreateInode(uint64_t inodeId, - const InodeParam ¶m, - Inode *newInode, - int64_t logIndex) { + const InodeParam& param, + Inode* newInode, int64_t logIndex) { CHECK_APPLIED(); VLOG(6) << "CreateInode, fsId = " << param.fsId << ", length = " << param.length << ", uid = " << param.uid @@ -98,7 +97,7 @@ MetaStatusCode InodeManager::CreateInode(uint64_t inodeId, return MetaStatusCode::OK; } -MetaStatusCode InodeManager::CreateRootInode(const InodeParam ¶m, +MetaStatusCode InodeManager::CreateRootInode(const InodeParam& param, int64_t logIndex) { CHECK_APPLIED(); LOG(INFO) << "CreateRootInode, fsId = " << param.fsId @@ -123,9 +122,9 @@ MetaStatusCode InodeManager::CreateRootInode(const InodeParam ¶m, return MetaStatusCode::OK; } -MetaStatusCode InodeManager::CreateManageInode(const InodeParam ¶m, +MetaStatusCode InodeManager::CreateManageInode(const InodeParam& param, ManageInodeType manageType, - Inode *newInode, + Inode* newInode, int64_t logIndex) { CHECK_APPLIED(); LOG(INFO) << "CreateManageInode, fsId = " << param.fsId @@ -207,7 +206,7 @@ void InodeManager::GenerateInodeInternal(uint64_t inodeId, } MetaStatusCode InodeManager::GetInode(uint32_t fsId, uint64_t inodeId, - Inode *inode, bool paddingS3ChunkInfo) { + Inode* inode, bool paddingS3ChunkInfo) { VLOG(6) << "GetInode, fsId = " << fsId << ", inodeId = " << inodeId; NameLockGuard lg(inodeLock_, GetInodeLockName(fsId, inodeId)); MetaStatusCode rc = inodeStorage_->Get(Key4Inode(fsId, inodeId), inode); @@ -305,7 +304,7 @@ MetaStatusCode InodeManager::DeleteInode(uint32_t fsId, uint64_t inodeId, return MetaStatusCode::OK; } -MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest &request, +MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest& request, int64_t logIndex) { CHECK_APPLIED(); VLOG(9) << "update inode, fsid: " << request.fsid() @@ -325,10 +324,10 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest &request, bool needUpdate = false; bool needAddTrash = false; -#define UPDATE_INODE(param) \ - if (request.has_##param()) { \ +#define UPDATE_INODE(param) \ + if (request.has_##param()) { \ old.set_##param(request.param()); \ - needUpdate = true; \ + needUpdate = true; \ } UPDATE_INODE(length) @@ -444,9 +443,9 @@ MetaStatusCode InodeManager::UpdateInode(const UpdateInodeRequest &request, } MetaStatusCode InodeManager::GetOrModifyS3ChunkInfo( - uint32_t fsId, uint64_t inodeId, const S3ChunkInfoMap &map2add, - const S3ChunkInfoMap &map2del, bool returnS3ChunkInfoMap, - std::shared_ptr *iterator4InodeS3Meta, int64_t logIndex) { + uint32_t fsId, uint64_t inodeId, const S3ChunkInfoMap& map2add, + const S3ChunkInfoMap& map2del, bool returnS3ChunkInfoMap, + std::shared_ptr* iterator4InodeS3Meta, int64_t logIndex) { VLOG(6) << "GetOrModifyS3ChunkInfo, fsId: " << fsId << ", inodeId: " << inodeId; @@ -454,11 +453,11 @@ MetaStatusCode InodeManager::GetOrModifyS3ChunkInfo( CHECK_APPLIED(); - const S3ChunkInfoList *list2add; - const S3ChunkInfoList *list2del; + const S3ChunkInfoList* list2add; + const S3ChunkInfoList* list2del; std::unordered_set deleted; std::shared_ptr txn; - for (const auto &item : map2add) { + for (const auto& item : map2add) { uint64_t chunkIndex = item.first; list2add = &item.second; auto iter = map2del.find(chunkIndex); @@ -481,7 +480,7 @@ MetaStatusCode InodeManager::GetOrModifyS3ChunkInfo( deleted.insert(chunkIndex); } - for (const auto &item : map2del) { + for (const auto& item : map2del) { uint64_t chunkIndex = item.first; if (deleted.find(chunkIndex) != deleted.end()) { // already deleted continue; @@ -529,7 +528,7 @@ MetaStatusCode InodeManager::GetOrModifyS3ChunkInfo( MetaStatusCode InodeManager::PaddingInodeS3ChunkInfo(int32_t fsId, uint64_t inodeId, - S3ChunkInfoMap *m, + S3ChunkInfoMap* m, uint64_t limit) { VLOG(6) << "PaddingInodeS3ChunkInfo, fsId: " << fsId << ", inodeId: " << inodeId; @@ -537,10 +536,7 @@ MetaStatusCode InodeManager::PaddingInodeS3ChunkInfo(int32_t fsId, } MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode( - const Dentry &dentry, - uint64_t now, - uint32_t now_ns, - bool isCreate, + const Dentry& dentry, uint64_t now, uint32_t now_ns, bool isCreate, int64_t logIndex) { uint64_t fsId = dentry.fsid(); uint64_t parentInodeId = dentry.parentinodeid(); @@ -596,17 +592,6 @@ MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode( parentInode.set_ctime_ns(now_ns); } - // update mctime and changetime - if (now != 0) { - parentInode.set_mtime(now); - parentInode.set_ctime(now); - } - - if (now_ns != 0) { - parentInode.set_mtime_ns(now_ns); - parentInode.set_ctime_ns(now_ns); - } - ret = inodeStorage_->Update(parentInode, logIndex); if (ret != MetaStatusCode::OK) { LOG(ERROR) << "UpdateInode fail, " << parentInode.ShortDebugString() @@ -619,8 +604,7 @@ MetaStatusCode InodeManager::UpdateInodeWhenCreateOrRemoveSubNode( return MetaStatusCode::OK; } -MetaStatusCode InodeManager::InsertInode(const Inode &inode, - int64_t logIndex) { +MetaStatusCode InodeManager::InsertInode(const Inode& inode, int64_t logIndex) { CHECK_APPLIED(); VLOG(6) << "InsertInode, " << inode.ShortDebugString(); @@ -639,39 +623,36 @@ MetaStatusCode InodeManager::InsertInode(const Inode &inode, return MetaStatusCode::OK; } -bool InodeManager::GetInodeIdList(std::list *inodeIdList) { +bool InodeManager::GetInodeIdList(std::list* inodeIdList) { return inodeStorage_->GetAllInodeId(inodeIdList); } -MetaStatusCode -InodeManager::UpdateVolumeExtentSliceLocked(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSlice &slice, - int64_t logIndex) { +MetaStatusCode InodeManager::UpdateVolumeExtentSliceLocked( + uint32_t fsId, uint64_t inodeId, const VolumeExtentSlice& slice, + int64_t logIndex) { return inodeStorage_->UpdateVolumeExtentSlice(fsId, inodeId, slice, logIndex); } MetaStatusCode InodeManager::UpdateVolumeExtentSliceLocked( - std::shared_ptr *txn, uint32_t fsId, - uint64_t inodeId, const VolumeExtentSlice &slice, int64_t logIndex) { + std::shared_ptr* txn, uint32_t fsId, + uint64_t inodeId, const VolumeExtentSlice& slice, int64_t logIndex) { return inodeStorage_->UpdateVolumeExtentSlice(txn, fsId, inodeId, slice, logIndex); } -MetaStatusCode -InodeManager::UpdateVolumeExtentSlice(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSlice &slice, - int64_t logIndex) { +MetaStatusCode InodeManager::UpdateVolumeExtentSlice( + uint32_t fsId, uint64_t inodeId, const VolumeExtentSlice& slice, + int64_t logIndex) { VLOG(6) << "UpdateInodeExtent, fsId: " << fsId << ", inodeId: " << inodeId << ", slice offset: " << slice.offset(); NameLockGuard guard(inodeLock_, GetInodeLockName(fsId, inodeId)); return UpdateVolumeExtentSliceLocked(fsId, inodeId, slice, logIndex); } -MetaStatusCode -InodeManager::UpdateVolumeExtent(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSliceList &extents, - int64_t logIndex) { +MetaStatusCode InodeManager::UpdateVolumeExtent( + uint32_t fsId, uint64_t inodeId, const VolumeExtentSliceList& extents, + int64_t logIndex) { VLOG(6) << "UpdateInodeExtent, fsId: " << fsId << ", inodeId: " << inodeId; NameLockGuard guard(inodeLock_, GetInodeLockName(fsId, inodeId)); @@ -689,10 +670,9 @@ InodeManager::UpdateVolumeExtent(uint32_t fsId, uint64_t inodeId, return MetaStatusCode::OK; } -MetaStatusCode -InodeManager::GetVolumeExtent(uint32_t fsId, uint64_t inodeId, - const std::vector &slices, - VolumeExtentSliceList *extents) { +MetaStatusCode InodeManager::GetVolumeExtent( + uint32_t fsId, uint64_t inodeId, const std::vector& slices, + VolumeExtentSliceList* extents) { VLOG(6) << "GetInodeExtent, fsId: " << fsId << ", inodeId: " << inodeId; if (slices.empty()) { @@ -715,8 +695,7 @@ InodeManager::GetVolumeExtent(uint32_t fsId, uint64_t inodeId, } MetaStatusCode InodeManager::UpdateDeallocatableBlockGroup( - const UpdateDeallocatableBlockGroupRequest &request, - int64_t logIndex) { + const UpdateDeallocatableBlockGroupRequest& request, int64_t logIndex) { CHECK_APPLIED(); return inodeStorage_->UpdateDeallocatableBlockGroup( request.fsid(), request.update(), logIndex); diff --git a/curvefs/src/metaserver/inode_manager.h b/curvefs/src/metaserver/inode_manager.h index 016ee910c5..bd28f65790 100644 --- a/curvefs/src/metaserver/inode_manager.h +++ b/curvefs/src/metaserver/inode_manager.h @@ -26,17 +26,17 @@ #include #include +#include #include #include #include -#include + #include "curvefs/proto/metaserver.pb.h" #include "curvefs/src/metaserver/inode_storage.h" #include "curvefs/src/metaserver/storage/storage.h" #include "curvefs/src/metaserver/trash.h" #include "src/common/concurrent/name_lock.h" - using ::curve::common::NameLock; using ::curvefs::metaserver::S3ChunkInfoList; @@ -62,26 +62,27 @@ struct InodeParam { class InodeManager { public: - InodeManager(const std::shared_ptr &inodeStorage, - const std::shared_ptr &trash, - FileType2InodeNumMap *type2InodeNum) - : inodeStorage_(inodeStorage), trash_(trash), - type2InodeNum_(type2InodeNum), appliedIndex_(-1) { + InodeManager(const std::shared_ptr& inodeStorage, + const std::shared_ptr& trash, + FileType2InodeNumMap* type2InodeNum) + : inodeStorage_(inodeStorage), + trash_(trash), + type2InodeNum_(type2InodeNum), + appliedIndex_(-1) { // for compatibility, we initialize applied index to -1 } bool Init(); - MetaStatusCode CreateInode(uint64_t inodeId, const InodeParam ¶m, - Inode *inode, int64_t logIndex); - MetaStatusCode CreateRootInode(const InodeParam ¶m, - int64_t logIndex); + MetaStatusCode CreateInode(uint64_t inodeId, const InodeParam& param, + Inode* inode, int64_t logIndex); + MetaStatusCode CreateRootInode(const InodeParam& param, int64_t logIndex); - MetaStatusCode CreateManageInode(const InodeParam ¶m, - ManageInodeType manageType, Inode *inode, + MetaStatusCode CreateManageInode(const InodeParam& param, + ManageInodeType manageType, Inode* inode, int64_t logIndex); - MetaStatusCode GetInode(uint32_t fsId, uint64_t inodeId, Inode *inode, + MetaStatusCode GetInode(uint32_t fsId, uint64_t inodeId, Inode* inode, bool paddingS3ChunkInfo = false); MetaStatusCode GetInodeAttr(uint32_t fsId, uint64_t inodeId, @@ -92,46 +93,44 @@ class InodeManager { MetaStatusCode DeleteInode(uint32_t fsId, uint64_t inodeId, int64_t logIndex); - MetaStatusCode UpdateInode(const UpdateInodeRequest &request, + MetaStatusCode UpdateInode(const UpdateInodeRequest& request, int64_t logIndex); MetaStatusCode GetOrModifyS3ChunkInfo( - uint32_t fsId, uint64_t inodeId, const S3ChunkInfoMap &map2add, - const S3ChunkInfoMap &map2del, bool returnS3ChunkInfoMap, - std::shared_ptr *iterator4InodeS3Meta, int64_t logIndex); + uint32_t fsId, uint64_t inodeId, const S3ChunkInfoMap& map2add, + const S3ChunkInfoMap& map2del, bool returnS3ChunkInfoMap, + std::shared_ptr* iterator4InodeS3Meta, int64_t logIndex); MetaStatusCode PaddingInodeS3ChunkInfo(int32_t fsId, uint64_t inodeId, - S3ChunkInfoMap *m, + S3ChunkInfoMap* m, uint64_t limit = 0); - MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode( - const Dentry &dentry, - uint64_t now, - uint32_t now_ns, - bool isCreate, - int64_t logIndex); + MetaStatusCode UpdateInodeWhenCreateOrRemoveSubNode(const Dentry& dentry, + uint64_t now, + uint32_t now_ns, + bool isCreate, + int64_t logIndex); - MetaStatusCode InsertInode(const Inode &inode, int64_t logIndex); + MetaStatusCode InsertInode(const Inode& inode, int64_t logIndex); - bool GetInodeIdList(std::list *inodeIdList); + bool GetInodeIdList(std::list* inodeIdList); // Update one or more volume extent slice MetaStatusCode UpdateVolumeExtent(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSliceList &extents, + const VolumeExtentSliceList& extents, int64_t logIndex); // Update only one volume extent slice MetaStatusCode UpdateVolumeExtentSlice(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSlice &slice, + const VolumeExtentSlice& slice, int64_t logIndex); MetaStatusCode GetVolumeExtent(uint32_t fsId, uint64_t inodeId, - const std::vector &slices, - VolumeExtentSliceList *extents); + const std::vector& slices, + VolumeExtentSliceList* extents); MetaStatusCode UpdateDeallocatableBlockGroup( - const UpdateDeallocatableBlockGroupRequest &request, - int64_t logIndex); + const UpdateDeallocatableBlockGroupRequest& request, int64_t logIndex); private: void GenerateInodeInternal(uint64_t inodeId, const InodeParam ¶m, @@ -146,18 +145,17 @@ class InodeManager { MetaStatusCode UpdateVolumeExtentSliceLocked(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSlice &slice, + const VolumeExtentSlice& slice, int64_t logIndex); MetaStatusCode UpdateVolumeExtentSliceLocked( - std::shared_ptr *txn, uint32_t fsId, - uint64_t inodeId, const VolumeExtentSlice &slice, - int64_t logIndex); + std::shared_ptr* txn, uint32_t fsId, + uint64_t inodeId, const VolumeExtentSlice& slice, int64_t logIndex); private: std::shared_ptr inodeStorage_; std::shared_ptr trash_; - FileType2InodeNumMap *type2InodeNum_; + FileType2InodeNumMap* type2InodeNum_; int64_t appliedIndex_; NameLock inodeLock_; diff --git a/curvefs/src/metaserver/inode_storage.cpp b/curvefs/src/metaserver/inode_storage.cpp index e834317c27..8e5da8a913 100644 --- a/curvefs/src/metaserver/inode_storage.cpp +++ b/curvefs/src/metaserver/inode_storage.cpp @@ -20,24 +20,25 @@ * Author: chenwei */ +#include "curvefs/src/metaserver/inode_storage.h" + #include +#include #include -#include #include -#include -#include #include +#include +#include +#include "curvefs/proto/common.pb.h" +#include "curvefs/proto/metaserver.pb.h" +#include "curvefs/src/metaserver/common/types.h" +#include "curvefs/src/metaserver/storage/converter.h" +#include "curvefs/src/metaserver/storage/status.h" #include "curvefs/src/metaserver/storage/storage.h" #include "src/common/concurrent/rw_lock.h" #include "src/common/string_util.h" -#include "curvefs/proto/metaserver.pb.h" -#include "curvefs/proto/common.pb.h" -#include "curvefs/src/metaserver/storage/status.h" -#include "curvefs/src/metaserver/inode_storage.h" -#include "curvefs/src/metaserver/storage/converter.h" -#include "curvefs/src/metaserver/common/types.h" namespace curvefs { namespace metaserver { @@ -75,7 +76,8 @@ InodeStorage::InodeStorage(std::shared_ptr kvStorage, nameGenerator->GetDeallocatableBlockGroupTableName()), table4AppliedIndex_(nameGenerator->GetAppliedIndexTableName()), table4InodeCount_(nameGenerator->GetInodeCountTableName()), - nInode_(nInode), conv_() { + nInode_(nInode), + conv_() { // NOTE: for compatibility with older versions // we cannot ignore `nInode` argument } @@ -107,16 +109,15 @@ storage::Status InodeStorage::DelInodeCount(storage::StorageTransaction* txn) { return txn->SDel(table4InodeCount_, kInodeCountKey); } -storage::Status -InodeStorage::SetAppliedIndex(storage::StorageTransaction* transaction, - int64_t index) { +storage::Status InodeStorage::SetAppliedIndex( + storage::StorageTransaction* transaction, int64_t index) { common::AppliedIndex val; val.set_index(index); return transaction->SSet(table4AppliedIndex_, kInodeAppliedKey, val); } -storage::Status -InodeStorage::DelAppliedIndex(storage::StorageTransaction* transaction) { +storage::Status InodeStorage::DelAppliedIndex( + storage::StorageTransaction* transaction) { return transaction->SDel(table4AppliedIndex_, kInodeAppliedKey); } @@ -262,9 +263,8 @@ MetaStatusCode InodeStorage::GetXAttr(const Key4Inode& key, XAttr* xattr) { // NOTE: if transaction success // we will commit transaction // it should be the last step of your operations -storage::Status -InodeStorage::DeleteInternal(storage::StorageTransaction *transaction, - const Key4Inode &key) { +storage::Status InodeStorage::DeleteInternal( + storage::StorageTransaction* transaction, const Key4Inode& key) { std::string skey = conv_.SerializeToString(key); Status s; const char* step = "Delete inode from transaction"; @@ -302,8 +302,7 @@ InodeStorage::DeleteInternal(storage::StorageTransaction *transaction, return s; } -MetaStatusCode InodeStorage::Delete(const Key4Inode& key, - int64_t logIndex) { +MetaStatusCode InodeStorage::Delete(const Key4Inode& key, int64_t logIndex) { WriteLockGuard lg(rwLock_); std::shared_ptr txn; Status s; @@ -358,10 +357,9 @@ MetaStatusCode InodeStorage::ForceDelete(const Key4Inode& key) { return MetaStatusCode::STORAGE_INTERNAL_ERROR; } -MetaStatusCode -InodeStorage::Update(std::shared_ptr* txn, - const Inode& inode, int64_t logIndex, - bool inodeDeallocate) { +MetaStatusCode InodeStorage::Update( + std::shared_ptr* txn, const Inode& inode, + int64_t logIndex, bool inodeDeallocate) { if (*txn == nullptr) { *txn = kvStorage_->BeginTransaction(); if (*txn == nullptr) { @@ -420,7 +418,6 @@ MetaStatusCode InodeStorage::Update(const Inode& inode, int64_t logIndex, return MetaStatusCode::STORAGE_INTERNAL_ERROR; } - std::shared_ptr InodeStorage::GetAllInode() { ReadLockGuard lg(rwLock_); std::string sprefix = conv_.SerializeToString(Prefix4AllInode()); @@ -528,9 +525,7 @@ MetaStatusCode InodeStorage::Clear() { nInode_ = 0; return MetaStatusCode::OK; } while (false); - LOG(ERROR) << step - << " failed, status = " - << s.ToString(); + LOG(ERROR) << step << " failed, status = " << s.ToString(); if (txn != nullptr && !txn->Rollback().ok()) { LOG(ERROR) << "Rollback transaction failed"; } @@ -592,12 +587,9 @@ uint64_t InodeStorage::GetInodeS3MetaSize(uint32_t fsId, uint64_t inodeId) { return size; } -MetaStatusCode -InodeStorage::AddS3ChunkInfoList(Transaction txn, - uint32_t fsId, - uint64_t inodeId, - uint64_t chunkIndex, - const S3ChunkInfoList* list2add) { +MetaStatusCode InodeStorage::AddS3ChunkInfoList( + Transaction txn, uint32_t fsId, uint64_t inodeId, uint64_t chunkIndex, + const S3ChunkInfoList* list2add) { if (nullptr == list2add || list2add->s3chunks_size() == 0) { return MetaStatusCode::OK; } @@ -606,8 +598,8 @@ InodeStorage::AddS3ChunkInfoList(Transaction txn, uint64_t firstChunkId = list2add->s3chunks(0).chunkid(); uint64_t lastChunkId = list2add->s3chunks(size - 1).chunkid(); - Key4S3ChunkInfoList key(fsId, inodeId, chunkIndex, - firstChunkId, lastChunkId, size); + Key4S3ChunkInfoList key(fsId, inodeId, chunkIndex, firstChunkId, + lastChunkId, size); std::string skey = conv_.SerializeToString(key); Status s; if (txn) { @@ -618,10 +610,9 @@ InodeStorage::AddS3ChunkInfoList(Transaction txn, return s.ok() ? MetaStatusCode::OK : MetaStatusCode::STORAGE_INTERNAL_ERROR; } -MetaStatusCode -InodeStorage::DelS3ChunkInfoList(Transaction txn, uint32_t fsId, - uint64_t inodeId, uint64_t chunkIndex, - const S3ChunkInfoList* list2del) { +MetaStatusCode InodeStorage::DelS3ChunkInfoList( + Transaction txn, uint32_t fsId, uint64_t inodeId, uint64_t chunkIndex, + const S3ChunkInfoList* list2del) { if (nullptr == list2del || list2del->s3chunks_size() == 0) { return MetaStatusCode::OK; } @@ -659,8 +650,8 @@ InodeStorage::DelS3ChunkInfoList(Transaction txn, uint32_t fsId, } else if (delLastChunkId < key.firstChunkId) { continue; } else { - LOG(ERROR) << "wrong delete list range (" << delFirstChunkId - << "," << delLastChunkId << "), skey=" << skey; + LOG(ERROR) << "wrong delete list range (" << delFirstChunkId << "," + << delLastChunkId << "), skey=" << skey; return MetaStatusCode::STORAGE_INTERNAL_ERROR; } } @@ -675,13 +666,9 @@ InodeStorage::DelS3ChunkInfoList(Transaction txn, uint32_t fsId, } MetaStatusCode InodeStorage::ModifyInodeS3ChunkInfoList( - std::shared_ptr* txn, - uint32_t fsId, - uint64_t inodeId, - uint64_t chunkIndex, - const S3ChunkInfoList* list2add, - const S3ChunkInfoList* list2del, - int64_t logIndex) { + std::shared_ptr* txn, uint32_t fsId, uint64_t inodeId, + uint64_t chunkIndex, const S3ChunkInfoList* list2add, + const S3ChunkInfoList* list2del, int64_t logIndex) { if (*txn == nullptr) { *txn = kvStorage_->BeginTransaction(); if (*txn == nullptr) { @@ -785,8 +772,8 @@ MetaStatusCode InodeStorage::PaddingInodeS3ChunkInfo(int32_t fsId, return MetaStatusCode::OK; } -std::shared_ptr -InodeStorage::GetInodeS3ChunkInfoList(uint32_t fsId, uint64_t inodeId) { +std::shared_ptr InodeStorage::GetInodeS3ChunkInfoList( + uint32_t fsId, uint64_t inodeId) { ReadLockGuard lg(rwLock_); Prefix4InodeS3ChunkInfoList prefix(fsId, inodeId); std::string sprefix = conv_.SerializeToString(prefix); @@ -832,10 +819,9 @@ MetaStatusCode InodeStorage::UpdateVolumeExtentSlice( return MetaStatusCode::OK; } -MetaStatusCode -InodeStorage::UpdateVolumeExtentSlice(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSlice& slice, - int64_t logIndex) { +MetaStatusCode InodeStorage::UpdateVolumeExtentSlice( + uint32_t fsId, uint64_t inodeId, const VolumeExtentSlice& slice, + int64_t logIndex) { std::shared_ptr txn; auto rc = UpdateVolumeExtentSlice(&txn, fsId, inodeId, slice, logIndex); if (rc != MetaStatusCode::OK) { @@ -855,9 +841,8 @@ InodeStorage::UpdateVolumeExtentSlice(uint32_t fsId, uint64_t inodeId, return MetaStatusCode::OK; } -MetaStatusCode -InodeStorage::GetAllVolumeExtent(uint32_t fsId, uint64_t inodeId, - VolumeExtentSliceList* extents) { +MetaStatusCode InodeStorage::GetAllVolumeExtent( + uint32_t fsId, uint64_t inodeId, VolumeExtentSliceList* extents) { ReadLockGuard guard(rwLock_); auto key = conv_.SerializeToString(Prefix4InodeVolumeExtent{fsId, inodeId}); auto iter = kvStorage_->SSeek(table4VolumeExtent_, key); @@ -933,8 +918,7 @@ MetaStatusCode InodeStorage::GetAllBlockGroup( } MetaStatusCode InodeStorage::UpdateDeallocatableBlockGroup( - uint32_t fsId, const DeallocatableBlockGroupVec& update, - int64_t logIndex) { + uint32_t fsId, const DeallocatableBlockGroupVec& update, int64_t logIndex) { auto txn = kvStorage_->BeginTransaction(); MetaStatusCode st = MetaStatusCode::OK; @@ -1000,10 +984,10 @@ MetaStatusCode InodeStorage::UpdateDeallocatableBlockGroup( return st; } -MetaStatusCode -InodeStorage::Increase(Transaction txn, uint32_t fsId, - const IncreaseDeallocatableBlockGroup& increase, - DeallocatableBlockGroup* out) { +MetaStatusCode InodeStorage::Increase( + Transaction txn, uint32_t fsId, + const IncreaseDeallocatableBlockGroup& increase, + DeallocatableBlockGroup* out) { MetaStatusCode st = MetaStatusCode::OK; // update DeallocatableBlockGroup @@ -1040,9 +1024,9 @@ InodeStorage::Increase(Transaction txn, uint32_t fsId, return st; } -MetaStatusCode -InodeStorage::Decrease(const DecreaseDeallocatableBlockGroup& decrease, - DeallocatableBlockGroup* out) { +MetaStatusCode InodeStorage::Decrease( + const DecreaseDeallocatableBlockGroup& decrease, + DeallocatableBlockGroup* out) { VLOG(6) << "InodeStorage handle increase=" << decrease.DebugString(); if (!out->IsInitialized() || !out->has_deallocatablesize()) { LOG(ERROR) diff --git a/curvefs/src/metaserver/inode_storage.h b/curvefs/src/metaserver/inode_storage.h index 6c282642df..38ad3c5f56 100644 --- a/curvefs/src/metaserver/inode_storage.h +++ b/curvefs/src/metaserver/inode_storage.h @@ -25,23 +25,23 @@ #include #include +#include #include -#include #include -#include -#include +#include #include #include +#include #include -#include "absl/container/btree_set.h" #include "absl/container/btree_map.h" -#include "curvefs/src/metaserver/storage/status.h" -#include "src/common/concurrent/rw_lock.h" +#include "absl/container/btree_set.h" #include "curvefs/proto/metaserver.pb.h" #include "curvefs/src/metaserver/storage/converter.h" -#include "curvefs/src/metaserver/storage/utils.h" +#include "curvefs/src/metaserver/storage/status.h" #include "curvefs/src/metaserver/storage/storage.h" +#include "curvefs/src/metaserver/storage/utils.h" +#include "src/common/concurrent/rw_lock.h" namespace curvefs { namespace metaserver { @@ -164,11 +164,9 @@ class InodeStorage { const VolumeExtentSlice& slice, int64_t logIndex); - MetaStatusCode - UpdateVolumeExtentSlice(std::shared_ptr* txn, - uint32_t fsId, uint64_t inodeId, - const VolumeExtentSlice& slice, - int64_t logIndex); + MetaStatusCode UpdateVolumeExtentSlice( + std::shared_ptr* txn, uint32_t fsId, + uint64_t inodeId, const VolumeExtentSlice& slice, int64_t logIndex); MetaStatusCode GetAllVolumeExtent(uint32_t fsId, uint64_t inodeId, VolumeExtentSliceList* extents); @@ -182,10 +180,9 @@ class InodeStorage { // use the transaction to delete {inodes} in the deallocatable_inode_list // and update the statistics of each item of blockgroup_list - MetaStatusCode - UpdateDeallocatableBlockGroup(uint32_t fsId, - const DeallocatableBlockGroupVec& update, - int64_t logIndex); + MetaStatusCode UpdateDeallocatableBlockGroup( + uint32_t fsId, const DeallocatableBlockGroupVec& update, + int64_t logIndex); MetaStatusCode GetAllBlockGroup( std::vector* deallocatableBlockGroupVec); diff --git a/curvefs/src/metaserver/metastore.cpp b/curvefs/src/metaserver/metastore.cpp index 79fcadb4e2..875f71cffc 100644 --- a/curvefs/src/metaserver/metastore.cpp +++ b/curvefs/src/metaserver/metastore.cpp @@ -168,15 +168,15 @@ void MetaStoreImpl::SaveBackground(const std::string &path, done->Run(); } -bool MetaStoreImpl::SaveMeta(const std::string &dir, - std::vector *files) { +bool MetaStoreImpl::SaveMeta(const std::string& dir, + std::vector* files) { // NOTE: we will keep meta fstream consistent with // snapshot metadata, so we should hold the locks // during `fstream.Save()` WriteLockGuard writeLockGuard(rwLock_); MetaStoreFStream fstream(&partitionMap_, kvStorage_, - copysetNode_->GetPoolId(), - copysetNode_->GetCopysetId()); + copysetNode_->GetPoolId(), + copysetNode_->GetCopysetId()); const std::string metadata = dir + "/" + kMetaDataFilename; if (fstream.Save(metadata)) { @@ -186,8 +186,8 @@ bool MetaStoreImpl::SaveMeta(const std::string &dir, return false; } -bool MetaStoreImpl::SaveData(const std::string &dir, - std::vector *files) { +bool MetaStoreImpl::SaveData(const std::string& dir, + std::vector* files) { butil::Timer timer; timer.start(); std::vector tmp; @@ -195,7 +195,7 @@ bool MetaStoreImpl::SaveData(const std::string &dir, if (!succ) { return false; } - for (auto & file : tmp) { + for (auto& file : tmp) { files->push_back(std::move(file)); } timer.stop(); @@ -241,10 +241,9 @@ bool MetaStoreImpl::Destroy() { return true; } -MetaStatusCode -MetaStoreImpl::CreatePartition(const CreatePartitionRequest *request, - CreatePartitionResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::CreatePartition( + const CreatePartitionRequest* request, CreatePartitionResponse* response, + int64_t logIndex) { // NOTE: we doesn't filter in-memory data changes (void)logIndex; WriteLockGuard writeLockGuard(rwLock_); @@ -264,10 +263,9 @@ MetaStoreImpl::CreatePartition(const CreatePartitionRequest *request, return MetaStatusCode::OK; } -MetaStatusCode -MetaStoreImpl::DeletePartition(const DeletePartitionRequest *request, - DeletePartitionResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::DeletePartition( + const DeletePartitionRequest* request, DeletePartitionResponse* response, + int64_t logIndex) { // NOTE: we doesn't filter in-memory data changes (void)logIndex; WriteLockGuard writeLockGuard(rwLock_); @@ -362,8 +360,8 @@ std::shared_ptr MetaStoreImpl::GetStreamServer() { // dentry -MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest *request, - CreateDentryResponse *response, +MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest* request, + CreateDentryResponse* response, int64_t logIndex) { ReadLockGuard readLockGuard(rwLock_); std::shared_ptr partition; @@ -383,8 +381,8 @@ MetaStatusCode MetaStoreImpl::CreateDentry(const CreateDentryRequest *request, return status; } -MetaStatusCode MetaStoreImpl::GetDentry(const GetDentryRequest *request, - GetDentryResponse *response, +MetaStatusCode MetaStoreImpl::GetDentry(const GetDentryRequest* request, + GetDentryResponse* response, int64_t logIndex) { // NOTE: filter read-only request is unnecessary (void)logIndex; @@ -411,8 +409,8 @@ MetaStatusCode MetaStoreImpl::GetDentry(const GetDentryRequest *request, return rc; } -MetaStatusCode MetaStoreImpl::DeleteDentry(const DeleteDentryRequest *request, - DeleteDentryResponse *response, +MetaStatusCode MetaStoreImpl::DeleteDentry(const DeleteDentryRequest* request, + DeleteDentryResponse* response, int64_t logIndex) { uint32_t fsId = request->fsid(); uint64_t parentInodeId = request->parentinodeid(); @@ -435,8 +433,8 @@ MetaStatusCode MetaStoreImpl::DeleteDentry(const DeleteDentryRequest *request, return rc; } -MetaStatusCode MetaStoreImpl::ListDentry(const ListDentryRequest *request, - ListDentryResponse *response, +MetaStatusCode MetaStoreImpl::ListDentry(const ListDentryRequest* request, + ListDentryResponse* response, int64_t logIndex) { // NOTE: filter read-only request is unnecessary (void)logIndex; @@ -471,10 +469,9 @@ MetaStatusCode MetaStoreImpl::ListDentry(const ListDentryRequest *request, return rc; } -MetaStatusCode -MetaStoreImpl::PrepareRenameTx(const PrepareRenameTxRequest *request, - PrepareRenameTxResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::PrepareRenameTx( + const PrepareRenameTxRequest* request, PrepareRenameTxResponse* response, + int64_t logIndex) { ReadLockGuard readLockGuard(rwLock_); MetaStatusCode rc; std::shared_ptr partition; @@ -491,8 +488,8 @@ MetaStoreImpl::PrepareRenameTx(const PrepareRenameTxRequest *request, } // inode -MetaStatusCode MetaStoreImpl::CreateInode(const CreateInodeRequest *request, - CreateInodeResponse *response, +MetaStatusCode MetaStoreImpl::CreateInode(const CreateInodeRequest* request, + CreateInodeResponse* response, int64_t logIndex) { InodeParam param; param.fsId = request->fsid(); @@ -536,10 +533,9 @@ MetaStatusCode MetaStoreImpl::CreateInode(const CreateInodeRequest *request, return status; } -MetaStatusCode -MetaStoreImpl::CreateRootInode(const CreateRootInodeRequest *request, - CreateRootInodeResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::CreateRootInode( + const CreateRootInodeRequest* request, CreateRootInodeResponse* response, + int64_t logIndex) { InodeParam param; param.fsId = request->fsid(); param.uid = request->uid(); @@ -570,10 +566,9 @@ MetaStoreImpl::CreateRootInode(const CreateRootInodeRequest *request, return status; } -MetaStatusCode -MetaStoreImpl::CreateManageInode(const CreateManageInodeRequest *request, - CreateManageInodeResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::CreateManageInode( + const CreateManageInodeRequest* request, + CreateManageInodeResponse* response, int64_t logIndex) { InodeParam param; param.fsId = request->fsid(); param.uid = request->uid(); @@ -619,8 +614,8 @@ MetaStoreImpl::CreateManageInode(const CreateManageInodeRequest *request, return MetaStatusCode::OK; } -MetaStatusCode MetaStoreImpl::GetInode(const GetInodeRequest *request, - GetInodeResponse *response, +MetaStatusCode MetaStoreImpl::GetInode(const GetInodeRequest* request, + GetInodeResponse* response, int64_t logIndex) { // NOTE: filter read-only request is unnecessary (void)logIndex; @@ -656,10 +651,9 @@ MetaStatusCode MetaStoreImpl::GetInode(const GetInodeRequest *request, return rc; } -MetaStatusCode -MetaStoreImpl::BatchGetInodeAttr(const BatchGetInodeAttrRequest *request, - BatchGetInodeAttrResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::BatchGetInodeAttr( + const BatchGetInodeAttrRequest* request, + BatchGetInodeAttrResponse* response, int64_t logIndex) { // NOTE: filter read-only request is unnecessary (void)logIndex; ReadLockGuard readLockGuard(rwLock_); @@ -681,8 +675,8 @@ MetaStoreImpl::BatchGetInodeAttr(const BatchGetInodeAttrRequest *request, return status; } -MetaStatusCode MetaStoreImpl::BatchGetXAttr(const BatchGetXAttrRequest *request, - BatchGetXAttrResponse *response, +MetaStatusCode MetaStoreImpl::BatchGetXAttr(const BatchGetXAttrRequest* request, + BatchGetXAttrResponse* response, int64_t logIndex) { // NOTE: filter read-only request is unnecessary (void)logIndex; @@ -705,8 +699,8 @@ MetaStatusCode MetaStoreImpl::BatchGetXAttr(const BatchGetXAttrRequest *request, return status; } -MetaStatusCode MetaStoreImpl::DeleteInode(const DeleteInodeRequest *request, - DeleteInodeResponse *response, +MetaStatusCode MetaStoreImpl::DeleteInode(const DeleteInodeRequest* request, + DeleteInodeResponse* response, int64_t logIndex) { uint32_t fsId = request->fsid(); uint64_t inodeId = request->inodeid(); @@ -720,8 +714,8 @@ MetaStatusCode MetaStoreImpl::DeleteInode(const DeleteInodeRequest *request, return status; } -MetaStatusCode MetaStoreImpl::UpdateInode(const UpdateInodeRequest *request, - UpdateInodeResponse *response, +MetaStatusCode MetaStoreImpl::UpdateInode(const UpdateInodeRequest* request, + UpdateInodeResponse* response, int64_t logIndex) { ReadLockGuard readLockGuard(rwLock_); VLOG(9) << "UpdateInode inode " << request->inodeid(); @@ -734,9 +728,9 @@ MetaStatusCode MetaStoreImpl::UpdateInode(const UpdateInodeRequest *request, } MetaStatusCode MetaStoreImpl::GetOrModifyS3ChunkInfo( - const GetOrModifyS3ChunkInfoRequest *request, - GetOrModifyS3ChunkInfoResponse *response, - std::shared_ptr *iterator, int64_t logIndex) { + const GetOrModifyS3ChunkInfoRequest* request, + GetOrModifyS3ChunkInfoResponse* response, + std::shared_ptr* iterator, int64_t logIndex) { MetaStatusCode rc; ReadLockGuard readLockGuard(rwLock_); std::shared_ptr partition; @@ -803,10 +797,9 @@ std::shared_ptr MetaStoreImpl::GetPartition(uint32_t partitionId) { return nullptr; } -MetaStatusCode -MetaStoreImpl::GetVolumeExtent(const GetVolumeExtentRequest *request, - GetVolumeExtentResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::GetVolumeExtent( + const GetVolumeExtentRequest* request, GetVolumeExtentResponse* response, + int64_t logIndex) { // NOTE: filter read-only request is unnecessary (void)logIndex; ReadLockGuard guard(rwLock_); @@ -825,10 +818,9 @@ MetaStoreImpl::GetVolumeExtent(const GetVolumeExtentRequest *request, return st; } -MetaStatusCode -MetaStoreImpl::UpdateVolumeExtent(const UpdateVolumeExtentRequest *request, - UpdateVolumeExtentResponse *response, - int64_t logIndex) { +MetaStatusCode MetaStoreImpl::UpdateVolumeExtent( + const UpdateVolumeExtentRequest* request, + UpdateVolumeExtentResponse* response, int64_t logIndex) { ReadLockGuard guard(rwLock_); std::shared_ptr partition; GET_PARTITION_OR_RETURN(partition); @@ -842,8 +834,8 @@ MetaStoreImpl::UpdateVolumeExtent(const UpdateVolumeExtentRequest *request, } MetaStatusCode MetaStoreImpl::UpdateDeallocatableBlockGroup( - const UpdateDeallocatableBlockGroupRequest *request, - UpdateDeallocatableBlockGroupResponse *response, int64_t logIndex) { + const UpdateDeallocatableBlockGroupRequest* request, + UpdateDeallocatableBlockGroupResponse* response, int64_t logIndex) { ReadLockGuard guard(rwLock_); std::shared_ptr partition; GET_PARTITION_OR_RETURN(partition); diff --git a/curvefs/src/metaserver/metastore.h b/curvefs/src/metaserver/metastore.h index 5af0ab63a2..a13c0a4980 100644 --- a/curvefs/src/metaserver/metastore.h +++ b/curvefs/src/metaserver/metastore.h @@ -112,21 +112,19 @@ class MetaStore { virtual ~MetaStore() = default; virtual bool Load(const std::string& pathname) = 0; - virtual bool SaveMeta(const std::string &dir, - std::vector *files) = 0; - virtual bool SaveData(const std::string &dir, - std::vector *files) = 0; + virtual bool SaveMeta(const std::string& dir, + std::vector* files) = 0; + virtual bool SaveData(const std::string& dir, + std::vector* files) = 0; virtual bool Clear() = 0; virtual bool Destroy() = 0; virtual MetaStatusCode CreatePartition( const CreatePartitionRequest* request, - CreatePartitionResponse* response, - int64_t logIndex) = 0; + CreatePartitionResponse* response, int64_t logIndex) = 0; virtual MetaStatusCode DeletePartition( const DeletePartitionRequest* request, - DeletePartitionResponse* response, - int64_t logIndex) = 0; + DeletePartitionResponse* response, int64_t logIndex) = 0; virtual bool GetPartitionInfoList( std::list *partitionInfoList) = 0; @@ -143,7 +141,7 @@ class MetaStore { virtual MetaStatusCode GetDentry(const GetDentryRequest* request, GetDentryResponse* response, - int64_t logIndex) = 0; + int64_t logIndex) = 0; virtual MetaStatusCode DeleteDentry(const DeleteDentryRequest* request, DeleteDentryResponse* response, @@ -151,54 +149,49 @@ class MetaStore { virtual MetaStatusCode ListDentry(const ListDentryRequest* request, ListDentryResponse* response, - int64_t logIndex) = 0; + int64_t logIndex) = 0; virtual MetaStatusCode PrepareRenameTx( const PrepareRenameTxRequest* request, - PrepareRenameTxResponse* response, - int64_t logIndex) = 0; + PrepareRenameTxResponse* response, int64_t logIndex) = 0; // inode virtual MetaStatusCode CreateInode(const CreateInodeRequest* request, CreateInodeResponse* response, - int64_t logIndex) = 0; + int64_t logIndex) = 0; virtual MetaStatusCode CreateRootInode( const CreateRootInodeRequest* request, - CreateRootInodeResponse* response, - int64_t logIndex) = 0; + CreateRootInodeResponse* response, int64_t logIndex) = 0; virtual MetaStatusCode CreateManageInode( - const CreateManageInodeRequest* request, - CreateManageInodeResponse* response, - int64_t logIndex) = 0; + const CreateManageInodeRequest* request, + CreateManageInodeResponse* response, int64_t logIndex) = 0; virtual MetaStatusCode GetInode(const GetInodeRequest* request, GetInodeResponse* response, int64_t logIndex) = 0; virtual MetaStatusCode BatchGetInodeAttr( - const BatchGetInodeAttrRequest* request, - BatchGetInodeAttrResponse* response, - int64_t logIndex) = 0; + const BatchGetInodeAttrRequest* request, + BatchGetInodeAttrResponse* response, int64_t logIndex) = 0; virtual MetaStatusCode BatchGetXAttr(const BatchGetXAttrRequest* request, - BatchGetXAttrResponse* response, - int64_t logIndex) = 0; + BatchGetXAttrResponse* response, + int64_t logIndex) = 0; virtual MetaStatusCode DeleteInode(const DeleteInodeRequest* request, DeleteInodeResponse* response, - int64_t logIndex) = 0; + int64_t logIndex) = 0; virtual MetaStatusCode UpdateInode(const UpdateInodeRequest* request, UpdateInodeResponse* response, - int64_t logIndex) = 0; + int64_t logIndex) = 0; virtual MetaStatusCode GetOrModifyS3ChunkInfo( const GetOrModifyS3ChunkInfoRequest* request, GetOrModifyS3ChunkInfoResponse* response, - std::shared_ptr* iterator, - int64_t logIndex) = 0; + std::shared_ptr* iterator, int64_t logIndex) = 0; virtual MetaStatusCode SendS3ChunkInfoByStream( std::shared_ptr connection, @@ -206,18 +199,15 @@ class MetaStore { virtual MetaStatusCode GetVolumeExtent( const GetVolumeExtentRequest* request, - GetVolumeExtentResponse* response, - int64_t logIndex) = 0; + GetVolumeExtentResponse* response, int64_t logIndex) = 0; virtual MetaStatusCode UpdateVolumeExtent( const UpdateVolumeExtentRequest* request, - UpdateVolumeExtentResponse* response, - int64_t logIndex) = 0; + UpdateVolumeExtentResponse* response, int64_t logIndex) = 0; virtual MetaStatusCode UpdateDeallocatableBlockGroup( - const UpdateDeallocatableBlockGroupRequest *request, - UpdateDeallocatableBlockGroupResponse *response, - int64_t logIndex) = 0; + const UpdateDeallocatableBlockGroupRequest* request, + UpdateDeallocatableBlockGroupResponse* response, int64_t logIndex) = 0; }; class MetaStoreImpl : public MetaStore { @@ -227,20 +217,20 @@ class MetaStoreImpl : public MetaStore { const storage::StorageOptions& storageOptions); bool Load(const std::string& checkpoint) override; - bool SaveMeta(const std::string &dir, - std::vector *files) override; - bool SaveData(const std::string &dir, - std::vector *files) override; + bool SaveMeta(const std::string& dir, + std::vector* files) override; + bool SaveData(const std::string& dir, + std::vector* files) override; bool Clear() override; bool Destroy() override; MetaStatusCode CreatePartition(const CreatePartitionRequest* request, CreatePartitionResponse* response, - int64_t logIndex) override; + int64_t logIndex) override; MetaStatusCode DeletePartition(const DeletePartitionRequest* request, DeletePartitionResponse* response, - int64_t logIndex) override; + int64_t logIndex) override; bool GetPartitionInfoList( std::list *partitionInfoList) override; @@ -280,18 +270,17 @@ class MetaStoreImpl : public MetaStore { CreateRootInodeResponse* response, int64_t logIndex) override; - MetaStatusCode CreateManageInode( - const CreateManageInodeRequest* request, - CreateManageInodeResponse* response, - int64_t logIndex) override; + MetaStatusCode CreateManageInode(const CreateManageInodeRequest* request, + CreateManageInodeResponse* response, + int64_t logIndex) override; MetaStatusCode GetInode(const GetInodeRequest* request, GetInodeResponse* response, int64_t logIndex) override; MetaStatusCode BatchGetInodeAttr(const BatchGetInodeAttrRequest* request, - BatchGetInodeAttrResponse* response, - int64_t logIndex) override; + BatchGetInodeAttrResponse* response, + int64_t logIndex) override; MetaStatusCode BatchGetXAttr(const BatchGetXAttrRequest* request, BatchGetXAttrResponse* response, @@ -310,8 +299,7 @@ class MetaStoreImpl : public MetaStore { MetaStatusCode GetOrModifyS3ChunkInfo( const GetOrModifyS3ChunkInfoRequest* request, GetOrModifyS3ChunkInfoResponse* response, - std::shared_ptr* iterator, - int64_t logIndex) override; + std::shared_ptr* iterator, int64_t logIndex) override; MetaStatusCode SendS3ChunkInfoByStream( std::shared_ptr connection, @@ -321,15 +309,14 @@ class MetaStoreImpl : public MetaStore { GetVolumeExtentResponse* response, int64_t logIndex) override; - MetaStatusCode UpdateVolumeExtent( - const UpdateVolumeExtentRequest* request, - UpdateVolumeExtentResponse* response, - int64_t logIndex) override; + MetaStatusCode UpdateVolumeExtent(const UpdateVolumeExtentRequest* request, + UpdateVolumeExtentResponse* response, + int64_t logIndex) override; // block group MetaStatusCode UpdateDeallocatableBlockGroup( - const UpdateDeallocatableBlockGroupRequest *request, - UpdateDeallocatableBlockGroupResponse *response, + const UpdateDeallocatableBlockGroupRequest* request, + UpdateDeallocatableBlockGroupResponse* response, int64_t logIndex) override; private: diff --git a/curvefs/src/metaserver/metastore_fstream.cpp b/curvefs/src/metaserver/metastore_fstream.cpp index 06cdae9e6d..c2782bfd26 100644 --- a/curvefs/src/metaserver/metastore_fstream.cpp +++ b/curvefs/src/metaserver/metastore_fstream.cpp @@ -207,34 +207,34 @@ bool MetaStoreFStream::Load(const std::string &pathname, uint8_t *version) { uint64_t totalPartition = 0; uint64_t totalPendingTx = 0; auto callback = [&](uint8_t version, ENTRY_TYPE entryType, - uint32_t partitionId, const std::string &key, - const std::string &value) -> bool { + uint32_t partitionId, const std::string& key, + const std::string& value) -> bool { (void)version; switch (entryType) { - case ENTRY_TYPE::PARTITION: - ++totalPartition; - return LoadPartition(partitionId, key, value); - case ENTRY_TYPE::INODE: - LOG(ERROR) - << "Snapshot is too old, incompatible with current version"; - break; - case ENTRY_TYPE::DENTRY: - LOG(ERROR) - << "Snapshot is too old, incompatible with current version"; - break; - case ENTRY_TYPE::PENDING_TX: - ++totalPendingTx; - return LoadPendingTx(partitionId, key, value); - case ENTRY_TYPE::S3_CHUNK_INFO_LIST: - LOG(ERROR) - << "Snapshot is too old, incompatible with current version"; - break; - case ENTRY_TYPE::VOLUME_EXTENT: - LOG(ERROR) - << "Snapshot is too old, incompatible with current version"; - break; - case ENTRY_TYPE::UNKNOWN: - break; + case ENTRY_TYPE::PARTITION: + ++totalPartition; + return LoadPartition(partitionId, key, value); + case ENTRY_TYPE::INODE: + LOG(ERROR) + << "Snapshot is too old, incompatible with current version"; + break; + case ENTRY_TYPE::DENTRY: + LOG(ERROR) + << "Snapshot is too old, incompatible with current version"; + break; + case ENTRY_TYPE::PENDING_TX: + ++totalPendingTx; + return LoadPendingTx(partitionId, key, value); + case ENTRY_TYPE::S3_CHUNK_INFO_LIST: + LOG(ERROR) + << "Snapshot is too old, incompatible with current version"; + break; + case ENTRY_TYPE::VOLUME_EXTENT: + LOG(ERROR) + << "Snapshot is too old, incompatible with current version"; + break; + case ENTRY_TYPE::UNKNOWN: + break; } LOG(ERROR) << "Load failed, unknown entry type"; diff --git a/curvefs/src/metaserver/partition.cpp b/curvefs/src/metaserver/partition.cpp index aa40f6f2a9..3c3e7d7b99 100644 --- a/curvefs/src/metaserver/partition.cpp +++ b/curvefs/src/metaserver/partition.cpp @@ -31,14 +31,14 @@ #include #include "curvefs/proto/metaserver.pb.h" -#include "curvefs/src/metaserver/s3compact_manager.h" -#include "curvefs/src/metaserver/trash_manager.h" -#include "curvefs/src/metaserver/storage/converter.h" +#include "curvefs/src/metaserver/copyset/copyset_node_manager.h" +#include "curvefs/src/metaserver/mds/fsinfo_manager.h" #include "curvefs/src/metaserver/s3compact.h" +#include "curvefs/src/metaserver/s3compact_manager.h" #include "curvefs/src/metaserver/space/inode_volume_space_deallocate.h" #include "curvefs/src/metaserver/space/volume_deallocate_manager.h" -#include "curvefs/src/metaserver/copyset/copyset_node_manager.h" -#include "curvefs/src/metaserver/mds/fsinfo_manager.h" +#include "curvefs/src/metaserver/storage/converter.h" +#include "curvefs/src/metaserver/trash_manager.h" namespace curvefs { namespace metaserver { @@ -68,7 +68,6 @@ Partition::Partition(PartitionInfo partition, dentryStorage_ = std::make_shared(kvStorage_, nameGen_, nDentry); - auto trash = std::make_shared(inodeStorage_); inodeManager_ = std::make_shared( inodeStorage_, trash, partitionInfo_.mutable_filetype2inodenum()); @@ -91,28 +90,27 @@ Partition::Partition(PartitionInfo partition, } } -#define PRECHECK(fsId, inodeId) \ - do { \ - if (!IsInodeBelongs((fsId), (inodeId))) { \ - return MetaStatusCode::PARTITION_ID_MISSMATCH; \ - } \ - if (GetStatus() == PartitionStatus::DELETING) { \ - return MetaStatusCode::PARTITION_DELETING; \ - } \ +#define PRECHECK(fsId, inodeId) \ + do { \ + if (!IsInodeBelongs((fsId), (inodeId))) { \ + return MetaStatusCode::PARTITION_ID_MISSMATCH; \ + } \ + if (GetStatus() == PartitionStatus::DELETING) { \ + return MetaStatusCode::PARTITION_DELETING; \ + } \ } while (0) -#define PRECHECK_FSID(fsId) \ - do { \ - if (!IsInodeBelongs((fsId))) { \ - return MetaStatusCode::PARTITION_ID_MISSMATCH; \ - } \ - if (GetStatus() == PartitionStatus::DELETING) { \ - return MetaStatusCode::PARTITION_DELETING; \ - } \ +#define PRECHECK_FSID(fsId) \ + do { \ + if (!IsInodeBelongs((fsId))) { \ + return MetaStatusCode::PARTITION_ID_MISSMATCH; \ + } \ + if (GetStatus() == PartitionStatus::DELETING) { \ + return MetaStatusCode::PARTITION_DELETING; \ + } \ } while (0) -MetaStatusCode Partition::CreateDentry(const Dentry& dentry, - const Time& tm, +MetaStatusCode Partition::CreateDentry(const Dentry& dentry, const Time& tm, int64_t logIndex) { PRECHECK(dentry.fsid(), dentry.parentinodeid()); MetaStatusCode ret = dentryManager_->CreateDentry(dentry, logIndex); @@ -130,8 +128,7 @@ MetaStatusCode Partition::CreateDentry(const Dentry& dentry, // NOTE: we enter here means that // this log maybe is "half apply" ret = inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry.fsid(), dentry.parentinodeid(), dentry.type(), true, - logIndex); + dentry, tm.sec(), tm.nsec(), true, logIndex); if (ret == MetaStatusCode::IDEMPOTENCE_OK) { ret = MetaStatusCode::OK; } @@ -158,8 +155,7 @@ MetaStatusCode Partition::LoadDentry(const DentryVec& vec, bool merge, return rc; } -MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, - int64_t logIndex) { +MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, int64_t logIndex) { PRECHECK(dentry.fsid(), dentry.parentinodeid()); MetaStatusCode ret = dentryManager_->DeleteDentry(dentry, logIndex); @@ -177,8 +173,7 @@ MetaStatusCode Partition::DeleteDentry(const Dentry& dentry, // NOTE: we enter here means that // this log maybe is "half apply" ret = inodeManager_->UpdateInodeWhenCreateOrRemoveSubNode( - dentry.fsid(), dentry.parentinodeid(), dentry.type(), false, - logIndex); + dentry, 0, 0, false, logIndex); } if (ret == MetaStatusCode::IDEMPOTENCE_OK) { ret = MetaStatusCode::OK; @@ -229,8 +224,7 @@ bool Partition::Init() { // NOTE: invoke `dentryStorage::Init()` // and `inodeStorage::Init()` is unnecessary // they will be invoked by `manager` - return dentryManager_->Init() && - inodeManager_->Init() && + return dentryManager_->Init() && inodeManager_->Init() && txManager_->Init(); } @@ -293,8 +287,7 @@ MetaStatusCode Partition::CreateRootInode(const InodeParam& param, MetaStatusCode Partition::CreateManageInode(const InodeParam& param, ManageInodeType manageType, - Inode* inode, - int64_t logIndex) { + Inode* inode, int64_t logIndex) { PRECHECK_FSID(param.fsId); auto ret = inodeManager_->CreateManageInode(param, manageType, inode, logIndex); @@ -364,8 +357,7 @@ MetaStatusCode Partition::PaddingInodeS3ChunkInfo(int32_t fsId, return inodeManager_->PaddingInodeS3ChunkInfo(fsId, inodeId, m, limit); } -MetaStatusCode Partition::InsertInode(const Inode& inode, - int64_t logIndex) { +MetaStatusCode Partition::InsertInode(const Inode& inode, int64_t logIndex) { PRECHECK(inode.fsid(), inode.inodeid()); auto ret = inodeManager_->InsertInode(inode, logIndex); if (ret == MetaStatusCode::IDEMPOTENCE_OK) { @@ -484,9 +476,7 @@ uint32_t Partition::GetDentryNum() { return static_cast(dentryStorage_->Size()); } -bool Partition::EmptyInodeStorage() { - return inodeStorage_->Empty(); -} +bool Partition::EmptyInodeStorage() { return inodeStorage_->Empty(); } std::string Partition::GetInodeTablename() { std::ostringstream oss; @@ -500,10 +490,9 @@ std::string Partition::GetDentryTablename() { return oss.str(); } -MetaStatusCode -Partition::UpdateVolumeExtent(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSliceList& extents, - int64_t logIndex) { +MetaStatusCode Partition::UpdateVolumeExtent( + uint32_t fsId, uint64_t inodeId, const VolumeExtentSliceList& extents, + int64_t logIndex) { PRECHECK(fsId, inodeId); auto ret = inodeManager_->UpdateVolumeExtent(fsId, inodeId, extents, logIndex); @@ -513,10 +502,9 @@ Partition::UpdateVolumeExtent(uint32_t fsId, uint64_t inodeId, return ret; } -MetaStatusCode -Partition::UpdateVolumeExtentSlice(uint32_t fsId, uint64_t inodeId, - const VolumeExtentSlice& slice, - int64_t logIndex) { +MetaStatusCode Partition::UpdateVolumeExtentSlice( + uint32_t fsId, uint64_t inodeId, const VolumeExtentSlice& slice, + int64_t logIndex) { PRECHECK(fsId, inodeId); auto ret = inodeManager_->UpdateVolumeExtentSlice(fsId, inodeId, slice, logIndex); @@ -534,8 +522,7 @@ MetaStatusCode Partition::GetVolumeExtent(uint32_t fsId, uint64_t inodeId, } MetaStatusCode Partition::UpdateDeallocatableBlockGroup( - const UpdateDeallocatableBlockGroupRequest& request, - int64_t logIndex) { + const UpdateDeallocatableBlockGroupRequest& request, int64_t logIndex) { PRECHECK_FSID(request.fsid()); auto ret = inodeManager_->UpdateDeallocatableBlockGroup(request, logIndex); if (ret == MetaStatusCode::IDEMPOTENCE_OK) { diff --git a/curvefs/src/metaserver/partition.h b/curvefs/src/metaserver/partition.h index 58cc0b63ca..c78738cb85 100644 --- a/curvefs/src/metaserver/partition.h +++ b/curvefs/src/metaserver/partition.h @@ -28,6 +28,7 @@ #include #include #include + #include "curvefs/proto/common.pb.h" #include "curvefs/proto/metaserver.pb.h" #include "curvefs/src/common/define.h" @@ -35,8 +36,8 @@ #include "curvefs/src/metaserver/dentry_storage.h" #include "curvefs/src/metaserver/inode_manager.h" #include "curvefs/src/metaserver/inode_storage.h" -#include "curvefs/src/metaserver/trash_manager.h" #include "curvefs/src/metaserver/storage/iterator.h" +#include "curvefs/src/metaserver/trash_manager.h" namespace curvefs { namespace metaserver { @@ -57,8 +58,7 @@ class Partition { Partition() = default; // dentry - MetaStatusCode CreateDentry(const Dentry& dentry, - const Time& tm, + MetaStatusCode CreateDentry(const Dentry& dentry, const Time& tm, int64_t logIndex); MetaStatusCode LoadDentry(const DentryVec& vec, bool merge, @@ -89,8 +89,7 @@ class Partition { MetaStatusCode CreateInode(const InodeParam& param, Inode* inode, int64_t logIndex); - MetaStatusCode CreateRootInode(const InodeParam& param, - int64_t logIndex); + MetaStatusCode CreateRootInode(const InodeParam& param, int64_t logIndex); MetaStatusCode CreateManageInode(const InodeParam& param, ManageInodeType manageType, Inode* inode, @@ -132,10 +131,8 @@ class Partition { const std::vector& slices, VolumeExtentSliceList* extents); - MetaStatusCode UpdateDeallocatableBlockGroup( - const UpdateDeallocatableBlockGroupRequest& request, - int64_t logIndex); + const UpdateDeallocatableBlockGroupRequest& request, int64_t logIndex); virtual MetaStatusCode GetAllBlockGroup( std::vector* deallocatableBlockGroupVec); diff --git a/curvefs/src/metaserver/storage/converter.cpp b/curvefs/src/metaserver/storage/converter.cpp index 5732dca9b9..2e48b20d50 100644 --- a/curvefs/src/metaserver/storage/converter.cpp +++ b/curvefs/src/metaserver/storage/converter.cpp @@ -160,7 +160,11 @@ const size_t Key4S3ChunkInfoList::kMaxUint64Length_ = std::to_string(std::numeric_limits::max()).size(); Key4S3ChunkInfoList::Key4S3ChunkInfoList() - : fsId(0), inodeId(0), chunkIndex(0), firstChunkId(0), lastChunkId(0), + : fsId(0), + inodeId(0), + chunkIndex(0), + firstChunkId(0), + lastChunkId(0), size(0) {} Key4S3ChunkInfoList::Key4S3ChunkInfoList(uint32_t fsId, uint64_t inodeId, @@ -175,36 +179,32 @@ Key4S3ChunkInfoList::Key4S3ChunkInfoList(uint32_t fsId, uint64_t inodeId, size(size) {} std::string Key4S3ChunkInfoList::SerializeToString() const { - return absl::StrCat(keyType_, ":", fsId, ":", inodeId, ":", - chunkIndex, ":", absl::StrFormat("%020" PRIu64"", firstChunkId), ":", - absl::StrFormat("%020" PRIu64"", lastChunkId), ":", size); + return absl::StrCat(keyType_, ":", fsId, ":", inodeId, ":", chunkIndex, ":", + absl::StrFormat("%020" PRIu64 "", firstChunkId), ":", + absl::StrFormat("%020" PRIu64 "", lastChunkId), ":", + size); } bool Key4S3ChunkInfoList::ParseFromString(const std::string& value) { std::vector items; SplitString(value, ":", &items); return items.size() == 7 && CompareType(items[0], keyType_) && - StringToUl(items[1], &fsId) && StringToUll(items[2], &inodeId) && - StringToUll(items[3], &chunkIndex) && - StringToUll(items[4], &firstChunkId) && - StringToUll(items[5], &lastChunkId) && - StringToUll(items[6], &size); + StringToUl(items[1], &fsId) && StringToUll(items[2], &inodeId) && + StringToUll(items[3], &chunkIndex) && + StringToUll(items[4], &firstChunkId) && + StringToUll(items[5], &lastChunkId) && StringToUll(items[6], &size); } Prefix4ChunkIndexS3ChunkInfoList::Prefix4ChunkIndexS3ChunkInfoList() : fsId(0), inodeId(0), chunkIndex(0) {} Prefix4ChunkIndexS3ChunkInfoList::Prefix4ChunkIndexS3ChunkInfoList( - uint32_t fsId, - uint64_t inodeId, - uint64_t chunkIndex) + uint32_t fsId, uint64_t inodeId, uint64_t chunkIndex) : fsId(fsId), inodeId(inodeId), chunkIndex(chunkIndex) {} std::string Prefix4ChunkIndexS3ChunkInfoList::SerializeToString() const { - return absl::StrCat(keyType_, ":", - fsId, ":", - inodeId, ":", - chunkIndex, ":"); + return absl::StrCat(keyType_, ":", fsId, ":", inodeId, ":", chunkIndex, + ":"); } bool Prefix4ChunkIndexS3ChunkInfoList::ParseFromString( @@ -212,8 +212,8 @@ bool Prefix4ChunkIndexS3ChunkInfoList::ParseFromString( std::vector items; SplitString(value, ":", &items); return items.size() == 4 && CompareType(items[0], keyType_) && - StringToUl(items[1], &fsId) && StringToUll(items[2], &inodeId) && - StringToUll(items[3], &chunkIndex); + StringToUl(items[1], &fsId) && StringToUll(items[2], &inodeId) && + StringToUll(items[3], &chunkIndex); } Prefix4InodeS3ChunkInfoList::Prefix4InodeS3ChunkInfoList() @@ -231,7 +231,7 @@ bool Prefix4InodeS3ChunkInfoList::ParseFromString(const std::string& value) { std::vector items; SplitString(value, ":", &items); return items.size() == 3 && CompareType(items[0], keyType_) && - StringToUl(items[1], &fsId) && StringToUll(items[2], &inodeId); + StringToUl(items[1], &fsId) && StringToUll(items[2], &inodeId); } std::string Prefix4AllS3ChunkInfoList::SerializeToString() const { @@ -244,8 +244,7 @@ bool Prefix4AllS3ChunkInfoList::ParseFromString(const std::string& value) { return items.size() == 1 && CompareType(items[0], keyType_); } -Key4Dentry::Key4Dentry(uint32_t fsId, - uint64_t parentInodeId, +Key4Dentry::Key4Dentry(uint32_t fsId, uint64_t parentInodeId, const std::string& name) : fsId(fsId), parentInodeId(parentInodeId), name(name) {} @@ -263,9 +262,7 @@ bool Key4Dentry::ParseFromString(const std::string& value) { return false; } - size_t prefixLength = items[0].size() + - items[1].size() + - items[2].size() + + size_t prefixLength = items[0].size() + items[1].size() + items[2].size() + 3 * strlen(kDelimiter); if (value.size() < prefixLength) { return false; @@ -279,8 +276,7 @@ Prefix4SameParentDentry::Prefix4SameParentDentry(uint32_t fsId, : fsId(fsId), parentInodeId(parentInodeId) {} std::string Prefix4SameParentDentry::SerializeToString() const { - return absl::StrCat(keyType_, kDelimiter, fsId, - kDelimiter, parentInodeId, + return absl::StrCat(keyType_, kDelimiter, fsId, kDelimiter, parentInodeId, kDelimiter); } @@ -301,8 +297,7 @@ bool Prefix4AllDentry::ParseFromString(const std::string& value) { return items.size() == 1 && CompareType(items[0], keyType_); } -Key4VolumeExtentSlice::Key4VolumeExtentSlice(uint32_t fsId, - uint64_t inodeId, +Key4VolumeExtentSlice::Key4VolumeExtentSlice(uint32_t fsId, uint64_t inodeId, uint64_t offset) : fsId_(fsId), inodeId_(inodeId), offset_(offset) {} @@ -348,8 +343,7 @@ bool Prefix4AllVolumeExtent::ParseFromString(const std::string& value) { return items.size() == 1 && CompareType(items[0], keyType_); } -Key4InodeAuxInfo::Key4InodeAuxInfo(uint32_t fsId, - uint64_t inodeId) +Key4InodeAuxInfo::Key4InodeAuxInfo(uint32_t fsId, uint64_t inodeId) : fsId(fsId), inodeId(inodeId) {} std::string Key4InodeAuxInfo::SerializeToString() const { diff --git a/curvefs/src/metaserver/transaction.cpp b/curvefs/src/metaserver/transaction.cpp index 38a2889a3d..0eb20c084f 100644 --- a/curvefs/src/metaserver/transaction.cpp +++ b/curvefs/src/metaserver/transaction.cpp @@ -33,9 +33,10 @@ RenameTx::RenameTx(const std::vector& dentrys, std::shared_ptr storage) : txId_(dentrys[0].txid()), txSequence_(dentrys[0].txsequence()), - dentrys_(dentrys), storage_(storage) {} + dentrys_(dentrys), + storage_(storage) {} -bool RenameTx::Prepare(const std::string &txPayload, int64_t logIndex) { +bool RenameTx::Prepare(const std::string& txPayload, int64_t logIndex) { metaserver::TransactionRequest request; request.set_type(metaserver::TransactionRequest::Rename); request.set_rawpayload(txPayload); @@ -57,9 +58,7 @@ uint64_t RenameTx::GetTxSequence() { return txSequence_; } std::vector* RenameTx::GetDentrys() { return &dentrys_; } -const std::vector* RenameTx::GetDentrys() const { - return &dentrys_; -} +const std::vector* RenameTx::GetDentrys() const { return &dentrys_; } inline bool RenameTx::operator==(const RenameTx& rhs) { return dentrys_ == rhs.dentrys_; @@ -77,7 +76,8 @@ std::ostream& operator<<(std::ostream& os, const RenameTx& renameTx) { TxManager::TxManager(std::shared_ptr storage, common::PartitionInfo partitionInfo) - : storage_(std::move(storage)), conv_(), + : storage_(std::move(storage)), + conv_(), partitionInfo_(std::move(partitionInfo)) {} MetaStatusCode TxManager::PreCheck(const std::vector& dentrys) { diff --git a/curvefs/src/metaserver/transaction.h b/curvefs/src/metaserver/transaction.h index 7a1f9d6d98..4172288c6d 100644 --- a/curvefs/src/metaserver/transaction.h +++ b/curvefs/src/metaserver/transaction.h @@ -23,14 +23,14 @@ #ifndef CURVEFS_SRC_METASERVER_TRANSACTION_H_ #define CURVEFS_SRC_METASERVER_TRANSACTION_H_ -#include #include -#include #include +#include #include +#include -#include "src/common/concurrent/rw_lock.h" #include "curvefs/src/metaserver/dentry_storage.h" +#include "src/common/concurrent/rw_lock.h" namespace curvefs { namespace metaserver { @@ -42,7 +42,7 @@ class RenameTx { RenameTx(const std::vector& dentrys, std::shared_ptr storage); - bool Prepare(const std::string &txPayload, int64_t logIndex); + bool Prepare(const std::string& txPayload, int64_t logIndex); bool Commit(int64_t logIndex); @@ -87,8 +87,7 @@ class TxManager { void DeletePendingTx(); - bool HandlePendingTx(uint64_t txId, RenameTx* pendingTx, - int64_t logIndex); + bool HandlePendingTx(uint64_t txId, RenameTx* pendingTx, int64_t logIndex); void SerializeRenameTx(const RenameTx& in, PrepareRenameTxRequest* out); diff --git a/curvefs/test/metaserver/copyset/meta_operator_test.cpp b/curvefs/test/metaserver/copyset/meta_operator_test.cpp index 5ff178dd03..0dae55632b 100644 --- a/curvefs/test/metaserver/copyset/meta_operator_test.cpp +++ b/curvefs/test/metaserver/copyset/meta_operator_test.cpp @@ -81,8 +81,7 @@ std::string Exec(const std::string& cmd) { char buffer[4096]; std::string result; while (!feof(pipe)) { - if (fgets(buffer, 1024, pipe) != NULL) - result += buffer; + if (fgets(buffer, 1024, pipe) != NULL) result += buffer; } pclose(pipe); return result; @@ -129,10 +128,10 @@ class MetaOperatorTest : public testing::Test { TEST_F(MetaOperatorTest, OperatorTypeTest) { std::unique_ptr meta; -#define TEST_OPERATOR_TYPE(TYPE) \ - do { \ - meta = absl::make_unique(nullptr, nullptr); \ - EXPECT_EQ(OperatorType::TYPE, meta->GetOperatorType()); \ +#define TEST_OPERATOR_TYPE(TYPE) \ + do { \ + meta = absl::make_unique(nullptr, nullptr); \ + EXPECT_EQ(OperatorType::TYPE, meta->GetOperatorType()); \ } while (0) TEST_OPERATOR_TYPE(GetDentry); @@ -298,14 +297,14 @@ TEST_F(MetaOperatorTest, OnApplyFromLogErrorTest) { brpc::Controller cntl; -#define OPERATOR_ON_APPLY_FROM_LOG_TEST(TYPE) \ - { \ - EXPECT_CALL(*mockMetaStore, TYPE(_, _, _)) \ - .WillOnce(Return(MetaStatusCode::UNKNOWN_ERROR)); \ - TYPE##Request request; \ - auto op = absl::make_unique(&node, &request, false); \ - op->OnApplyFromLog(logIndex_++, TimeUtility::GetTimeofDayUs()); \ - op.release(); \ +#define OPERATOR_ON_APPLY_FROM_LOG_TEST(TYPE) \ + { \ + EXPECT_CALL(*mockMetaStore, TYPE(_, _, _)) \ + .WillOnce(Return(MetaStatusCode::UNKNOWN_ERROR)); \ + TYPE##Request request; \ + auto op = absl::make_unique(&node, &request, false); \ + op->OnApplyFromLog(logIndex_++, TimeUtility::GetTimeofDayUs()); \ + op.release(); \ } OPERATOR_ON_APPLY_FROM_LOG_TEST(CreateDentry); @@ -332,13 +331,13 @@ TEST_F(MetaOperatorTest, OnApplyFromLogErrorTest) { op.release(); } -#define OPERATOR_ON_APPLY_FROM_LOG_DO_NOTHING_TEST(TYPE) \ - { \ - EXPECT_CALL(*mockMetaStore, TYPE(_, _, _)).Times(0); \ - TYPE##Request request; \ - auto op = absl::make_unique(&node, &request, false); \ - op->OnApplyFromLog(logIndex_++, TimeUtility::GetTimeofDayUs()); \ - op.release(); \ +#define OPERATOR_ON_APPLY_FROM_LOG_DO_NOTHING_TEST(TYPE) \ + { \ + EXPECT_CALL(*mockMetaStore, TYPE(_, _, _)).Times(0); \ + TYPE##Request request; \ + auto op = absl::make_unique(&node, &request, false); \ + op->OnApplyFromLog(logIndex_++, TimeUtility::GetTimeofDayUs()); \ + op.release(); \ } OPERATOR_ON_APPLY_FROM_LOG_DO_NOTHING_TEST(GetDentry); @@ -375,26 +374,30 @@ TEST_F(MetaOperatorTest, OnApplyFromLogErrorTest) { "/vars | grep " "op_apply_from_log_pool_100_copyset_100_delete_inode_total_error", 1)); - EXPECT_TRUE(CheckMetric( - "curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + - "/vars | grep " - "op_apply_from_log_pool_100_copyset_100_create_root_inode_total_error", - 1)); - EXPECT_TRUE(CheckMetric( - "curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + - "/vars | grep " - "op_apply_from_log_pool_100_copyset_100_create_partition_total_error", - 1)); - EXPECT_TRUE(CheckMetric( - "curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + - "/vars | grep " - "op_apply_from_log_pool_100_copyset_100_delete_partition_total_error", - 1)); - EXPECT_TRUE(CheckMetric( - "curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + - "/vars | grep " - "op_apply_from_log_pool_100_copyset_100_prepare_rename_tx_total_error", - 1)); + EXPECT_TRUE( + CheckMetric("curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + + "/vars | grep " + "op_apply_from_log_pool_100_copyset_100_create_root_" + "inode_total_error", + 1)); + EXPECT_TRUE( + CheckMetric("curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + + "/vars | grep " + "op_apply_from_log_pool_100_copyset_100_create_" + "partition_total_error", + 1)); + EXPECT_TRUE( + CheckMetric("curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + + "/vars | grep " + "op_apply_from_log_pool_100_copyset_100_delete_" + "partition_total_error", + 1)); + EXPECT_TRUE( + CheckMetric("curl -s 0.0.0.0:" + std::to_string(kDummyServerPort) + + "/vars | grep " + "op_apply_from_log_pool_100_copyset_100_prepare_rename_" + "tx_total_error", + 1)); } TEST_F(MetaOperatorTest, PropostTest_IsNotLeader) { @@ -437,14 +440,10 @@ TEST_F(MetaOperatorTest, PropostTest_RequestCanBypassProcess) { auto* mockRaftNode = new MockRaftNode(); node.SetRaftNode(mockRaftNode); - ON_CALL(*mockMetaStore, Clear()) - .WillByDefault(Return(true)); - EXPECT_CALL(*mockRaftNode, apply(_)) - .Times(0); - EXPECT_CALL(*mockRaftNode, shutdown(_)) - .Times(AtLeast(1)); - EXPECT_CALL(*mockRaftNode, join()) - .Times(AtLeast(1)); + ON_CALL(*mockMetaStore, Clear()).WillByDefault(Return(true)); + EXPECT_CALL(*mockRaftNode, apply(_)).Times(0); + EXPECT_CALL(*mockRaftNode, shutdown(_)).Times(AtLeast(1)); + EXPECT_CALL(*mockRaftNode, join()).Times(AtLeast(1)); EXPECT_CALL(*mockMetaStore, GetDentry(_, _, _)) .WillOnce(Return(MetaStatusCode::OK)); @@ -486,8 +485,7 @@ TEST_F(MetaOperatorTest, PropostTest_IsNotLeaseLeader) { options.localFileSystem = &localFs; options.storageOptions.type = "memory"; - EXPECT_CALL(localFs, Mkdir(_)) - .WillOnce(Return(0)); + EXPECT_CALL(localFs, Mkdir(_)).WillOnce(Return(0)); EXPECT_TRUE(node.Init(options)); auto* mockRaftNode = new MockRaftNode(); @@ -522,8 +520,7 @@ TEST_F(MetaOperatorTest, PropostTest_PropostTaskFailed) { options.localFileSystem = &localFs; options.storageOptions.type = "memory"; - EXPECT_CALL(localFs, Mkdir(_)) - .WillOnce(Return(0)); + EXPECT_CALL(localFs, Mkdir(_)).WillOnce(Return(0)); EXPECT_TRUE(node.Init(options)); auto* mockRaftNode = new MockRaftNode(); diff --git a/curvefs/test/metaserver/dentry_manager_test.cpp b/curvefs/test/metaserver/dentry_manager_test.cpp index 1ffef8882b..f113eca4dc 100644 --- a/curvefs/test/metaserver/dentry_manager_test.cpp +++ b/curvefs/test/metaserver/dentry_manager_test.cpp @@ -89,12 +89,8 @@ class DentryManagerTest : public ::testing::Test { return result; } - Dentry GenDentry(uint32_t fsId, - uint64_t parentId, - const std::string& name, - uint64_t txId, - uint64_t inodeId, - bool deleteMarkFlag) { + Dentry GenDentry(uint32_t fsId, uint64_t parentId, const std::string& name, + uint64_t txId, uint64_t inodeId, bool deleteMarkFlag) { Dentry dentry; dentry.set_fsid(fsId); dentry.set_parentinodeid(parentId); diff --git a/curvefs/test/metaserver/dentry_storage_test.cpp b/curvefs/test/metaserver/dentry_storage_test.cpp index bde4ecd537..4464f20c76 100644 --- a/curvefs/test/metaserver/dentry_storage_test.cpp +++ b/curvefs/test/metaserver/dentry_storage_test.cpp @@ -244,7 +244,8 @@ TEST_F(DentryStorageTest, Get) { ASSERT_EQ(storage.Get(&dentry), MetaStatusCode::NOT_FOUND); // CASE 2: get success - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "B", 0, 2, false), @@ -262,7 +263,8 @@ TEST_F(DentryStorageTest, Get) { // CASE 3: get multi-dentrys with different txid storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "A", 1, 2, false), @@ -275,7 +277,8 @@ TEST_F(DentryStorageTest, Get) { // CASE 4: get dentry with DELETE_MARK_FLAG flag storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "A", 1, 1, true), @@ -294,7 +297,8 @@ TEST_F(DentryStorageTest, List) { Dentry dentry; // CASE 1: basic list - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A1", 0, 1, false), GenDentry(1, 0, "A2", 0, 2, false), @@ -307,12 +311,12 @@ TEST_F(DentryStorageTest, List) { ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 5); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 0, "A1", 0, 1, false), - GenDentry(1, 0, "A2", 0, 2, false), - GenDentry(1, 0, "A3", 0, 3, false), - GenDentry(1, 0, "A4", 0, 4, false), - GenDentry(1, 0, "A5", 0, 5, false), - }); + GenDentry(1, 0, "A1", 0, 1, false), + GenDentry(1, 0, "A2", 0, 2, false), + GenDentry(1, 0, "A3", 0, 3, false), + GenDentry(1, 0, "A4", 0, 4, false), + GenDentry(1, 0, "A5", 0, 5, false), + }); // CASE 2: list by specify name dentrys.clear(); @@ -320,13 +324,14 @@ TEST_F(DentryStorageTest, List) { ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 2); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 0, "A4", 0, 4, false), - GenDentry(1, 0, "A5", 0, 5, false), - }); + GenDentry(1, 0, "A4", 0, 4, false), + GenDentry(1, 0, "A5", 0, 5, false), + }); // CASE 3: list by lower txid storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A1", 1, 1, false), GenDentry(1, 0, "A2", 2, 2, false), @@ -338,9 +343,9 @@ TEST_F(DentryStorageTest, List) { ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 2); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 0, "A1", 1, 1, false), - GenDentry(1, 0, "A2", 2, 2, false), - }); + GenDentry(1, 0, "A1", 1, 1, false), + GenDentry(1, 0, "A2", 2, 2, false), + }); // CASE 4: list by higher txid dentrys.clear(); @@ -348,14 +353,15 @@ TEST_F(DentryStorageTest, List) { ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 3); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 0, "A1", 1, 1, false), - GenDentry(1, 0, "A2", 2, 2, false), - GenDentry(1, 0, "A3", 3, 3, false), - }); + GenDentry(1, 0, "A1", 1, 1, false), + GenDentry(1, 0, "A2", 2, 2, false), + GenDentry(1, 0, "A3", 3, 3, false), + }); // CASE 5: list dentrys which has DELETE_MARK_FLAG flag storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A1", 1, 1, false), GenDentry(1, 0, "A2", 2, 2, true), @@ -367,13 +373,14 @@ TEST_F(DentryStorageTest, List) { ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 2); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 0, "A1", 1, 1, false), - GenDentry(1, 0, "A3", 3, 3, false), - }); + GenDentry(1, 0, "A1", 1, 1, false), + GenDentry(1, 0, "A3", 3, 3, false), + }); // CASE 6: list same dentrys with different txid storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "A", 1, 1, false), @@ -385,12 +392,13 @@ TEST_F(DentryStorageTest, List) { ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 1); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 0, "A", 2, 1, false), - }); + GenDentry(1, 0, "A", 2, 1, false), + }); // CASE 7: list by dentry tree storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "B", 0, 2, false), @@ -406,22 +414,23 @@ TEST_F(DentryStorageTest, List) { ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 3); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 2, "C", 0, 3, false), - GenDentry(1, 2, "D", 0, 4, false), - GenDentry(1, 2, "E", 0, 5, false), - }); + GenDentry(1, 2, "C", 0, 3, false), + GenDentry(1, 2, "D", 0, 4, false), + GenDentry(1, 2, "E", 0, 5, false), + }); dentrys.clear(); dentry = GenDentry(1, 4, "", 0, 0, false); ASSERT_EQ(storage.List(dentry, &dentrys, 0), MetaStatusCode::OK); ASSERT_EQ(dentrys.size(), 1); ASSERT_DENTRYS_EQ(dentrys, std::vector{ - GenDentry(1, 4, "G", 0, 7, false), - }); + GenDentry(1, 4, "G", 0, 7, false), + }); // CASE 8: list empty directory storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "B", 0, 2, false), @@ -463,7 +472,8 @@ TEST_F(DentryStorageTest, List) { // CASE 10: list directory only with limit storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "B", 0, 2, false), @@ -501,7 +511,8 @@ TEST_F(DentryStorageTest, HandleTx) { request.set_type(metaserver::TransactionRequest::None); request.set_rawpayload(""); // CASE 1: prepare success - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), }); @@ -530,7 +541,8 @@ TEST_F(DentryStorageTest, HandleTx) { // CASE 3: commit dentry with DELETE_MARK_FLAG flag storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "A", 1, 1, true), @@ -543,7 +555,8 @@ TEST_F(DentryStorageTest, HandleTx) { // CASE 4: Rollback success storage.Clear(); - InsertDentrys(&storage, std::vector{ + InsertDentrys(&storage, + std::vector{ // { fsId, parentId, name, txId, inodeId, deleteMarkFlag } GenDentry(1, 0, "A", 0, 1, false), GenDentry(1, 0, "A", 1, 2, false), diff --git a/curvefs/test/metaserver/inode_manager_test.cpp b/curvefs/test/metaserver/inode_manager_test.cpp index 2b60cde3b4..a407ccde1a 100644 --- a/curvefs/test/metaserver/inode_manager_test.cpp +++ b/curvefs/test/metaserver/inode_manager_test.cpp @@ -128,8 +128,7 @@ class InodeManagerTest : public ::testing::Test { bool EqualS3ChunkInfo(const S3ChunkInfo& lhs, const S3ChunkInfo& rhs) { return lhs.chunkid() == rhs.chunkid() && lhs.compaction() == rhs.compaction() && - lhs.offset() == rhs.offset() && - lhs.len() == rhs.len() && + lhs.offset() == rhs.offset() && lhs.len() == rhs.len() && lhs.size() == rhs.size() && lhs.zero() == rhs.zero(); } @@ -297,8 +296,7 @@ TEST_F(InodeManagerTest, GetOrModifyS3ChunkInfo) { fsId, inodeId, map2add, map2del, true, &iterator, logIndex_++); ASSERT_EQ(rc, MetaStatusCode::OK); - CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, - std::vector{1, 2, 3}, + CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, std::vector{1, 2, 3}, std::vector{ GenS3ChunkInfoList(1, 1), GenS3ChunkInfoList(2, 2), @@ -310,8 +308,7 @@ TEST_F(InodeManagerTest, GetOrModifyS3ChunkInfo) { true, &iterator, logIndex_++); ASSERT_EQ(rc, MetaStatusCode::OK); - CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, - std::vector{1, 2, 3}, + CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, std::vector{1, 2, 3}, std::vector{ GenS3ChunkInfoList(1, 1), GenS3ChunkInfoList(2, 2), @@ -334,8 +331,7 @@ TEST_F(InodeManagerTest, GetOrModifyS3ChunkInfo) { fsId, inodeId, map2add, map2del, true, &iterator, logIndex_++); ASSERT_EQ(rc, MetaStatusCode::OK); - CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, - std::vector{}, + CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, std::vector{}, std::vector{}); } @@ -379,15 +375,15 @@ TEST_F(InodeManagerTest, GetOrModifyS3ChunkInfo) { ASSERT_EQ(iterator->Status(), 0); CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, - std::vector{ 0, 1, 2, 7, 8, 9 }, - std::vector{ - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(1, 100), - GenS3ChunkInfoList(1, 100), - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(100, 100), - }); + std::vector{0, 1, 2, 7, 8, 9}, + std::vector{ + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(1, 100), + GenS3ChunkInfoList(1, 100), + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(100, 100), + }); // step3: delete all s3chunkinfo map2add.clear(); @@ -404,15 +400,15 @@ TEST_F(InodeManagerTest, GetOrModifyS3ChunkInfo) { ASSERT_EQ(iterator->Status(), 0); CHECK_ITERATOR_S3CHUNKINFOLIST(iterator, - std::vector{ 0, 1, 2, 7, 8, 9 }, - std::vector{ - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(100, 100), - GenS3ChunkInfoList(100, 100), - }); + std::vector{0, 1, 2, 7, 8, 9}, + std::vector{ + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(100, 100), + GenS3ChunkInfoList(100, 100), + }); } } diff --git a/curvefs/test/metaserver/inode_storage_test.cpp b/curvefs/test/metaserver/inode_storage_test.cpp index 47c10a0aed..279831ce54 100644 --- a/curvefs/test/metaserver/inode_storage_test.cpp +++ b/curvefs/test/metaserver/inode_storage_test.cpp @@ -766,7 +766,6 @@ TEST_F(InodeStorageTest, TestUpdateVolumeExtentSlice) { nameGenerator_->GetAppliedIndexTableName(); const std::string appliedKey = "inode"; - if (test.second.ok()) { EXPECT_CALL(*kvStorage, SSet(appliedTableName, appliedKey, _)) .Times(1) diff --git a/curvefs/test/metaserver/metastore_test.cpp b/curvefs/test/metaserver/metastore_test.cpp index 1b95839902..f8910d046f 100644 --- a/curvefs/test/metaserver/metastore_test.cpp +++ b/curvefs/test/metaserver/metastore_test.cpp @@ -125,15 +125,11 @@ class MetastoreTest : public ::testing::Test { } bool CompareInode(const Inode& first, const Inode& second) { - uint64_t firstMtime = first.mtime() * 1000000000u - + first.mtime_ns(); - uint64_t secondMtime = second.mtime() * 1000000000u - + second.mtime_ns(); + uint64_t firstMtime = first.mtime() * 1000000000u + first.mtime_ns(); + uint64_t secondMtime = second.mtime() * 1000000000u + second.mtime_ns(); - uint64_t firstCtime = first.ctime() * 1000000000u - + first.ctime_ns(); - uint64_t secondCtime = second.ctime() * 1000000000u - + second.ctime_ns(); + uint64_t firstCtime = first.ctime() * 1000000000u + first.ctime_ns(); + uint64_t secondCtime = second.ctime() * 1000000000u + second.ctime_ns(); return first.fsid() == second.fsid() && first.atime() == second.atime() && @@ -142,8 +138,7 @@ class MetastoreTest : public ::testing::Test { first.length() == second.length() && first.uid() == second.uid() && first.gid() == second.gid() && first.mode() == second.mode() && first.type() == second.type() && - firstMtime >= secondMtime && - firstCtime >= secondCtime && + firstMtime >= secondMtime && firstCtime >= secondCtime && first.symlink() == second.symlink() && first.nlink() >= second.nlink(); } diff --git a/curvefs/test/metaserver/mock/mock_metastore.h b/curvefs/test/metaserver/mock/mock_metastore.h index e999331bc0..a8c923d3aa 100644 --- a/curvefs/test/metaserver/mock/mock_metastore.h +++ b/curvefs/test/metaserver/mock/mock_metastore.h @@ -25,10 +25,10 @@ #include -#include #include -#include #include +#include +#include #include #include "curvefs/src/metaserver/metastore.h" @@ -47,12 +47,12 @@ class MockMetaStore : public curvefs::metaserver::MetaStore { MOCK_METHOD0(Clear, bool()); MOCK_METHOD0(Destroy, bool()); - MOCK_METHOD3(CreatePartition, MetaStatusCode(const CreatePartitionRequest*, - CreatePartitionResponse*, - int64_t logIndex)); - MOCK_METHOD3(DeletePartition, MetaStatusCode(const DeletePartitionRequest*, - DeletePartitionResponse*, - int64_t logIndex)); + MOCK_METHOD3(CreatePartition, + MetaStatusCode(const CreatePartitionRequest*, + CreatePartitionResponse*, int64_t logIndex)); + MOCK_METHOD3(DeletePartition, + MetaStatusCode(const DeletePartitionRequest*, + DeletePartitionResponse*, int64_t logIndex)); MOCK_METHOD1(GetPartitionInfoList, bool(std::list*)); MOCK_METHOD1(GetPartitionSnap, bool(std::map>*)); @@ -73,20 +73,17 @@ class MockMetaStore : public curvefs::metaserver::MetaStore { MOCK_METHOD3(CreateInode, MetaStatusCode(const CreateInodeRequest*, CreateInodeResponse*, int64_t logIndex)); - MOCK_METHOD3(CreateRootInode, MetaStatusCode(const CreateRootInodeRequest*, - CreateRootInodeResponse*, - int64_t logIndex)); + MOCK_METHOD3(CreateRootInode, + MetaStatusCode(const CreateRootInodeRequest*, + CreateRootInodeResponse*, int64_t logIndex)); MOCK_METHOD3(CreateManageInode, MetaStatusCode(const CreateManageInodeRequest*, - CreateManageInodeResponse*, - int64_t logIndex)); - MOCK_METHOD3(GetInode, - MetaStatusCode(const GetInodeRequest*, GetInodeResponse*, - int64_t logIndex)); + CreateManageInodeResponse*, int64_t logIndex)); + MOCK_METHOD3(GetInode, MetaStatusCode(const GetInodeRequest*, + GetInodeResponse*, int64_t logIndex)); MOCK_METHOD3(BatchGetInodeAttr, MetaStatusCode(const BatchGetInodeAttrRequest*, - BatchGetInodeAttrResponse*, - int64_t logIndex)); + BatchGetInodeAttrResponse*, int64_t logIndex)); MOCK_METHOD3(BatchGetXAttr, MetaStatusCode(const BatchGetXAttrRequest*, BatchGetXAttrResponse*, int64_t logIndex)); @@ -97,9 +94,9 @@ class MockMetaStore : public curvefs::metaserver::MetaStore { MetaStatusCode(const UpdateInodeRequest*, UpdateInodeResponse*, int64_t logIndex)); - MOCK_METHOD3(PrepareRenameTx, MetaStatusCode(const PrepareRenameTxRequest*, - PrepareRenameTxResponse*, - int64_t logIndex)); + MOCK_METHOD3(PrepareRenameTx, + MetaStatusCode(const PrepareRenameTxRequest*, + PrepareRenameTxResponse*, int64_t logIndex)); MOCK_METHOD0(GetStreamServer, std::shared_ptr()); @@ -113,14 +110,13 @@ class MockMetaStore : public curvefs::metaserver::MetaStore { MetaStatusCode(std::shared_ptr connection, std::shared_ptr iterator)); - MOCK_METHOD3(GetVolumeExtent, MetaStatusCode(const GetVolumeExtentRequest*, - GetVolumeExtentResponse*, - int64_t logIndex)); + MOCK_METHOD3(GetVolumeExtent, + MetaStatusCode(const GetVolumeExtentRequest*, + GetVolumeExtentResponse*, int64_t logIndex)); MOCK_METHOD3(UpdateVolumeExtent, MetaStatusCode(const UpdateVolumeExtentRequest*, - UpdateVolumeExtentResponse*, - int64_t logIndex)); + UpdateVolumeExtentResponse*, int64_t logIndex)); MOCK_METHOD3(UpdateDeallocatableBlockGroup, MetaStatusCode(const UpdateDeallocatableBlockGroupRequest*, diff --git a/curvefs/test/metaserver/partition_clean_test.cpp b/curvefs/test/metaserver/partition_clean_test.cpp index bc78cebf6f..901b0bc5be 100644 --- a/curvefs/test/metaserver/partition_clean_test.cpp +++ b/curvefs/test/metaserver/partition_clean_test.cpp @@ -168,7 +168,7 @@ TEST_F(PartitionCleanManagerTest, test1) { .WillRepeatedly(Return(true)); EXPECT_CALL(*copyset_, Propose(_)) - .WillOnce(Invoke([partition, fsId, this](const braft::Task &task) { + .WillOnce(Invoke([partition, fsId, this](const braft::Task& task) { ASSERT_EQ(partition->DeleteInode(fsId, ROOTINODEID, logIndex_++), MetaStatusCode::OK); LOG(INFO) << "Partition DeleteInode, fsId = " << fsId @@ -176,7 +176,7 @@ TEST_F(PartitionCleanManagerTest, test1) { task.done->Run(); })) .WillOnce( - Invoke([partition, fsId, inode1, this](const braft::Task &task) { + Invoke([partition, fsId, inode1, this](const braft::Task& task) { ASSERT_EQ( partition->DeleteInode(fsId, inode1.inodeid(), logIndex_++), MetaStatusCode::OK); @@ -184,7 +184,7 @@ TEST_F(PartitionCleanManagerTest, test1) { << ", inodeId = " << inode1.inodeid(); task.done->Run(); })) - .WillOnce(Invoke([partition](const braft::Task &task) { + .WillOnce(Invoke([partition](const braft::Task& task) { LOG(INFO) << "Partition deletePartition"; task.done->Run(); })); diff --git a/curvefs/test/metaserver/recycle_cleaner_test.cpp b/curvefs/test/metaserver/recycle_cleaner_test.cpp index 1ff153de3f..f7b6481ac4 100644 --- a/curvefs/test/metaserver/recycle_cleaner_test.cpp +++ b/curvefs/test/metaserver/recycle_cleaner_test.cpp @@ -96,10 +96,10 @@ class RecycleCleanerTest : public testing::Test { managePram.parent = ROOTINODEID; managePram.type = FsFileType::TYPE_DIRECTORY; Inode inode; - ASSERT_EQ(partition_->CreateManageInode(managePram, - ManageInodeType::TYPE_RECYCLE, - &inode, logIndex_++), - MetaStatusCode::OK); + ASSERT_EQ( + partition_->CreateManageInode( + managePram, ManageInodeType::TYPE_RECYCLE, &inode, logIndex_++), + MetaStatusCode::OK); Dentry dentry; dentry.set_fsid(fsId); dentry.set_inodeid(RECYCLEINODEID); diff --git a/curvefs/test/metaserver/recycle_manager_test.cpp b/curvefs/test/metaserver/recycle_manager_test.cpp index 078ed4dbcd..f2017ff8ba 100644 --- a/curvefs/test/metaserver/recycle_manager_test.cpp +++ b/curvefs/test/metaserver/recycle_manager_test.cpp @@ -165,10 +165,10 @@ TEST_F(RecycleManangeTest, test_empty_recycle) { managePram.parent = ROOTINODEID; managePram.type = FsFileType::TYPE_DIRECTORY; Inode manageInode; - ASSERT_EQ(partition->CreateManageInode(managePram, - ManageInodeType::TYPE_RECYCLE, - &manageInode, logIndex_++), - MetaStatusCode::OK); + ASSERT_EQ( + partition->CreateManageInode(managePram, ManageInodeType::TYPE_RECYCLE, + &manageInode, logIndex_++), + MetaStatusCode::OK); Dentry dentry; dentry.set_fsid(fsId); dentry.set_inodeid(RECYCLEINODEID); diff --git a/curvefs/test/metaserver/s3compact/s3compact_test.cpp b/curvefs/test/metaserver/s3compact/s3compact_test.cpp index 0e348f56fd..d8fed36dab 100644 --- a/curvefs/test/metaserver/s3compact/s3compact_test.cpp +++ b/curvefs/test/metaserver/s3compact/s3compact_test.cpp @@ -146,10 +146,8 @@ TEST_F(S3CompactTest, test_CopysetNodeWrapper) { TEST_F(S3CompactTest, test_S3InfoCache) { auto mock_requests3info = [](uint64_t fsid, S3Info* info) { - if (fsid == 0) - return S3InfoCache::RequestStatusCode::NOS3INFO; - if (fsid == 1) - return S3InfoCache::RequestStatusCode::RPCFAILURE; + if (fsid == 0) return S3InfoCache::RequestStatusCode::NOS3INFO; + if (fsid == 1) return S3InfoCache::RequestStatusCode::RPCFAILURE; return S3InfoCache::RequestStatusCode::SUCCESS; }; EXPECT_CALL(*s3infoCache_, GetS3Info(_, _)) diff --git a/curvefs/test/metaserver/space/utils.h b/curvefs/test/metaserver/space/utils.h index 039e3241d6..49456c1c5c 100644 --- a/curvefs/test/metaserver/space/utils.h +++ b/curvefs/test/metaserver/space/utils.h @@ -23,11 +23,11 @@ #ifndef CURVEFS_TEST_METASERVER_SPACE_UTILS_H_ #define CURVEFS_TEST_METASERVER_SPACE_UTILS_H_ -#include -#include #include #include #include +#include +#include namespace curvefs { namespace metaserver { diff --git a/curvefs/test/metaserver/transaction_test.cpp b/curvefs/test/metaserver/transaction_test.cpp index 2c0a81e03f..c21cf91651 100644 --- a/curvefs/test/metaserver/transaction_test.cpp +++ b/curvefs/test/metaserver/transaction_test.cpp @@ -88,12 +88,8 @@ class TransactionTest : public ::testing::Test { return result; } - Dentry GenDentry(uint32_t fsId, - uint64_t parentId, - const std::string& name, - uint64_t txId, - uint64_t inodeId, - uint32_t flag) { + Dentry GenDentry(uint32_t fsId, uint64_t parentId, const std::string& name, + uint64_t txId, uint64_t inodeId, uint32_t flag) { Dentry dentry; dentry.set_fsid(fsId); dentry.set_parentinodeid(parentId);