Skip to content

Commit

Permalink
[feat] CurveFS: support braft lease read
Browse files Browse the repository at this point in the history
Signed-off-by: Xinlong Chen <[email protected]>
  • Loading branch information
Xinlong-Chen authored and wu-hanqing committed Jul 18, 2023
1 parent 5e04407 commit 402f237
Show file tree
Hide file tree
Showing 21 changed files with 393 additions and 669 deletions.
5 changes: 5 additions & 0 deletions curvefs/conf/metaserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ metaserver.loglevel=0
# metaserver meta file path, every metaserver need persist MetaServerMetadata on its own disk
metaserver.meta_file_path=./0/metaserver.dat # __CURVEADM_TEMPLATE__ ${prefix}/data/metaserver.dat __CURVEADM_TEMPLATE__

# enable lease read, default value is true
# if value = true: read requests will judge lease.
# if value = false: all requests including read requests will propose to raft.
copyset.enable_lease_read=true

# copyset data uri
# all uri (data_uri/raft_log_uri/raft_meta_uri/raft_snapshot_uri/trash.uri) are ${protocol}://${path}
# e.g., when save data to local disk, protocol is `local`, path can be `absolute path` or `relative path`
Expand Down
46 changes: 6 additions & 40 deletions curvefs/src/client/rpcclient/metacache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ bool MetaCache::RefreshTxId() {
}

bool MetaCache::GetTarget(uint32_t fsID, uint64_t inodeID,
CopysetTarget *target, uint64_t *applyIndex,
bool refresh) {
CopysetTarget *target, bool refresh) {
// get copysetID with inodeID
if (!GetCopysetIDwithInodeID(inodeID, &target->groupID,
&target->partitionID, &target->txId)) {
Expand All @@ -111,11 +110,10 @@ bool MetaCache::GetTarget(uint32_t fsID, uint64_t inodeID,
}

// get target copyset leader with (poolID, copysetID)
return GetTargetLeader(target, applyIndex, refresh);
return GetTargetLeader(target, refresh);
}

bool MetaCache::SelectTarget(uint32_t fsID, CopysetTarget *target,
uint64_t *applyIndex) {
bool MetaCache::SelectTarget(uint32_t fsID, CopysetTarget *target) {
// select a partition
if (!SelectPartition(target)) {
// list from mds
Expand All @@ -133,36 +131,7 @@ bool MetaCache::SelectTarget(uint32_t fsID, CopysetTarget *target,
}

// get target copyset leader with (poolID, copysetID)
return GetTargetLeader(target, applyIndex);
}

void MetaCache::UpdateApplyIndex(const CopysetGroupID &groupID,
uint64_t applyIndex) {
const auto key = CalcLogicPoolCopysetID(groupID);

ReadLockGuard rl(rwlock4copysetInfoMap_);
auto iter = copysetInfoMap_.find(key);
if (iter == copysetInfoMap_.end()) {
LOG(WARNING) << "update apply index for copyset:" << groupID.ToString()
<< " fail, copyset not found.";
return;
}

iter->second.UpdateAppliedIndex(applyIndex);
}

uint64_t MetaCache::GetApplyIndex(const CopysetGroupID &groupID) {
const auto key = CalcLogicPoolCopysetID(groupID);

ReadLockGuard rl(rwlock4copysetInfoMap_);
auto iter = copysetInfoMap_.find(key);
if (iter == copysetInfoMap_.end()) {
LOG(WARNING) << "get apply index for copyset:" << groupID.ToString()
<< " fail, copyset not found.";
return 0;
}

return iter->second.GetAppliedIndex();
return GetTargetLeader(target);
}

bool MetaCache::IsLeaderMayChange(const CopysetGroupID &groupID) {
Expand All @@ -172,7 +141,7 @@ bool MetaCache::IsLeaderMayChange(const CopysetGroupID &groupID) {
ReadLockGuard rl(rwlock4copysetInfoMap_);
auto iter = copysetInfoMap_.find(key);
if (iter == copysetInfoMap_.end()) {
LOG(WARNING) << "get apply index for copyset:" << groupID.ToString()
LOG(WARNING) << "get information for copyset:" << groupID.ToString()
<< " fail, copyset not found.";
return false;
}
Expand All @@ -188,8 +157,7 @@ void MetaCache::UpdateCopysetInfo(const CopysetGroupID &groupID,
copysetInfoMap_[key] = csinfo;
}

bool MetaCache::GetTargetLeader(CopysetTarget *target, uint64_t *applyindex,
bool refresh) {
bool MetaCache::GetTargetLeader(CopysetTarget *target, bool refresh) {
// get copyset with (poolid, copysetid)
CopysetInfo<MetaserverID> copysetInfo;
if (!GetCopysetInfowithCopySetID(target->groupID, &copysetInfo)) {
Expand All @@ -202,7 +170,6 @@ bool MetaCache::GetTargetLeader(CopysetTarget *target, uint64_t *applyindex,
if (!refresh && !copysetInfo.LeaderMayChange()) {
if (0 == copysetInfo.GetLeaderInfo(&target->metaServerID,
&target->endPoint)) {
*applyindex = copysetInfo.GetAppliedIndex();
return true;
}
LOG(WARNING) << "{copyset:" << target->groupID.ToString()
Expand Down Expand Up @@ -242,7 +209,6 @@ bool MetaCache::GetTargetLeader(CopysetTarget *target, uint64_t *applyindex,
return false;
}

*applyindex = copysetInfo.GetAppliedIndex();
return 0 ==
copysetInfo.GetLeaderInfo(&target->metaServerID, &target->endPoint);
}
Expand Down
15 changes: 4 additions & 11 deletions curvefs/src/client/rpcclient/metacache.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,9 @@ class MetaCache {
virtual void GetAllTxIds(std::vector<PartitionTxId> *txIds);

virtual bool GetTarget(uint32_t fsID, uint64_t inodeID,
CopysetTarget *target, uint64_t *applyIndex,
bool refresh = false);
CopysetTarget *target, bool refresh = false);

virtual bool SelectTarget(uint32_t fsID, CopysetTarget *target,
uint64_t *applyIndex);

virtual void UpdateApplyIndex(const CopysetGroupID &groupID,
uint64_t applyIndex);

virtual uint64_t GetApplyIndex(const CopysetGroupID &groupID);
virtual bool SelectTarget(uint32_t fsID, CopysetTarget *target);

virtual bool IsLeaderMayChange(const CopysetGroupID &groupID);

Expand All @@ -149,8 +142,7 @@ class MetaCache {
virtual void UpdateCopysetInfo(const CopysetGroupID &groupID,
const CopysetInfo<MetaserverID> &csinfo);

virtual bool GetTargetLeader(CopysetTarget *target, uint64_t *applyindex,
bool refresh = false);
virtual bool GetTargetLeader(CopysetTarget *target, bool refresh = false);

virtual bool GetPartitionIdByInodeId(uint32_t fsID, uint64_t inodeID,
PartitionID *pid);
Expand Down Expand Up @@ -208,6 +200,7 @@ class MetaCache {
RWLock rwlock4Partitions_;
PartitionInfoList partitionInfos_;
RWLock rwlock4copysetInfoMap_;
// TODO(Xinlong-Chen): delete appliedindex from CopysetInfo
CopysetInfoMap copysetInfoMap_;

Mutex createMutex_;
Expand Down
Loading

0 comments on commit 402f237

Please sign in to comment.