shuwenwei opened a new pull request, #18389:
URL: https://github.com/apache/iotdb/pull/18389

   ## Description
   
   Fix `IndexOutOfBoundsException: Index 0 out of bounds for length 0` thrown in
   `AlignedTVList.deleteTime()` / `delete()` when a DELETE races with a query 
that
   sorts the shared working TVList in place.
   
   ### Root cause
   - Query path: `FileLoaderUtils.loadAlignedTimeSeriesMetadata()` -> ...
     -> `AlignedReadOnlyMemChunk.sortTvLists()` calls `AlignedTVList.sort()` in
     place on the shared (still writable) working TVList. `sort()` is
     `synchronized` on the TVList instance and rebuilds `indices` non-atomically
     (`indices = new ArrayList<>()` then fills it).
   - Delete path: `AlignedTVList.deleteTime()` / `delete()` were **not**
     synchronized, so a concurrent DELETE could call `getValueIndex(0)` ->
     `indices.get(0)` while `indices` was momentarily empty ->
     `IndexOutOfBoundsException`, or read half-rebuilt indices and silently 
delete
     wrong rows.
   
   ### Fix
   Make `delete()` / `deleteTime()` / `delete(column)` / `deleteColumn()` of
   `AlignedTVList` (and `TVList.delete()` for the non-aligned path) 
`synchronized`
   on the same TVList instance as `sort()`, matching the existing monitor 
already
   used 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`) 
call
   `memTable.delete()` directly but only during single-threaded startup, so no
   concurrent query/sort exists there.
   
   Lock order stays consistent (`flushQueryLock` -> tvlist monitor on both 
delete
   and query-clone paths; query in-place sort holds only the tvlist monitor 
because
   the read lock is released before `sortTvLists()` runs), so no deadlock is
   introduced.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to