From ebdef04d31255eee0d81f28430c40c7ac3e5fba3 Mon Sep 17 00:00:00 2001 From: wanghai01 Date: Thu, 26 May 2022 10:58:20 +0800 Subject: [PATCH] curvefs/mds: fix create partition error at parallel case --- curvefs/src/mds/topology/topology_manager.cpp | 3 +++ curvefs/src/mds/topology/topology_manager.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/curvefs/src/mds/topology/topology_manager.cpp b/curvefs/src/mds/topology/topology_manager.cpp index c0ae50d67b..09076205ba 100644 --- a/curvefs/src/mds/topology/topology_manager.cpp +++ b/curvefs/src/mds/topology/topology_manager.cpp @@ -632,6 +632,9 @@ void TopologyManager::CreatePartitions(const CreatePartitionRequest *request, auto partitionInfoList = response->mutable_partitioninfolist(); response->set_statuscode(TopoStatusCode::TOPO_OK); + // get lock and avoid multiMountpoint create concurrently + NameLockGuard lock(createPartitionMutex_, std::to_string(fsId)); + while (partitionInfoList->size() < count) { if (topology_->GetAvailableCopysetNum() < option_.minAvailableCopysetNum) { diff --git a/curvefs/src/mds/topology/topology_manager.h b/curvefs/src/mds/topology/topology_manager.h index 0a1d423461..66946b0b1b 100644 --- a/curvefs/src/mds/topology/topology_manager.h +++ b/curvefs/src/mds/topology/topology_manager.h @@ -186,6 +186,8 @@ class TopologyManager { */ NameLock registMsMutex; + NameLock createPartitionMutex_; + /** * @brief topology options */