From e2ec9db371b731b74d4cc6a50857bf6e908d0ce2 Mon Sep 17 00:00:00 2001 From: leventov Date: Tue, 9 Feb 2016 14:57:44 +0700 Subject: [PATCH] Register Chronicle Map's randomAccessFile cleaner only after all creation/recovery procedures complete, to avoid double release --- .../chronicle/hash/impl/VanillaChronicleHash.java | 15 +++++++++------ .../chronicle/map/ChronicleMapBuilder.java | 11 +++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index dec6ed9c3..b9b1a873f 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -129,7 +129,7 @@ public abstract class VanillaChronicleHash implements //noinspection ResultOfMethodCallIgnored file.createNewFile(); } - ChronicleMap result = null; + VanillaChronicleMap result = null; RandomAccessFile raf = CanonicalRandomAccessFiles.acquire(file); try { if (raf.length() > 0) @@ -1461,8 +1461,11 @@ public final class ChronicleMapBuilder implements return result = openWithExistingFile(file, raf, recover, overrideBuilderConfig); } } finally { - if (result == null) + if (result != null) { + result.registerRafReleaser(); + } else { CanonicalRandomAccessFiles.release(file); + } } } @@ -1558,7 +1561,7 @@ public final class ChronicleMapBuilder implements return LongHashFunction.xx_r39().hashBytes(headerBuffer, SIZE_WORD_OFFSET, headerSize + 4); } - private ChronicleMap createWithNewFile( + private VanillaChronicleMap createWithNewFile( VanillaChronicleMap map, File file, RandomAccessFile raf, ByteBuffer headerBuffer, int headerSize) throws IOException { FileChannel fileChannel = raf.getChannel(); @@ -1569,7 +1572,7 @@ public final class ChronicleMapBuilder implements return map; } - private ChronicleMap openWithExistingFile( + private VanillaChronicleMap openWithExistingFile( File file, RandomAccessFile raf, boolean recover, boolean overrideBuilderConfig) throws IOException { try {