Skip to content

fix #6150: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph - #6152

Merged
xiajingchun merged 5 commits into
vesoft-inc:masterfrom
cccxgit:master-bug-fix-3
May 18, 2026
Merged

fix #6150: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph#6152
xiajingchun merged 5 commits into
vesoft-inc:masterfrom
cccxgit:master-bug-fix-3

Conversation

@cccxgit

@cccxgit cccxgit commented May 17, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number:

Issue(s) number: #6150

Description:

This PR fixes a deadlock risk when space creation happens concurrently with leader balance in NebulaGraph 3.6.

NebulaStore::addSpace() used to hold NebulaStore::lock_ as a write lock and then wait on newEngineAsync().get(). Since newEngineAsync() runs on folly::getGlobalIOExecutor(), and transfer-leader follow-up checks also run on the same executor and call partLeader() (which needs the store lock), this could create a lock/executor dependency cycle under concurrency.

How do you solve it?

  • Extract engine creation logic into a synchronous helper createEngine()
  • Keep newEngineAsync() for the startup path that scans existing engines from disk
  • Change newEngine() to call createEngine() directly instead of waiting on newEngineAsync().get()

This removes the dependency on folly::getGlobalIOExecutor() from the addSpace() path while the store write lock is held.

Special notes for your reviewer, ex. impact of this fix, design document, etc:

The change only affects the synchronous space-creation path. Startup-time async engine loading remains unchanged.

Checklist:

Tests:

  • Unit test(positive and negative cases)
  • Function test
  • Performance test
  • N/A

Affects:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

Please confirm whether to be reflected in release notes and how to describe:

fix bug: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph 3.6.

cccxgit added 2 commits May 17, 2026 12:41
fix vesoft-inc#6150: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph
fix vesoft-inc#6150: A deadlock risk when space creation happens concurrently with leader balance in NebulaGraph
@CLAassistant

CLAassistant commented May 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a deadlock risk during concurrent space creation and leader-balance operations by removing addSpace()’s dependency on folly::getGlobalIOExecutor() while the store write lock is held.

Changes:

  • Extract KV engine construction into a synchronous helper NebulaStore::createEngine().
  • Update newEngineAsync() to delegate engine construction to createEngine() (preserving async startup behavior).
  • Update newEngine() to construct engines synchronously via createEngine() instead of blocking on newEngineAsync().get().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/kvstore/NebulaStore.h Declares the new synchronous createEngine() helper used to decouple space creation from the global IO executor.
src/kvstore/NebulaStore.cpp Implements createEngine() and refactors newEngine()/newEngineAsync() to use it, eliminating the lock/executor dependency cycle in the addSpace() path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

critical27
critical27 previously approved these changes May 17, 2026
@critical27 critical27 added the ready-for-testing PR: ready for the CI test label May 17, 2026
xiajingchun
xiajingchun previously approved these changes May 17, 2026
@yuhongwei380 yuhongwei380 added ready-for-testing PR: ready for the CI test and removed ready-for-testing PR: ready for the CI test labels May 17, 2026
@critical27
critical27 enabled auto-merge (squash) May 18, 2026 01:54
@cccxgit

cccxgit commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

@xiajingchun 你好请问 ,流水线执行失败,是因为流水线本身问题还是测试用例没通过呢?

@xiajingchun

xiajingchun commented May 18, 2026

Copy link
Copy Markdown
Contributor

@xiajingchun 你好请问 ,流水线执行失败,是因为流水线本身问题还是测试用例没通过呢?

@cccxgit 之前workflow有些问题,现在好了。但是lint的format check没过,你再改改:

Run git diff -U0 --no-color c1d657d3811892b716e2bbb76f86690186129335 HEAD | /usr/share/clang/clang-format-10/clang-format-diff.py -p1 | tee /tmp/.clang-format-diff
  
--- src/kvstore/NebulaStore.cpp	(before formatting)
+++ src/kvstore/NebulaStore.cpp	(after formatting)
@@ -368,12 +368,8 @@
       cfFactory = options_.cffBuilder_->buildCfFactory(spaceId);
     }
     auto vIdLen = getSpaceVidLen(spaceId);
-    engine = std::make_unique<RocksEngine>(spaceId,
-                                           vIdLen,
-                                           dataPath,
-                                           walPath,
-                                           options_.mergeOp_,
-                                           cfFactory);
+    engine = std::make_unique<RocksEngine>(
+        spaceId, vIdLen, dataPath, walPath, options_.mergeOp_, cfFactory);
   } else {
     LOG(FATAL) << "Unknown engine type " << FLAGS_engine_type;
   }
Error: Process completed with exit code 1.

fix format check
auto-merge was automatically disabled May 18, 2026 06:53

Head branch was pushed to by a user without write access

@cccxgit
cccxgit dismissed stale reviews from xiajingchun and critical27 via dd63ec1 May 18, 2026 06:53
@xiajingchun

Copy link
Copy Markdown
Contributor

@cccxgit still failing:

Run git diff -U0 --no-color c1d657d3811892b716e2bbb76f86690186129335 HEAD | /usr/share/clang/clang-format-10/clang-format-diff.py -p1 | tee /tmp/.clang-format-diff
--- src/kvstore/NebulaStore.cpp	(before formatting)
+++ src/kvstore/NebulaStore.cpp	(after formatting)
@@ -369,7 +369,7 @@
     }
     auto vIdLen = getSpaceVidLen(spaceId);
     engine = std::make_unique<RocksEngine>(
-      spaceId, vIdLen, dataPath, walPath, options_.mergeOp_, cfFactory);
+        spaceId, vIdLen, dataPath, walPath, options_.mergeOp_, cfFactory);
   } else {
     LOG(FATAL) << "Unknown engine type " << FLAGS_engine_type;
   }
Error: Process completed with exit code 1.

fix format check
@cccxgit

cccxgit commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

@cccxgit仍然失败:

Run git diff -U0 --no-color c1d657d3811892b716e2bbb76f86690186129335 HEAD | /usr/share/clang/clang-format-10/clang-format-diff.py -p1 | tee /tmp/.clang-format-diff
--- src/kvstore/NebulaStore.cpp	(before formatting)
+++ src/kvstore/NebulaStore.cpp	(after formatting)
@@ -369,7 +369,7 @@
     }
     auto vIdLen = getSpaceVidLen(spaceId);
     engine = std::make_unique<RocksEngine>(
-      spaceId, vIdLen, dataPath, walPath, options_.mergeOp_, cfFactory);
+        spaceId, vIdLen, dataPath, walPath, options_.mergeOp_, cfFactory);
   } else {
     LOG(FATAL) << "Unknown engine type " << FLAGS_engine_type;
   }
Error: Process completed with exit code 1.

已按照建议修改,感谢哈

@xiajingchun
xiajingchun enabled auto-merge (squash) May 18, 2026 07:52
@cccxgit

cccxgit commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

@xiajingchun 不好意思打扰,流水线好像还有问题

@xiajingchun
xiajingchun merged commit cdef57e into vesoft-inc:master May 18, 2026
4 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-testing PR: ready for the CI test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants