From d2b67c3e7bc5053fcce50d0dc16f7026fdbcad7f Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Fri, 16 Nov 2018 16:57:06 +0000 Subject: [PATCH] attempting to get net.openhft.chronicle.map.MissSizedMapsTest to work --- pom.xml | 2 +- .../net/openhft/chronicle/map/MapMethods.java | 14 +-- .../chronicle/map/MissSizedMapsTest.java | 100 +++++++++++++----- .../chronicle/map/VanillaChronicleMap.java | 19 ++++ .../map/impl/stage/entry/MapEntryStages.java | 6 +- .../stage/entry/ReplicatedMapEntryStages.java | 4 +- 6 files changed, 99 insertions(+), 46 deletions(-) diff --git a/pom.xml b/pom.xml index 641b12c16..41ac013e0 100755 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ net.openhft chronicle-bom - 2.17.44 + 2.17-SNAPSHOT pom import diff --git a/src/main/java/net/openhft/chronicle/map/MapMethods.java b/src/main/java/net/openhft/chronicle/map/MapMethods.java index f9f603f8a..66a026dc2 100644 --- a/src/main/java/net/openhft/chronicle/map/MapMethods.java +++ b/src/main/java/net/openhft/chronicle/map/MapMethods.java @@ -82,13 +82,7 @@ public interface MapMethods { // between, that will break ConcurrentMap.put() atomicity guarantee. So, we acquire // update lock from the start: q.updateLock().lock(); - if (MissSizedMapsTest.COUNT_1.get() == 99504) { - assert "9|19633|4|1|1|testHarness".equals(q.queriedKey().toString()); - System.out.println(""); - ((CompiledMapQueryContext)q).initKeySearch(); - assert ((CompiledMapQueryContext)q).searchState() == PRESENT; - - } + MapEntry entry = q.entry(); if (entry != null) { returnValue.returnValue(entry.value()); @@ -97,12 +91,6 @@ public interface MapMethods { q.insert(q.absentEntry(), value); } - if ("9|19633|4|1|1|testHarness".equals(q.queriedKey().toString()) ){ - ((CompiledMapQueryContext)q).initKeySearch(); - assert ((CompiledMapQueryContext)q).searchState() == PRESENT; - } - - } /** diff --git a/src/main/java/net/openhft/chronicle/map/MissSizedMapsTest.java b/src/main/java/net/openhft/chronicle/map/MissSizedMapsTest.java index a407bf193..578fca41f 100755 --- a/src/main/java/net/openhft/chronicle/map/MissSizedMapsTest.java +++ b/src/main/java/net/openhft/chronicle/map/MissSizedMapsTest.java @@ -14,6 +14,9 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import static net.openhft.chronicle.algo.bitset.ReusableBitSet.INSTANCE; +import static net.openhft.chronicle.map.VanillaChronicleMap.*; + /** * Created by catst01 on 24/10/2018. */ @@ -49,10 +52,13 @@ public class MissSizedMapsTest { private static ChronicleMap createMapInstance() throws IOException { return ChronicleMapBuilder.of(String.class, String.class) .averageKey("D-6.0149935894066442E18").averageValue("226|16533|4|1|1|testHarness").entries(150 << 10) + .actualSegments(1) .createPersistedTo(File.createTempFile("chronicle", "cmap")); } - AtomicBoolean writtenKey = new AtomicBoolean(); + AtomicBoolean w30 = new AtomicBoolean(); + + String v; private boolean check(final ChronicleMap actual, String s, @@ -60,44 +66,83 @@ public class MissSizedMapsTest { AtomicInteger count, String lable) { String[] split = s.split("&"); String key = split[0]; - Object old = expected.put(key, split[1]); - //System.out.println("old=" + old); - //if (old == null) - - if (count.get() == 85124) { - boolean before = actual.containsKey("9|19633|4|1|1|testHarness"); - actual.put(key, split[1].substring(0, split[1].length() - 4)); - boolean after = actual.containsKey("9|19633|4|1|1|testHarness"); - - System.out.println("before=" + before); - System.out.println("after=" + after); + String value = split[1]; + if (key.equals("30|5235|4|1|1|testHarness")) { + System.out.println(INSTANCE.isSet(124851)); + System.out.println(""); } - if (key.equals("9|19633|4|1|1|testHarness")) { - writtenKey.set(true); + if ("27|31|4|1|1|testHarness".equals(key)) { + System.out.println(""); } - if (count.get() == 99504) - actual.put(key, split[1]); - else - actual.put(key, split[1]); + if (count.get() == 52592) { + + System.out.println("BEFORE PUT \t- expected=" + expected.size() + ", actual= " + actual.size()); + System.out.println(INSTANCE.isSet(124851)); + + int start = 4968576; + long end = 4968754; + System.out.println(bSeg.toHexString(start, end - start)); + Object old = expected.put(key, value); + String old1 = actual.put(key, value); + // assert old1 == null; + + System.out.println("AFTER PUT \t- expected=" + expected.size() + ", actual= " + actual.size()); + printRow(actual, key); + + /* if (expected.size() != actual.size()) { + + String k = actual.keySet()) .forEach(e -> expected.containsKey(e)); + + System.out.println("expected keyset=" + expected.keySet()); + System.out.println("actual keyset=" + actual.keySet()); + }*/ + + } else { + Object old = expected.put(key, value); + actual.put(key, value); + + if (w30.get() && !actual.containsKey("30|5235|4|1|1|testHarness")) { + System.out.println("\n\n\n\n" + key); + } + printRow(actual, key); + } + + if (key.equals("30|5235|4|1|1|testHarness")) + w30.set(true); + + + + /* if ("5|2311|4|1|1|testHarness".equals(key)) + System.out.println(expected.containsKey("9|19633|4|1|1|testHarness")); +*/ count.incrementAndGet(); - if (!actual.containsKey(key)) - System.out.println("key"); - - if (actual.size() != expected.size()) { - System.out.println(lable + " count=" + count.get()); + if (expected.size() != actual.size()) { + System.out.println("expected=" + expected.size()); + System.out.println("actual=" + actual.size()); return false; } - if (writtenKey.get()) { - if (!actual.containsKey("9|19633|4|1|1|testHarness")) - System.out.println("it got coruppted here"); + return true; + } + + private void printRow(final ChronicleMap actual, final String key) { + String s1 = actual.get(key); + System.out.println(lower + " - " + upper + + "\t " + + "key=" + key + ",\t value=" + s1 + "\t" + " " + + "start=0x" + Long.toHexString(start) + ", end=0x" + Long.toHexString(end + 4)); + + if (start >= 0x4bd0c0 && end <= 0x4bd0f6) { + int start = 0x4bd0c0 - 64; + long end = VanillaChronicleMap.end + 64; + System.out.println(bSeg.toHexString(start, end - start)); + return; } - return true; } @NotNull @@ -108,3 +153,4 @@ public class MissSizedMapsTest { } } + diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index bf9ceef5a..9ea6e2fa6 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -614,6 +614,7 @@ public class VanillaChronicleMap } long keySizeOffset = entrySpaceOffset + (entryPos * chunkSize); + bs.readLimit(bs.capacity()); bs.readPosition(keySizeOffset); long keySize = keySizeMarshaller.readSize(bs); @@ -625,11 +626,29 @@ public class VanillaChronicleMap long valueSizeOffset = keyOffset + keySize; bs.readPosition(valueSizeOffset); long valueSize = readValueSize(bs); + + q.initInputKey(inputKey); + q.entry(); + lower = q.pos(); + long l1 = 4 + (q.entryEnd() - q.keySizeOffset()); + long l = q.m().inChunks(l1); + + start = q.keySizeOffset(); + end = q.entryEnd(); + + upper = q.pos() + l; + bSeg = bs; return q.valueReader.read(bs, valueSize, using); } return null; } + public static long lower; + public static long upper; + public static long start; + public static long end; + public static Bytes bSeg; + @Override public V getUsing(K key, V usingValue) { return defaultEntryOperationsAndMethods ? optimizedGet(key, usingValue) : 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 8c6d58dc4..6b59b780f 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 @@ -145,7 +145,7 @@ public abstract class MapEntryStages extends HashEntryStages if (s.realloc(pos, entrySizeInChunks, newSizeInChunks)) { break newValueDoesNotFit; } - relocation(newValue, newSizeOfEverythingBeforeValue); + relocation(newValue, newEntrySize); return; } else if (newSizeInChunks < entrySizeInChunks) { s.freeExtra(pos, entrySizeInChunks, newSizeInChunks); @@ -186,8 +186,8 @@ public abstract class MapEntryStages extends HashEntryStages newValueOffset + newValue.size() - entryStartOffset; } - protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + protected void relocation(Data newValue, long entrySize) { + // long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); // need to copy, because in initEntryAndKeyCopying(), in alloc(), nextTier() called -> // hashLookupPos cleared, as a dependant long oldHashLookupPos = hlp.hashLookupPos; diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/entry/ReplicatedMapEntryStages.java b/src/main/java/net/openhft/chronicle/map/impl/stage/entry/ReplicatedMapEntryStages.java index 6716a013d..3fd1764df 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/entry/ReplicatedMapEntryStages.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/entry/ReplicatedMapEntryStages.java @@ -167,10 +167,10 @@ public abstract class ReplicatedMapEntryStages extends MapEntryStages newValue, long newSizeOfEverythingBeforeValue) { + protected void relocation(Data newValue, long entrySize) { long oldPos = pos; long oldTierIndex = s.tierIndex; - super.relocation(newValue, newSizeOfEverythingBeforeValue); + super.relocation(newValue, entrySize); ru.moveChange(oldTierIndex, oldPos, pos); }