Skip to content

Commit

Permalink
[refactor][metaserver] Refact metastore rw lock scope and some log
Browse files Browse the repository at this point in the history
  • Loading branch information
chuandew committed Jan 13, 2025
1 parent 792663e commit 85c893b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/metaserver/copyset/copyset_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void CopysetNode::ListPeers(std::vector<Peer>* peers) const {
// partition info list success.
bool CopysetNode::GetPartitionInfoList(
std::list<pb::common::PartitionInfo>* partitionInfoList) {
uint32_t retryCount = 0;
uint32_t retry_count = 0;
while (true) {
if (IsLoading()) {
LOG(INFO) << "Copyset is loading, return empty partition list";
Expand All @@ -587,8 +587,11 @@ bool CopysetNode::GetPartitionInfoList(
if (ret) {
return true;
}
LOG(WARNING) << "Copyset is not loading, but GetPartitionInfoList fail,"
<< " retryCount = " << retryCount++;
retry_count++;
if (retry_count % 100 == 0) {
LOG(WARNING) << "Copyset is not loading, but GetPartitionInfoList fail,"
<< " retryCount = " << retry_count;
}
}
}

Expand Down
33 changes: 16 additions & 17 deletions src/metaserver/metastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include <vector>

#include "absl/types/optional.h"
#include "dingofs/metaserver.pb.h"
#include "common/define.h"
#include "dingofs/metaserver.pb.h"
#include "metaserver/copyset/copyset_node.h"
#include "metaserver/partition_clean_manager.h"
#include "metaserver/recycle_cleaner.h"
Expand Down Expand Up @@ -219,25 +219,27 @@ void MetaStoreImpl::SaveBackground(const std::string& path,

bool MetaStoreImpl::Save(const std::string& dir,
OnSnapshotSaveDoneClosure* done) {
brpc::ClosureGuard doneGuard(done);
WriteLockGuard writeLockGuard(rwLock_);
brpc::ClosureGuard done_guard(done);
{
WriteLockGuard write_lock_guard(rwLock_);

MetaStoreFStream fstream(&partitionMap_, kvStorage_,
copysetNode_->GetPoolId(),
copysetNode_->GetCopysetId());
MetaStoreFStream fstream(&partitionMap_, kvStorage_,
copysetNode_->GetPoolId(),
copysetNode_->GetCopysetId());

const std::string metadata = dir + "/" + kMetaDataFilename;
bool succ = fstream.Save(metadata);
if (!succ) {
done->SetError(MetaStatusCode::SAVE_META_FAIL);
return false;
const std::string metadata = dir + "/" + kMetaDataFilename;
bool succ = fstream.Save(metadata);
if (!succ) {
done->SetError(MetaStatusCode::SAVE_META_FAIL);
return false;
}
}

// checkpoint storage
butil::Timer timer;
timer.start();
std::vector<std::string> files;
succ = kvStorage_->Checkpoint(dir, &files);
bool succ = kvStorage_->Checkpoint(dir, &files);
if (!succ) {
done->SetError(MetaStatusCode::SAVE_META_FAIL);
return false;
Expand Down Expand Up @@ -443,15 +445,12 @@ bool MetaStoreImpl::GetPartitionInfoList(
int ret = rwLock_.TryRDLock();
if (ret == 0) {
for (const auto& it : partitionMap_) {
PartitionInfo partitionInfo = it.second->GetPartitionInfo();
partitionInfoList->push_back(std::move(partitionInfo));
PartitionInfo partition_info = it.second->GetPartitionInfo();
partitionInfoList->push_back(std::move(partition_info));
}
rwLock_.Unlock();
return true;
} else {
LOG(WARNING) << "metastore GetPartitionInfoList fail, it fail to get"
" the rwLock_, ret:"
<< ret;
return false;
}
}
Expand Down

0 comments on commit 85c893b

Please sign in to comment.