Skip to content

Pipe: order historical TsFiles by query priority#18088

Open
Caideyipi wants to merge 2 commits into
masterfrom
pipe-history-tsfile-flush-order
Open

Pipe: order historical TsFiles by query priority#18088
Caideyipi wants to merge 2 commits into
masterfrom
pipe-history-tsfile-flush-order

Conversation

@Caideyipi

@Caideyipi Caideyipi commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR adds a historical Pipe source option:

  • extractor.history.tsfile.order-by-query-priority
  • source.history.tsfile.order-by-query-priority
  • default: true

When enabled for historical TsFile-only extraction, selected TsFiles are transferred from lower query/compaction priority to higher priority. This matches the real point coverage semantics used by query and compaction: unsequence files cover sequence files, and within the same seq/unseq category, higher file version wins before higher file-name timestamp.

The receiver loads incoming TsFiles into the unsequence list with monotonically increasing versions, so covered files must be loaded first and covering files later. This preserves duplicated-timestamp overwrite semantics after transfer.

Semantic Changes

For historical TsFile extraction where insertions are captured and deletions are not captured:

  1. Historical working TsFile processors are closed synchronously before extraction, so the source has a stable set of TsFiles to order.
  2. Selected TsFiles are sorted by MergeReaderPriority in ascending order, then by compaction version and file path as deterministic tie-breakers.
  3. TsFiles filtered out by progress, time, path, delete status, pipe-generated status, or pin failure are removed before computing delayed progress. Their progressIndex is not reported by this reordered historical path.
  4. Because query-priority order is not guaranteed to be compatible with progressIndex topological order, per-TsFile commit progress reporting is disabled for reordered historical TsFile events.
  5. Tablet events generated from those TsFile events inherit the no-report behavior, so decomposing a TsFile into tablets does not accidentally advance progress early.
  6. After all selected reordered historical TsFiles are supplied, the source emits one ProgressReportEvent with the max progressIndex of the selected resources.

When historical deletions are captured together with insertions, the source keeps the previous progressIndex ordering. Deletion resources only carry progressIndex ordering information, so this avoids changing insertion/deletion ordering semantics.

The option can be set to false to keep the previous progressIndex-based ordering.

Tests / Coverage

Added or updated unit coverage for:

  • the new option defaulting to true,
  • both source.* and extractor.* disable keys,
  • ordering by real query coverage priority, including version before file-name timestamp and unseq after seq,
  • falling back to progressIndex order when deletions are extracted together with insertions,
  • delaying progress reporting until all reordered historical resources are consumed,
  • excluding filtered-out TsFiles from the delayed max progressIndex,
  • preserving the no-progress-report flag when a TsFile event is shallow-copied,
  • making generated tablet events inherit the source TsFile event's no-progress-report behavior.

I did not add an integration test because ordinary end-to-end SQL write scenarios do not deterministically create the exact file-version/file-timestamp/seq-unseq priority conflicts needed for this regression. The deterministic behavior that matters here is the historical source's resource ordering and progress reporting contract, which is covered by unit tests with explicit TsFileResource setup.

Local verification:

  • mvn spotless:apply -pl iotdb-core/datanode
  • mvn spotless:apply -pl iotdb-core/node-commons
  • mvn "-Ddevelocity.off=true" -o install -pl iotdb-core/node-commons "-DskipTests=true" "-Dcheckstyle.skip=true" "-Dspotless.check.skip=true"
  • git diff --check

Attempted targeted datanode UT execution with:

  • mvn -U "-Ddevelocity.off=true" test -pl iotdb-core/datanode -Dtest=PipeHistoricalDataRegionTsFileAndDeletionSourceTest -DfailIfNoTests=false

It failed before test execution because the configured repositories do not currently contain org.apache.iotdb:iotdb-thrift:jar:2.0.7-20260702.105822-1.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.72816% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.66%. Comparing base (220e7a3) to head (528c372).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...peHistoricalDataRegionTsFileAndDeletionSource.java 70.51% 23 Missing ⚠️
.../event/common/tsfile/PipeTsFileInsertionEvent.java 77.77% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18088      +/-   ##
============================================
+ Coverage     41.65%   41.66%   +0.01%     
  Complexity      318      318              
============================================
  Files          5296     5296              
  Lines        371663   371760      +97     
  Branches      48088    48101      +13     
============================================
+ Hits         154819   154908      +89     
- Misses       216844   216852       +8     

☔ 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 changed the title Pipe: order historical TsFiles by flush time Pipe: order historical TsFiles by query priority Jul 3, 2026
@sonarqubecloud

sonarqubecloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

Comment on lines +990 to +1009
while (true) {
final PersistentResource resource = pendingQueue.peek();
if (resource == null) {
if (shouldReportMaxHistoricalProgressIndex) {
shouldReportMaxHistoricalProgressIndex = false;
return supplyProgressReportEvent(maxHistoricalProgressIndex);
}
return supplyTerminateEvent();
}

if (resource instanceof TsFileResource) {
final TsFileResource tsFileResource = (TsFileResource) resource;
if (consumeSkippedHistoricalTsFileEventIfNecessary(tsFileResource)) {
clearReplicateIndexForResource(tsFileResource);
pendingQueue.poll();
if (shouldUseHistoricalTsFileQueryPriorityOrder()) {
continue;
}
return supplyProgressReportEvent(tsFileResource.getMaxProgressIndex());
}

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.

The historical task will only report progress once, which means if the pipe is restarted, all files will be retransmitted?

The cost is just too high. Maybe we can find some resources that can still be reported after processing.
For example, if we use a simple integer to represent the progressIndex of each TsFile, and we have 5 TsFiles ordered by the query order:
[1, 2, 4, 3, 5]
Then we can report progress on TsFile 1, 2, 3, 5, because for these files, we know that there is no file that is behind them and has a smaller index than them.

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.

2 participants