-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fixed concurrency issues caused by write and flush sorting during query execution #17193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #17193 +/- ##
============================================
- Coverage 39.51% 39.51% -0.01%
Complexity 282 282
============================================
Files 5101 5101
Lines 341807 341876 +69
Branches 43518 43524 +6
============================================
+ Hits 135062 135081 +19
- Misses 206745 206795 +50 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
...ain/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractWritableMemChunk.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java
Outdated
Show resolved
Hide resolved
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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 addresses a concurrency hazard between query execution and flush-time sorting of in-memory TVLists by introducing a dedicated “flush-sort clone” path and routing flush encoding through a stable workingListForFlush.
Changes:
- Added
cloneForFlushSort()toTVListand implemented it across TVList variants to clone sort-sensitive structures (timestamps/indices) for flush sorting under contention. - Centralized flush sorting in
AbstractWritableMemChunk.sortTvListForFlush()and updated memchunk encoding to read fromworkingListForFlushrather than the mutable working list. - Added a regression test covering the interaction between query sorting and flush sorting.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/PrimitiveMemTableTest.java | Adds a regression test for query execution interacting with flush-sort behavior. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java | Introduces cloneForFlushSort() as a new abstraction for flush-safe sorting. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java | Implements flush-sort cloning for long TVLists. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/IntTVList.java | Implements flush-sort cloning for int/date TVLists. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java | Implements flush-sort cloning for float TVLists. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java | Implements flush-sort cloning for double TVLists. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/BooleanTVList.java | Implements flush-sort cloning for boolean TVLists. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java | Implements flush-sort cloning for binary/text TVLists. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java | Implements flush-sort cloning for aligned TVLists. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/WritableMemChunk.java | Switches flush encoding to use workingListForFlush rather than the mutable list. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/IWritableMemChunk.java | Adds releaseTemporaryTvListForFlush() to allow releasing the flush-time clone reference. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java | Switches aligned flush encoding to use workingListForFlush. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractWritableMemChunk.java | Centralizes flush sort logic and introduces workingListForFlush lifecycle. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/flush/MemTableFlushTask.java | Releases temporary flush TVList reference after encoding. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...node/src/main/java/org/apache/iotdb/db/storageengine/dataregion/flush/MemTableFlushTask.java
Show resolved
Hide resolved
...ain/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractWritableMemChunk.java
Show resolved
Hide resolved
…ngine/dataregion/memtable/AbstractWritableMemChunk.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|



Description
When writing and flushing data, the internal TVList sorting mechanism could conflict with active queries.
✅ What’s Changed
✔️ Concurrency control enhancements
• The write and flush sort logic has been revised to safely handle concurrent queries by introducing synchronization and controlled cloning of TVLists under contention.
• The implementation ensures that sorting operations do not corrupt or disrupt query access on the same data structures.
✔️ Memtable & TVList adjustments
• Modified internal MemChunk and TVList management to better isolate sort state changes from active queries.
• New clone-on-flush behaviour ensures that a working TVList can be safely sorted even when there are concurrent readers.