Fix IndexOutOfBoundsException caused by concurrent sort and delete on TVList - #18389
Merged
Merged
Conversation
… TVList
A query may sort the shared working TVList in place while a DELETE is
running on the same list. sort() is synchronized, but the delete methods
(AlignedTVList.delete/deleteTime/delete(column)/deleteColumn and
TVList.delete) were not, so the delete thread could observe the
half-rebuilt indices during sort and throw IndexOutOfBoundsException
("Index 0 out of bounds for length 0") or silently delete wrong rows.
Synchronize the delete methods with sort() on the same TVList instance,
consistent with putAlignedValue/clone/cloneForFlushSort which are already
synchronized. The runtime delete path always holds
TsFileProcessor.flushQueryLock.writeLock() before touching the TVList, so
the lock order (flushQueryLock -> tvlist monitor) stays consistent with
the query path and no deadlock is introduced.
jt2594838
approved these changes
Aug 4, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18389 +/- ##
============================================
- Coverage 43.46% 43.28% -0.19%
Complexity 374 374
============================================
Files 5364 5394 +30
Lines 383224 385138 +1914
Branches 49868 50087 +219
============================================
+ Hits 166560 166692 +132
- Misses 216664 218446 +1782 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JackieTien97
approved these changes
Aug 4, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix
IndexOutOfBoundsException: Index 0 out of bounds for length 0thrown inAlignedTVList.deleteTime()/delete()when a DELETE races with a query thatsorts the shared working TVList in place.
Root cause
FileLoaderUtils.loadAlignedTimeSeriesMetadata()-> ...->
AlignedReadOnlyMemChunk.sortTvLists()callsAlignedTVList.sort()inplace on the shared (still writable) working TVList.
sort()issynchronizedon the TVList instance and rebuildsindicesnon-atomically(
indices = new ArrayList<>()then fills it).AlignedTVList.deleteTime()/delete()were notsynchronized, so a concurrent DELETE could call
getValueIndex(0)->indices.get(0)whileindiceswas momentarily empty ->IndexOutOfBoundsException, or read half-rebuilt indices and silently deletewrong rows.
Fix
Make
delete()/deleteTime()/delete(column)/deleteColumn()ofAlignedTVList(andTVList.delete()for the non-aligned path)synchronizedon the same TVList instance as
sort(), matching the existing monitor alreadyused by
putAlignedValue/clone/cloneForFlushSort.Delete path audit
All runtime delete paths converge to
TsFileProcessor.deleteDataInMemory()which holds
flushQueryLock.writeLock():DataRegion.deleteByDevice/deleteDataDirectly->deleteDataInUnsealedFiles/deleteDataInSealedFiles/deleteDataDirectlyInFile->TsFileProcessor.deleteDataInMemory->AbstractMemTable.delete->AlignedWritableMemChunkGroup.delete/deleteTime->AlignedTVList.delete*.WAL recovery paths (
TsFilePlanRedoer,UnsealedTsFileRecoverPerformer) callmemTable.delete()directly but only during single-threaded startup, so noconcurrent query/sort exists there.
Lock order stays consistent (
flushQueryLock-> tvlist monitor on both deleteand query-clone paths; query in-place sort holds only the tvlist monitor because
the read lock is released before
sortTvLists()runs), so no deadlock isintroduced.