Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -121,11 +122,36 @@ public synchronized void close() throws IOException {
allocatedMemoryBlock = null;
}

Files.deleteIfExists(hardlinkOrCopiedFile.toPath());
deleteFileWithRetry(hardlinkOrCopiedFile.toPath());

LOGGER.info("PipeTsFileResource: Closed tsfile {} and cleaned up.", hardlinkOrCopiedFile);
}

private void deleteFileWithRetry(Path path) throws IOException {
final int maxRetries = 10;
final long waitIntervalInMs = 5000;

for (int i = 0; i < maxRetries; i++) {
try {
if (Files.deleteIfExists(path)) {
return;
}
} catch (IOException e) {
LOGGER.warn("Delete file failed, retrying... (" + (i + 1) + "/" + maxRetries + ")", e);
}

try {
Thread.sleep(waitIntervalInMs * i);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted while deleting tsfile: " + path, e);
}
}

LOGGER.error("Failed to delete file, max retry times reached: " + path);
throw new IOException("Failed to delete file: " + path);
}

//////////////////////////// Cache Getter ////////////////////////////

public synchronized Map<String, List<String>> tryGetDeviceMeasurementsMap() throws IOException {
Expand Down