HCOLL-253 optimized VanillaChronicleMap.HeapWriteLocked.close() (force put), added force replication on NativeWriteLocked.close()

This commit is contained in:
leventov
2014-12-16 12:14:45 +07:00
parent c0df25de32
commit bcc5501499
2 changed files with 33 additions and 10 deletions
@@ -2818,6 +2818,14 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
@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<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
@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();
@@ -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<CharSequence, TestInstrumentVOInterface> map2 = ChronicleMapBuilder.of(CharSequence.class,
try (ChronicleMap<CharSequence, TestInstrumentVOInterface> 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<CharSequence, TestInstrumentVOInterface> wc = map1
.acquireUsingLocked
("KEY1", instrumentVOInterface)) {
try (WriteContext<CharSequence, TestInstrumentVOInterface> wc =
map1.acquireUsingLocked("KEY1", instrumentVOInterface)) {
instrumentVOInterface.setSymbol("Flyer");
instrumentVOInterface.setCurrencyCode("USA");
}