diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java index 9bd2ccaf6..25497b177 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/HashQuery.java @@ -30,7 +30,6 @@ import net.openhft.sg.StageRef; import net.openhft.sg.Staged; import static net.openhft.chronicle.hash.impl.stage.query.KeySearch.SearchState.ABSENT; -import static net.openhft.chronicle.hash.impl.stage.query.KeySearch.SearchState.PRESENT; @Staged public abstract class HashQuery implements SetEntry { @@ -70,7 +69,7 @@ public abstract class HashQuery implements SetEntry { if (s.nestedContextsLockedOnSameSegment && s.rootContextLockedOnThisSegment.latestSameThreadSegmentModCount() != s.contextModCount) { - if (ks.keySearchInit() && ks.searchState == PRESENT && + if (ks.keySearchInit() && ks.searchStatePresent() && !hashLookupSearch.checkSlotContainsExpectedKeyAndValue(entry.pos)) { hlp.closeHashLookupPos(); } diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/query/MapQuery.java b/src/main/java/net/openhft/chronicle/map/impl/stage/query/MapQuery.java index 5b24e9094..cafc775cb 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/query/MapQuery.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/query/MapQuery.java @@ -91,13 +91,14 @@ public abstract class MapQuery extends HashQuery protected void putPrefix() { checkOnEachPublicOperation.checkOnEachPublicOperation(); - boolean underUpdatedLockIsHeld = !s.innerUpdateLock.isHeldByCurrentThread(); - if (underUpdatedLockIsHeld) + if (!s.innerUpdateLock.isHeldByCurrentThread()) s.innerUpdateLock.lock(); - boolean searchResultsNotTrusted = underUpdatedLockIsHeld || - s.nestedContextsLockedOnSameSegment; - if (hlp.hashLookupPosInit() && ks.searchStateAbsent() && searchResultsNotTrusted) - hlp.closeHashLookupPos(); + if (s.nestedContextsLockedOnSameSegment && + s.rootContextLockedOnThisSegment.latestSameThreadSegmentModCount() != + s.contextModCount) { + if (hlp.hashLookupPosInit() && ks.searchStateAbsent()) + hlp.closeHashLookupPos(); + } } @Override