Skip to content

[Bug] Fix SeriesScanUtil/AlignedSeriesScanUtil correctness bugs and remove dead streamingQueryMemChunk config - #19444

Closed
JackieTien97 wants to merge 2 commits into
apache:masterfrom
JackieTien97:ty/glm-scan-test
Closed

JackieTien97 wants to merge 2 commits into
apache:masterfrom
JackieTien97:ty/glm-scan-test

Conversation

@JackieTien97

Copy link
Copy Markdown
Contributor

Description

Fixes #19443

How the Bugs Were Located

  1. Randomized differential fuzzing (SeriesScanUtilFuzzTest): We built an oracle-checked differential test harness driving SeriesScanUtil and AlignedSeriesScanUtil across three data models (non-aligned, aligned tree, aligned table), ascending/descending scans, closed and open files (flushed chunks + memtables), file/memtable deletions, time/value filters, LIMIT/OFFSET, and three scan drivers (SeriesScanOperator style, explicit file→chunk→page statistics audit, and SeriesAggregationScanOperator style).
  2. Production-reachability audit & end-to-end IT reproduction (IoTDBSeriesScanDefectIT): From 12 minimal UT failures surfaced by the fuzzer, we audited each candidate against production code paths:
    • 8 bugs confirmed production-reachable and reproduced end-to-end in both 1C1D (SimpleIT) and 1C3D (ClusterIT) before applying fixes (11/11 IT cases failing on baseline).
    • 3 legacy-path issues confirmed unreachable in production:
      • Multi-memtable priority tie in a single open file (TsFileProcessor.asyncFlush() has 0 callers in src/main since DirectFlushPolicy unconditionally closes the processor).
      • Two non-streaming memchunk issues (IoTDBConfig.streamingQueryMemChunk is hardcoded true with no config key or production setter).
    • Removed the dead IoTDBConfig.streamingQueryMemChunk field/getters/setters and simplified the unreachable non-streaming branches accordingly; removed the 3 unreachable defect UTs.

Root Causes & Solutions (with Examples)

1. Flushing aligned memtable value-column deletions ignored on point-read and multi-TVList paths

  • Example: Aligned d1(s0, s1) with closed seq file (2, 200, 99) and flushing unseq memtable (1, 10, 1), (2, 20, 2) (or two non-overlapping sorted TVLists in a flushing memtable). After DELETE FROM root.db.d1.s0 WHERE time >= 1 AND time <= 2 (recorded in modsToMemtable), SELECT s0, s1 FROM root.db.d1 WHERE time <= 2:
    • Before: Returned deleted s0 values (1 -> (10, 1), 2 -> (20, 2)).
    • After: Returns 1 -> (null, 1), 2 -> (null, 2).
  • Root cause & fix:
    • AlignedTVListIterator.nextTimeValuePair() / currentTimeValuePair() read raw values without checking valueColumnsDeletionList, and AlignedTVListIterator.reset() / batch DESC scans did not reset delete cursors properly.
    • OrderedMultiAlignedTVListIterator.currentIteratorIndex(int) ignored the per-column deletion bitMap.
    • Fixed in AlignedTVList (track per-column deletion flags in prepareNext(), apply them in nextTimeValuePair() / currentTimeValuePair(), properly initialize/reset delete cursors for ASC/DESC) and OrderedMultiAlignedTVListIterator (return -1 when bitMap.isMarked(columnIndex)).

2. Stale file-unpack horizon after a fully-deleted leading seq file breaks OFFSET/LIMIT pushdown and aggregation statistics

  • Example: Non-aligned d1.s0 with seq File A (1, 1), (2, 2) (fully deleted via mods; kept alive by sibling s1), unseq File U (2, 20), (3, 30), and seq File B (3, 3), (4, 4):
    • SELECT s0 FROM root.db.d1 LIMIT 2 OFFSET 2: Before returned 3 -> 3, 4 -> 4; After returns 4 -> 4.
    • SELECT COUNT(s0), SUM(s0) FROM root.db.d1: Before returned 4, 57.0; After returns 3, 54.0.
  • Root cause & fix: SeriesScanUtil.initFirstChunkMetadata() unpacked overlapped files only up to the first TimeSeriesMetadata's endpoint (2). When File A yielded zero chunks, File U's chunk (ending at 3) became firstChunkMetadata without advancing the unpack horizon to 3, leaving File B unpacked and undetected as overlapping.
  • Fixed in SeriesScanUtil: stabilize the unpack horizon in a loop whenever unpacked metadata/chunks extend past the previous horizon before filtering or returning firstChunkMetadata.

3. Wildcard SELECT * OFFSET/LIMIT over-consumes offset on all-null rows in tree model

  • Example: Aligned tree d1(s0, s1), page 1 (1, 1, null), (2, null, 2), (3, 3, null), page 2 (4, 4, null), (5, 5, null), after DELETE FROM root.db.d1.s1 WHERE time >= 1 AND time <= 5. SELECT * FROM root.db.d1 LIMIT 5 OFFSET 3:
    • Before: Skipped page 1 consuming 3 rows of offset (including all-null row 2), returning 4 -> (4, null), 5 -> (5, null).
    • After: Returns 5 -> (5, null).
  • Root cause & fix: AlignedSeriesScanUtil.timeAllSelected() returned true whenever queryAllSensors was set, ignoring dropped/deleted columns. Removed the queryAllSensors shortcut in AlignedSeriesScanUtil.timeAllSelected(IMetadata) so it always delegates to metadata.timeAllSelected() under tree mode (ignoreAllNullRows == true).

4. Value-filter pushdown returns rows deleted to null on modified aligned pages

  • Example: Aligned d1(s0, s1) with (1, 10, 1), (2, 20, 2), (3, 30, 3), after DELETE FROM root.db.d1.s0 WHERE time = 2. SELECT s0, s1 FROM root.db.d1 WHERE s0 != 173:
    • Before: Returned 1 -> (10, 1), 2 -> (null, 2), 3 -> (30, 3).
    • After: Returns 1 -> (10, 1), 3 -> (30, 3).
  • Root cause & fix: Upstream AbstractAlignedPageReader evaluates pushDownFilter.allSatisfy(...) against pre-deletion statistics (min=10, max=30), bypassing row-level filtering for values turned null by mods.
  • Fixed in SeriesScanUtil.nextPage(): for modified AbstractAlignedPageReader with a pushDownFilter, decode the page with deletions applied first and then apply pushDownFilter and pagination via TsBlockUtil.applyFilterAndLimitOffsetToTsBlock(...). (An upstream fix in Apache TsFile can complement this.)

5. COUNT_TIME(*) over-counts dropped/all-null rows on aligned tree devices (subset/dropped columns, full-column deletion, dropped value pages)

  • Examples (SELECT COUNT_TIME(*) FROM root.db.d1):
    • Dropped column: (1, 1, null), (2, null, 2), (3, 3, null) + DELETE TIMESERIES root.db.d1.s1 (and 3-column variant dropping s2): Before 3 → After 2.
    • Full-column deletion: Same data + DELETE FROM root.db.d1.s1 WHERE time >= 1 AND time <= 3: Before 3 → After 2.
    • Whole-row deletion dropping an entire value page: Page 1 (1, null, 1), (2, 2, null), (3, 3, null), Page 2 (4, 4, null) + DELETE FROM root.db.d1.* WHERE time = 1: Before 4 → After 3.
  • Root cause & fix:
    • Value-only aggregations (COUNT(s0), SUM(s1)) can still safely use value statistics on sparse aligned files (preserving AlignedSeriesScanPredicatePushDownTest and avoiding performance regression), whereas COUNT_TIME(*) (valueColumnIndex == -1) relies on time-column statistics that include all-null rows.
    • Added canUseCurrent{File,Chunk,Page}TimeStatistics() on SeriesScanUtil / AlignedSeriesScanUtil and routed time-statistics aggregators (TreeAggregator.usesTimeStatistics()) through them in AbstractSeriesAggregationScanOperator. When at most one queried measurement is non-null in tree mode, AlignedSeriesScanUtil.current*TimeStatistics() returns that column's exact statistics; when multiple sparse columns exist without timeAllSelected, COUNT_TIME(*) falls back to row-level scanning.
    • Propagated modified flags in ModificationUtils / DiskAlignedChunkMetadataLoader when a value column's chunk metadata is deleted to null, and in DiskAlignedChunkLoader when deletions overlap a page's time range or drop an entire value page. Also overrode getMeasurementCount() in AlignedPageMetadata and MemAlignedPageReader.

6. Dead IoTDBConfig.streamingQueryMemChunk cleanup

  • Removed immutable IoTDBConfig.streamingQueryMemChunk (isStreamingQueryMemChunk / setStreamingQueryMemChunk) and simplified the always-streaming branches in ResourceByPathUtils, MemChunkLoader, MemAlignedChunkLoader, ReadOnlyMemChunk, AlignedReadOnlyMemChunk, and SeriesScanUtil.

Verification

  • End-to-end IT (IoTDBSeriesScanDefectIT):
    • Before fix: SimpleIT (1C1D) 11/11 FAIL, ClusterIT (1C3D) 11/11 FAIL.
    • After fix: SimpleIT (1C1D) 11/11 PASS, ClusterIT (1C3D) 11/11 PASS.
  • Existing IT regression (SimpleIT 1C1D + ClusterIT 1C3D):
    • IoTDBCountTimeAlignedDeviceIT (7/7), IoTDBCountTimeIT (6/6), IoTDBAlignedDataDeletionIT (12/12), IoTDBAlignedSeriesQueryWithDeletionIT (3/3) — all PASS.
  • Unit & fuzz tests:
    • SeriesScanUtilDefectTest: 9/9 PASS.
    • SeriesScanUtilFuzzTest: default (360 scenarios, 0 skipped) PASS; strict full-dimension (scan_strict=1 scan_scenarios=200 scan_flushed=1 scan_subset=1, 1,200 scenarios, 0 skipped) PASS.
    • 18 existing scan/reader/aggregation UT suites (including AlignedSeriesScanPredicatePushDownTest, MemChunkLoaderTest, MemAlignedChunkLoaderTest, AlignedMemPageReaderTest, AlignedPriorityMergeReaderTest, etc.) — all PASS.
  • Checks: mvn spotless:apply, python3 .github/scripts/check-it-selection.py, and both en & -P with-zh-locale builds PASS.

This PR has:

  • been self-reviewed.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes in this PR
  • AlignedTVList, OrderedMultiAlignedTVListIterator
  • SeriesScanUtil, AlignedSeriesScanUtil
  • TreeAggregator, AbstractSeriesAggregationScanOperator
  • ModificationUtils, DiskAlignedChunkMetadataLoader, DiskAlignedChunkLoader, AlignedPageMetadata, MemAlignedPageReader
  • IoTDBConfig, ResourceByPathUtils, MemChunkLoader, MemAlignedChunkLoader, ReadOnlyMemChunk, AlignedReadOnlyMemChunk
  • IoTDBSeriesScanDefectIT and scanfuzz/* test suite

Cover SeriesScanUtil and AlignedSeriesScanUtil with a differential test
harness in the test sources of datanode:

- SeriesScanUtilFuzzTest generates scenarios (closed and open files,
  flushed chunks, memory tables, deletions, time and value filters, limit
  and offset, ascending and descending) and checks three ways of scanning
  against a brute-force oracle.
- SeriesScanUtilDefectTest pins twelve defects with minimal scenarios and
  asserts the correct result, so its tests fail until each defect is fixed.
- SeriesScanKnownIssues keeps the randomized test green by leaving out the
  scenarios that hit a known defect; scan_strict=1 runs them all the same.

No production code is changed.
…streamingQueryMemChunk

Fixes apache#19443

- Apply value-column deletions in AlignedTVListIterator point-read paths and OrderedMultiAlignedTVListIterator (and reset delete cursors on reset / DESC scans).
- Advance the file unpack horizon in SeriesScanUtil when leading metadata yields no chunks so overlapping seq/unseq chunks are not skipped by OFFSET/LIMIT or double-counted by aggregation statistics.
- Stop trusting queryAllSensors as timeAllSelected in AlignedSeriesScanUtil for tree-model wildcard OFFSET/LIMIT pushdown.
- Decode modified AbstractAlignedPageReader pages with deletions applied before evaluating pushDownFilter and pagination in SeriesScanUtil.nextPage().
- Gate COUNT_TIME statistics via canUseCurrent*TimeStatistics() and exact single-non-null aligned time statistics without regressing value-only aggregation statistics; propagate modified flags for deleted value columns and dropped value pages in ModificationUtils, DiskAlignedChunkMetadataLoader, and DiskAlignedChunkLoader.
- Remove immutable IoTDBConfig.streamingQueryMemChunk and dead non-streaming branches in ResourceByPathUtils, MemChunkLoader, MemAlignedChunkLoader, and SeriesScanUtil.
- Remove unreachable D2/D6/D8 defect UTs, fix queried-column deletion projection in SeriesScanMaterializer, and add end-to-end IoTDBSeriesScanDefectIT covering all 8 bugs.
@JackieTien97

Copy link
Copy Markdown
Contributor Author

Closing to reopen from an apache/iotdb branch so SonarCloud checks can run.

@JackieTien97
JackieTien97 deleted the ty/glm-scan-test branch November 29, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Multiple correctness issues in SeriesScanUtil and AlignedSeriesScanUtil with deletions, overlaps, pushdown filters, and COUNT_TIME

1 participant