Skip to content

Commit cdef57e

Browse files
cccxgitxiajingchun
andauthored
fix #6150: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph (#6152)
* Update NebulaStore.cpp fix #6150: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph * Update NebulaStore.h fix #6150: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph * Update NebulaStore.cpp fix format check * Update NebulaStore.cpp fix format check --------- Co-authored-by: jingchun.xia <6269380+xiajingchun@users.noreply.github.com>
1 parent c1d657d commit cdef57e

2 files changed

Lines changed: 32 additions & 15 deletions

File tree

src/kvstore/NebulaStore.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,32 @@ void NebulaStore::stop() {
354354
folly::Future<std::pair<GraphSpaceID, std::unique_ptr<KVEngine>>> NebulaStore::newEngineAsync(
355355
GraphSpaceID spaceId, const std::string& dataPath, const std::string& walPath) {
356356
return folly::via(folly::getGlobalIOExecutor().get(), [this, spaceId, dataPath, walPath]() {
357-
std::unique_ptr<KVEngine> engine;
358-
if (FLAGS_engine_type == "rocksdb") {
359-
std::shared_ptr<KVCompactionFilterFactory> cfFactory = nullptr;
360-
if (options_.cffBuilder_ != nullptr) {
361-
cfFactory = options_.cffBuilder_->buildCfFactory(spaceId);
362-
}
363-
auto vIdLen = getSpaceVidLen(spaceId);
364-
engine = std::make_unique<RocksEngine>(
365-
spaceId, vIdLen, dataPath, walPath, options_.mergeOp_, cfFactory);
366-
} else {
367-
LOG(FATAL) << "Unknown engine type " << FLAGS_engine_type;
368-
}
369-
return std::make_pair(spaceId, std::move(engine));
357+
return std::make_pair(spaceId, createEngine(spaceId, dataPath, walPath));
370358
});
371359
}
372360

361+
std::unique_ptr<KVEngine> NebulaStore::createEngine(GraphSpaceID spaceId,
362+
const std::string& dataPath,
363+
const std::string& walPath) {
364+
std::unique_ptr<KVEngine> engine;
365+
if (FLAGS_engine_type == "rocksdb") {
366+
std::shared_ptr<KVCompactionFilterFactory> cfFactory = nullptr;
367+
if (options_.cffBuilder_ != nullptr) {
368+
cfFactory = options_.cffBuilder_->buildCfFactory(spaceId);
369+
}
370+
auto vIdLen = getSpaceVidLen(spaceId);
371+
engine = std::make_unique<RocksEngine>(
372+
spaceId, vIdLen, dataPath, walPath, options_.mergeOp_, cfFactory);
373+
} else {
374+
LOG(FATAL) << "Unknown engine type " << FLAGS_engine_type;
375+
}
376+
return engine;
377+
}
378+
373379
std::unique_ptr<KVEngine> NebulaStore::newEngine(GraphSpaceID spaceId,
374380
const std::string& dataPath,
375381
const std::string& walPath) {
376-
auto pair = this->newEngineAsync(spaceId, dataPath, walPath).get();
377-
return std::move(pair.second);
382+
return createEngine(spaceId, dataPath, walPath);
378383
}
379384

380385
ErrorOr<nebula::cpp2::ErrorCode, HostAddr> NebulaStore::partLeader(GraphSpaceID spaceId,

src/kvstore/NebulaStore.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,18 @@ class NebulaStore : public KVStore, public Handler {
797797
const std::string& dataPath,
798798
const std::string& walPath);
799799

800+
/**
801+
* @brief Build a new kv engine on the current thread
802+
*
803+
* @param spaceId
804+
* @param dataPath
805+
* @param walPath
806+
* @return std::unique_ptr<KVEngine>
807+
*/
808+
std::unique_ptr<KVEngine> createEngine(GraphSpaceID spaceId,
809+
const std::string& dataPath,
810+
const std::string& walPath);
811+
800812
/**
801813
* @brief Start a new part
802814
*

0 commit comments

Comments
 (0)