Make loading segment disk cache fail safe in case when write operation is interrupted by failure
Explicitly closing the channel before move operation
@@ -139,8 +139,11 @@ public class PersistentDiskCache extends AbstractPersistentCache {
Runnable task = () -> {
if (writesPending.add(segmentId)) {
+ try {
+ int fileSize;
try (FileChannel channel = new FileOutputStream(tempSegmentFile).getChannel()) {
- int fileSize = bufferCopy.write(channel);
+ fileSize = bufferCopy.write(channel);
+ }
try {
Files.move(tempSegmentFile.toPath(), segmentFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
