diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 3164a834c..c286c476f 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -2818,6 +2818,14 @@ class VanillaChronicleMap, @Override public void close() { + // TODO optimize -- keep replication bytes offset in SegmentState to jump directly + long pos = segmentState.pos; + long offset = segment.offsetFromPos(pos); + MultiStoreBytes entry = segment.reuse(segmentState.tmpBytes, offset); + long keySize = map.keySizeMarshaller.readSize(entry); + entry.skip(keySize); + segment.manageReplicationBytes(entry, true, false); + map.onPut(segment, pos); segmentState.close(); segment.writeUnlock(); } @@ -2849,9 +2857,25 @@ class VanillaChronicleMap, @Override public void close() { if (putOnClose) { - segment.putWithoutLock(copies, segmentState, - metaKeyInterop, keyInterop, key(), keySize, map.keyIdentity(), - map, value(), map.valueIdentity(), segmentHash, true, map, true); + // TODO optimize -- keep keySize, valueSizePos, entryEndAddr, etc. inside + // segmentState + long pos = segmentState.pos; + long offset = segment.offsetFromPos(pos); + MultiStoreBytes entry = segment.reuse(segmentState.tmpBytes, offset); + long keySize = map.keySizeMarshaller.readSize(entry); + entry.skip(keySize); + segment.manageReplicationBytes(entry, true, false); + long valueSizePos = entry.position(); + long valueSize = map.readValueSize(entry); + long entryEndAddr = entry.positionAddr() + valueSize; + VI valueInterop = map.valueInteropProvider.get(copies, map.originalValueInterop); + V value = value(); + MVI metaValueInterop = map.metaValueInteropProvider + .get(copies, map.originalMetaValueInterop, valueInterop, value); + long newValueSize = metaValueInterop.size(valueInterop, value); + segment.putValue(pos, offset, entry, valueSizePos, entryEndAddr, segmentState, + metaValueInterop, valueInterop, value, newValueSize, segment.hashLookup()); + map.onPut(segment, segmentState.pos); } putOnClose = true; segmentState.close(); diff --git a/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java b/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java index d71615c9a..d802908fc 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpReplicationWithAcquireUsingLockedTest.java @@ -3,7 +3,6 @@ package net.openhft.chronicle.map; import eg.TestInstrumentVOInterface; import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import java.net.InetSocketAddress; @@ -14,7 +13,6 @@ import java.net.InetSocketAddress; public class TcpReplicationWithAcquireUsingLockedTest { - @Ignore("HCOLL-253 TcpReplication is not working when used with acquireUsingLocked") @Test public void testReplicationWithAcquireUsingLocked() throws Exception { @@ -31,10 +29,12 @@ public class TcpReplicationWithAcquireUsingLockedTest { map1a = map1; - TcpTransportAndNetworkConfig config2 = TcpTransportAndNetworkConfig.of(8077, new InetSocketAddress("127.0.0.1", 8076)); + TcpTransportAndNetworkConfig config2 = + TcpTransportAndNetworkConfig.of(8077, new InetSocketAddress("127.0.0.1", 8076)); - try (ChronicleMap map2 = ChronicleMapBuilder.of(CharSequence.class, + try (ChronicleMap map2 = + ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class) .replication((byte) 2, config2) .create()) { @@ -45,9 +45,8 @@ public class TcpReplicationWithAcquireUsingLockedTest { TestInstrumentVOInterface instrumentVOInterface = map1.newValueInstance(); - try (WriteContext wc = map1 - .acquireUsingLocked - ("KEY1", instrumentVOInterface)) { + try (WriteContext wc = + map1.acquireUsingLocked("KEY1", instrumentVOInterface)) { instrumentVOInterface.setSymbol("Flyer"); instrumentVOInterface.setCurrencyCode("USA"); }