diff --git a/curvefs/conf/metaserver.conf b/curvefs/conf/metaserver.conf index 5f9fb129b1..1140bef40d 100644 --- a/curvefs/conf/metaserver.conf +++ b/curvefs/conf/metaserver.conf @@ -293,7 +293,7 @@ storage.rocksdb.perf_sampling_ratio=0 # padding its into inode (default: 25000, about 25000 * 41 (byte) = 1MB) storage.s3_meta_inside_inode.limit_size=25000 # TTL(millisecond) for tx lock -storage.rocksdb.tx_lock_ttl_ms=5000 +storage.tx_lock_ttl_ms=5000 # recycle options # metaserver scan recycle period, default 1h diff --git a/curvefs/proto/mds.proto b/curvefs/proto/mds.proto index df2e0357f3..12f6ca6ee1 100644 --- a/curvefs/proto/mds.proto +++ b/curvefs/proto/mds.proto @@ -234,11 +234,13 @@ message CommitTxResponse { required FSStatusCode statusCode = 1; } -message TsoRequest {} +message TsoRequest { + required uint32 fsId = 1; +} message TsoResponse { required FSStatusCode statusCode = 1; - optional uint64 sn = 2; + optional uint64 ts = 2; // transaction sequence number optional uint64 timestamp = 3; } diff --git a/curvefs/src/client/client_operator.cpp b/curvefs/src/client/client_operator.cpp index b1a63880d3..02cf0d881f 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(&startTs_, ×tamp); + auto rc = mdsClient_->Tso(srcDentry_.fsid(), &startTs_, ×tamp); if (rc != FSStatusCode::OK) { LOG_ERROR("start Tso", rc); return CURVEFS_ERROR::INTERNAL; @@ -333,8 +333,8 @@ CURVEFS_ERROR RenameOperator::PrewriteTx() { txLockIn.set_timestamp(timestamp); if (!metaClient_->GetPartitionId(dentry_.fsid(), dentry_.parentinodeid(), - &srcPartitionId_) || !metaClient_->GetPartitionId(newDentry_.fsid(), - newDentry_.parentinodeid(), &dstPartitionId_)) { + &srcPartitionId_) || !metaClient_->GetPartitionId(newDentry_.fsid(), + newDentry_.parentinodeid(), &dstPartitionId_)) { LOG_ERROR("GetPartitionId", 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(&commitTs, ×tamp); + auto rc = mdsClient_->Tso(srcDentry_.fsid(), &commitTs, ×tamp); if (rc != FSStatusCode::OK) { LOG_ERROR("CommitTxV2 Tso", rc); return CURVEFS_ERROR::INTERNAL; diff --git a/curvefs/src/client/dentry_cache_manager.cpp b/curvefs/src/client/dentry_cache_manager.cpp index a66b0c7430..d9155dccd2 100644 --- a/curvefs/src/client/dentry_cache_manager.cpp +++ b/curvefs/src/client/dentry_cache_manager.cpp @@ -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(&ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(fsId_, &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(&ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(fsId_, &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(&ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(fsId_, &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(&ts, ×tamp) != FSStatusCode::OK) { + if (mdsClient_->Tso(fsId_, &ts, ×tamp) != FSStatusCode::OK) { LOG(ERROR) << "ListDentry Tso failed, parent = " << parent; return CURVEFS_ERROR::INTERNAL; } diff --git a/curvefs/src/client/rpcclient/mds_client.cpp b/curvefs/src/client/rpcclient/mds_client.cpp index 4a65c6efbc..8e187fb7f3 100644 --- a/curvefs/src/client/rpcclient/mds_client.cpp +++ b/curvefs/src/client/rpcclient/mds_client.cpp @@ -682,19 +682,22 @@ FSStatusCode MdsClientImpl::CommitTxWithLock( return CommitTx(request); } -FSStatusCode MdsClientImpl::Tso(uint64_t* sn, uint64_t* timestamp) { +FSStatusCode MdsClientImpl::Tso( + uint32_t fsId, 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(); } @@ -702,10 +705,11 @@ FSStatusCode MdsClientImpl::Tso(uint64_t* sn, uint64_t* timestamp) { FSStatusCode ret = response.statuscode(); if (ret != FSStatusCode::OK) { LOG(ERROR) << "Tso: errcode = " << ret - << ", errmsg = " << FSStatusCode_Name(ret); + << ", errmsg = " << FSStatusCode_Name(ret) + << ", fsId = " << fsId; return ret; } else { - *sn = response.sn(); + *ts = response.ts(); *timestamp = response.timestamp(); } return ret; diff --git a/curvefs/src/client/rpcclient/mds_client.h b/curvefs/src/client/rpcclient/mds_client.h index d1fb59b10c..81394d1f10 100644 --- a/curvefs/src/client/rpcclient/mds_client.h +++ b/curvefs/src/client/rpcclient/mds_client.h @@ -137,7 +137,8 @@ class MdsClient { const std::string& uuid, uint64_t sequence) = 0; - virtual FSStatusCode Tso(uint64_t* sn, uint64_t* timestamp) = 0; + virtual FSStatusCode Tso(uint32_t fsId, uint64_t* ts, + uint64_t* timestamp) = 0; // allocate block group virtual SpaceErrCode AllocateVolumeBlockGroup( @@ -226,7 +227,7 @@ class MdsClientImpl : public MdsClient { const std::string& uuid, uint64_t sequence) override; - FSStatusCode Tso(uint64_t* sn, uint64_t* timestamp) override; + FSStatusCode Tso(uint32_t fsId, uint64_t* ts, uint64_t* timestamp) override; // allocate block group SpaceErrCode AllocateVolumeBlockGroup( diff --git a/curvefs/src/mds/codec/codec.cpp b/curvefs/src/mds/codec/codec.cpp index 3bee130c98..de5b4b3925 100644 --- a/curvefs/src/mds/codec/codec.cpp +++ b/curvefs/src/mds/codec/codec.cpp @@ -33,6 +33,7 @@ namespace codec { using ::curve::common::EncodeBigEndian; using ::curve::common::EncodeBigEndian_uint32; +using ::curve::common::DecodeBigEndian_uint32; using ::curvefs::mds::BLOCKGROUP_KEY_END; using ::curvefs::mds::BLOCKGROUP_KEY_PREFIX; using ::curvefs::mds::COMMON_PREFIX_LENGTH; @@ -78,6 +79,23 @@ 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 a23891a04c..d38812d3f4 100644 --- a/curvefs/src/mds/codec/codec.h +++ b/curvefs/src/mds/codec/codec.h @@ -66,6 +66,10 @@ 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 bfa10ac5d7..9edfed6092 100644 --- a/curvefs/src/mds/common/storage_key.h +++ b/curvefs/src/mds/common/storage_key.h @@ -45,6 +45,8 @@ 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"; constexpr uint32_t COMMON_PREFIX_LENGTH = 5; @@ -65,7 +67,6 @@ const char MEMCACHE_CLUSTER_KEY_PREFIX[] = "fs_1009"; const char MEMCACHE_CLUSTER_KEY_END[] = "fs_1010"; const char FS_2_MEMCACHE_CLUSTER_KEY_PREFIX[] = "fs_1010"; const char FS_2_MEMCACHE_CLUSTER_KEY_END[] = "fs_1011"; -const char TS_INFO_KEY[] = "fs_1012"; constexpr uint32_t TOPOLOGY_PREFIX_LENGTH = 7; diff --git a/curvefs/src/mds/fs_manager.cpp b/curvefs/src/mds/fs_manager.cpp index bda870f333..5dbf9f697e 100644 --- a/curvefs/src/mds/fs_manager.cpp +++ b/curvefs/src/mds/fs_manager.cpp @@ -1297,11 +1297,18 @@ bool FsManager::FillVolumeInfo(common::Volume* volume) { } void FsManager::Tso(const TsoRequest* request, TsoResponse* response) { - if (topoManager_->Tso(request, response)) { - response->set_statuscode(FSStatusCode::OK); - } else { - response->set_statuscode(FSStatusCode::INTERNAL_ERROR); + uint64_t ts; + uint64_t timestamp; + auto ret = fsStorage_->Tso(request->fsid(), &ts, ×tamp); + if (ret != FSStatusCode::OK) { + LOG(ERROR) << "Tso fail, fsid = " << request->fsid() + << ", ret = " << FSStatusCode_Name(ret); + response->set_statuscode(ret); + return; } + response->set_ts(ts); + response->set_timestamp(timestamp); + response->set_statuscode(ret); } } // namespace mds diff --git a/curvefs/src/mds/fs_storage.cpp b/curvefs/src/mds/fs_storage.cpp index b38b9f9803..59ffe8e6fd 100644 --- a/curvefs/src/mds/fs_storage.cpp +++ b/curvefs/src/mds/fs_storage.cpp @@ -30,6 +30,7 @@ #include "curvefs/src/mds/codec/codec.h" #include "curvefs/src/mds/metric/fs_metric.h" +#include "src/common/timeutility.h" namespace curvefs { namespace mds { @@ -186,6 +187,22 @@ 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_); + *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; + return FSStatusCode::OK; +} + PersisKVStorage::PersisKVStorage( const std::shared_ptr& storage) : storage_(storage), @@ -208,7 +225,16 @@ FSStatusCode PersisKVStorage::Get(uint64_t fsId, FsInfoWrapper* fsInfo) { bool PersisKVStorage::Init() { bool ret = LoadAllFs(); - return ret; + if (!ret) { + LOG(ERROR) << "Load all fs failed"; + return false; + } + ret = LoadAllTsInfo(); + if (!ret) { + LOG(ERROR) << "Load all tsInfo failed"; + return false; + } + return true; } void PersisKVStorage::Uninit() {} @@ -419,6 +445,30 @@ 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); @@ -570,5 +620,35 @@ 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_); + *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; + } + tsMap_[fsId] = tsInfo; + return FSStatusCode::OK; +} + } // namespace mds } // namespace curvefs diff --git a/curvefs/src/mds/fs_storage.h b/curvefs/src/mds/fs_storage.h index d2ed8d674d..bfc5980ed4 100644 --- a/curvefs/src/mds/fs_storage.h +++ b/curvefs/src/mds/fs_storage.h @@ -37,10 +37,13 @@ #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" namespace curvefs { namespace mds { +using ::curvefs::metaserver::TS; + constexpr uint64_t INVALID_FS_ID = std::numeric_limits::max(); class FsStorage { @@ -76,6 +79,9 @@ class FsStorage { virtual FSStatusCode GetFsUsage( 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; }; class MemoryFsStorage : public FsStorage { @@ -182,6 +188,9 @@ 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; + private: std::unordered_map fsInfoMap_; curve::common::RWLock rwLock_; @@ -190,6 +199,9 @@ class MemoryFsStorage : public FsStorage { std::unordered_map fsUsageMap_; curve::common::RWLock fsUsedUsageLock_; + + std::unordered_map tsMap_; + mutable RWLock tsLock_; }; // Persist all data to kvstorage and cache all fsinfo in memory @@ -225,9 +237,14 @@ 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; + private: bool LoadAllFs(); + bool LoadAllTsInfo(); + bool FsIDToName(uint64_t fsId, std::string* name) const; bool PersistToStorage(const FsInfoWrapper& fs); @@ -259,6 +276,9 @@ class PersisKVStorage : public FsStorage { // fs usage cache map std::unordered_map fsUsageCache_; mutable RWLock fsUsageCacheMutex_; + + std::unordered_map tsMap_; + mutable RWLock tsLock_; }; } // namespace mds diff --git a/curvefs/src/mds/topology/topology.cpp b/curvefs/src/mds/topology/topology.cpp index 8c51d9aa96..a929336918 100644 --- a/curvefs/src/mds/topology/topology.cpp +++ b/curvefs/src/mds/topology/topology.cpp @@ -975,11 +975,6 @@ TopoStatusCode TopologyImpl::Init(const TopologyOption &option) { return ret; } - if (!storage_->LoadTsInfo(&tsInfo_)) { - LOG(ERROR) << "[TopologyImpl::init], LoadTsInfo fail."; - return TopoStatusCode::TOPO_STORGE_FAIL; - } - PoolIdType maxPoolId; if (!storage_->LoadPool(&poolMap_, &maxPoolId)) { LOG(ERROR) << "[TopologyImpl::init], LoadPool fail."; @@ -1785,12 +1780,6 @@ TopologyImpl::AllocOrGetMemcacheCluster(FsIdType fsId, return ret; } -bool TopologyImpl::Tso(uint64_t* ts, uint64_t* timestamp) { - *timestamp = curve::common::TimeUtility::GetTimeofDayMs(); - *ts = tsInfo_.GetTs(); - return storage_->StorageTsInfo(tsInfo_); -} - } // namespace topology } // namespace mds } // namespace curvefs diff --git a/curvefs/src/mds/topology/topology.h b/curvefs/src/mds/topology/topology.h index 4d4757c1f9..6078564507 100644 --- a/curvefs/src/mds/topology/topology.h +++ b/curvefs/src/mds/topology/topology.h @@ -297,8 +297,6 @@ class Topology { virtual std::list ListMemcacheClusters() const = 0; virtual TopoStatusCode AllocOrGetMemcacheCluster( FsIdType fsId, MemcacheClusterInfo* cluster) = 0; - - virtual bool Tso(uint64_t* ts, uint64_t* timestamp) = 0; }; class TopologyImpl : public Topology { @@ -554,8 +552,6 @@ class TopologyImpl : public Topology { TopoStatusCode AllocOrGetMemcacheCluster( FsIdType fsId, MemcacheClusterInfo* cluster) override; - bool Tso(uint64_t* ts, uint64_t* timestamp) override; - private: TopoStatusCode LoadClusterInfo(); @@ -589,9 +585,6 @@ class TopologyImpl : public Topology { ClusterInformation clusterInfo_; mutable RWLock clusterMutex_; - // ts info - TsInfo tsInfo_; - std::shared_ptr idGenerator_; std::shared_ptr tokenGenerator_; std::shared_ptr storage_; diff --git a/curvefs/src/mds/topology/topology_item.cpp b/curvefs/src/mds/topology/topology_item.cpp index fa7d81eada..b1774b701a 100644 --- a/curvefs/src/mds/topology/topology_item.cpp +++ b/curvefs/src/mds/topology/topology_item.cpp @@ -52,19 +52,6 @@ bool ClusterInformation::ParseFromString(const std::string &value) { return ret; } -bool TsInfo::SerializeToString(std::string* value) const { - curvefs::metaserver::TS data; - data.set_ts(ts); - return data.SerializeToString(value); -} - -bool TsInfo::ParseFromString(const std::string& value) { - curvefs::metaserver::TS data; - bool ret = data.ParseFromString(value); - ts = data.ts(); - return ret; -} - bool Pool::TransRedundanceAndPlaceMentPolicyFromJsonStr( const std::string &jsonStr, RedundanceAndPlaceMentPolicy *rap) { Json::CharReaderBuilder builder; diff --git a/curvefs/src/mds/topology/topology_item.h b/curvefs/src/mds/topology/topology_item.h index b56624df26..80099511d5 100644 --- a/curvefs/src/mds/topology/topology_item.h +++ b/curvefs/src/mds/topology/topology_item.h @@ -91,31 +91,6 @@ struct ClusterInformation { bool ParseFromString(const std::string &value); }; -struct TsInfo { - TsInfo() : ts(0) {} - - explicit TsInfo(uint64_t ts) : ts(ts) {} - - TsInfo(const TsInfo &v) : ts(v.ts.load()) {} - - TsInfo &operator=(const TsInfo &v) { - if (&v == this) { - return *this; - } - ts.store(v.ts.load()); - return *this; - } - - // only transaction sequence number now - std::atomic ts; - - uint64_t GetTs() { return ++ts; } - - bool SerializeToString(std::string* value) const; - - bool ParseFromString(const std::string& value); -}; - class Pool { public: struct RedundanceAndPlaceMentPolicy { diff --git a/curvefs/src/mds/topology/topology_manager.cpp b/curvefs/src/mds/topology/topology_manager.cpp index eafef87430..0b50a15c2d 100644 --- a/curvefs/src/mds/topology/topology_manager.cpp +++ b/curvefs/src/mds/topology/topology_manager.cpp @@ -1406,17 +1406,6 @@ void TopologyManager::AllocOrGetMemcacheCluster( response->set_statuscode(statusCode); } -bool TopologyManager::Tso(const TsoRequest* request, TsoResponse* response) { - uint64_t sn; - uint64_t timestamp; - if (topology_->Tso(&sn, ×tamp)) { - response->set_sn(sn); - response->set_timestamp(timestamp); - return true; - } - return false; -} - } // namespace topology } // namespace mds } // namespace curvefs diff --git a/curvefs/src/mds/topology/topology_manager.h b/curvefs/src/mds/topology/topology_manager.h index 360fa20124..d31be90b9a 100644 --- a/curvefs/src/mds/topology/topology_manager.h +++ b/curvefs/src/mds/topology/topology_manager.h @@ -178,8 +178,6 @@ class TopologyManager { const AllocOrGetMemcacheClusterRequest* request, AllocOrGetMemcacheClusterResponse* response); - virtual bool Tso(const TsoRequest* request, TsoResponse* response); - private: TopoStatusCode CreateEnoughCopyset(int32_t createNum); diff --git a/curvefs/src/mds/topology/topology_storage_codec.cpp b/curvefs/src/mds/topology/topology_storage_codec.cpp index 4e1c86db43..7ba8edb105 100644 --- a/curvefs/src/mds/topology/topology_storage_codec.cpp +++ b/curvefs/src/mds/topology/topology_storage_codec.cpp @@ -153,16 +153,6 @@ bool TopologyStorageCodec::DecodeClusterInfoData(const std::string &value, return data->ParseFromString(value); } -bool TopologyStorageCodec::EncodeTsData( - const TsInfo& data, std::string* value) { - return data.SerializeToString(value); -} - -bool TopologyStorageCodec::DecodeTsData( - const std::string& value, TsInfo* data) { - return data->ParseFromString(value); -} - std::string TopologyStorageCodec::EncodeMemcacheClusterKey( MetaServerIdType id) { std::string key = MEMCACHE_CLUSTER_KEY_PREFIX; diff --git a/curvefs/src/mds/topology/topology_storage_codec.h b/curvefs/src/mds/topology/topology_storage_codec.h index 8976f94769..a6e3f7bb86 100644 --- a/curvefs/src/mds/topology/topology_storage_codec.h +++ b/curvefs/src/mds/topology/topology_storage_codec.h @@ -82,9 +82,6 @@ class TopologyStorageCodec { bool DecodeClusterInfoData(const std::string &value, ClusterInformation *data); - bool EncodeTsData(const TsInfo& data, std::string* value); - bool DecodeTsData(const std::string& value, TsInfo* data); - std::string EncodeMemcacheClusterKey(MetaServerIdType id); bool EncodeMemcacheClusterData(const MemcacheCluster& data, std::string* value); diff --git a/curvefs/src/mds/topology/topology_storge.h b/curvefs/src/mds/topology/topology_storge.h index aee49f7fad..85587944c5 100644 --- a/curvefs/src/mds/topology/topology_storge.h +++ b/curvefs/src/mds/topology/topology_storge.h @@ -95,9 +95,6 @@ class TopologyStorage { fs2MemcacheCluster) = 0; virtual bool StorageFs2MemcacheCluster( FsIdType fsId, MemcacheClusterIdType memcacheClusterId) = 0; - - virtual bool LoadTsInfo(TsInfo* info) = 0; - virtual bool StorageTsInfo(const TsInfo& info) = 0; }; } // namespace topology diff --git a/curvefs/src/mds/topology/topology_storge_etcd.cpp b/curvefs/src/mds/topology/topology_storge_etcd.cpp index 1f77ef5d9f..c70aa7dd8d 100644 --- a/curvefs/src/mds/topology/topology_storge_etcd.cpp +++ b/curvefs/src/mds/topology/topology_storge_etcd.cpp @@ -644,43 +644,6 @@ bool TopologyStorageEtcd::LoadFs2MemcacheCluster( return true; } -bool TopologyStorageEtcd::StorageTsInfo(const TsInfo& info) { - std::string key = TS_INFO_KEY; - std::string value; - if (!codec_->EncodeTsData(info, &value)) { - LOG(ERROR) << "EncodeTsData err"; - return false; - } - - auto errCode = client_->Put(key, value); - if (errCode != EtcdErrCode::EtcdOK) { - LOG(ERROR) << "Put TsInfo into etcd err" - << ", errcode = " << errCode; - return false; - } - return true; -} - -bool TopologyStorageEtcd::LoadTsInfo(TsInfo* info) { - std::string value; - int errCode = client_->Get(TS_INFO_KEY, &value); - if (errCode == EtcdErrCode::EtcdKeyNotExist) { - return true; - } - if (errCode != EtcdErrCode::EtcdOK) { - LOG(ERROR) << "Get TsInfo from etcd err" - << ", errCode = " << errCode; - return false; - } - - errCode = codec_->DecodeTsData(value, info); - if (!errCode) { - LOG(ERROR) << "DecodeTxData err"; - return false; - } - return true; -} - } // namespace topology } // namespace mds } // namespace curvefs diff --git a/curvefs/src/mds/topology/topology_storge_etcd.h b/curvefs/src/mds/topology/topology_storge_etcd.h index 2c0b9dfd78..3fa5fb780d 100644 --- a/curvefs/src/mds/topology/topology_storge_etcd.h +++ b/curvefs/src/mds/topology/topology_storge_etcd.h @@ -98,9 +98,6 @@ class TopologyStorageEtcd : public TopologyStorage { std::unordered_map* fs2MemcacheCluster) override; - bool LoadTsInfo(TsInfo* info) override; - bool StorageTsInfo(const TsInfo& info) override; - private: // underlying storage media std::shared_ptr client_; diff --git a/curvefs/src/metaserver/dentry_storage.cpp b/curvefs/src/metaserver/dentry_storage.cpp index ff4cc11da3..3023bbc9e9 100644 --- a/curvefs/src/metaserver/dentry_storage.cpp +++ b/curvefs/src/metaserver/dentry_storage.cpp @@ -39,7 +39,7 @@ namespace curvefs { namespace metaserver { namespace storage { - DECLARE_int32(rocksdb_tx_lock_ttl_ms); + DECLARE_int32(tx_lock_ttl_ms); } using ::curve::common::ReadLockGuard; @@ -51,7 +51,7 @@ using ::curvefs::metaserver::storage::Prefix4SameParentDentry; using ::curvefs::metaserver::storage::Prefix4TxWrite; using ::curvefs::metaserver::storage::Key4TxWrite; using ::curvefs::metaserver::storage::Status; -using ::curvefs::metaserver::storage::FLAGS_rocksdb_tx_lock_ttl_ms; +using ::curvefs::metaserver::storage::FLAGS_tx_lock_ttl_ms; const char* DentryStorage::kDentryAppliedKey("dentry"); const char* DentryStorage::kDentryCountKey("count"); @@ -427,7 +427,7 @@ MetaStatusCode DentryStorage::Find(storage::StorageTransaction* txn, return rc; } -#define OnError(msg) \ +#define ON_ERROR(msg) \ do \ { \ LOG(ERROR) << msg; \ @@ -437,13 +437,13 @@ MetaStatusCode DentryStorage::Find(storage::StorageTransaction* txn, return rc; \ } while (false) -#define OnCommit() \ +#define ON_COMMIT() \ do \ { \ s = txn->Commit(); \ if (!s.ok()) { \ rc = MetaStatusCode::STORAGE_INTERNAL_ERROR; \ - OnError("Commit transaction failed, " + s.ToString()); \ + ON_ERROR("Commit transaction failed, " + s.ToString()); \ } \ nDentry_ = count; \ return rc; \ @@ -458,12 +458,12 @@ MetaStatusCode DentryStorage::Get(Dentry* dentry, TxLock* txLock) { std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } DentryVec vec; rc = Find(txn.get(), *dentry, dentry, &vec, nullptr, txLock); - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::List(const Dentry& dentry, @@ -547,19 +547,19 @@ MetaStatusCode DentryStorage::Insert( std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } // 1. set applied index s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to transaction"); + ON_ERROR("Insert applied index to transaction"); } // find dentry Dentry out; DentryVec vec; rc = Find(txn.get(), dentry, &out, &vec, &count, txLock); if (rc == MetaStatusCode::TX_KEY_LOCKED) { - OnCommit(); + ON_COMMIT(); } if (rc == MetaStatusCode::OK) { if (BelongSomeOne(out, dentry)) { @@ -567,24 +567,24 @@ MetaStatusCode DentryStorage::Insert( } else { rc = MetaStatusCode::DENTRY_EXIST; } - OnCommit(); + ON_COMMIT(); } else if (rc != MetaStatusCode::NOT_FOUND) { - OnError("Find dentry failed"); + ON_ERROR("Find dentry failed"); } // rc == MetaStatusCode::NOT_FOUND DentryVector vector(&vec); vector.Insert(dentry); s = txn->SSet(table4Dentry_, DentryKey(dentry), vec); if (!s.ok()) { - OnError("Insert dentry to transaction"); + ON_ERROR("Insert dentry to transaction"); } vector.Confirm(&count); s = SetDentryCount(txn.get(), count); if (!s.ok()) { - OnError("Insert dentry count to transaction"); + ON_ERROR("Insert dentry count to transaction"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::Insert(const DentryVec& vec, bool merge, @@ -596,7 +596,7 @@ MetaStatusCode DentryStorage::Insert(const DentryVec& vec, bool merge, std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } DentryVec oldVec; @@ -606,26 +606,26 @@ MetaStatusCode DentryStorage::Insert(const DentryVec& vec, bool merge, if (s.IsNotFound()) { // do nothing } else if (!s.ok()) { - OnError("Find old version from transaction"); + ON_ERROR("Find old version from transaction"); } } DentryVector vector(&oldVec); vector.Merge(vec); s = txn->SSet(table4Dentry_, skey, oldVec); if (!s.ok()) { - OnError("Insert dentry vector to tranasction"); + ON_ERROR("Insert dentry vector to tranasction"); } s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to tranasction"); + ON_ERROR("Insert applied index to tranasction"); } vector.Confirm(&count); s = SetDentryCount(txn.get(), count); if (!s.ok()) { - OnError("Insert dentry count to transaction"); + ON_ERROR("Insert dentry count to transaction"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::Delete( @@ -637,22 +637,22 @@ MetaStatusCode DentryStorage::Delete( std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to transaction"); + ON_ERROR("Insert applied index to transaction"); } Dentry out; DentryVec vec; rc = Find(txn.get(), dentry, &out, &vec, &count, txLock); if (rc == MetaStatusCode::TX_KEY_LOCKED) { - OnCommit(); + ON_COMMIT(); } if (rc == MetaStatusCode::NOT_FOUND) { - OnCommit(); + ON_COMMIT(); } else if (rc != MetaStatusCode::OK) { - OnError("Find dentry failed"); + ON_ERROR("Find dentry failed"); } // OK DentryVector vector(&vec); @@ -664,7 +664,7 @@ MetaStatusCode DentryStorage::Delete( s = txn->SSet(table4Dentry_, skey, vec); } if (!s.ok()) { - OnError("Delete dentry vector from transaction"); + ON_ERROR("Delete dentry vector from transaction"); } // NOTE: we should use count variable instead of nDentry_ // (it means that we should not reset count to nDentry_) @@ -672,10 +672,10 @@ MetaStatusCode DentryStorage::Delete( vector.Confirm(&count); s = SetDentryCount(txn.get(), count); if (!s.ok()) { - OnError("Insert dentry count to transaction"); + ON_ERROR("Insert dentry count to transaction"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::PrepareTx( @@ -688,7 +688,7 @@ MetaStatusCode DentryStorage::PrepareTx( std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } for (const auto& dentry : dentrys) { DentryVec vec; @@ -696,26 +696,26 @@ MetaStatusCode DentryStorage::PrepareTx( std::string skey = DentryKey(dentry); s = txn->SGet(table4Dentry_, skey, &vec); if (!s.ok() && !s.IsNotFound()) { - OnError("Get dentry from transaction"); + ON_ERROR("Get dentry from transaction"); } // OK || NOT_FOUND vector.Insert(dentry); s = txn->SSet(table4Dentry_, skey, vec); if (!s.ok()) { - OnError("Insert dentry to transaction"); + ON_ERROR("Insert dentry to transaction"); } vector.Confirm(&count); } s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to transaction"); + ON_ERROR("Insert applied index to transaction"); } s = SetPendingTx(txn.get(), txRequest); if (!s.ok()) { - OnError("Insert tx request to transaction"); + ON_ERROR("Insert tx request to transaction"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::CommitTx(const std::vector& dentrys, @@ -739,26 +739,26 @@ MetaStatusCode DentryStorage::CommitTx(const std::vector& dentrys, std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } for (const auto& dentry : dentrys) { Dentry out; DentryVec vec; rc = Find(txn.get(), dentry, &out, &vec, &count, nullptr); if (rc != MetaStatusCode::OK && rc != MetaStatusCode::NOT_FOUND) { - OnError("Find dentry from transaction"); + ON_ERROR("Find dentry from transaction"); } } s = SetHandleTxIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert handle tx index to transaction"); + ON_ERROR("Insert handle tx index to transaction"); } s = ClearPendingTx(txn.get()); if (!s.ok()) { - OnError("Delete pending tx from transaction"); + ON_ERROR("Delete pending tx from transaction"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::RollbackTx(const std::vector& dentrys, @@ -782,7 +782,7 @@ MetaStatusCode DentryStorage::RollbackTx(const std::vector& dentrys, std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } for (const auto& dentry : dentrys) { DentryVec vec; @@ -790,7 +790,7 @@ MetaStatusCode DentryStorage::RollbackTx(const std::vector& dentrys, std::string skey = DentryKey(dentry); s = txn->SGet(table4Dentry_, skey, &vec); if (!s.ok() && !s.IsNotFound()) { - OnError("Get dentry from transaction"); + ON_ERROR("Get dentry from transaction"); } // OK || NOT_FOUND vector.Delete(dentry); @@ -800,24 +800,24 @@ MetaStatusCode DentryStorage::RollbackTx(const std::vector& dentrys, s = txn->SSet(table4Dentry_, skey, vec); } if (!s.ok()) { - OnError("Delete dentry from transaction"); + ON_ERROR("Delete dentry from transaction"); } vector.Confirm(&count); } s = SetDentryCount(txn.get(), count); if (!s.ok()) { - OnError("Insert dentry count to transaction"); + ON_ERROR("Insert dentry count to transaction"); } s = SetHandleTxIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert handle tx index to transaction"); + ON_ERROR("Insert handle tx index to transaction"); } s = ClearPendingTx(txn.get()); if (!s.ok()) { - OnError("Delete pending tx from transaction"); + ON_ERROR("Delete pending tx from transaction"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } std::shared_ptr DentryStorage::GetAll() { @@ -1046,7 +1046,7 @@ storage::Status DentryStorage::DelTxLock( MetaStatusCode DentryStorage::WriteTx(storage::StorageTransaction* txn, const Dentry& dentry, TxLock txLock, uint64_t* count) { // 1. set tx lock - txLock.set_ttl(FLAGS_rocksdb_tx_lock_ttl_ms); + txLock.set_ttl(FLAGS_tx_lock_ttl_ms); Status s = SetTxLock(txn, DentryKey(dentry), txLock); if (!s.ok()) { return MetaStatusCode::STORAGE_INTERNAL_ERROR; @@ -1083,23 +1083,23 @@ MetaStatusCode DentryStorage::PrewriteTx(const std::vector& dentrys, std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } // 1. set applied index s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to transaction failed"); + ON_ERROR("Insert applied index to transaction failed"); } for (int i = 0; i < dentrys.size(); i++) { // 2. check write confict uint64_t commitTs = 0; if (MetaStatusCode::OK != GetLastTxWriteTs(txn.get(), dentrys[i], &commitTs)) { - OnError("Get last tx write ts failed"); + ON_ERROR("Get last tx write ts failed"); } if (commitTs >= txLock.startts()) { rc = MetaStatusCode::TX_WRITE_CONFLICT; - OnError("Tx write conflict"); + ON_ERROR("Tx write conflict"); } // 3. check tx lock s = GetTxLock(txn.get(), DentryKey(dentrys[i]), out); @@ -1109,18 +1109,18 @@ MetaStatusCode DentryStorage::PrewriteTx(const std::vector& dentrys, } out->set_index(i); rc = MetaStatusCode::TX_KEY_LOCKED; - OnCommit(); + ON_COMMIT(); } else if (!s.IsNotFound()) { - OnError("Get tx lock failed"); + ON_ERROR("Get tx lock failed"); } // 4. write tx if (WriteTx(txn.get(), dentrys[i], txLock, &count) != MetaStatusCode::OK) { - OnError("Write tx failed"); + ON_ERROR("Write tx failed"); } } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::CheckTxStatus(const std::string& primaryKey, @@ -1132,12 +1132,12 @@ MetaStatusCode DentryStorage::CheckTxStatus(const std::string& primaryKey, std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } // 1. set applied index s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to transaction failed"); + ON_ERROR("Insert applied index to transaction failed"); } // 2. check tx lock TxLock txLock; @@ -1146,20 +1146,20 @@ MetaStatusCode DentryStorage::CheckTxStatus(const std::string& primaryKey, // inprogress or timeout if (curTimestamp > txLock.timestamp() + txLock.ttl()) { rc = MetaStatusCode::TX_TIMEOUT; - OnCommit(); + ON_COMMIT(); } else { rc = MetaStatusCode::TX_INPROGRESS; - OnCommit(); + ON_COMMIT(); } } else if (s.IsNotFound()) { // committed or rollbacked rc = CheckTxStatus(txn.get(), primaryKey, startTs); - OnCommit(); + ON_COMMIT(); } else { - OnError("Get tx lock failed"); + ON_ERROR("Get tx lock failed"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::ResolveTxLock(const Dentry& dentry, @@ -1171,45 +1171,45 @@ MetaStatusCode DentryStorage::ResolveTxLock(const Dentry& dentry, std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } // 1. set applied index s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to transaction failed"); + ON_ERROR("Insert applied index to transaction failed"); } TxLock outLock; s = GetTxLock(txn.get(), DentryKey(dentry), &outLock); if (s.IsNotFound()) { rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } else if (!s.ok()) { - OnError("Get tx lock failed"); + ON_ERROR("Get tx lock failed"); } if (outLock.startts() != startTs) { rc = MetaStatusCode::TX_MISMATCH; - OnError("tx lock mismatch"); + ON_ERROR("tx lock mismatch"); } // roll forward if (commitTs > 0) { if (!DelTxLock(txn.get(), DentryKey(dentry)).ok()) { - OnError("Delete tx lock failed"); + ON_ERROR("Delete tx lock failed"); } TxWrite txWrite; txWrite.set_startts(startTs); txWrite.set_kind(TxWriteKind::Commit); if (!SetTxWrite(txn.get(), TxWriteKey(dentry, commitTs), txWrite).ok()) { - OnError("Set tx write failed"); + ON_ERROR("Set tx write failed"); } // update latest commit if (!SetLatestCommit(txn.get(), commitTs).ok()) { - OnError("update latest commit failed"); + ON_ERROR("update latest commit failed"); } } else { // 1. delete tx lock if (!DelTxLock(txn.get(), DentryKey(dentry)).ok()) { - OnError("Delete tx lock failed"); + ON_ERROR("Delete tx lock failed"); } // 2. delete tx data with startTs DentryVec vec; @@ -1217,7 +1217,7 @@ MetaStatusCode DentryStorage::ResolveTxLock(const Dentry& dentry, std::string skey = DentryKey(dentry); s = txn->SGet(table4Dentry_, skey, &vec); if (!s.ok() && !s.IsNotFound()) { - OnError("Get dentry from transaction failed"); + ON_ERROR("Get dentry from transaction failed"); } // OK || NOT_FOUND Dentry preDentry(dentry); @@ -1229,7 +1229,7 @@ MetaStatusCode DentryStorage::ResolveTxLock(const Dentry& dentry, s = txn->SSet(table4Dentry_, skey, vec); } if (!s.ok()) { - OnError("Delete dentry from transaction failed"); + ON_ERROR("Delete dentry from transaction failed"); } vector.Confirm(&count); // 3. set tx write @@ -1238,11 +1238,11 @@ MetaStatusCode DentryStorage::ResolveTxLock(const Dentry& dentry, txWrite.set_kind(TxWriteKind::Rollback); if (!SetTxWrite( txn.get(), TxWriteKey(dentry, startTs), txWrite).ok()) { - OnError("Set tx write failed"); + ON_ERROR("Set tx write failed"); } } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } MetaStatusCode DentryStorage::CommitTx(const std::vector& dentrys, @@ -1254,25 +1254,31 @@ MetaStatusCode DentryStorage::CommitTx(const std::vector& dentrys, std::shared_ptr txn; txn = kvStorage_->BeginTransaction(); if (txn == nullptr) { - OnError("Begin transaction failed"); + ON_ERROR("Begin transaction failed"); } // 1. set applied index s = SetAppliedIndex(txn.get(), logIndex); if (!s.ok()) { - OnError("Insert applied index to transaction failed"); + ON_ERROR("Insert applied index to transaction failed"); } for (const auto& dentry : dentrys) { // check tx lock TxLock txLock; s = GetTxLock(txn.get(), DentryKey(dentry), &txLock); if (s.IsNotFound()) { - continue; + // commited or rollbacked + rc = CheckTxStatus(txn.get(), DentryKey(dentry), startTs); + if (rc == MetaStatusCode::TX_COMMITTED) { + continue; + } else { + ON_ERROR("tx have been rollbacked when commit"); + } } else if (!s.ok()) { - OnError("Get tx lock failed"); + ON_ERROR("Get tx lock failed"); } if (txLock.startts() != startTs) { rc = MetaStatusCode::TX_MISMATCH; - OnError("tx lock mismatch"); + ON_ERROR("tx lock mismatch"); } // set tx write TxWrite txWrite; @@ -1280,19 +1286,19 @@ MetaStatusCode DentryStorage::CommitTx(const std::vector& dentrys, txWrite.set_kind(TxWriteKind::Commit); if (!SetTxWrite( txn.get(), TxWriteKey(dentry, commitTs), txWrite).ok()) { - OnError("Set tx write failed"); + ON_ERROR("Set tx write failed"); } // delete tx lock if (!DelTxLock(txn.get(), DentryKey(dentry)).ok()) { - OnError("Delete tx lock failed"); + ON_ERROR("Delete tx lock failed"); } } // update latest commit if (!SetLatestCommit(txn.get(), startTs).ok()) { - OnError("update latest commit failed"); + ON_ERROR("update latest commit failed"); } rc = MetaStatusCode::OK; - OnCommit(); + ON_COMMIT(); } } // namespace metaserver diff --git a/curvefs/src/metaserver/storage/rocksdb_options.cpp b/curvefs/src/metaserver/storage/rocksdb_options.cpp index fff9702b1a..50631cd75c 100644 --- a/curvefs/src/metaserver/storage/rocksdb_options.cpp +++ b/curvefs/src/metaserver/storage/rocksdb_options.cpp @@ -114,7 +114,7 @@ DEFINE_int32(rocksdb_stats_dump_period_sec, 180, "Dump rocksdb.stats to LOG every stats_dump_period_sec"); -DEFINE_int32(rocksdb_tx_lock_ttl_ms, +DEFINE_int32(tx_lock_ttl_ms, 5000, "tx lock timeout after ttl ms"); @@ -296,9 +296,9 @@ void ParseRocksdbOptions(curve::common::Configuration* conf) { dummy.Load(conf, "rocksdb_stats_dump_period_sec", "storage.rocksdb.stats_dump_period_sec", &FLAGS_rocksdb_stats_dump_period_sec, /*fatalIfMissing*/ false); - dummy.Load(conf, "rocksdb_tx_lock_ttl_ms", - "storage.rocksdb.tx_lock_ttl_ms", - &FLAGS_rocksdb_tx_lock_ttl_ms, /*fatalIfMissing*/ false); + dummy.Load(conf, "tx_lock_ttl_ms", + "storage.tx_lock_ttl_ms", + &FLAGS_tx_lock_ttl_ms, /*fatalIfMissing*/ false); } } // namespace storage diff --git a/curvefs/test/client/client_operator_test.cpp b/curvefs/test/client/client_operator_test.cpp index 80f3c826d8..846d9b6621 100644 --- a/curvefs/test/client/client_operator_test.cpp +++ b/curvefs/test/client/client_operator_test.cpp @@ -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/rpcclient/mds_client_test.cpp b/curvefs/test/client/rpcclient/mds_client_test.cpp index 9778c10780..0ec3644845 100644 --- a/curvefs/test/client/rpcclient/mds_client_test.cpp +++ b/curvefs/test/client/rpcclient/mds_client_test.cpp @@ -1043,20 +1043,21 @@ TEST_F(MdsClientImplTest, test_AllocOrGetMemcacheCluster) { } TEST_F(MdsClientImplTest, Tso) { + uint32_t fsId = 1; curvefs::mds::TsoResponse response; // CASE 1: Tso success response.set_statuscode(FSStatusCode::OK); - response.set_sn(1); + response.set_ts(1); response.set_timestamp(100); EXPECT_CALL(mockmdsbasecli_, Tso(_, _, _, _)) .WillOnce(SetArgPointee<1>(response)); - uint64_t sn; + uint64_t ts; uint64_t timestamp; - auto rc = mdsclient_.Tso(&sn, ×tamp); + auto rc = mdsclient_.Tso(fsId, &ts, ×tamp); ASSERT_EQ(rc, FSStatusCode::OK); - ASSERT_EQ(sn, 1); + ASSERT_EQ(ts, 1); ASSERT_EQ(timestamp, 100); // CASE 2: Tso fail @@ -1064,7 +1065,7 @@ TEST_F(MdsClientImplTest, Tso) { EXPECT_CALL(mockmdsbasecli_, Tso(_, _, _, _)) .WillOnce(SetArgPointee<1>(response)); - rc = mdsclient_.Tso(&sn, ×tamp); + rc = mdsclient_.Tso(fsId, &ts, ×tamp); ASSERT_EQ(rc, FSStatusCode::UNKNOWN_ERROR); // CASE 3: RPC error, retry until success @@ -1083,7 +1084,7 @@ TEST_F(MdsClientImplTest, Tso) { } })); - rc = mdsclient_.Tso(&sn, ×tamp); + rc = mdsclient_.Tso(fsId, &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 0e6290b821..f1d5161d09 100644 --- a/curvefs/test/client/rpcclient/mock_mds_client.h +++ b/curvefs/test/client/rpcclient/mock_mds_client.h @@ -133,7 +133,8 @@ class MockMdsClient : public MdsClient { MOCK_METHOD2(AllocOrGetMemcacheCluster, bool(uint32_t, curvefs::mds::topology::MemcacheClusterInfo*)); - MOCK_METHOD(FSStatusCode, Tso, (uint64_t*, uint64_t*), (override)); + MOCK_METHOD(FSStatusCode, Tso, (uint32_t, uint64_t*, uint64_t*), + (override)); }; } // namespace rpcclient } // namespace client diff --git a/curvefs/test/client/test_dentry_cache_manager.cpp b/curvefs/test/client/test_dentry_cache_manager.cpp index 8b24f547ba..f1b52dccea 100644 --- a/curvefs/test/client/test_dentry_cache_manager.cpp +++ b/curvefs/test/client/test_dentry_cache_manager.cpp @@ -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/mds/fs_manager_test.cpp b/curvefs/test/mds/fs_manager_test.cpp index 483e1796f2..af5d78d80d 100644 --- a/curvefs/test/mds/fs_manager_test.cpp +++ b/curvefs/test/mds/fs_manager_test.cpp @@ -1032,26 +1032,5 @@ TEST_F(FSManagerTest, test_success_get_latest_txid_with_fsid) { ASSERT_EQ(response.txids_size(), 1); } -TEST_F(FSManagerTest, test_tso) { - // Tso success - TsoRequest request; - TsoResponse response; - response.set_sn(1); - response.set_timestamp(100); - EXPECT_CALL(*topoManager_, Tso(_, _)). - WillOnce(DoAll(SetArgPointee<1>(response), - Return(true))); - fsManager_->Tso(&request, &response); - ASSERT_EQ(response.statuscode(), FSStatusCode::OK); - ASSERT_EQ(response.sn(), 1); - ASSERT_EQ(response.timestamp(), 100); - - // Tso failed - EXPECT_CALL(*topoManager_, Tso(_, _)). - WillOnce(Return(false)); - fsManager_->Tso(&request, &response); - ASSERT_EQ(response.statuscode(), FSStatusCode::INTERNAL_ERROR); -} - } // namespace mds } // namespace curvefs diff --git a/curvefs/test/mds/fs_manager_test2.cpp b/curvefs/test/mds/fs_manager_test2.cpp index 08c6c40d10..61968b4f1d 100644 --- a/curvefs/test/mds/fs_manager_test2.cpp +++ b/curvefs/test/mds/fs_manager_test2.cpp @@ -436,5 +436,26 @@ TEST_F(FsManagerTest2, checkFsName) { EXPECT_FALSE(FsManager::CheckFsName("curve-test--01")); } +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), + Return(FSStatusCode::OK))); + fsManager_->Tso(&request, &response); + ASSERT_EQ(response.statuscode(), FSStatusCode::OK); + ASSERT_EQ(response.ts(), 1); + ASSERT_EQ(response.timestamp(), 100); + + // Tso failed + EXPECT_CALL(*storage_, Tso(1, _, _)). + WillOnce(Return(FSStatusCode::INTERNAL_ERROR)); + fsManager_->Tso(&request, &response); + ASSERT_EQ(response.statuscode(), FSStatusCode::INTERNAL_ERROR); +} + } // namespace mds } // namespace curvefs diff --git a/curvefs/test/mds/fs_storage_test.cpp b/curvefs/test/mds/fs_storage_test.cpp index c2d56b4618..559dfe4a08 100644 --- a/curvefs/test/mds/fs_storage_test.cpp +++ b/curvefs/test/mds/fs_storage_test.cpp @@ -23,6 +23,7 @@ #include #include #include +#include "curvefs/test/mds/mock/mock_kvstorage_client.h" using ::testing::AtLeast; using ::testing::StrEq; @@ -115,6 +116,15 @@ TEST_F(FSStorageTest, test1) { ASSERT_EQ(FSStatusCode::NOT_FOUND, storage.Delete(fs1.GetFsName())); ASSERT_EQ(FSStatusCode::OK, storage.Delete(fs5.GetFsName())); ASSERT_EQ(FSStatusCode::NOT_FOUND, storage.Delete(fs5.GetFsName())); + + // test tso + uint64_t ts; + uint64_t timestamp; + for (int i = 1; i < 5; i++) { + ASSERT_EQ(FSStatusCode::OK, storage.Tso(fsId, &ts, ×tamp)); + ASSERT_EQ(ts, i); + } } + } // namespace mds } // namespace curvefs diff --git a/curvefs/test/mds/mds_service_test.cpp b/curvefs/test/mds/mds_service_test.cpp index 829d71cc2f..d9dfe3cbc2 100644 --- a/curvefs/test/mds/mds_service_test.cpp +++ b/curvefs/test/mds/mds_service_test.cpp @@ -953,35 +953,19 @@ TEST_F(MdsServiceTest, test_update_fsinfo_parameter_error) { } TEST_F(MdsServiceTest, test_tso) { - // 1. tso ok TsoRequest tsoRequest; + tsoRequest.set_fsid(1); TsoResponse tsoResponse; - tsoResponse.set_sn(1); - tsoResponse.set_timestamp(100); - EXPECT_CALL(*topoManager_, Tso(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(tsoResponse), - Return(true))); - cntl.Reset(); - stub_->Tso(&cntl, &tsoRequest, &tsoResponse, nullptr); - if (!cntl.Failed()) { - ASSERT_EQ(tsoResponse.statuscode(), FSStatusCode::OK); - ASSERT_EQ(tsoResponse.sn(), 1); - ASSERT_EQ(tsoResponse.timestamp(), 100); - } else { - LOG(ERROR) << "error = " << cntl.ErrorText(); - ASSERT_TRUE(false); - } - // 2. tso fail - cntl.Reset(); - EXPECT_CALL(*topoManager_, Tso(_, _)) - .WillOnce(Return(false)); - stub_->Tso(&cntl, &tsoRequest, &tsoResponse, nullptr); - if (!cntl.Failed()) { - ASSERT_EQ(tsoResponse.statuscode(), FSStatusCode::INTERNAL_ERROR); - } else { - LOG(ERROR) << "error = " << cntl.ErrorText(); - ASSERT_TRUE(false); + for (int i = 1; i < 5; i++) { + cntl.Reset(); + stub_->Tso(&cntl, &tsoRequest, &tsoResponse, nullptr); + if (!cntl.Failed()) { + ASSERT_EQ(tsoResponse.statuscode(), FSStatusCode::OK); + ASSERT_EQ(tsoResponse.ts(), i); + } else { + LOG(ERROR) << "error = " << cntl.ErrorText(); + ASSERT_TRUE(false); + } } } diff --git a/curvefs/test/mds/metaserver_balance_poc.cpp b/curvefs/test/mds/metaserver_balance_poc.cpp index 6189927604..1685ead719 100644 --- a/curvefs/test/mds/metaserver_balance_poc.cpp +++ b/curvefs/test/mds/metaserver_balance_poc.cpp @@ -110,7 +110,6 @@ class MetaserverBalancePOC : public ::testing::Test { EXPECT_CALL(*storage_, LoadClusterInfo(_)).WillRepeatedly(Return(true)); EXPECT_CALL(*storage_, StorageClusterInfo(_)) .WillRepeatedly(Return(true)); - EXPECT_CALL(*storage_, LoadTsInfo(_)).WillRepeatedly(Return(true)); EXPECT_CALL(*storage_, LoadPool(_, _)).WillRepeatedly(Return(true)); EXPECT_CALL(*storage_, LoadZone(_, _)).WillRepeatedly(Return(true)); EXPECT_CALL(*storage_, LoadServer(_, _)).WillRepeatedly(Return(true)); diff --git a/curvefs/test/mds/mock/mock_fs_stroage.h b/curvefs/test/mds/mock/mock_fs_stroage.h index c3d08e4ea9..6d314540dd 100644 --- a/curvefs/test/mds/mock/mock_fs_stroage.h +++ b/curvefs/test/mds/mock/mock_fs_stroage.h @@ -61,6 +61,8 @@ 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*), + (override)); }; } // namespace mds diff --git a/curvefs/test/mds/mock/mock_topology.h b/curvefs/test/mds/mock/mock_topology.h index 1a4ebc042b..7a4eb18d64 100644 --- a/curvefs/test/mds/mock/mock_topology.h +++ b/curvefs/test/mds/mock/mock_topology.h @@ -182,8 +182,6 @@ class MockStorage : public TopologyStorage { bool(FsIdType, MemcacheClusterIdType)); MOCK_METHOD1(LoadFs2MemcacheCluster, bool(std::unordered_map*)); - MOCK_METHOD(bool, LoadTsInfo, (TsInfo* info), (override)); - MOCK_METHOD(bool, StorageTsInfo, (const TsInfo& info), (override)); }; class MockEtcdClient : public EtcdClientImp { @@ -456,9 +454,6 @@ class MockTopologyManager : public TopologyManager { RegistMemcacheClusterResponse*)); MOCK_METHOD1(ListMemcacheCluster, void(ListMemcacheClusterResponse*)); - - MOCK_METHOD(bool, Tso, (const TsoRequest* request, TsoResponse* response), - (override)); }; } // namespace topology diff --git a/curvefs/test/mds/persist_kvstorage_test.cpp b/curvefs/test/mds/persist_kvstorage_test.cpp index c5d25b0760..c025ae9820 100644 --- a/curvefs/test/mds/persist_kvstorage_test.cpp +++ b/curvefs/test/mds/persist_kvstorage_test.cpp @@ -122,6 +122,20 @@ class PersistKVStorageTest : public ::testing::Test { std::shared_ptr storageCli_; }; +#define DO_INIT(storage, storageCli_) \ + 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))); \ + EXPECT_CALL(*storageCli_, Get(_, _)) \ + .WillRepeatedly(Return(EtcdErrCode::EtcdOK)); \ + } while (false) + TEST_F(PersistKVStorageTest, TestInit) { // list from storage failed { @@ -152,14 +166,7 @@ TEST_F(PersistKVStorageTest, TestInit) { { PersisKVStorage storage(storageCli_); - - std::vector> encoded = - PrepareFsInfoSamples(); - - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); - + DO_INIT(storage, storageCli_); EXPECT_TRUE(storage.Init()); EXPECT_TRUE(storage.Exist(1)); @@ -181,10 +188,15 @@ 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))); + DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))) + .WillOnce( + DoAll(SetArgPointee<2>(loadTs), Return(EtcdErrCode::EtcdOK))); + EXPECT_CALL(*storageCli_, Get(_, _)) + .WillRepeatedly(Return(EtcdErrCode::EtcdOK)); EXPECT_TRUE(storage.Init()); EXPECT_FALSE(storage.Exist(1)); @@ -197,14 +209,9 @@ TEST_F(PersistKVStorageTest, TestGetAndExist) { { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); - - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); - + DO_INIT(storage, storageCli_); EXPECT_TRUE(storage.Init()); + EXPECT_TRUE(storage.Exist(1)); EXPECT_TRUE(storage.Exist("hello")); EXPECT_TRUE(storage.Exist(2)); @@ -290,17 +297,12 @@ TEST_F(PersistKVStorageTest, TestInsert) { // fs already exists { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Put(_, _)) .Times(0); - EXPECT_TRUE(storage.Init()); - FsInfoWrapper wrapper; EXPECT_EQ(FSStatusCode::OK, storage.Get("hello", &wrapper)); @@ -310,18 +312,13 @@ TEST_F(PersistKVStorageTest, TestInsert) { // kvstorage error { - PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + PersisKVStorage storage(storageCli_); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Put(_, _)) .WillOnce(Return(EtcdErrCode::EtcdInternal)); - EXPECT_TRUE(storage.Init()); - FsInfoWrapper wrapper; EXPECT_EQ(FSStatusCode::OK, storage.Get("hello", &wrapper)); @@ -337,17 +334,12 @@ TEST_F(PersistKVStorageTest, TestInsert) { // kvstorage persist ok { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Put(_, _)) .WillOnce(Return(EtcdErrCode::EtcdOK)); - EXPECT_TRUE(storage.Init()); - FsInfoWrapper wrapper; EXPECT_EQ(FSStatusCode::OK, storage.Get("hello", &wrapper)); @@ -370,17 +362,12 @@ TEST_F(PersistKVStorageTest, TestUpdate) { // fs not found { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Put(_, _)) .Times(0); - EXPECT_TRUE(storage.Init()); - FsInfoWrapper wrapper; EXPECT_EQ(FSStatusCode::OK, storage.Get("hello", &wrapper)); @@ -395,17 +382,12 @@ TEST_F(PersistKVStorageTest, TestUpdate) { // fs id mismatch { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Put(_, _)) .Times(0); - EXPECT_TRUE(storage.Init()); - FsInfoWrapper wrapper; EXPECT_EQ(FSStatusCode::OK, storage.Get("hello", &wrapper)); @@ -420,17 +402,12 @@ TEST_F(PersistKVStorageTest, TestUpdate) { // storage failed { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Put(_, _)) .WillOnce(Return(EtcdErrCode::EtcdInternal)); - EXPECT_TRUE(storage.Init()); - FsInfoWrapper wrapper; EXPECT_EQ(FSStatusCode::OK, storage.Get("hello", &wrapper)); @@ -449,17 +426,12 @@ TEST_F(PersistKVStorageTest, TestUpdate) { // storage ok { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Put(_, _)) .WillOnce(Return(EtcdErrCode::EtcdOK)); - EXPECT_TRUE(storage.Init()); - FsInfoWrapper wrapper; EXPECT_EQ(FSStatusCode::OK, storage.Get("hello", &wrapper)); @@ -480,34 +452,22 @@ TEST_F(PersistKVStorageTest, TestDelete) { // fs not found { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Delete(_)) .Times(0); - - EXPECT_TRUE(storage.Init()); - EXPECT_EQ(FSStatusCode::NOT_FOUND, storage.Delete("bvar")); } // storage failed { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Delete(_)) .WillOnce(Return(EtcdErrCode::EtcdInternal)); - - EXPECT_TRUE(storage.Init()); - EXPECT_EQ(FSStatusCode::STORAGE_ERROR, storage.Delete("hello")); EXPECT_TRUE(storage.Exist("hello")); EXPECT_TRUE(storage.Exist(1)); @@ -516,17 +476,11 @@ TEST_F(PersistKVStorageTest, TestDelete) { // storage ok { PersisKVStorage storage(storageCli_); - std::vector> encoded = - PrepareFsInfoSamples(); + DO_INIT(storage, storageCli_); + EXPECT_TRUE(storage.Init()); - EXPECT_CALL(*storageCli_, List(_, _, Matcher(_))) - .WillOnce( - DoAll(SetArgPointee<2>(encoded), Return(EtcdErrCode::EtcdOK))); EXPECT_CALL(*storageCli_, Delete(_)) .WillOnce(Return(EtcdErrCode::EtcdOK)); - - EXPECT_TRUE(storage.Init()); - EXPECT_EQ(FSStatusCode::OK, storage.Delete("hello")); EXPECT_FALSE(storage.Exist("hello")); EXPECT_FALSE(storage.Exist(1)); @@ -535,5 +489,27 @@ TEST_F(PersistKVStorageTest, TestDelete) { EXPECT_TRUE(storage.Exist(2)); } } + +TEST_F(PersistKVStorageTest, TestTso) { + PersisKVStorage storage(storageCli_); + uint32_t fsId = 1; + uint64_t ts; + uint64_t timestamp; + + // store failed + EXPECT_CALL(*storageCli_, Put(_, _)) + .WillOnce(Return(EtcdErrCode::EtcdUnknown)); + ASSERT_EQ(FSStatusCode::INTERNAL_ERROR, + storage.Tso(fsId, &ts, ×tamp)); + + // store success + 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(ts, i); + } +} + } // namespace mds } // namespace curvefs diff --git a/curvefs/test/mds/topology/test_topology.cpp b/curvefs/test/mds/topology/test_topology.cpp index 1536b830c9..f972172b58 100644 --- a/curvefs/test/mds/topology/test_topology.cpp +++ b/curvefs/test/mds/topology/test_topology.cpp @@ -162,10 +162,6 @@ TEST_F(TestTopology, test_init_success) { EXPECT_CALL(*storage_, StorageClusterInfo(_)) .Times(2).WillRepeatedly(Return(true)); - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(true))); - std::unordered_map poolMap_; std::unordered_map zoneMap_; std::unordered_map serverMap_; @@ -241,24 +237,6 @@ TEST_F(TestTopology, test_init_StorageClusterInfoFail) { ASSERT_EQ(TopoStatusCode::TOPO_STORGE_FAIL, ret); } -TEST_F(TestTopology, test_init_loadTsInfoFail) { - std::vector infos; - EXPECT_CALL(*storage_, LoadClusterInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(infos), - Return(true))); - - EXPECT_CALL(*storage_, StorageClusterInfo(_)) - .WillOnce(Return(true)); - - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(false))); - - TopologyOption option; - int ret = topology_->Init(option); - ASSERT_EQ(TopoStatusCode::TOPO_STORGE_FAIL, ret); -} - TEST_F(TestTopology, test_init_loadPoolFail) { std::vector infos; ClusterInformation info("uuid1"); @@ -266,9 +244,6 @@ TEST_F(TestTopology, test_init_loadPoolFail) { EXPECT_CALL(*storage_, LoadClusterInfo(_)) .WillOnce(DoAll(SetArgPointee<0>(infos), Return(true))); - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(true))); EXPECT_CALL(*storage_, LoadPool(_, _)) .WillOnce(Return(false)); @@ -285,9 +260,6 @@ TEST_F(TestTopology, test_init_LoadZoneFail) { EXPECT_CALL(*storage_, LoadClusterInfo(_)) .WillOnce(DoAll(SetArgPointee<0>(infos), Return(true))); - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(true))); EXPECT_CALL(*storage_, LoadPool(_, _)) .WillOnce(Return(true)); @@ -307,9 +279,6 @@ TEST_F(TestTopology, test_init_LoadServerFail) { EXPECT_CALL(*storage_, LoadClusterInfo(_)) .WillOnce(DoAll(SetArgPointee<0>(infos), Return(true))); - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(true))); EXPECT_CALL(*storage_, LoadPool(_, _)) .WillOnce(Return(true)); @@ -333,9 +302,6 @@ TEST_F(TestTopology, test_init_LoadMetaServerFail) { EXPECT_CALL(*storage_, LoadClusterInfo(_)) .WillOnce(DoAll(SetArgPointee<0>(infos), Return(true))); - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(true))); EXPECT_CALL(*storage_, LoadPool(_, _)) .WillOnce(Return(true)); @@ -362,9 +328,6 @@ TEST_F(TestTopology, test_init_LoadCopysetFail) { EXPECT_CALL(*storage_, LoadClusterInfo(_)) .WillOnce(DoAll(SetArgPointee<0>(infos), Return(true))); - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(true))); EXPECT_CALL(*storage_, LoadPool(_, _)) .WillOnce(Return(true)); @@ -394,9 +357,6 @@ TEST_F(TestTopology, test_init_LoadPartitionFail) { EXPECT_CALL(*storage_, LoadClusterInfo(_)) .WillOnce(DoAll(SetArgPointee<0>(infos), Return(true))); - TsInfo tsinfo; - EXPECT_CALL(*storage_, LoadTsInfo(_)) - .WillOnce(DoAll(SetArgPointee<0>(tsinfo), Return(true))); EXPECT_CALL(*storage_, LoadPool(_, _)) .WillOnce(Return(true)); @@ -2413,22 +2373,6 @@ TEST_F(TestTopology, test_AddMemcacheCluster_fail) { ASSERT_EQ(TopoStatusCode::TOPO_STORGE_FAIL, ret); } -TEST_F(TestTopology, test_tso) { - uint64_t sn; - uint64_t timestamp; - // 1. success - for (int i = 1; i < 10; i++) { - EXPECT_CALL(*storage_, StorageTsInfo(_)) - .WillOnce(Return(true)); - ASSERT_TRUE(topology_->Tso(&sn, ×tamp)); - ASSERT_EQ(i, sn); - } - // 2. fail - EXPECT_CALL(*storage_, StorageTsInfo(_)) - .WillOnce(Return(false)); - ASSERT_FALSE(topology_->Tso(&sn, ×tamp)); -} - } // namespace topology } // namespace mds } // namespace curvefs diff --git a/curvefs/test/mds/topology/test_topology_storage_etcd.cpp b/curvefs/test/mds/topology/test_topology_storage_etcd.cpp index 6df87a91d0..e601ab5b2b 100644 --- a/curvefs/test/mds/topology/test_topology_storage_etcd.cpp +++ b/curvefs/test/mds/topology/test_topology_storage_etcd.cpp @@ -1047,61 +1047,6 @@ TEST_F(TestTopologyStorageEtcd, ASSERT_FALSE(ret); } -TEST_F(TestTopologyStorageEtcd, test_LoadTsInfo_success) { - TsInfo data(100); - - std::string value; - ASSERT_TRUE(codec_->EncodeTsData(data, &value)); - - EXPECT_CALL(*kvStorageClient_, Get(_, _)) - .WillOnce(DoAll(SetArgPointee<1>(value), Return(EtcdErrCode::EtcdOK))); - - TsInfo tsInfo; - bool ret = storage_->LoadTsInfo(&tsInfo); - ASSERT_TRUE(ret); - ASSERT_EQ(data.ts, tsInfo.ts); -} - -TEST_F(TestTopologyStorageEtcd, test_LoadTsInfo_success_empty) { - EXPECT_CALL(*kvStorageClient_, Get(_, _)) - .WillOnce(Return(EtcdErrCode::EtcdKeyNotExist)); - - TsInfo tsInfo; - bool ret = storage_->LoadTsInfo(&tsInfo); - ASSERT_TRUE(ret); -} - -TEST_F(TestTopologyStorageEtcd, test_LoadTsInfo_decodeError) { - std::string value; - - EXPECT_CALL(*kvStorageClient_, Get(_, _)) - .WillOnce(DoAll(SetArgPointee<1>(value), Return(EtcdErrCode::EtcdOK))); - - TsInfo tsInfo; - bool ret = storage_->LoadTsInfo(&tsInfo); - ASSERT_FALSE(ret); -} - -TEST_F(TestTopologyStorageEtcd, test_StorageTsInfo_success) { - TsInfo data(100); - - EXPECT_CALL(*kvStorageClient_, Put(_, _)) - .WillOnce(Return(EtcdErrCode::EtcdOK)); - - bool ret = storage_->StorageTsInfo(data); - ASSERT_TRUE(ret); -} - -TEST_F(TestTopologyStorageEtcd, test_StorageTsInfo_fail) { - TsInfo data(100); - - EXPECT_CALL(*kvStorageClient_, Put(_, _)) - .WillOnce(Return(EtcdErrCode::EtcdUnknown)); - - bool ret = storage_->StorageTsInfo(data); - ASSERT_FALSE(ret); -} - } // namespace topology } // namespace mds } // namespace curvefs diff --git a/curvefs/test/mds/topology/topology_storage_codec_test.cpp b/curvefs/test/mds/topology/topology_storage_codec_test.cpp index 8799c127be..6246c18a61 100644 --- a/curvefs/test/mds/topology/topology_storage_codec_test.cpp +++ b/curvefs/test/mds/topology/topology_storage_codec_test.cpp @@ -196,17 +196,6 @@ TEST_F(TopologyStorageCodecTest, TestMemcacheClusterEncodeDecodeEqual) { ASSERT_EQ(data, out); } -TEST_F(TopologyStorageCodecTest, TestTsInfoEncodeDecodeEqual) { - TsInfo data(100); - std::string encodeData; - ASSERT_TRUE(testObj.EncodeTsData(data, &encodeData)); - - TsInfo outData; - ASSERT_TRUE(testObj.DecodeTsData(encodeData, &outData)); - - ASSERT_EQ(data.ts, outData.ts); -} - } // namespace topology } // namespace mds } // namespace curvefs diff --git a/curvefs/test/metaserver/dentry_manager_test.cpp b/curvefs/test/metaserver/dentry_manager_test.cpp index a775b1cd2f..905ef307c1 100644 --- a/curvefs/test/metaserver/dentry_manager_test.cpp +++ b/curvefs/test/metaserver/dentry_manager_test.cpp @@ -36,7 +36,7 @@ namespace curvefs { namespace metaserver { namespace storage { - DECLARE_int32(rocksdb_tx_lock_ttl_ms); + DECLARE_int32(tx_lock_ttl_ms); } using ::curvefs::metaserver::storage::KVStorage; @@ -233,7 +233,7 @@ TEST_F(DentryManagerTest, PrewriteRenameTx) { } TEST_F(DentryManagerTest, CheckTxStatus) { - storage::FLAGS_rocksdb_tx_lock_ttl_ms = 100; + storage::FLAGS_tx_lock_ttl_ms = 100; TxLock txLockIn; TxLock txLockOut; diff --git a/src/common/encode.h b/src/common/encode.h index 0540ee0193..ab28d11321 100644 --- a/src/common/encode.h +++ b/src/common/encode.h @@ -54,6 +54,11 @@ inline void EncodeBigEndian_uint32(char* buf, uint32_t value) { buf[3] = value & 0xff; } +inline uint32_t DecodeBigEndian_uint32(const char* buf) { + return (uint32_t(buf[0]) << 24) | (uint32_t(buf[1]) << 16) | + (uint32_t(buf[2]) << 8) | uint32_t(buf[3]); +} + } // namespace common } // namespace curve