Skip to content

Commit

Permalink
fix deadlock when removing part
Browse files Browse the repository at this point in the history
  • Loading branch information
liwenhui-soul committed Jan 19, 2022
1 parent 3c83012 commit d10d446
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/kvstore/raftex/RaftexService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,17 @@ void RaftexService::addPartition(std::shared_ptr<RaftPart> part) {
}

void RaftexService::removePartition(std::shared_ptr<RaftPart> part) {
folly::RWSpinLock::WriteHolder wh(partsLock_);
parts_.erase(std::make_pair(part->spaceId(), part->partitionId()));
using FType = decltype(folly::makeFuture());
using FTValype = typename FType::value_type;
// Stop the partition
part->stop();
folly::makeFuture()
.thenValue([this, &part](FTValype) {
folly::RWSpinLock::WriteHolder wh(partsLock_);
parts_.erase(std::make_pair(part->spaceId(), part->partitionId()));
})
.via(getThreadManager().get())
.thenValue([part](FTValype) { part->stop(); })
.wait();
}

std::shared_ptr<RaftPart> RaftexService::findPart(GraphSpaceID spaceId, PartitionID partId) {
Expand Down

0 comments on commit d10d446

Please sign in to comment.