Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] CurveFS: support braft lease read #2599

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this problem be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CopysetInfo is defined in metacache_struct.h in curvebs. If I change this struct, it will cause some ci problems, so I will fix it when prs merge. It's not difficult to do it.

#include "src/client/metacache_struct.h"

CopysetInfoMap copysetInfoMap_;

Mutex createMutex_;
Expand Down
Loading