Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
fix disk manager thread conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Jul 5, 2021
1 parent 8f38df5 commit f988991
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/kvstore/DiskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ StatusOr<std::string> DiskManager::path(GraphSpaceID spaceId, PartitionID partId
void DiskManager::addPartToPath(GraphSpaceID spaceId,
PartitionID partId,
const std::string& path) {
std::lock_guard<std::mutex> lg(lock_);
try {
auto canonical = boost::filesystem::canonical(path);
auto dataPath = canonical.parent_path().parent_path();
Expand All @@ -85,6 +86,7 @@ void DiskManager::addPartToPath(GraphSpaceID spaceId,
void DiskManager::removePartFromPath(GraphSpaceID spaceId,
PartitionID partId,
const std::string& path) {
std::lock_guard<std::mutex> lg(lock_);
try {
auto canonical = boost::filesystem::canonical(path);
auto dataPath = canonical.parent_path().parent_path();
Expand Down
3 changes: 3 additions & 0 deletions src/kvstore/DiskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class DiskManager {

// the index in dataPaths_ for a given space + part
std::unordered_map<GraphSpaceID, std::unordered_map<PartitionID, size_t>> partIndex_;

// lock used to protect partPath_ and partIndex_
std::mutex lock_;
};

} // namespace kvstore
Expand Down
8 changes: 5 additions & 3 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ void RaftPart::appendLogsInternal(AppendLogsIterator iter, TermID termId) {
} while (false);

if (!checkAppendLogResult(res)) {
LOG(ERROR) << idStr_ << "Failed append logs";
LOG_EVERY_N(WARNING, 100) << idStr_ << "Failed to write wal";
return;
}
// Step 2: Replicate to followers
Expand Down Expand Up @@ -805,7 +805,7 @@ void RaftPart::replicateLogs(folly::EventBase* eb,
} while (false);

if (!checkAppendLogResult(res)) {
LOG(ERROR) << idStr_ << "Replicate logs failed";
LOG(WARNING) << idStr_ << "replicateLogs failed because of not leader or term changed";
return;
}

Expand Down Expand Up @@ -911,7 +911,9 @@ void RaftPart::processAppendLogResponses(
} while (false);

if (!checkAppendLogResult(res)) {
LOG(ERROR) << idStr_ << "processAppendLogResponses failed!";
LOG(WARNING)
<< idStr_
<< "processAppendLogResponses failed because of not leader or term changed";
return;
}

Expand Down

0 comments on commit f988991

Please sign in to comment.