Kaixuan-Duan commented on code in PR #3132:
URL: https://github.com/apache/fluss/pull/3132#discussion_r3224035208
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/RemoteLogFetcher.java:
##########
@@ -189,16 +294,80 @@ private File downloadSegment(RemoteLogSegment segment)
throws IOException {
segment.remoteLogEndOffset(),
localFile);
+ boolean success = false;
try (InputStream inputStream = remoteLogStorage.fetchLogData(segment);
OutputStream outputStream =
Files.newOutputStream(localFile.toPath())) {
IOUtils.copyBytes(inputStream, outputStream, false);
+ success = true;
} catch (RemoteStorageException e) {
throw new IOException(
"Failed to download remote log segment: " +
segment.remoteLogSegmentId(), e);
+ } finally {
+ // Most remote/file InputStreams don't honor Thread.interrupt()
mid-read: the
+ // call simply returns a normally-completed copy and we'd fall
through with
+ // success=true while the worker has been interrupted by
close()/cancel(true).
+ // Treat "interrupt observed during the copy" as a failure for
cleanup purposes
+ // so we don't leave a stale segment file behind in tempDir.
+ if (!success || Thread.currentThread().isInterrupted()) {
Review Comment:
Fixed. Added || Thread.currentThread().isInterrupted() to the finally block:
if the copy succeeds but the thread was interrupted, the file is deleted and
IOException is thrown instead of returning a dangling reference.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]