diff --git a/curvefs/proto/mds.proto b/curvefs/proto/mds.proto index 12f6ca6ee1..eb855e52f9 100644 --- a/curvefs/proto/mds.proto +++ b/curvefs/proto/mds.proto @@ -234,9 +234,7 @@ message CommitTxResponse { required FSStatusCode statusCode = 1; } -message TsoRequest { - required uint32 fsId = 1; -} +message TsoRequest {} message TsoResponse { required FSStatusCode statusCode = 1; diff --git a/curvefs/src/client/client_operator.cpp b/curvefs/src/client/client_operator.cpp index 02cf0d881f..fc41375caf 100644 --- a/curvefs/src/client/client_operator.cpp +++ b/curvefs/src/client/client_operator.cpp @@ -306,7 +306,7 @@ CURVEFS_ERROR RenameOperator::PrewriteRenameTx( CURVEFS_ERROR RenameOperator::PrewriteTx() { uint64_t timestamp; - auto rc = mdsClient_->Tso(srcDentry_.fsid(), &startTs_, ×tamp); + auto rc = mdsClient_->Tso(&startTs_, ×tamp); if (rc != FSStatusCode::OK) { LOG_ERROR("start Tso", rc); return CURVEFS_ERROR::INTERNAL; @@ -362,7 +362,7 @@ CURVEFS_ERROR RenameOperator::PrewriteTx() { CURVEFS_ERROR RenameOperator::CommitTxV2() { uint64_t commitTs; uint64_t timestamp; - auto rc = mdsClient_->Tso(srcDentry_.fsid(), &commitTs, ×tamp); + auto rc = mdsClient_->Tso(&commitTs, ×tamp); if (rc != FSStatusCode::OK) { LOG_ERROR("CommitTxV2 Tso", rc); return CURVEFS_ERROR::INTERNAL; diff --git a/curvefs/src/client/client_operator.h b/curvefs/src/client/client_operator.h index 3fbc0bd833..0408fd1181 100644 --- a/curvefs/src/client/client_operator.h +++ b/curvefs/src/client/client_operator.h @@ -27,8 +27,8 @@ #include #include -#include "curvefs/src/client/inode_cache_manager.h" -#include "curvefs/src/client/dentry_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" +#include "curvefs/src/client/dentry_manager.h" #include "curvefs/src/client/rpcclient/mds_client.h" namespace curvefs { diff --git a/curvefs/src/client/dentry_cache_manager.cpp b/curvefs/src/client/dentry_manager.cpp similarity index 96% rename from curvefs/src/client/dentry_cache_manager.cpp rename to curvefs/src/client/dentry_manager.cpp index d9155dccd2..9c5227ccfb 100644 --- a/curvefs/src/client/dentry_cache_manager.cpp +++ b/curvefs/src/client/dentry_manager.cpp @@ -20,7 +20,7 @@ * Created Date: Thur May 27 2021 * Author: xuchaojie */ -#include "curvefs/src/client/dentry_cache_manager.h" +#include "curvefs/src/client/dentry_manager.h" #include #include @@ -93,7 +93,7 @@ CURVEFS_ERROR DentryCacheManagerImpl::GetDentry(uint64_t parent, while (ret == MetaStatusCode::TX_KEY_LOCKED) { uint64_t ts = 0; uint64_t timestamp = 0; - if (mdsClient_->Tso(fsId_, &ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(&ts, ×tamp) != FSStatusCode::OK) { LOG(ERROR) << "GetDentry Tso failed, parent = " << parent << ", name = " << name; return CURVEFS_ERROR::INTERNAL; @@ -130,7 +130,7 @@ CURVEFS_ERROR DentryCacheManagerImpl::CreateDentry(const Dentry &dentry) { while (ret == MetaStatusCode::TX_KEY_LOCKED) { uint64_t ts = 0; uint64_t timestamp = 0; - if (mdsClient_->Tso(fsId_, &ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(&ts, ×tamp) != FSStatusCode::OK) { LOG(ERROR) << "CreateDentry Tso failed, dentry = " << dentry.ShortDebugString(); return CURVEFS_ERROR::INTERNAL; @@ -166,7 +166,7 @@ CURVEFS_ERROR DentryCacheManagerImpl::DeleteDentry(uint64_t parent, while (ret == MetaStatusCode::TX_KEY_LOCKED) { uint64_t ts = 0; uint64_t timestamp = 0; - if (mdsClient_->Tso(fsId_, &ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(&ts, ×tamp) != FSStatusCode::OK) { LOG(ERROR) << "DeleteDentry Tso failed, parent = " << parent << ", name = " << name; return CURVEFS_ERROR::INTERNAL; @@ -222,7 +222,7 @@ CURVEFS_ERROR DentryCacheManagerImpl::ListDentry(uint64_t parent, if (ret == MetaStatusCode::TX_KEY_LOCKED) { uint64_t ts = 0; uint64_t timestamp = 0; - if (mdsClient_->Tso(fsId_, &ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(&ts, ×tamp) != FSStatusCode::OK) { LOG(ERROR) << "ListDentry Tso failed, parent = " << parent; return CURVEFS_ERROR::INTERNAL; } diff --git a/curvefs/src/client/dentry_cache_manager.h b/curvefs/src/client/dentry_manager.h similarity index 96% rename from curvefs/src/client/dentry_cache_manager.h rename to curvefs/src/client/dentry_manager.h index 93d9448cd1..0014a28349 100644 --- a/curvefs/src/client/dentry_cache_manager.h +++ b/curvefs/src/client/dentry_manager.h @@ -21,8 +21,8 @@ * Author: xuchaojie */ -#ifndef CURVEFS_SRC_CLIENT_DENTRY_CACHE_MANAGER_H_ -#define CURVEFS_SRC_CLIENT_DENTRY_CACHE_MANAGER_H_ +#ifndef CURVEFS_SRC_CLIENT_DENTRY_MANAGER_H_ +#define CURVEFS_SRC_CLIENT_DENTRY_MANAGER_H_ #include #include @@ -130,4 +130,4 @@ class DentryCacheManagerImpl : public DentryCacheManager { } // namespace client } // namespace curvefs -#endif // CURVEFS_SRC_CLIENT_DENTRY_CACHE_MANAGER_H_ +#endif // CURVEFS_SRC_CLIENT_DENTRY_MANAGER_H_ diff --git a/curvefs/src/client/filesystem/package.h b/curvefs/src/client/filesystem/package.h index 47f9fccc36..8eb7a14b23 100644 --- a/curvefs/src/client/filesystem/package.h +++ b/curvefs/src/client/filesystem/package.h @@ -25,8 +25,8 @@ #include -#include "curvefs/src/client/dentry_cache_manager.h" -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/dentry_manager.h" +#include "curvefs/src/client/inode_manager.h" #include "curvefs/src/client/xattr_manager.h" namespace curvefs { diff --git a/curvefs/src/client/fuse_client.h b/curvefs/src/client/fuse_client.h index cad4af68c7..aae53041cb 100644 --- a/curvefs/src/client/fuse_client.h +++ b/curvefs/src/client/fuse_client.h @@ -41,13 +41,13 @@ #include "curvefs/src/client/client_operator.h" #include "curvefs/src/client/common/common.h" #include "curvefs/src/client/common/config.h" -#include "curvefs/src/client/dentry_cache_manager.h" +#include "curvefs/src/client/dentry_manager.h" #include "curvefs/src/client/dir_buffer.h" #include "curvefs/src/client/filesystem/error.h" #include "curvefs/src/client/filesystem/filesystem.h" #include "curvefs/src/client/filesystem/meta.h" #include "curvefs/src/client/fuse_common.h" -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" #include "curvefs/src/client/lease/lease_excutor.h" #include "curvefs/src/client/metric/client_metric.h" #include "curvefs/src/client/rpcclient/mds_client.h" diff --git a/curvefs/src/client/inode_cache_manager.cpp b/curvefs/src/client/inode_manager.cpp similarity index 99% rename from curvefs/src/client/inode_cache_manager.cpp rename to curvefs/src/client/inode_manager.cpp index b30dd4ee16..d3aa1c9fac 100644 --- a/curvefs/src/client/inode_cache_manager.cpp +++ b/curvefs/src/client/inode_manager.cpp @@ -21,7 +21,7 @@ * Author: xuchaojie */ -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" #include #include diff --git a/curvefs/src/client/inode_cache_manager.h b/curvefs/src/client/inode_manager.h similarity index 98% rename from curvefs/src/client/inode_cache_manager.h rename to curvefs/src/client/inode_manager.h index 49c642c0e3..093b5e750d 100644 --- a/curvefs/src/client/inode_cache_manager.h +++ b/curvefs/src/client/inode_manager.h @@ -21,8 +21,8 @@ * Author: xuchaojie */ -#ifndef CURVEFS_SRC_CLIENT_INODE_CACHE_MANAGER_H_ -#define CURVEFS_SRC_CLIENT_INODE_CACHE_MANAGER_H_ +#ifndef CURVEFS_SRC_CLIENT_INODE_MANAGER_H_ +#define CURVEFS_SRC_CLIENT_INODE_MANAGER_H_ #include #include @@ -242,4 +242,4 @@ class BatchGetInodeAttrAsyncDone : public BatchGetInodeAttrDone { } // namespace client } // namespace curvefs -#endif // CURVEFS_SRC_CLIENT_INODE_CACHE_MANAGER_H_ +#endif // CURVEFS_SRC_CLIENT_INODE_MANAGER_H_ diff --git a/curvefs/src/client/rpcclient/mds_client.cpp b/curvefs/src/client/rpcclient/mds_client.cpp index 8e187fb7f3..ceb4ccf71b 100644 --- a/curvefs/src/client/rpcclient/mds_client.cpp +++ b/curvefs/src/client/rpcclient/mds_client.cpp @@ -682,22 +682,19 @@ FSStatusCode MdsClientImpl::CommitTxWithLock( return CommitTx(request); } -FSStatusCode MdsClientImpl::Tso( - uint32_t fsId, uint64_t* ts, uint64_t* timestamp) { +FSStatusCode MdsClientImpl::Tso(uint64_t* ts, uint64_t* timestamp) { auto task = RPCTask { (void)addrindex; (void)rpctimeoutMS; mdsClientMetric_.tso.qps.count << 1; LatencyUpdater updater(&mdsClientMetric_.tso.latency); TsoRequest request; - request.set_fsid(fsId); TsoResponse response; mdsbasecli_->Tso(request, &response, cntl, channel); if (cntl->Failed()) { mdsClientMetric_.tso.eps.count << 1; LOG(WARNING) << "Tso Failed, errorcode = " << cntl->ErrorCode() << ", error content:" << cntl->ErrorText() - << ", fsId = " << fsId << ", log id = " << cntl->log_id(); return -cntl->ErrorCode(); } @@ -705,8 +702,7 @@ FSStatusCode MdsClientImpl::Tso( FSStatusCode ret = response.statuscode(); if (ret != FSStatusCode::OK) { LOG(ERROR) << "Tso: errcode = " << ret - << ", errmsg = " << FSStatusCode_Name(ret) - << ", fsId = " << fsId; + << ", errmsg = " << FSStatusCode_Name(ret); return ret; } else { *ts = response.ts(); diff --git a/curvefs/src/client/rpcclient/mds_client.h b/curvefs/src/client/rpcclient/mds_client.h index 81394d1f10..bedbfa9edc 100644 --- a/curvefs/src/client/rpcclient/mds_client.h +++ b/curvefs/src/client/rpcclient/mds_client.h @@ -137,8 +137,7 @@ class MdsClient { const std::string& uuid, uint64_t sequence) = 0; - virtual FSStatusCode Tso(uint32_t fsId, uint64_t* ts, - uint64_t* timestamp) = 0; + virtual FSStatusCode Tso(uint64_t* ts, uint64_t* timestamp) = 0; // allocate block group virtual SpaceErrCode AllocateVolumeBlockGroup( @@ -227,7 +226,7 @@ class MdsClientImpl : public MdsClient { const std::string& uuid, uint64_t sequence) override; - FSStatusCode Tso(uint32_t fsId, uint64_t* ts, uint64_t* timestamp) override; + FSStatusCode Tso(uint64_t* ts, uint64_t* timestamp) override; // allocate block group SpaceErrCode AllocateVolumeBlockGroup( diff --git a/curvefs/src/client/s3/client_s3_adaptor.h b/curvefs/src/client/s3/client_s3_adaptor.h index dcc25c3795..453efb8931 100644 --- a/curvefs/src/client/s3/client_s3_adaptor.h +++ b/curvefs/src/client/s3/client_s3_adaptor.h @@ -34,7 +34,7 @@ #include "curvefs/src/client/common/common.h" #include "curvefs/src/client/common/config.h" #include "curvefs/src/client/filesystem/error.h" -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" #include "curvefs/src/client/rpcclient/mds_client.h" #include "curvefs/src/client/s3/client_s3.h" #include "curvefs/src/client/s3/client_s3_cache_manager.h" diff --git a/curvefs/src/client/volume/default_volume_storage.cpp b/curvefs/src/client/volume/default_volume_storage.cpp index 4b2618b170..010b1e1902 100644 --- a/curvefs/src/client/volume/default_volume_storage.cpp +++ b/curvefs/src/client/volume/default_volume_storage.cpp @@ -31,7 +31,7 @@ #include "absl/meta/type_traits.h" #include "curvefs/src/client/filesystem/error.h" -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" #include "curvefs/src/client/inode_wrapper.h" #include "curvefs/src/client/volume/extent_cache.h" #include "curvefs/src/client/volume/utils.h" diff --git a/curvefs/src/client/warmup/warmup_manager.h b/curvefs/src/client/warmup/warmup_manager.h index f55752c801..e83772ed35 100644 --- a/curvefs/src/client/warmup/warmup_manager.h +++ b/curvefs/src/client/warmup/warmup_manager.h @@ -40,9 +40,9 @@ #include #include "curvefs/src/client/common/common.h" -#include "curvefs/src/client/dentry_cache_manager.h" +#include "curvefs/src/client/dentry_manager.h" #include "curvefs/src/client/fuse_common.h" -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" #include "curvefs/src/client/kvclient/kvclient_manager.h" #include "curvefs/src/client/metric/client_metric.h" #include "curvefs/src/client/rpcclient/metaserver_client.h" diff --git a/curvefs/src/mds/codec/codec.cpp b/curvefs/src/mds/codec/codec.cpp index de5b4b3925..1089533842 100644 --- a/curvefs/src/mds/codec/codec.cpp +++ b/curvefs/src/mds/codec/codec.cpp @@ -79,23 +79,6 @@ std::string EncodeFsUsageKey(const std::string& fsName) { return key; } -std::string EncodeTsKey(uint32_t fsId) { - static const size_t size = COMMON_PREFIX_LENGTH + sizeof(fsId); - - std::string key; - key.resize(size); - - memcpy(&key[0], TS_INFO_KEY_PREFIX, COMMON_PREFIX_LENGTH); - - EncodeBigEndian_uint32(&key[COMMON_PREFIX_LENGTH], fsId); - - return key; -} - -uint32_t DecodeTsKey(const std::string& key) { - return DecodeBigEndian_uint32(&key[COMMON_PREFIX_LENGTH]); -} - } // namespace codec } // namespace mds } // namespace curvefs diff --git a/curvefs/src/mds/codec/codec.h b/curvefs/src/mds/codec/codec.h index d38812d3f4..a23891a04c 100644 --- a/curvefs/src/mds/codec/codec.h +++ b/curvefs/src/mds/codec/codec.h @@ -66,10 +66,6 @@ std::string EncodeBlockGroupKey(uint32_t fsId, uint64_t offset); std::string EncodeFsUsageKey(const std::string& fsName); -std::string EncodeTsKey(uint32_t fsId); - -uint32_t DecodeTsKey(const std::string& key); - } // namespace codec } // namespace mds } // namespace curvefs diff --git a/curvefs/src/mds/common/storage_key.h b/curvefs/src/mds/common/storage_key.h index 9edfed6092..81a7ae85b3 100644 --- a/curvefs/src/mds/common/storage_key.h +++ b/curvefs/src/mds/common/storage_key.h @@ -45,8 +45,7 @@ const char BLOCKGROUP_KEY_PREFIX[] = "fs_04"; const char BLOCKGROUP_KEY_END[] = "fs_05"; const char FS_USAGE_KEY_PREFIX[] = "fs_05"; const char FS_USAGE_KEY_END[] = "fs_06"; -const char TS_INFO_KEY_PREFIX[] = "fs_06"; -const char TS_INFO_KEY_END[] = "fs_07"; +const char TS_INFO_KEY_PREFIX[] = "fs_07"; constexpr uint32_t COMMON_PREFIX_LENGTH = 5; diff --git a/curvefs/src/mds/fs_manager.cpp b/curvefs/src/mds/fs_manager.cpp index 5dbf9f697e..ff2db4605b 100644 --- a/curvefs/src/mds/fs_manager.cpp +++ b/curvefs/src/mds/fs_manager.cpp @@ -1299,10 +1299,9 @@ bool FsManager::FillVolumeInfo(common::Volume* volume) { void FsManager::Tso(const TsoRequest* request, TsoResponse* response) { uint64_t ts; uint64_t timestamp; - auto ret = fsStorage_->Tso(request->fsid(), &ts, ×tamp); + auto ret = fsStorage_->Tso(&ts, ×tamp); if (ret != FSStatusCode::OK) { - LOG(ERROR) << "Tso fail, fsid = " << request->fsid() - << ", ret = " << FSStatusCode_Name(ret); + LOG(ERROR) << "Tso fail, ret = " << FSStatusCode_Name(ret); response->set_statuscode(ret); return; } diff --git a/curvefs/src/mds/fs_storage.cpp b/curvefs/src/mds/fs_storage.cpp index 59ffe8e6fd..0ff68a9664 100644 --- a/curvefs/src/mds/fs_storage.cpp +++ b/curvefs/src/mds/fs_storage.cpp @@ -41,6 +41,7 @@ using ::curve::kvstorage::KVStorageClient; bool MemoryFsStorage::Init() { WriteLockGuard writeLockGuard(rwLock_); fsInfoMap_.clear(); + tsId_.store(1); return true; } @@ -187,19 +188,9 @@ FSStatusCode MemoryFsStorage::DeleteFsUsage(const std::string& fsName) { return FSStatusCode::OK; } -FSStatusCode MemoryFsStorage::Tso(uint32_t fsId, uint64_t* ts, - uint64_t* timestamp) { - WriteLockGuard lock(tsLock_); +FSStatusCode MemoryFsStorage::Tso(uint64_t* ts, uint64_t* timestamp) { *timestamp = curve::common::TimeUtility::GetTimeofDayMs(); - auto it = tsMap_.find(fsId); - if (it == tsMap_.end()) { - *ts = 1; - } else { - *ts = it->second.ts() + 1; - } - TS tsInfo; - tsInfo.set_ts(*ts); - tsMap_[fsId] = tsInfo; + *ts = tsId_.fetch_add(1, std::memory_order_relaxed); return FSStatusCode::OK; } @@ -210,7 +201,8 @@ PersisKVStorage::PersisKVStorage( fsLock_(), fs_(), idToNameLock_(), - idToName_() {} + idToName_(), + tsIdGen_(new TsIdGenerator(storage_)) {} PersisKVStorage::~PersisKVStorage() = default; @@ -224,16 +216,10 @@ FSStatusCode PersisKVStorage::Get(uint64_t fsId, FsInfoWrapper* fsInfo) { } bool PersisKVStorage::Init() { - bool ret = LoadAllFs(); - if (!ret) { + if (!LoadAllFs()) { LOG(ERROR) << "Load all fs failed"; return false; } - ret = LoadAllTsInfo(); - if (!ret) { - LOG(ERROR) << "Load all tsInfo failed"; - return false; - } return true; } @@ -445,30 +431,6 @@ bool PersisKVStorage::LoadAllFs() { return true; } -bool PersisKVStorage::LoadAllTsInfo() { - WriteLockGuard lock(tsLock_); - tsMap_.clear(); - std::vector> out; - int err = storage_->List(TS_INFO_KEY_PREFIX, - TS_INFO_KEY_END, &out); - - if (err != EtcdErrCode::EtcdOK) { - LOG(ERROR) << "List all tsInfo from etcd failed, error: " << err; - return false; - } - - for (const auto& kv : out) { - TS tsInfo; - uint32_t fsId = codec::DecodeTsKey(kv.first); - if (!codec::DecodeProtobufMessage(kv.second, &tsInfo)) { - LOG(ERROR) << "Decode ts info failed, fsId: " << fsId; - return false; - } - tsMap_[fsId] = tsInfo; - } - return true; -} - bool PersisKVStorage::FsIDToName(uint64_t fsId, std::string* name) const { ReadLockGuard lock(idToNameLock_); auto iter = idToName_.find(fsId); @@ -620,34 +582,13 @@ FSStatusCode PersisKVStorage::DeleteFsUsage(const std::string& fsName) { return FSStatusCode::OK; } -FSStatusCode PersisKVStorage::Tso(uint32_t fsId, uint64_t* ts, - uint64_t* timestamp) { - WriteLockGuard lock(tsLock_); +FSStatusCode PersisKVStorage::Tso(uint64_t* ts, uint64_t* timestamp) { *timestamp = curve::common::TimeUtility::GetTimeofDayMs(); - auto it = tsMap_.find(fsId); - if (it == tsMap_.end()) { - *ts = 1; - } else { - *ts = it->second.ts() + 1; - } - TS tsInfo; - tsInfo.set_ts(*ts); - // persist to storage - std::string key = codec::EncodeTsKey(fsId); - std::string value; - if (!codec::EncodeProtobufMessage(tsInfo, &value)) { - LOG(ERROR) << "Encode tsInfo failed, " << tsInfo.ShortDebugString(); - return FSStatusCode::INTERNAL_ERROR; - } - - int ret = storage_->Put(key, value); - if (ret != EtcdErrCode::EtcdOK) { - LOG(ERROR) << "Put key-value to storage failed, tsInfo, " - << tsInfo.ShortDebugString(); - return FSStatusCode::INTERNAL_ERROR; + if (tsIdGen_->GenTsId(ts)) { + return FSStatusCode::OK; } - tsMap_[fsId] = tsInfo; - return FSStatusCode::OK; + LOG(ERROR) << "Gen ts failed"; + return FSStatusCode::INTERNAL_ERROR; } } // namespace mds diff --git a/curvefs/src/mds/fs_storage.h b/curvefs/src/mds/fs_storage.h index bfc5980ed4..fcf1105469 100644 --- a/curvefs/src/mds/fs_storage.h +++ b/curvefs/src/mds/fs_storage.h @@ -37,13 +37,11 @@ #include "src/common/concurrent/rw_lock.h" #include "src/idgenerator/etcd_id_generator.h" #include "src/kvstorageclient/etcd_client.h" -#include "curvefs/proto/metaserver.pb.h" +#include "curvefs/src/mds/idgenerator/ts_id_generator.h" namespace curvefs { namespace mds { -using ::curvefs::metaserver::TS; - constexpr uint64_t INVALID_FS_ID = std::numeric_limits::max(); class FsStorage { @@ -80,8 +78,7 @@ class FsStorage { const std::string& fsName, FsUsage* fsUsage, bool fromCache) = 0; virtual FSStatusCode DeleteFsUsage(const std::string& fsName) = 0; - virtual FSStatusCode Tso(uint32_t fsId, uint64_t* ts, - uint64_t* timestamp) = 0; + virtual FSStatusCode Tso(uint64_t* ts, uint64_t* timestamp) = 0; }; class MemoryFsStorage : public FsStorage { @@ -188,8 +185,7 @@ class MemoryFsStorage : public FsStorage { const std::string& fsName, FsUsage*, bool fromCache) override; FSStatusCode DeleteFsUsage(const std::string& fsName) override; - FSStatusCode Tso(uint32_t fsId, uint64_t* ts, - uint64_t* timestamp) override; + FSStatusCode Tso(uint64_t* ts, uint64_t* timestamp) override; private: std::unordered_map fsInfoMap_; @@ -200,8 +196,7 @@ class MemoryFsStorage : public FsStorage { std::unordered_map fsUsageMap_; curve::common::RWLock fsUsedUsageLock_; - std::unordered_map tsMap_; - mutable RWLock tsLock_; + std::atomic tsId_; }; // Persist all data to kvstorage and cache all fsinfo in memory @@ -237,14 +232,11 @@ class PersisKVStorage : public FsStorage { const std::string& fsName, FsUsage*, bool fromCache) override; FSStatusCode DeleteFsUsage(const std::string& fsName) override; - FSStatusCode Tso(uint32_t fsId, uint64_t* ts, - uint64_t* timestamp) override; + FSStatusCode Tso(uint64_t* ts, uint64_t* timestamp) override; private: bool LoadAllFs(); - bool LoadAllTsInfo(); - bool FsIDToName(uint64_t fsId, std::string* name) const; bool PersistToStorage(const FsInfoWrapper& fs); @@ -277,8 +269,7 @@ class PersisKVStorage : public FsStorage { std::unordered_map fsUsageCache_; mutable RWLock fsUsageCacheMutex_; - std::unordered_map tsMap_; - mutable RWLock tsLock_; + std::unique_ptr tsIdGen_; }; } // namespace mds diff --git a/curvefs/src/mds/idgenerator/BUILD b/curvefs/src/mds/idgenerator/BUILD index fdde4ecd6b..fc465923ab 100644 --- a/curvefs/src/mds/idgenerator/BUILD +++ b/curvefs/src/mds/idgenerator/BUILD @@ -18,7 +18,8 @@ load("//:copts.bzl", "CURVE_DEFAULT_COPTS") cc_library( name = "fs_mds_idgenerator", - hdrs = ["fs_id_generator.h"], + hdrs = ["fs_id_generator.h", + "ts_id_generator.h"], copts = CURVE_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ diff --git a/curvefs/src/mds/idgenerator/ts_id_generator.h b/curvefs/src/mds/idgenerator/ts_id_generator.h new file mode 100644 index 0000000000..68060d1384 --- /dev/null +++ b/curvefs/src/mds/idgenerator/ts_id_generator.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Project: curve + * Created Date: 2023-12-07 + * Author: wanghai01 + */ + +#ifndef CURVEFS_SRC_MDS_IDGENERATOR_TS_ID_GENERATOR_H_ +#define CURVEFS_SRC_MDS_IDGENERATOR_TS_ID_GENERATOR_H_ + +#include "curvefs/src/mds/common/storage_key.h" +#include "src/idgenerator/etcd_id_generator.h" + +namespace curvefs { +namespace mds { + +class TsIdGenerator { + public: + explicit TsIdGenerator( + const std::shared_ptr& client) + : generator_(new curve::idgenerator::EtcdIdGenerator( + client, TS_INFO_KEY_PREFIX, TS_ID_INIT, TS_ID_ALLOCATE_BUNDLE)) {} + + bool GenTsId(uint64_t* id) { + return generator_->GenID(id); + } + + private: + static constexpr uint64_t TS_ID_INIT = 0; + static constexpr uint64_t TS_ID_ALLOCATE_BUNDLE = 100; + + private: + std::unique_ptr generator_; +}; + +} // namespace mds +} // namespace curvefs + +#endif // CURVEFS_SRC_MDS_IDGENERATOR_TS_ID_GENERATOR_H_ diff --git a/curvefs/test/client/client_operator_test.cpp b/curvefs/test/client/client_operator_test.cpp index 846d9b6621..41dda5c9fa 100644 --- a/curvefs/test/client/client_operator_test.cpp +++ b/curvefs/test/client/client_operator_test.cpp @@ -25,8 +25,8 @@ #include #include "curvefs/src/client/client_operator.h" -#include "curvefs/test/client/mock_dentry_cache_mamager.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_dentry_mamager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/mock_metaserver_client.h" #include "curvefs/test/client/rpcclient/mock_mds_client.h" @@ -194,12 +194,12 @@ TEST_F(ClientOperatorTest, CommitTx) { TEST_F(ClientOperatorTest, PrewriteTx) { CURVEFS_ERROR rc = CURVEFS_ERROR::OK; // 1. tso failed - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::UNKNOWN_ERROR)); rc = renameOp_->PrewriteTx(); ASSERT_EQ(rc, CURVEFS_ERROR::INTERNAL); // 2. GetPartitionId failed - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, GetPartitionId(_, _, _)) @@ -211,7 +211,7 @@ TEST_F(ClientOperatorTest, PrewriteTx) { rc = renameOp_->PrewriteTx(); ASSERT_EQ(rc, CURVEFS_ERROR::INTERNAL); // 3. PrewriteRenameTx failed - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, GetPartitionId(_, _, _)) .WillOnce(DoAll(SetArgPointee<2>(1), Return(true))) @@ -221,7 +221,7 @@ TEST_F(ClientOperatorTest, PrewriteTx) { rc = renameOp_->PrewriteTx(); ASSERT_EQ(rc, CURVEFS_ERROR::INTERNAL); // 4. PrewriteRenameTx key is locked and CheckAndResolveTx failed - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, GetPartitionId(_, _, _)) .WillOnce(DoAll(SetArgPointee<2>(1), Return(true))) @@ -233,7 +233,7 @@ TEST_F(ClientOperatorTest, PrewriteTx) { rc = renameOp_->PrewriteTx(); ASSERT_EQ(rc, CURVEFS_ERROR::INTERNAL); // 5. PrewriteRenameTx key is locked and CheckAndResolveTx success - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, GetPartitionId(_, _, _)) .WillOnce(DoAll(SetArgPointee<2>(1), Return(true))) @@ -251,19 +251,19 @@ TEST_F(ClientOperatorTest, PrewriteTx) { TEST_F(ClientOperatorTest, CommitTxV2) { CURVEFS_ERROR rc = CURVEFS_ERROR::OK; // 1. tso failed - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::UNKNOWN_ERROR)); rc = renameOp_->CommitTxV2(); ASSERT_EQ(rc, CURVEFS_ERROR::INTERNAL); // 2. CommitTx failed - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, CommitTx(_, _, _)) .WillOnce(Return(MetaStatusCode::STORAGE_INTERNAL_ERROR)); rc = renameOp_->CommitTxV2(); ASSERT_EQ(rc, CURVEFS_ERROR::INTERNAL); // 3. CommitTx success - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, CommitTx(_, _, _)) .WillOnce(Return(MetaStatusCode::OK)); diff --git a/curvefs/test/client/client_prefetch_test.cpp b/curvefs/test/client/client_prefetch_test.cpp index 712fbd208d..896467fcc0 100644 --- a/curvefs/test/client/client_prefetch_test.cpp +++ b/curvefs/test/client/client_prefetch_test.cpp @@ -33,7 +33,7 @@ #include "curvefs/test/client/mock_disk_cache_manager.h" #include "curvefs/test/client/mock_disk_cache_read.h" #include "curvefs/test/client/mock_disk_cache_write.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/mock_kvclient.h" #include "curvefs/test/client/mock_test_posix_wapper.h" #include "src/common/concurrent/task_thread_pool.h" diff --git a/curvefs/test/client/client_s3_adaptor_Integration.cpp b/curvefs/test/client/client_s3_adaptor_Integration.cpp index 1b4ee2a280..1127dda78c 100644 --- a/curvefs/test/client/client_s3_adaptor_Integration.cpp +++ b/curvefs/test/client/client_s3_adaptor_Integration.cpp @@ -30,7 +30,7 @@ #include "curvefs/src/client/kvclient/kvclient_manager.h" #include "src/common/curve_define.h" #include "curvefs/test/client/mock_client_s3.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/mock_metaserver_service.h" #include "curvefs/test/client/mock_kvclient.h" #include "curvefs/test/client/rpcclient/mock_mds_client.h" diff --git a/curvefs/test/client/client_s3_adaptor_test.cpp b/curvefs/test/client/client_s3_adaptor_test.cpp index 7430a14856..d062d5e674 100644 --- a/curvefs/test/client/client_s3_adaptor_test.cpp +++ b/curvefs/test/client/client_s3_adaptor_test.cpp @@ -30,7 +30,7 @@ #include "curvefs/test/client/mock_client_s3.h" #include "curvefs/test/client/mock_client_s3_cache_manager.h" #include "curvefs/test/client/mock_disk_cache_manager.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/mock_metaserver_service.h" #include "curvefs/test/client/rpcclient/mock_mds_client.h" #include "src/common/curve_define.h" diff --git a/curvefs/test/client/file_cache_manager_test.cpp b/curvefs/test/client/file_cache_manager_test.cpp index 013e64b6f8..d9549611f7 100644 --- a/curvefs/test/client/file_cache_manager_test.cpp +++ b/curvefs/test/client/file_cache_manager_test.cpp @@ -26,7 +26,7 @@ #include "curvefs/src/client/s3/client_s3_adaptor.h" #include "curvefs/src/client/s3/client_s3_cache_manager.h" #include "curvefs/test/client/mock_client_s3_cache_manager.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/mock_client_s3.h" #include "src/common/concurrent/task_thread_pool.h" diff --git a/curvefs/test/client/filesystem/helper/builder.h b/curvefs/test/client/filesystem/helper/builder.h index 2370dad311..31178733af 100644 --- a/curvefs/test/client/filesystem/helper/builder.h +++ b/curvefs/test/client/filesystem/helper/builder.h @@ -32,8 +32,8 @@ #include "curvefs/src/client/filesystem/meta.h" #include "curvefs/src/client/filesystem/filesystem.h" #include "curvefs/test/client/mock_metaserver_client.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" -#include "curvefs/test/client/mock_dentry_cache_mamager.h" +#include "curvefs/test/client/mock_inode_manager.h" +#include "curvefs/test/client/mock_dentry_mamager.h" namespace curvefs { namespace client { diff --git a/curvefs/test/client/filesystem/helper/expect.h b/curvefs/test/client/filesystem/helper/expect.h index 5daad73d9c..a3df7b5b91 100644 --- a/curvefs/test/client/filesystem/helper/expect.h +++ b/curvefs/test/client/filesystem/helper/expect.h @@ -26,8 +26,8 @@ #include #include "curvefs/test/client/mock_metaserver_client.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" -#include "curvefs/test/client/mock_dentry_cache_mamager.h" +#include "curvefs/test/client/mock_inode_manager.h" +#include "curvefs/test/client/mock_dentry_mamager.h" namespace curvefs { namespace client { diff --git a/curvefs/test/client/mock_dentry_cache_mamager.h b/curvefs/test/client/mock_dentry_mamager.h similarity index 89% rename from curvefs/test/client/mock_dentry_cache_mamager.h rename to curvefs/test/client/mock_dentry_mamager.h index f052a29c80..f20a3217c4 100644 --- a/curvefs/test/client/mock_dentry_cache_mamager.h +++ b/curvefs/test/client/mock_dentry_mamager.h @@ -20,15 +20,15 @@ * Author: xuchaojie */ -#ifndef CURVEFS_TEST_CLIENT_MOCK_DENTRY_CACHE_MAMAGER_H_ -#define CURVEFS_TEST_CLIENT_MOCK_DENTRY_CACHE_MAMAGER_H_ +#ifndef CURVEFS_TEST_CLIENT_MOCK_DENTRY_MAMAGER_H_ +#define CURVEFS_TEST_CLIENT_MOCK_DENTRY_MAMAGER_H_ #include #include #include #include #include -#include "curvefs/src/client/dentry_cache_manager.h" +#include "curvefs/src/client/dentry_manager.h" namespace curvefs { namespace client { @@ -64,4 +64,4 @@ class MockDentryCacheManager : public DentryCacheManager { } // namespace client } // namespace curvefs -#endif // CURVEFS_TEST_CLIENT_MOCK_DENTRY_CACHE_MAMAGER_H_ +#endif // CURVEFS_TEST_CLIENT_MOCK_DENTRY_MAMAGER_H_ diff --git a/curvefs/test/client/mock_inode_cache_manager.h b/curvefs/test/client/mock_inode_manager.h similarity index 91% rename from curvefs/test/client/mock_inode_cache_manager.h rename to curvefs/test/client/mock_inode_manager.h index 39c332ce04..adc043d4a5 100644 --- a/curvefs/test/client/mock_inode_cache_manager.h +++ b/curvefs/test/client/mock_inode_manager.h @@ -20,8 +20,8 @@ * Author: xuchaojie */ -#ifndef CURVEFS_TEST_CLIENT_MOCK_INODE_CACHE_MANAGER_H_ -#define CURVEFS_TEST_CLIENT_MOCK_INODE_CACHE_MANAGER_H_ +#ifndef CURVEFS_TEST_CLIENT_MOCK_INODE_MANAGER_H_ +#define CURVEFS_TEST_CLIENT_MOCK_INODE_MANAGER_H_ #include #include @@ -30,7 +30,7 @@ #include #include -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" namespace curvefs { namespace client { @@ -77,4 +77,4 @@ class MockInodeCacheManager : public InodeCacheManager { } // namespace curvefs -#endif // CURVEFS_TEST_CLIENT_MOCK_INODE_CACHE_MANAGER_H_ +#endif // CURVEFS_TEST_CLIENT_MOCK_INODE_MANAGER_H_ diff --git a/curvefs/test/client/rpcclient/mds_client_test.cpp b/curvefs/test/client/rpcclient/mds_client_test.cpp index 0ec3644845..d5193871dd 100644 --- a/curvefs/test/client/rpcclient/mds_client_test.cpp +++ b/curvefs/test/client/rpcclient/mds_client_test.cpp @@ -1043,7 +1043,6 @@ TEST_F(MdsClientImplTest, test_AllocOrGetMemcacheCluster) { } TEST_F(MdsClientImplTest, Tso) { - uint32_t fsId = 1; curvefs::mds::TsoResponse response; // CASE 1: Tso success @@ -1055,7 +1054,7 @@ TEST_F(MdsClientImplTest, Tso) { uint64_t ts; uint64_t timestamp; - auto rc = mdsclient_.Tso(fsId, &ts, ×tamp); + auto rc = mdsclient_.Tso(&ts, ×tamp); ASSERT_EQ(rc, FSStatusCode::OK); ASSERT_EQ(ts, 1); ASSERT_EQ(timestamp, 100); @@ -1065,7 +1064,7 @@ TEST_F(MdsClientImplTest, Tso) { EXPECT_CALL(mockmdsbasecli_, Tso(_, _, _, _)) .WillOnce(SetArgPointee<1>(response)); - rc = mdsclient_.Tso(fsId, &ts, ×tamp); + rc = mdsclient_.Tso(&ts, ×tamp); ASSERT_EQ(rc, FSStatusCode::UNKNOWN_ERROR); // CASE 3: RPC error, retry until success @@ -1084,7 +1083,7 @@ TEST_F(MdsClientImplTest, Tso) { } })); - rc = mdsclient_.Tso(fsId, &ts, ×tamp); + rc = mdsclient_.Tso(&ts, ×tamp); ASSERT_EQ(rc, FSStatusCode::OK); } diff --git a/curvefs/test/client/rpcclient/mock_mds_client.h b/curvefs/test/client/rpcclient/mock_mds_client.h index f1d5161d09..3dbded765a 100644 --- a/curvefs/test/client/rpcclient/mock_mds_client.h +++ b/curvefs/test/client/rpcclient/mock_mds_client.h @@ -133,7 +133,7 @@ class MockMdsClient : public MdsClient { MOCK_METHOD2(AllocOrGetMemcacheCluster, bool(uint32_t, curvefs::mds::topology::MemcacheClusterInfo*)); - MOCK_METHOD(FSStatusCode, Tso, (uint32_t, uint64_t*, uint64_t*), + MOCK_METHOD(FSStatusCode, Tso, (uint64_t*, uint64_t*), (override)); }; } // namespace rpcclient diff --git a/curvefs/test/client/test_dentry_cache_manager.cpp b/curvefs/test/client/test_dentry_cache_manager.cpp index f1b52dccea..2f80e82b00 100644 --- a/curvefs/test/client/test_dentry_cache_manager.cpp +++ b/curvefs/test/client/test_dentry_cache_manager.cpp @@ -27,7 +27,7 @@ #include "curvefs/test/client/rpcclient/mock_mds_client.h" #include "curvefs/test/client/mock_metaserver_client.h" -#include "curvefs/src/client/dentry_cache_manager.h" +#include "curvefs/src/client/dentry_manager.h" namespace curvefs { namespace client { @@ -197,14 +197,14 @@ TEST_F(TestDentryCacheManager, GetDentry) { // 1. Tso failed EXPECT_CALL(*metaClient_, GetDentry(fsId_, parent, name, _, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::UNKNOWN_ERROR)); ret = dCacheManager_->GetDentry(parent, name, &out); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); // 2. CheckAndResolveTx failed EXPECT_CALL(*metaClient_, GetDentry(fsId_, parent, name, _, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); ret = dCacheManager_->GetDentry(parent, name, &out); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); @@ -217,7 +217,7 @@ TEST_F(TestDentryCacheManager, GetDentry) { Return(MetaStatusCode::TX_KEY_LOCKED))) .WillOnce(DoAll(SetArgPointee<3>(dentryExp), Return(MetaStatusCode::OK))); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, CheckTxStatus(_, _, _, _, _)) .WillOnce(Return(MetaStatusCode::TX_COMMITTED)); @@ -283,14 +283,14 @@ TEST_F(TestDentryCacheManager, CreateAndGetDentry) { // 1. Tso failed EXPECT_CALL(*metaClient_, CreateDentry(_, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::UNKNOWN_ERROR)); ret = dCacheManager_->CreateDentry(dentryExp); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); // 2. CheckAndResolveTx failed EXPECT_CALL(*metaClient_, CreateDentry(_, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); ret = dCacheManager_->CreateDentry(dentryExp); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); @@ -302,7 +302,7 @@ TEST_F(TestDentryCacheManager, CreateAndGetDentry) { .WillOnce(DoAll(SetArgPointee<1>(txLock), Return(MetaStatusCode::TX_KEY_LOCKED))) .WillOnce(Return(MetaStatusCode::OK)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, CheckTxStatus(_, _, _, _, _)) .WillOnce(Return(MetaStatusCode::TX_COMMITTED)); @@ -333,7 +333,7 @@ TEST_F(TestDentryCacheManager, DeleteDentry) { EXPECT_CALL(*metaClient_, DeleteDentry( fsId_, parent, name, FsFileType::TYPE_FILE, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::UNKNOWN_ERROR)); ret = dCacheManager_->DeleteDentry(parent, name, FsFileType::TYPE_FILE); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); @@ -341,7 +341,7 @@ TEST_F(TestDentryCacheManager, DeleteDentry) { EXPECT_CALL(*metaClient_, DeleteDentry( fsId_, parent, name, FsFileType::TYPE_FILE, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); ret = dCacheManager_->DeleteDentry(parent, name, FsFileType::TYPE_FILE); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); @@ -354,7 +354,7 @@ TEST_F(TestDentryCacheManager, DeleteDentry) { .WillOnce(DoAll(SetArgPointee<4>(txLock), Return(MetaStatusCode::TX_KEY_LOCKED))) .WillOnce(Return(MetaStatusCode::OK)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, CheckTxStatus(_, _, _, _, _)) .WillOnce(Return(MetaStatusCode::TX_COMMITTED)); @@ -423,14 +423,14 @@ TEST_F(TestDentryCacheManager, ListDentry_txLocked) { // 1. Tso failed EXPECT_CALL(*metaClient_, ListDentry(fsId_, parent, _, _, _, _, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::UNKNOWN_ERROR)); CURVEFS_ERROR ret = dCacheManager_->ListDentry(parent, &out, 100); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); // 2. tx key locked but part empty EXPECT_CALL(*metaClient_, ListDentry(fsId_, parent, _, _, _, _, _)) .WillOnce(Return(MetaStatusCode::TX_KEY_LOCKED)); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); ret = dCacheManager_->ListDentry(parent, &out, 100); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); @@ -438,7 +438,7 @@ TEST_F(TestDentryCacheManager, ListDentry_txLocked) { EXPECT_CALL(*metaClient_, ListDentry(fsId_, parent, _, _, _, _, _)) .WillOnce(DoAll(SetArgPointee<5>(part), Return(MetaStatusCode::TX_KEY_LOCKED))); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); Dentry dentry; dentry.set_fsid(fsId_); @@ -457,7 +457,7 @@ TEST_F(TestDentryCacheManager, ListDentry_txLocked) { Return(MetaStatusCode::TX_KEY_LOCKED))) .WillOnce(DoAll(SetArgPointee<5>(part), Return(MetaStatusCode::OK))); - EXPECT_CALL(*mdsClient_, Tso(_, _, _)) + EXPECT_CALL(*mdsClient_, Tso(_, _)) .WillOnce(Return(FSStatusCode::OK)); EXPECT_CALL(*metaClient_, CheckTxStatus(_, _, _, _, _)) .WillOnce(Return(MetaStatusCode::TX_COMMITTED)); diff --git a/curvefs/test/client/test_fuse_s3_client.cpp b/curvefs/test/client/test_fuse_s3_client.cpp index 422c3c140f..c948fdf25e 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -41,9 +41,9 @@ #include "curvefs/src/common/define.h" #include "curvefs/test/client/mock_client_s3.h" #include "curvefs/test/client/mock_client_s3_adaptor.h" -#include "curvefs/test/client/mock_dentry_cache_mamager.h" +#include "curvefs/test/client/mock_dentry_mamager.h" #include "curvefs/test/client/mock_disk_cache_manager.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/mock_metaserver_client.h" #include "curvefs/test/client/rpcclient/mock_mds_client.h" #include "fuse3/fuse_lowlevel.h" diff --git a/curvefs/test/client/test_fuse_volume_client.cpp b/curvefs/test/client/test_fuse_volume_client.cpp index 9185e275a5..4aafa17fee 100644 --- a/curvefs/test/client/test_fuse_volume_client.cpp +++ b/curvefs/test/client/test_fuse_volume_client.cpp @@ -27,8 +27,8 @@ #include "curvefs/proto/metaserver.pb.h" #include "curvefs/src/client/fuse_volume_client.h" #include "curvefs/src/common/define.h" -#include "curvefs/test/client/mock_dentry_cache_mamager.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_dentry_mamager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/rpcclient/mock_mds_client.h" #include "curvefs/test/client/mock_metaserver_client.h" #include "curvefs/test/client/mock_volume_storage.h" diff --git a/curvefs/test/client/test_inode_cache_manager.cpp b/curvefs/test/client/test_inode_cache_manager.cpp index 6617d3c390..2499913c9a 100644 --- a/curvefs/test/client/test_inode_cache_manager.cpp +++ b/curvefs/test/client/test_inode_cache_manager.cpp @@ -30,7 +30,7 @@ #include "curvefs/src/client/inode_wrapper.h" #include "curvefs/src/client/rpcclient/metaserver_client.h" #include "curvefs/test/client/mock_metaserver_client.h" -#include "curvefs/src/client/inode_cache_manager.h" +#include "curvefs/src/client/inode_manager.h" #include "curvefs/src/common/define.h" #include "curvefs/src/client/filesystem/defer_sync.h" #include "curvefs/src/client/filesystem/openfile.h" diff --git a/curvefs/test/client/volume/default_volume_storage_test.cpp b/curvefs/test/client/volume/default_volume_storage_test.cpp index 008b0d2004..879addb5f2 100644 --- a/curvefs/test/client/volume/default_volume_storage_test.cpp +++ b/curvefs/test/client/volume/default_volume_storage_test.cpp @@ -27,7 +27,7 @@ #include "curvefs/src/client/filesystem/error.h" #include "curvefs/src/client/filesystem/meta.h" -#include "curvefs/test/client/mock_inode_cache_manager.h" +#include "curvefs/test/client/mock_inode_manager.h" #include "curvefs/test/client/mock_metaserver_client.h" #include "curvefs/test/volume/mock/mock_block_device_client.h" #include "curvefs/test/volume/mock/mock_space_manager.h" diff --git a/curvefs/test/mds/fs_manager_test2.cpp b/curvefs/test/mds/fs_manager_test2.cpp index 61968b4f1d..fb3ee29ec6 100644 --- a/curvefs/test/mds/fs_manager_test2.cpp +++ b/curvefs/test/mds/fs_manager_test2.cpp @@ -439,11 +439,10 @@ TEST_F(FsManagerTest2, checkFsName) { TEST_F(FsManagerTest2, test_tso) { // Tso success TsoRequest request; - request.set_fsid(1); TsoResponse response; - EXPECT_CALL(*storage_, Tso(1, _, _)). - WillOnce(DoAll(SetArgPointee<1>(1), - SetArgPointee<2>(100), + EXPECT_CALL(*storage_, Tso(_, _)). + WillOnce(DoAll(SetArgPointee<0>(1), + SetArgPointee<1>(100), Return(FSStatusCode::OK))); fsManager_->Tso(&request, &response); ASSERT_EQ(response.statuscode(), FSStatusCode::OK); @@ -451,7 +450,7 @@ TEST_F(FsManagerTest2, test_tso) { ASSERT_EQ(response.timestamp(), 100); // Tso failed - EXPECT_CALL(*storage_, Tso(1, _, _)). + EXPECT_CALL(*storage_, Tso(_, _)). WillOnce(Return(FSStatusCode::INTERNAL_ERROR)); fsManager_->Tso(&request, &response); ASSERT_EQ(response.statuscode(), FSStatusCode::INTERNAL_ERROR); diff --git a/curvefs/test/mds/fs_storage_test.cpp b/curvefs/test/mds/fs_storage_test.cpp index 559dfe4a08..f293434628 100644 --- a/curvefs/test/mds/fs_storage_test.cpp +++ b/curvefs/test/mds/fs_storage_test.cpp @@ -51,6 +51,8 @@ class FSStorageTest : public ::testing::Test { TEST_F(FSStorageTest, test1) { MemoryFsStorage storage; + ASSERT_TRUE(storage.Init()); + common::Volume volume; uint32_t fsId = 1; uint64_t rootInodeId = 1; @@ -121,7 +123,7 @@ TEST_F(FSStorageTest, test1) { uint64_t ts; uint64_t timestamp; for (int i = 1; i < 5; i++) { - ASSERT_EQ(FSStatusCode::OK, storage.Tso(fsId, &ts, ×tamp)); + ASSERT_EQ(FSStatusCode::OK, storage.Tso(&ts, ×tamp)); ASSERT_EQ(ts, i); } } diff --git a/curvefs/test/mds/mds_service_test.cpp b/curvefs/test/mds/mds_service_test.cpp index d9dfe3cbc2..cb5a60b765 100644 --- a/curvefs/test/mds/mds_service_test.cpp +++ b/curvefs/test/mds/mds_service_test.cpp @@ -954,7 +954,6 @@ TEST_F(MdsServiceTest, test_update_fsinfo_parameter_error) { TEST_F(MdsServiceTest, test_tso) { TsoRequest tsoRequest; - tsoRequest.set_fsid(1); TsoResponse tsoResponse; for (int i = 1; i < 5; i++) { cntl.Reset(); diff --git a/curvefs/test/mds/mock/mock_fs_stroage.h b/curvefs/test/mds/mock/mock_fs_stroage.h index 6d314540dd..aa178c5526 100644 --- a/curvefs/test/mds/mock/mock_fs_stroage.h +++ b/curvefs/test/mds/mock/mock_fs_stroage.h @@ -61,7 +61,7 @@ class MockFsStorage : public FsStorage { MOCK_METHOD3( GetFsUsage, FSStatusCode(const std::string&, FsUsage*, bool fromCache)); MOCK_METHOD1(DeleteFsUsage, FSStatusCode(const std::string&)); - MOCK_METHOD(FSStatusCode, Tso, (uint32_t, uint64_t*, uint64_t*), + MOCK_METHOD(FSStatusCode, Tso, (uint64_t*, uint64_t*), (override)); }; diff --git a/curvefs/test/mds/persist_kvstorage_test.cpp b/curvefs/test/mds/persist_kvstorage_test.cpp index fc6fb3f834..8595fd86ee 100644 --- a/curvefs/test/mds/persist_kvstorage_test.cpp +++ b/curvefs/test/mds/persist_kvstorage_test.cpp @@ -126,12 +126,9 @@ class PersistKVStorageTest : public ::testing::Test { do { \ std::vector> encoded = \ PrepareFsInfoSamples(); \ - std::vector> loadTs; \ EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) \ .WillOnce( \ - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))) \ - .WillOnce( \ - DoAll(SetArgPointee<2>(loadTs), Return(EtcdErrCode::EtcdOK))); \ + DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK)));\ EXPECT_CALL(*storageCli_, Get(_, _)) \ .WillRepeatedly(Return(EtcdErrCode::EtcdOK)); \ } while (false) @@ -188,13 +185,10 @@ TEST_F(PersistKVStorageTest, TestGetAndExist) { { PersisKVStorage storage(storageCli_); std::vector> encoded; - std::vector> loadTs; EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))) - .WillOnce( - DoAll(SetArgPointee<2>(loadTs), Return(EtcdErrCode::EtcdOK))); + DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Get(_, _)) .WillRepeatedly(Return(EtcdErrCode::EtcdOK)); @@ -491,52 +485,47 @@ TEST_F(PersistKVStorageTest, TestDelete) { } TEST_F(PersistKVStorageTest, TestTso) { - uint32_t fsId = 1; uint64_t ts; uint64_t timestamp; - // tsinfo not exist + // tsid not exist { PersisKVStorage storage(storageCli_); - // store failed - EXPECT_CALL(*storageCli_, Put(_, _)) + // get failed + EXPECT_CALL(*storageCli_, Get(_, _)) .WillOnce(Return(EtcdErrCode::EtcdUnknown)); ASSERT_EQ(FSStatusCode::INTERNAL_ERROR, - storage.Tso(fsId, &ts, ×tamp)); - - // store success + storage.Tso(&ts, ×tamp)); + // CompareAndSwap failed + EXPECT_CALL(*storageCli_, Get(_, _)) + .WillOnce(Return(EtcdErrCode::EtcdKeyNotExist)); + EXPECT_CALL(*storageCli_, CompareAndSwap(_, _, _)) + .WillOnce(Return(EtcdErrCode::EtcdUnknown)); + ASSERT_EQ(FSStatusCode::INTERNAL_ERROR, + storage.Tso(&ts, ×tamp)); + // success + EXPECT_CALL(*storageCli_, Get(_, _)) + .WillOnce(Return(EtcdErrCode::EtcdKeyNotExist)); + EXPECT_CALL(*storageCli_, CompareAndSwap(_, _, _)) + .WillOnce(Return(EtcdErrCode::EtcdOK)); for (int i = 1; i < 5; i++) { - EXPECT_CALL(*storageCli_, Put(_, _)) - .WillOnce(Return(EtcdErrCode::EtcdOK)); - ASSERT_EQ(FSStatusCode::OK, storage.Tso(fsId, &ts, ×tamp)); + ASSERT_EQ(FSStatusCode::OK, storage.Tso(&ts, ×tamp)); ASSERT_EQ(ts, i); } } - // exist + // txid exist { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); - std::vector> loadTs; - std::string encodedTsKey = codec::EncodeTsKey(fsId); - TS tsInfo; - tsInfo.set_ts(10); - std::string encodedTsInfo; - EXPECT_TRUE(codec::EncodeProtobufMessage(tsInfo, &encodedTsInfo)); - loadTs.emplace_back(encodedTsKey, encodedTsInfo); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))) - .WillOnce( - DoAll(SetArgPointee<2>(loadTs), Return(EtcdErrCode::EtcdOK))); + uint64_t tsId = 10000; + // success EXPECT_CALL(*storageCli_, Get(_, _)) - .WillRepeatedly(Return(EtcdErrCode::EtcdOK)); - - EXPECT_TRUE(storage.Init()); - - EXPECT_CALL(*storageCli_, Put(_, _)) + .WillOnce(DoAll(SetArgPointee<1>(std::to_string(tsId)), + Return(EtcdErrCode::EtcdOK))); + EXPECT_CALL(*storageCli_, CompareAndSwap(_, _, _)) .WillOnce(Return(EtcdErrCode::EtcdOK)); - ASSERT_EQ(FSStatusCode::OK, storage.Tso(fsId, &ts, ×tamp)); - ASSERT_EQ(ts, 11); + for (int i = 1; i < 5; i++) { + ASSERT_EQ(FSStatusCode::OK, storage.Tso(&ts, ×tamp)); + ASSERT_EQ(ts, i + tsId); + } } } diff --git a/curvefs/test/metaserver/copyset/raft_cli_service2_test.cpp b/curvefs/test/metaserver/copyset/raft_cli_service2_test.cpp index 5a3f8e5d85..09dc39c3dc 100644 --- a/curvefs/test/metaserver/copyset/raft_cli_service2_test.cpp +++ b/curvefs/test/metaserver/copyset/raft_cli_service2_test.cpp @@ -472,7 +472,7 @@ TEST_F(RaftCliService2Test, ChangePeerTest) { // change peer succeed { - sleep(60); + // sleep(60); ChangePeersRequest2 request; ChangePeersResponse2 response; SetRequestPoolAndCopysetId(&request); @@ -495,7 +495,7 @@ TEST_F(RaftCliService2Test, ChangePeerTest) { brpc::Controller cntl; CliService2_Stub stub(&channel_); stub.ChangePeers(&cntl, &request, &response, nullptr); - ASSERT_FALSE(cntl.Failed()); + ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); // check response ASSERT_EQ(3, response.oldpeers_size());