-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix SimpleBatcher Concurrency Issue (#2196) ### Problem: - **Flush Operation Conflict:** - When one thread (T1) performs a flush, it may read and dispatch batched commands before resetting the `flushing` flag. - If another thread (T2) adds a command and forced flush at this moment. Command might be added to the queue but does not trigger a flush. - As a result, the command remains in the queue until the next flush request, causing a delay in dispatching. - **Flag Reset Between Iterations:** - During a default flush operation, if multiple batches are processed, the `flushing` flag is reset between iterations. - This allows another thread to take over, potentially causing the initial thread to return `BatchTasks.EMPTY` instead of properly processed commands. 1. T1 -> batch(command, CommandBatching.flush() 2. T1 -> flushing.compareAndSet(false, true) == true 3. T1 -> flush()->doFlush() 4. T2 -> batch(command, CommandBatching.flush() 5. T2 -> flushing.compareAndSet(false, true) == false #already flushing will skip doFlush and command remain not dispatched 6. T1 -> batch() completes 7. T2 -> batch() completes ### Fix: If force flush is requested while flushing, perform additional flush iteration after ongoing completes * format * Update src/main/java/io/lettuce/core/dynamic/SimpleBatcher.java Co-authored-by: Tihomir Krasimirov Mateev <tihomir.mateev@redis.com> * Update src/main/java/io/lettuce/core/dynamic/SimpleBatcher.java Co-authored-by: ggivo <ivo.gaydajiev@gmail.com> --------- Co-authored-by: Tihomir Krasimirov Mateev <tihomir.mateev@redis.com>
- Loading branch information
Showing
2 changed files
with
85 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters