diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 88abf77df..d86a193eb 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -255,45 +255,47 @@ class ReplicatedChronicleMap, return (Segment) segments[segmentNum]; } + @Override T lookupUsing(K key, V value, LockType lockTypeType) { checkKey(key); ThreadLocalCopies copies = keyInteropProvider.getCopies(null); - KI keyInterop = keyInteropProvider.get(copies, originalKeyInterop); + KI keyWriter = keyInteropProvider.get(copies, originalKeyInterop); copies = metaKeyInteropProvider.getCopies(copies); - MKI metaKeyInterop = - metaKeyInteropProvider.get(copies, originalMetaKeyInterop, keyInterop, key); - long hash = metaKeyInterop.hash(keyInterop, key); + MKI metaKeyWriter = + metaKeyInteropProvider.get(copies, originalMetaKeyInterop, keyWriter, key); + long hash = metaKeyWriter.hash(keyWriter, key); int segmentNum = getSegment(hash); long segmentHash = segmentHash(hash); + boolean create =lockTypeType == LockType.WRITE_LOCK; Segment segment = segment(segmentNum); + MutableLockedEntry lock = (lockTypeType == LockType.WRITE_LOCK) ? segment.writeLock() : segment.readLock(); - V v = segment.acquireWithoutLock(copies, metaKeyInterop, keyInterop, key, value, - segmentHash, lockTypeType == LockType.WRITE_LOCK, - (lockTypeType == LockType.WRITE_LOCK) ? timeProvider.currentTimeMillis() : 0L); + V v = segment.acquireWithoutLock(copies, metaKeyWriter, keyWriter, key, + value, + segmentHash, create, create ? timeProvider.currentTimeMillis() : 0L); + lock.copies = copies; + lock.metaKeyInterop = metaKeyWriter; + lock.keyInterop = keyWriter; + lock.segmentHash = segmentHash; - // we want to call put on heap objects that don't currently exist in the map - if (v == null && !isNativeValueClass && lockTypeType == LockType.WRITE_LOCK) { - lock.copies = copies; - lock.metaKeyInterop = metaKeyInterop; - lock.keyInterop = keyInterop; - lock.segmentHash = segmentHash; + if (!isNativeValueClass && lockTypeType == LockType.WRITE_LOCK && v == null) v = value; - } - - //todo set dirty when using replication on lock.value(v); lock.key(key); return (T) lock; - } + + + + @Override public V remove(final Object key) { return removeIfValueIs(key, null, localIdentifier, timeProvider.currentTimeMillis()); diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 9a5c0ea95..7046cde57 100644 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -420,7 +420,6 @@ class VanillaChronicleMap, lock.metaKeyInterop = metaKeyInterop; lock.keyInterop = keyInterop; lock.segmentHash = segmentHash; - lock.value = null; // todo is this really needed? if (!isNativeValueClass && lockTypeType == LockType.WRITE_LOCK && v == null) v = value; @@ -1419,8 +1418,7 @@ class VanillaChronicleMap, @Override public void removeEntry() { - if (copies != null) - removeWithoutLock(copies, metaKeyInterop, keyInterop, key(), null, segmentHash); + removeWithoutLock(copies, metaKeyInterop, keyInterop, key(), null, segmentHash); } } @@ -1434,9 +1432,7 @@ class VanillaChronicleMap, putWithoutLock(copies, metaKeyInterop, keyInterop, key(), value(), segmentHash, true); - copies = null; putOnClose = true; - Segment.this.writeUnlock(); } @@ -1638,6 +1634,7 @@ class VanillaChronicleMap, KI keyInterop; long segmentHash; + private K key; private V value;