diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index 693880efb..c232e1b09 100644 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -167,6 +167,7 @@ public final class ChronicleMapBuilder implements } }; private static final int MAX_BOOTSTRAPPING_HEADER_SIZE = (int) MemoryUnit.KILOBYTES.toBytes(16); + private static final boolean MAP_CREATION_DEBUG = Jvm.getBoolean("chronicle.map.creation.debug"); SerializationBuilder keyBuilder; SerializationBuilder valueBuilder; @@ -1829,6 +1830,11 @@ public final class ChronicleMapBuilder implements @NotNull final ChronicleHashResources resources, @NotNull final ByteBuffer headerBuffer, final int headerSize) throws IOException { + if (MAP_CREATION_DEBUG) { + Jvm.warn().on(getClass(), " File [canonizedMapDataFile=" + canonicalFile.getAbsolutePath() + + "] is missing or empty, creating Map from scratch"); + } + map.initBeforeMapping(canonicalFile, raf, headerBuffer.limit(), false); map.createMappedStoreAndSegments(resources); FileLockUtil.acquireSharedFileLock(canonicalFile, raf.getChannel()); @@ -1851,6 +1857,12 @@ public final class ChronicleMapBuilder implements if (headerSize != headerBuffer.remaining()) throw new AssertionError(); final boolean headerCorrect = checkSumSelfBootstrappingHeader(headerBuffer, headerSize); + + if (MAP_CREATION_DEBUG) { + Jvm.warn().on(getClass(), " Using existing file [canonizedMapDataFile=" + file.getAbsolutePath() + + ", size=" + raf.length() + ", headerCorrect=" + headerCorrect + "] for map creation"); + } + boolean headerWritten = false; if (!headerCorrect) { if (overrideBuilderConfig) { @@ -1868,6 +1880,12 @@ public final class ChronicleMapBuilder implements headerBytes.readPosition(headerBuffer.position()); headerBytes.readLimit(headerBuffer.limit()); final Wire wire = new TextWire(headerBytes); + + if (MAP_CREATION_DEBUG) { + Jvm.warn().on(getClass(), " Read header from file [canonizedMapDataFile=" + + file.getAbsolutePath() + "]: " + wire.toString()); + } + final VanillaChronicleMap map = wire.getValueIn().typedMarshallable(); map.initBeforeMapping(file, raf, headerBuffer.limit(), recover); @@ -1896,6 +1914,11 @@ public final class ChronicleMapBuilder implements commitChronicleMapReady(map, raf, headerBuffer, headerSize); } map.addCloseable(() -> FileLockUtil.releaseFileLock(file)); + if (MAP_CREATION_DEBUG) { + Jvm.warn().on(getClass(), " Created map [name=" + map.name() + + ", size=" + map.longSize() + "] from file [canonizedMapDataFile=" + + file.getAbsolutePath() + "]"); + } return map; } catch (Throwable t) { if (recover && !(t instanceof IOException) &&