Skip to content

Fix aligned TsFile LOAD data loss - #19371

Merged
jt2594838 merged 8 commits into
masterfrom
codex/fix-aligned-load-conflict
Nov 26, 2026
Merged

jt2594838 merged 8 commits into
masterfrom
codex/fix-aligned-load-conflict

Conversation

@Caideyipi

Copy link
Copy Markdown
Collaborator

Problem

When loading a tree-model TsFile with convert-on-type-mismatch=true, a scan of an aligned device can emit only part of its data (or no tablets) before reaching normal EOF when target measurement types conflict. Treating that EOF as complete can silently omit points; with delete-after-load enabled, the source file may also be removed.

For example, a TsFile with aligned d.s0 and d.s1 Boolean values at timestamps 1–4, loaded into existing INT32 and INT64 series with conversion enabled, must preserve all four timestamps and the converted values for both measurements.

Fix

Use per-device and per-measurement point counts from TsFile metadata to identify incomplete scans at EOF. Query fallback recovers the missing data and checks its actual point counts against the expected counts; if recovery is incomplete, LOAD fails instead of reporting success, and the source is retained. Existing type-conversion semantics remain unchanged.

Validation

  • DataNode LoadTreeStatementDataTypeConvertExecutionVisitorTest: 26 tests passed.
  • IoTDBLoadTsFileIT#testLoadWithAllConflictingAlignedDataTypes: passed.
  • IoTDBPipeTypeConversionSemanticIT#testHistoryPipeReceiverTypeConversionForAlignedAllConflicts: passed.
  • Spotless and git diff --check: passed.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Local Review Summary

Reviewed candidate f40292393adf3256fd38a86619fb213742031ca1 against master. The review examined EOF completeness against TsFile metadata and actual per-measurement scan/fallback counts, including aligned data, duplicate timestamps, chunk-group boundaries, and deletion handling. Recovery now fails explicitly when its point counts remain incomplete, rather than allowing a partial load to succeed; failed loads retain the source. Existing type-conversion semantics are unchanged.

Regression coverage includes duplicate-timestamp fallback that cannot resume without skipping a point. No unresolved findings remain.

Validation passed locally: LoadTreeStatementDataTypeConvertExecutionVisitorTest (26 tests), IoTDBLoadTsFileIT#testLoadWithAllConflictingAlignedDataTypes, IoTDBPipeTypeConversionSemanticIT#testHistoryPipeReceiverTypeConversionForAlignedAllConflicts, Spotless, and git diff --check. All added tests were run locally.

Final local SHA: f40292393adf3256fd38a86619fb213742031ca1.
Confirmed remote branch and PR head SHA: f40292393adf3256fd38a86619fb213742031ca1.

@Caideyipi
Caideyipi marked this pull request as draft November 24, 2026 02:19
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.57%. Comparing base (45cb995) to head (32ca26c).
⚠️ Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
...e/load/converter/LoadTreeTsFileTabletIterator.java 86.34% 40 Missing ⚠️
...le/parser/scan/TsFileInsertionEventScanParser.java 98.68% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19371      +/-   ##
============================================
+ Coverage     49.58%   50.57%   +0.98%     
+ Complexity      718      129     -589     
============================================
  Files          5671     5786     +115     
  Lines        419579   426060    +6481     
  Branches      55492    56524    +1032     
============================================
+ Hits         208066   215471    +7405     
+ Misses       211513   210589     -924     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Caideyipi
Caideyipi marked this pull request as ready for review November 24, 2026 06:39
@Caideyipi
Caideyipi marked this pull request as draft November 24, 2026 06:53
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Independent Re-review Summary

Reviewed the complete diff from base 45cb9959f16bb5350c136b0e5ca6847cde853d2b at head 94ae3e0953d16435bf74852582e5e09b2164e64d. This round found and fixed one source-behavior issue: aligned value-chunk indices advanced only after filtering, so a value chunk fully skipped by deletion mods could cause later chunks to be associated with an earlier time chunk. The parser now advances the per-measurement index as soon as each value-chunk header is read. A regression covers two aligned chunks in one chunk group with the first value chunk deleted.

Validation passed:

  • mvn spotless:apply -P with-integration-tests -pl iotdb-core/datanode -nsu
  • mvn -nsu clean test -pl iotdb-core/datanode -am -Dtest=LoadTreeStatementDataTypeConvertExecutionVisitorTest -Dsurefire.failIfNoSpecifiedTests=false -Ddevelocity.off=true — 29 tests; 0 failures, errors, or skips.
  • git diff --check

Reviewed SHA: 94ae3e0953d16435bf74852582e5e09b2164e64d.
Final local commit and confirmed source branch/PR head: c3e16e07e4f51b33a52c7c5dbe1b966e60ccc168.

The PR remains Draft pending a fresh independent review because this round found and fixed a behavioral issue. Remote CI and Sonar re-analysis were not awaited.

@Caideyipi
Caideyipi marked this pull request as ready for review November 24, 2026 09:04
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Independent Re-review Summary

Reviewed the complete PR diff from base 45cb9959f16bb5350c136b0e5ca6847cde853d2b to head c3e16e07e4f51b33a52c7c5dbe1b966e60ccc168. No actionable source-behavior or test-logic findings remain; no further changes were needed in this round.

Local verification passed on the reviewed code: Spotless; the clean DataNode reactor run of LoadTreeStatementDataTypeConvertExecutionVisitorTest (29 tests, 0 failures, errors, or skips), including the aligned deleted-chunk ordering regression; and git diff --check.

The source branch and PR head both match c3e16e07e4f51b33a52c7c5dbe1b966e60ccc168. The PR is ready for review. Remote CI is still running, and a fresh Sonar analysis result has not yet been reported; neither was awaited.

@Caideyipi
Caideyipi marked this pull request as draft November 24, 2026 09:21
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review summary (round: re-review)

  • Reviewed candidate SHA: f0309f1331c08dc2315163921332b500c07096b1 (rebased on PR head c3e16e07e4f51b33a52c7c5dbe1b966e60ccc168).
  • Finding: the visible-point counting path also did per-point work for unmodified LOADs.
  • Fix: ef431c0180e66a876f815a94fa41dfad0f19044e skips that counting when the TsFile has no modifications; modified-file fallback remains intact.
  • Verification: mvn spotless:apply -P with-integration-tests -pl iotdb-core/datanode passed. The focused test on the final snapshot did not reach test execution because Maven could not resolve the org.apache.tsfile:tsfile:2.5.1-261118-SNAPSHOT POM (HTTP 403). A 27-test pass from an earlier snapshot is not final-snapshot evidence.
  • Final local SHA: ef431c0180e66a876f815a94fa41dfad0f19044e.
  • Confirmed remote branch and PR head SHA: ef431c0180e66a876f815a94fa41dfad0f19044e.
  • The PR remains draft pending an independent review.

@Caideyipi
Caideyipi marked this pull request as ready for review November 24, 2026 10:10
@jt2594838

Copy link
Copy Markdown
Contributor

Independent review of head ef431c0180e66a876f815a94fa41dfad0f19044e found no additional correctness issues.

Scope covered the changed files in PR order, including the conflicting-type LOAD cases, the historical Pipe regression case, scan and metadata point-count reconciliation, modification handling, timestamp resume boundaries, and failed-fallback behavior that preserves the source TsFile.

The PR description reports 26 passing DataNode tests, both added integration tests passing, Spotless, and git diff --check. I did not rerun them. An author update in the discussion notes that a focused Maven run against this head did not reach test execution because dependency resolution for org.apache.tsfile:tsfile:2.5.1-261118-SNAPSHOT returned HTTP 403, so I cannot independently confirm final-head test execution.

@jt2594838 jt2594838 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the scan fails, is it possible to maintain a heap of ChunkMetadata via the index area, sorted by the chunk offset?

Then we could jump to the next chunk offset and try to resume the scan from it.
This could avoid the complex point counting introduced here.

@Caideyipi

Caideyipi commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review-comment handling summary

  • Reviewed SHA: ef431c0180e66a876f815a94fa41dfad0f19044e. Thanks for the independent review; I addressed the follow-up implementation questions below.
  • Reused the existing sorted modification cursor, imported IChunkMetadata, and added a localized fallback-count mismatch diagnostic with device, measurement, expected count, and recovered count. A regression assertion covers the diagnostic.
  • The metadata-derived expected counts are retained and compared with actual query-fallback progress, so the scan results are reused across query tasks. The existing insertion-ordered map comparison is linear with average constant-time lookups; TreeMap would not reduce its complexity.
  • A heap ordered by chunk offsets may be explored as a separate resume strategy, but it does not replace point-count reconciliation for normal EOF after a partial scan within a chunk. No broader recovery redesign was added.
  • The Codecov report is for the preceding head and flags uncovered lines. This update adds a focused assertion for mismatch details; refreshed coverage data is not yet available.
  • Verification passed: Spotless; 30 focused DataNode tests; Chinese-locale test-compile; git diff --check. Remote CI was not awaited.
  • Final local SHA: 32ca26c93591c223b2e67361c873f3b436e1fcd0.
  • Confirmed source-branch and PR head SHA: 32ca26c93591c223b2e67361c873f3b436e1fcd0.

@sonarqubecloud

Copy link
Copy Markdown

@jt2594838
jt2594838 merged commit 7b386bf into master Nov 26, 2026
41 of 42 checks passed
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.

3 participants