diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/AllocatedChunks.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/AllocatedChunks.java index d49981a3c..90ed73c6c 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/AllocatedChunks.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/entry/AllocatedChunks.java @@ -41,7 +41,10 @@ public class AllocatedChunks { public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { initAllocatedChunks(hh.h().inChunks(entrySize)); - entry.copyExistingEntry(s.alloc(allocatedChunks), bytesToCopy); + // call incrementSegmentEntriesIfNeeded() before entry.copyExistingEntry(), because + // the latter clears out searchState, and it performs the search again, but in inconsistent + // state incrementSegmentEntriesIfNeeded(); + entry.copyExistingEntry(s.alloc(allocatedChunks), bytesToCopy); } } diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/SearchAllocatedChunks.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/SearchAllocatedChunks.java index c04a50e1e..47ed42597 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/SearchAllocatedChunks.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/SearchAllocatedChunks.java @@ -39,7 +39,9 @@ public class SearchAllocatedChunks extends AllocatedChunks { public void initEntryAndKey(long entrySize) { initAllocatedChunks(hh.h().inChunks(entrySize)); - entry.writeNewEntry(s.alloc(allocatedChunks), q.inputKey); + // call incrementSegmentEntriesIfNeeded() before entry.writeNewEntry(), because the latter + // clears out searchState, and it performs the search again, but in inconsistent state incrementSegmentEntriesIfNeeded(); + entry.writeNewEntry(s.alloc(allocatedChunks), q.inputKey); } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java b/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java index 9259f36f4..32c0ace1d 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/entry/MapEntryStages.java @@ -52,7 +52,8 @@ public abstract class MapEntryStages extends HashEntryStages @Stage("ValSize") public long valueSize = -1; @Stage("ValSize") public long valueOffset; - @Stage("ValSize") private void countValueOffset() { + @Stage("ValSize") + private void countValueOffset() { mh.m().alignment.alignPositionAddr(entryBytes); valueOffset = entryBytes.position(); }