fix: Eliminate RwLock in SequenceCounter to avoid read-write deadlock issues#19432
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6018ad90c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/query/service/src/pipelines/processors/transforms/transform_async_function.rs
Outdated
Show resolved
Hide resolved
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d06f74c98
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/query/service/src/pipelines/processors/transforms/transform_async_function.rs
Outdated
Show resolved
Hide resolved
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37f0d12ff5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/query/service/src/pipelines/processors/transforms/transform_async_function.rs
Show resolved
Hide resolved
e66f769 to
c759f70
Compare
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
This issue points out that the current usage of
RwLockinSequenceCountermay lead to deadlocks or degraded performance due to blocking. The issue also suggests usingtokio::spawnto avoid blocking.In this PR, instead of introducing a larger refactor(), I aimed to address the root cause of the problem by minimizing the reliance on
RwLock. The solution is to initialize the counter using arefill_lockwith double-checked locking on the slow path. As a result, locking is only required during the slow-path refill/initialization, while the normal fast-path sequence increment remains lock-free.This PR also adds two unit test based on the reproduction case from the issue:
test_no_stall_when_refill_lock_waiting&test_high_concurrency_fast_path_progress_during_refill_contention.Special thanks to @YZL0v3ZZ for the careful review and valuable feedback.
Tips:
next_val_v0andnext_val_v1is not fully consistent yet, and the migration is still ongoing. A larger refactor at this stage could further increase the complexity. Therefore, this change tries to preserve the original structure and behavior as much as possible.Tests
Type of change
This change is