Skip to content

Optionally skip Pipe events after TsFile close failures - #19507

Draft
Caideyipi wants to merge 8 commits into
apache:masterfrom
Caideyipi:codex/pipe-skip-on-failed-close
Draft

Caideyipi wants to merge 8 commits into
apache:masterfrom
Caideyipi:codex/pipe-skip-on-failed-close

Conversation

@Caideyipi

Copy link
Copy Markdown
Collaborator

Summary

Add the optional source.skip-on-failed-close source parameter, defaulting to false, for DataRegion TsFile events.

When enabled, Pipe advances past a TsFile only after a close failure is recorded and its hardlink is retained with a verified, synced manual-intervention marker. The retained file survives node restart and is removed when the pipe is dropped. If marker creation or validation fails, Pipe continues waiting and does not advance progress. The default behavior remains to wait.

Example

With source.skip-on-failed-close=false (the default), a failed TsFile close continues waiting. With source.skip-on-failed-close=true, the same file is skipped and its progress is reported only when the durable retention marker succeeds; if marker creation or sync fails, waiting continues and progress is not reported.

Tests

The focused DataNode test run passed 110 tests, including default waiting, successful retained-file skip/progress, marker-failure waiting, restart retention, multi-directory restoration, and pipe-drop cleanup.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Re-review summary

Reviewed head 0f45d964c6456608fab8fe44fd19b490fe094347. Found a Windows-specific blocker: FileChannel.open(directory, READ) cannot open directory handles on Windows, so marker creation failed and source.skip-on-failed-close=true kept waiting instead of advancing. Fixed in 1f2a45aec6dfcbe8e1981bb39a041fce53658870 with Win32 directory flushing and a regression test that exercises the production sync path.

  • spotless:apply passed.
  • Clean focused DataNode tests passed: 36 tests, no failures or errors.
  • Clean DataNode test-compile with with-zh-locale passed.
  • Full-reactor English test-compile was interrupted at 48/50 modules when available memory fell below 0.6 GiB; DataNode had completed, but the full reactor result is incomplete.
  • Final local commit and confirmed source-branch/PR head: 1f2a45aec6dfcbe8e1981bb39a041fce53658870.
  • PR remains draft pending a fresh independent review.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Independent re-review summary

Reviewed the full PR #19507 diff against master at head 1f2a45aec6dfcbe8e1981bb39a041fce53658870. Found one actionable cleanup issue: when moving an unretained child directory aside failed and bounded direct deletion did not finish in the current round, the remaining path was not queued for retry. Fixed by queuing unfinished child paths for periodic cleanup and adding a deterministic interruption regression test.

  • spotless:apply passed.
  • Clean focused DataNode reactor tests passed: 37 tests, no failures or errors (Windows, JDK 17). The initial forkCount=0 attempt hit Java module access in the existing reflection-based test; the configured forked rerun passed.
  • git diff --check passed.
  • Final local commit and confirmed PR/source-branch head: 77a115b63d83cc33c86683ce7406f1749aa1dc16.
  • PR remains draft pending a fresh independent review.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Independent re-review summary

Reviewed PR #19507 at 77a115b63d83cc33c86683ce7406f1749aa1dc16 against master (current target head 09d4ba803f9c84aee97e4cdd5ee9302023667d81; merge base 493b3867f281ec57841047168ba820256d72659e). Found that sealed realtime TsFile events bypassed source.skip-on-failed-close after a close failure had been recorded, allowing the failed file to be transferred. Fixed this while preserving the sealed fast path when no failure is recorded, with regression coverage. The Windows directory sync/rollback, dropped-pipe cleanup, retry, restart-retention, and failure paths had no further actionable findings.

  • spotless:apply passed.
  • The five relevant DataNode test classes passed: 112 tests, 0 failures, 0 errors, 0 skipped (Windows, JDK 17).
  • git diff --check passed.
  • Final local commit and confirmed source-branch/PR head: 051d7ac995dd14bb12c119f13f17cea629717849.
  • PR remains open and Draft pending a fresh independent re-review.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Self-review update — round 4

Reviewed PR head 051d7ac995dd14bb12c119f13f17cea629717849 and found a timing gap in PipeTsFileInsertionEvent: with source.skip-on-failed-close=true, the sealed-file fast path could accept an event while close was still pending, before a later close failure was recorded. This could release a failed TsFile before failure-retention handling.

  • Fix: require the TsFile resource to be closed before the sealed-file fast path succeeds in this mode.
  • Regression tests cover a wait started before a normal close and a failure recorded after waiting begins.
  • Verification: the focused DataNode test run passed 17 tests (0 failures, 0 errors, 0 skipped) on Windows/JDK 17; spotless:apply and git diff --check passed.
  • Final local commit and confirmed PR/source-branch head: 3672b72eba8c2e7476a839f8a21fd105c36c52ca.
  • The PR remains Draft pending a fresh independent review of the updated head.

@Caideyipi
Caideyipi marked this pull request as ready for review December 3, 2026 09:54
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Independent review summary — round 5

Reviewed the complete diff from merge base 493b3867f281ec57841047168ba820256d72659e through PR head 3672b72eba8c2e7476a839f8a21fd105c36c52ca, including close-failure detection and wait behavior, durable manual-intervention markers, startup/restart restoration, and dropped-pipe cleanup. No actionable findings.

All newly added tests have already been run locally. No code changes were needed in this round; PR #19507 is marked ready for review after confirming that the source branch and PR head still match the reviewed SHA.

final Path marker = scope.resolve(PipeTsFileResource.MANUAL_INTERVENTION_MARKER_DIR);
try {
Files.move(marker, scope.resolve(DROPPED_RETENTION_DIR_NAME));
try (final FileChannel channel = FileChannel.open(scope, StandardOpenOption.READ)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/resource/PipeDataNodeHardlinkOrCopiedFileDirStartupCleaner.java:317 — Dropped-pipe marker rename is never fsynced on Windows

retireManualInterventionMarker makes the Files.move to .manual-intervention-dropped durable with FileChannel.open(scope, READ) on a directory, which always throws on Windows (the exact failure fixed for PipeTsFileResourceManager.forceDirectory in this PR). Trigger: pipe drop of a retained pipe dir while tryMoveDroppedPipeDir fails (a Windows-with-open-handles case this PR retries). Result: the IOException is swallowed into a WARN, the rename is never fsynced, and if it is lost on crash the .manual-intervention-required marker resurrects; since the pipe is already dropped, cleanPipeTsFileDir is never called again and the retained TsFile hardlinks leak permanently.

Fix: Reuse the Windows-aware helper (e.g. make PipeTsFileResourceManager.forceDirectory accessible as a static utility) instead of FileChannel.open(directory, READ); only catch the missing-marker case as ignorable.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in c9301e9b915. The dropped-pipe cleaner now uses PipeTsFileResourceManager.forceDirectoryMetadata, including the Windows-aware directory flush. A missing marker is ignored only during the rename; directory-sync failures are logged.

break;
}

if (skipOnFailedClose && retainTsFileAfterCloseFailure()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/PipeTsFileInsertionEvent.java:409 — Failed marker creation is retried with directory fsync every 100 ms

When a close failure is recorded and marker creation cannot succeed (blocked marker dir, filesystem without hardlinks, missing/unreadable pipe dir), retainTsFileAfterCloseFailure() returns false and the loop re-invokes it on every 100 ms poll iteration forever. Each attempt performs forceDirectory(pipeDir) plus the ancestor fsync chain while holding the isClosed monitor, so a single stuck pipe issues ~10 durable directory flushes per second indefinitely and blocks the TsFile close callback that synchronizes on the same monitor. Their own testFailedCloseWaitsWhenRetentionMarkerDirectoryIsBlocked exercises this repeating path.

Fix: Attempt retention once (or with a growing backoff/next-attempt timestamp) instead of on every poll iteration, and do the fsync work outside the synchronized (isClosed) block.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in c9301e9b915. Retention retries now start at 1 second and back off exponentially to 60 seconds; marker creation and fsync run outside the isClosed monitor. Regression tests cover retry throttling and close-listener progress during a blocked sync.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review Comment Updates

Handled both actionable inline comments on reviewed head f846b4c9cb12b149fb56b43cdf4a78563602af38.

  • Dropped-pipe marker renames now sync directory metadata through the Windows-aware helper; a missing marker is ignored only during the rename, and sync failures are logged.
  • Failed-close retention retries use exponential backoff from 1 second to a 60-second cap. Marker creation and fsync run outside the isClosed monitor.
  • Added regression coverage for directory-handle sync, retry throttling, and close-listener progress during a blocked sync.

Verification

  • mvn spotless:apply -P with-integration-tests -pl iotdb-core/datanode -am passed.
  • Clean DataNode reactor tests passed: 40 tests, 0 failures, 0 errors, 0 skipped.
  • Patch-helper Pester tests passed: 8/8. git diff --check passed.
  • Remote CI status was not checked.

Final local commit and confirmed source-branch/PR head: c9301e9b91574c1288f41aba48daefd66296f97d. PR #19507 remains open and non-draft.

@Caideyipi
Caideyipi marked this pull request as draft December 4, 2026 10:33
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Self-review update — IT coverage

Reviewed PR head 0c4345ac923575797dfa6701431ea1fdb8850d13 against base fba8ff77389ce7ae44ddc641a67e3720e6bdd550. Added an integration test for source.skip-on-failed-close=true, covering extractor parameter visibility and historical plus realtime batch TsFile delivery. No findings in this update.

Verification: Spotless passed; IT selection/shard coverage check passed; git diff --check passed. The targeted Failsafe IT did not complete locally because parallel Java builds exhausted available memory; it is not reported as passing. A fresh independent review of the full updated PR is still required before returning it to open.

Final local commit and confirmed source-branch/PR head: 0c4345ac923575797dfa6701431ea1fdb8850d13. The PR remains draft pending independent review.

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