Repository navigation
Conversation
|
Could I haven’t reproduced this interleaving. The new test blocks inside an overridden |
|
Hey @shihchengwei-lab Thanks for the review, Addressed your concern by waiting for the real download worker to finish before deleting the snapshot directory, and also Added a regression test covering the stream-registration and cleanup race. PTAL another look when you have some time, Thanks again |
532182a to
0022952
Compare
|
The CI failure is in FlinkSourceEnumeratorTest.testBatchPartitionFilterOnlyGeneratesMatchingPartitionSplits, failing with UnknownTableOrBucketException while listing offsets. This test seems unrelated to the KV snapshot scanner changes, which only modify download cancellation and cleanup |
|
Thanks for updating this. Suppose worker B has registered its input stream and pauses just before creating the local directory. Worker A then fails, and the initialization thread starts waiting in I traced this sequence in the code but haven’t reproduced it in a test. |
0022952 to
fa8a949
Compare
|
@shihchengwei-lab Thanks for tracing it further. I changed the failure path to wait uninterruptibly for every download future before cleanup, preserving the interrupt for the caller afterward. Combined with the cancellation checks around directory/file creation, the directory cannot be deleted until the workers have finished. The focused scanner tests pass. |
|
Hi @swuferhong Thanks for Re trigerring the CI multiple times, Still it is failing, since we Merged the fix yesterday, Let me rebase the PR |
fa8a949 to
cc29404
Compare
polyzos
left a comment
There was a problem hiding this comment.
Thanks @pbanakar for picking this up, the overall approach looks right.
Two asks beyond the inline comments:
- The description says
close()no longer waits for the download. It now does, so please update it. - The change to the shared download utility also affects tablet-server KV recovery: on failure it now waits for in-flight downloads before cleanup. Could you mention this in the description, and confirm the server download tests still pass?
| () -> { | ||
| if (!closed.get()) { | ||
| initSnapshotFilesReaderException = e; | ||
| readerIsReady.signalAll(); |
There was a problem hiding this comment.
Thanks for the fix! This signal wakes a waiting pollBatch while snapshotFilesReader is still null and closed is false, so line 168 throws an NPE and the real download error is lost. Could pollBatch call ensureNoException() after the await, and return NO_DATA_AVAILABLE if the reader is still null? A test where the download fails while pollBatch is waiting would cover it.
| boolean interrupted = false; | ||
| while (!initExecutor.isTerminated()) { | ||
| try { | ||
| initExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); |
There was a problem hiding this comment.
This makes close() wait with no limit, and ignore interrupts, until every download worker reacts to its stream being closed. How fast that happens depends on the filesystem's stream close(), and close() runs on the Flink fetcher thread during cancellation. Could we bound this wait? Or could the init thread own the final directory delete instead? It already deletes when it sees closed in the catch path. Only the success path at line 256 skips it.
| // Cancel background downloading tasks and abort active download streams. | ||
| IOUtils.closeQuietly(downloadCloseableRegistry); | ||
| if (initFuture != null) { | ||
| initFuture.cancel(true); |
There was a problem hiding this comment.
CompletableFuture.cancel doesn't interrupt the running task. shutdownNow() below does. Could we drop this call and the initFuture field?
There was a problem hiding this comment.
Removed shutdownNow()
| FSDataInputStream inputStream = fileSystem.open(remoteFilePath); | ||
| closeableRegistry.registerCloseable(inputStream); | ||
|
|
||
| if (closeableRegistry.isClosed()) { |
There was a problem hiding this comment.
registerCloseable already closes the argument and throws if the registry is closed, so this check and the one after the output stream is registered can go. Only the check before newOutputStream adds anything.
| assertThat(openStarted.await(10, TimeUnit.SECONDS)).isTrue(); | ||
| closeThread.start(); | ||
| assertThat(inputCloseStarted.await(10, TimeUnit.SECONDS)).isTrue(); | ||
| releaseInputClose.countDown(); |
There was a problem hiding this comment.
Because read() returns -1 at once, the worker may finish and pause in its own close before scanner.close() runs, so this passes for either ordering. Could the worker block in open() instead, and could we assert that closeThread is still alive before releasing it?
|
Thanks @polyzos for the review. I’ve addressed the inline comments and updated the PR description to clarify the bounded close() wait and the shared download utility’s effect on tablet-server KV recovery. The scanner and tablet-server download tests pass. |
Purpose
Linked issue: close #5239
When KvSnapshotBatchScanner was closed during a KV snapshot download, background download workers could continue writing to disk after the scanner deleted the local snapshot directory. On shared TaskManagers, this could cause disk usage to grow after jobs were stopped or cancelled.
This PR closes registered download streams and interrupts the scanner’s initialization task when the scanner is closed. close() waits for initialization for a bounded time; if a worker has not stopped by then, the initialization task performs the final directory cleanup after the workers finish. This prevents cleanup from racing with workers that may still create files.
The shared download utility is also used by tablet-server KV recovery. On download failure, it now closes registered streams and waits for in-flight workers to finish before deleting their target directories.
Brief change log
Tests
API and Format
Does not change any public API, wire protocol, or storage format.
Documentation
Does not introduce new user-facing features or configuration changes.