Skip to content

Commit

Permalink
remove parts by storage's info before remove space
Browse files Browse the repository at this point in the history
  • Loading branch information
liwenhui-soul committed Mar 18, 2022
1 parent 372f6b4 commit 8ee969e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/kvstore/NebulaStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ NebulaStore::~NebulaStore() {
raftService_->stop();
LOG(INFO) << "Waiting for the raft service stop...";
raftService_->waitUntilStop();
spaces_.clear();
spaceListeners_.clear();
bgWorkers_->stop();
bgWorkers_->wait();
storeWorker_->stop();
storeWorker_->wait();
spaces_.clear();
spaceListeners_.clear();
LOG(INFO) << "~NebulaStore()";
}

Expand Down Expand Up @@ -437,6 +437,13 @@ void NebulaStore::removeSpace(GraphSpaceID spaceId, bool isListener) {
if (!isListener) {
auto spaceIt = this->spaces_.find(spaceId);
if (spaceIt != this->spaces_.end()) {
for (auto& [partId, part] : spaceIt->second->parts_) {
// before calling removeSpace, meta client would call removePart to remove all parts in
// meta cache, which do not contain learners, so we remove them here
if (part->isLearner()) {
removePart(spaceId, partId, false);
}
}
auto& engines = spaceIt->second->engines_;
for (auto& engine : engines) {
auto parts = engine->allParts();
Expand Down Expand Up @@ -490,8 +497,11 @@ nebula::cpp2::ErrorCode NebulaStore::clearSpace(GraphSpaceID spaceId) {
return nebula::cpp2::ErrorCode::SUCCEEDED;
}

void NebulaStore::removePart(GraphSpaceID spaceId, PartitionID partId) {
folly::RWSpinLock::WriteHolder wh(&lock_);
void NebulaStore::removePart(GraphSpaceID spaceId, PartitionID partId, bool needLock) {
folly::RWSpinLock::WriteHolder wh(nullptr);
if (needLock) {
wh.reset(&lock_);
}
auto spaceIt = this->spaces_.find(spaceId);
if (spaceIt != this->spaces_.end()) {
auto partIt = spaceIt->second->parts_.find(partId);
Expand Down
4 changes: 3 additions & 1 deletion src/kvstore/NebulaStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,10 @@ class NebulaStore : public KVStore, public Handler {
*
* @param spaceId
* @param partId
* @param needLock if lock_ has already been locked, we need
* to set needLock as false, or we set it as true
*/
void removePart(GraphSpaceID spaceId, PartitionID partId) override;
void removePart(GraphSpaceID spaceId, PartitionID partId, bool needLock = true) override;

/**
* @brief Retrive the leader distribution
Expand Down
2 changes: 1 addition & 1 deletion src/kvstore/PartManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Handler {
* @param spaceId
* @param partId
*/
virtual void removePart(GraphSpaceID spaceId, PartitionID partId) = 0;
virtual void removePart(GraphSpaceID spaceId, PartitionID partId, bool needLock = true) = 0;

/**
* @brief Add a partition as listener
Expand Down

0 comments on commit 8ee969e

Please sign in to comment.