Repository navigation
Conversation
|
Initial self-review summary (reviewed commit
|
|
Follow-up self-review summary (reviewed commit
|
| tsFileProcessor.asyncFlush(); | ||
| final Future<?> ordinaryFlushFuture = tsFileProcessor.getCloseFuture(); | ||
| Assert.assertNotNull(ordinaryFlushFuture); | ||
| ordinaryFlushFuture.get(); |
There was a problem hiding this comment.
minor iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/DataRegionTest.java:3117 — New test never exercises the full-flush close retry loop it claims to cover
testAsyncFullFlushClosesSpecifiedProcessorAfterOrdinaryAsyncFlush awaits ordinaryFlushFuture.get() before calling asyncCloseOneTsFileProcessorForFullFlush, so managedByFlushManager is already false (FlushManager.FlushThread calls setManagedByFlushManager(false) before the task future completes) and shouldClose is set on the first iteration. The retry branch added in the new wrapper (DataRegion.java:2996-2999: future.get() + waitUntilFlushManagerReleased() + re-loop) is never executed, so a regression there stays undetected.
Fix: Invoke asyncCloseOneTsFileProcessorForFullFlush while an ordinary flush is still blocked (FlushListener latch as in testFullFlushWaitsForRunningOrdinaryAsyncFlush), then release it and assert the processor closes.
There was a problem hiding this comment.
There are no ordinary flushes in the production code
|
Comment follow-up for the review on
|
| return CompletableFuture.completedFuture(null); | ||
| } | ||
|
|
||
| while (!tsFileProcessor.alreadyMarkedClosing()) { |
There was a problem hiding this comment.
major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java:2983 — Removing the blocking wait turns the full-flush close retry into a lock-hammering busy spin
While an ordinary async flush owns the processor (managedByFlushManager==true) the inner call returns the flush future without setting shouldClose, so this loop re-iterates immediately, re-taking the DataRegion insertLock write lock and flushQueryLock with no park until the flush ends: a core spins and inserts starve. If asyncClose keeps failing (it only logs, shouldClose stays false) the loop never terminates. The deleted future.get()/waitUntilFlushManagerReleased() blocked outside the locks, per TsFileProcessor#asyncCloseForFullFlush.
Fix: Restore the blocking wait outside the locks before re-looping, as done in syncCloseAllWorkingAndClosingTsFileProcessors: if (future != null) future.get(); tsFileProcessor.waitUntilFlushManagerReleased();
There was a problem hiding this comment.
There are no ordinary flushes in the production code
|
major extractTsFiles now refreshes only when attempt 1 reports pinFailedCount>0 (line 836 of the source), but these setups swap the manager content and every pin succeeds, so the refresh/fallback branch is never entered: originalResources still holds the stale resource and this assertion (also line 510) fails; the renamed tests at line 652 additionally block for 10s waiting for refreshedReadLockEntered. Commit 66c96e3 dropped the isTsFilePartitionSnapshotCurrent trigger without updating them. Fix: Either keep a snapshot-currency refresh trigger, or make the first attempt fail to pin (e.g. wrap the stale resource in CanonicalPathFailingFile) in testHistoricalExtractionRefreshesReplacedPartitionSnapshot/RefreshesPartitionReplacedDuringScan and assertHistoricalExtractionFallsBackToLockedSnapshot. |
1591114 to
0243c54
Compare
| } | ||
|
|
||
| if (currentResult.snapshotInvalid) { | ||
| if (currentResult.statistics.pinFailedCount > 0) { |
There was a problem hiding this comment.
major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java:836 — pinFailedCount>0 escalates retryable pin failures into a fatal PipeException
A single pin failure is now treated as a stale snapshot. Attempt 1 fails the pin for an unclosed resource (deliberately kept for retry at extractTsFileResource:1062) or for a rolled-back mod pin, the refreshed attempt and the locked-snapshot attempt fail identically, so throw new PipeException(snapshotChangedMessage) aborts the whole historical extraction. testActiveUnclosedTsFilePinFailureKeepsResourceForRetry (invoke at line 232) and testHistoricalModPinFailureRollsBackTsFilePin (line 790) now throw.
Fix: Only treat a pin failure as a stale snapshot when the file really vanished (separate counter for missing-file pins, or skip refresh when !resource.isClosed()); keep retryable unclosed/mod pin failures on the existing supply-time retry path.
There was a problem hiding this comment.
Thanks for the report. I kept production behavior unchanged and aligned the legacy tests with the current retry path: if an unclosed TsFile or mod-file pin keeps failing across refresh/fallback attempts, historical extraction propagates PipeException, and successfully acquired partial pins are rolled back. The snapshot-recovery test now triggers refresh with actual pin failures instead of a manager snapshot change alone. The focused historical extraction test class passes (37 tests).
|
Historical extraction test update
|
| } | ||
|
|
||
| try { | ||
| dataRegion.asyncCloseOneTsFileProcessorForFullFlush(processor); |
There was a problem hiding this comment.
major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java:1012 — Close of refreshed unclosed TsFile is not awaited, so every retry pins the still-open file
closeUnclosedTsFileOnSnapshotRefresh discards the Future returned by DataRegion.asyncCloseOneTsFileProcessorForFullFlush, which returns once shouldClose is set (DataRegionTest line 3171 must await closeFuture.get() for the actual closure). The retry at line 858 and the fallback at line 872 thus extract while the TsFile is still open; a file whose pipe-dir hardlink cannot be created while unclosed (PipeTsFileResourceManager:462-476) fails the pin in all three attempts, so line 883 throws PipeException although the region was just asked to close the file.
Fix: Capture and wait for the close Future (future.get(), or poll resource.isClosed()) before re-extracting, and request the close before the fallback extraction at line 872 instead of after it.
There was a problem hiding this comment.
Fixed in d9bb43042b3c. The refresh now requests close futures for all unclosed resources, then waits for them before pinning; the wait happens outside the TsFileManager read lock. This wait is intentional: when a hard link cannot be created (for example, across file systems), the fallback copies the TsFile, so copying before close completes can produce an incomplete file and stall synchronization. The regression test verifies that all requested futures complete before extraction proceeds, and already-closed resources are not closed again.
| extractTsFilesInPartitionWithTsFileManagerReadLock(tsFileManager, timePartition); | ||
| closeUnclosedTsFilesOnSnapshotRefresh(dataRegion, currentResult.resources); | ||
| if (currentResult.statistics.pinFailedCount > 0 | ||
| || currentResult.statistics.skippedDeletedCount > 0) { |
There was a problem hiding this comment.
minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java:876 — skippedDeletedCount>0 aborts the locked fallback although deleted TsFiles are normally skipped
Only the locked fallback treats skippedDeletedCount>0 as fatal. A TsFile marked DELETED but not yet removed from the list (DataRegion.java:4363 marks the status, then deleteDataDirectlyInFile calls tsFileManager.remove) is visible during the fallback scan, which holds only the tsFileManager read lock, so the removal blocks. The code then throws PipeException and aborts historical extraction, while attempts 1-2 just skip such resources; under the read lock the counter cannot indicate snapshot staleness.
Fix: Remove the skippedDeletedCount condition from the fallback check and keep only pinFailedCount, so deleted-but-not-removed TsFiles are skipped as in the earlier attempts.
There was a problem hiding this comment.
Agreed. skippedDeletedCount records resources marked deleted when extraction examines them; it does not prove that physical deletion has completed. The locked fallback now treats only pin failures as fatal and keeps marked-deleted resources out of the selected and pinned set, so they are not synchronized. Added regression coverage for this case.
|
Review summary (reviewed base SHA: Both review comments are addressed. Snapshot refresh now captures asynchronous close futures and waits outside the Added regression coverage for close-future completion, already-closed resources, and deleted-resource fallback. Verification passed: Spotless and the focused Maven test class (39 tests, 0 failures, 0 errors, 0 skipped). |
| || !areSameTsFileResources(resources.unsequenceResources, currentSnapshot.right)) { | ||
| throw new PipeException(snapshotChangedMessage); | ||
| } | ||
| return extractTsFilesInPartition(resources); |
There was a problem hiding this comment.
major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java:1001 — Locked fallback pins/copies TsFiles while holding the TsFileManager read lock, stalling region writes
extractTsFilesInPartition(resources) runs under tsFileManager.readLock(), and it pins every selected file: pinTsFileResource copies the whole TsFile when the pipe-dir hard link cannot be created (PipeTsFileResourceManager.createHardLinkOrCopy:479). TsFileManager.add/remove/replace need the write lock, and the insert path holds the DataRegion write lock while calling add (DataRegion.java:2404 via getOrCreateTsFileProcessor:1730), so one large copy under the read lock blocks new-processor creation, deletes and compaction for the whole region.
Fix: Hold the read lock only for the snapshot capture and the membership re-validation, and perform pinning (hard link/copy) after releasing it, re-checking membership or holding per-resource read locks instead.
There was a problem hiding this comment.
Thanks for the detailed review. The retry path now reuses references for files that remain selected after the refreshed snapshot is filtered, unpins only resources that are no longer selected, and pins only newly selected resources. If a reused TsFile needs a mod-file reference that was not present earlier, that reference is acquired separately without pinning the TsFile again. This avoids most redundant pinning, hard-linking, and copying for files unaffected by compaction.
The final locked fallback remains a last-resort progress path. Turning every pin race into an exception and relying on a later Pipe Meta Sync retry would make pipe creation latency unpredictable and could require multiple meta sync rounds.
Dedicated lifetime protection for these snapshot files could eventually let copying happen outside the manager lock, but coordinating file replacement, deletion, and reference ownership adds complexity. That optimization is out of scope for this PR; this change retains the fallback while reducing its work through difference-based reuse.
| return future; | ||
| } | ||
| } | ||
| return tsFileProcessor.getCloseFuture(); |
There was a problem hiding this comment.
minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java:2997 — asyncCloseOneTsFileProcessorForFullFlush can return a null close future while another thread is closing
TsFileProcessor.asyncClose publishes shouldClose=true (line 1837) before closeFuture (line 1838), both volatile and read without flushQueryLock. If a concurrent closer (another pipe's flush, mem-control or time-partition rolling) is inside that window, the wrapper skips its loop and returns getCloseFuture()==null; requestCloseOfUnclosedTsFileOnSnapshotRefresh (line 1061) then throws PipeException("Failed to get the close future...") although the TsFile is closing normally, aborting the whole historical extraction.
Fix: Assign closeFuture before shouldClose in TsFileProcessor.asyncClose so shouldClose==true implies a non-null future, and/or retry in the pipe instead of throwing when the future is still null.
There was a problem hiding this comment.
Fixed in a2852f67fb. TsFileProcessor.asyncClose now publishes closeFuture before setting the volatile shouldClose flag. A caller that observes the closing flag can see the published close future, avoiding the race in which historical extraction receives a null future. The focused clean reactor run passed all 41 tests, including historical extraction and the DataRegion full-flush and already-closing-processor cases.
Close-future comment follow-upThe scoped review of the latest minor comment confirmed a publication-order race in
|
| return null; | ||
| }); | ||
|
|
||
| Assert.assertFalse(closeWait.isDone()); |
There was a problem hiding this comment.
minor iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSourceTest.java:447 — Close-wait test asserts before the waiting task starts, so it cannot catch a non-blocking wait
closeWait is submitted and immediately asserted not-done, with no start barrier (compare replacementStarted/fullFlushCloseStarted). If waitForTsFileCloseFuturesOnSnapshotRefresh did not wait at all, the worker may still not have run when both assertFalse(closeWait.isDone()) checks execute, and closeWait.get(10s) still succeeds, so the regression the test targets stays undetected.
Fix: Have the worker count down a latch before invoking the method and await it before the assertions, or assert TimeoutException from closeWait.get(100ms) before completing the futures.
There was a problem hiding this comment.
Thanks for catching this. The worker now signals a start latch before invoking the close-wait method, and the test expects a timed wait to expire before either close future completes. It then verifies that the task is still pending after only the first future completes. This makes the test exercise the blocking behavior rather than relying only on task scheduling.
Review summary
|
| try { | ||
| final Pair<List<TsFileResource>, List<TsFileResource>> currentSnapshot = | ||
| tsFileManager.getAllTsFileListForQuery(Collections.singletonList(timePartition), null); | ||
| if (!areSameTsFileResources(resources.sequenceResources, currentSnapshot.left) |
There was a problem hiding this comment.
major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java:998 — Locked fallback validates an exact snapshot after closing its own captured TsFiles, so its close aborts the extraction
extractTsFilesInPartitionWithTsFileManagerReadLock captures the partition snapshot (line 980), requests close of its unclosed TsFiles (line 991), then still requires areSameTsFileResources to hold (line 998). Closing drops the processor from workSequenceTsFileProcessors (DataRegion.java:3029), so the next insert adds a new TsFile to that partition (DataRegion.java:2404), and closing an empty TsFile removes one from the manager (DataRegion.java:4424). Any such write/removal during the close wait makes the check fail and throws PipeException, aborting the whole historical extraction.
Fix: Request the closes before capturing the snapshot used for the equality check, or re-validate only that the captured resources are still present (containment) instead of requiring the list to be identical.
Purpose
TsFileProcessor.asyncFlush()path has no production call sites and is exercised only by tests.