From b73f2b60580f6736ae5caae5e3caf0dd06fdb19b Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Tue, 2 Jun 2015 19:04:59 +0100 Subject: [PATCH 1/5] fixed typo --- .../java/net/openhft/chronicle/hash/locks/InterProcessLock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/hash/locks/InterProcessLock.java b/src/main/java/net/openhft/chronicle/hash/locks/InterProcessLock.java index c924eca78..ad82e9677 100644 --- a/src/main/java/net/openhft/chronicle/hash/locks/InterProcessLock.java +++ b/src/main/java/net/openhft/chronicle/hash/locks/InterProcessLock.java @@ -26,7 +26,7 @@ import java.util.concurrent.locks.Lock; /** * Abstracts inter-process lock of {@link ChronicleHash} data: segments, entries. * - *

This lock is not reentrant, but kind of "saturating": multiple {@link #lock()} calls has + *

This lock is not reentrant, but kind of "saturating": multiple {@link #lock()} calls have * the same effect as a single call. Likewise {@link #unlock()} -- multiple unlocks, or "unlocking" * when the lock isn't actually held, has no negative effects. * From 8fa83d42c900f82f65ef095a7a77fda6485e1bda Mon Sep 17 00:00:00 2001 From: danielshaya Date: Tue, 2 Jun 2015 21:42:09 +0100 Subject: [PATCH 2/5] Removed FilePerKeyMap (now only in Engine) --- .../net/openhft/chronicle/map/FPMEvent.java | 64 ---- .../chronicle/map/FilePerKeyChronicleMap.java | 232 ------------ .../openhft/chronicle/map/FilePerKeyMap.java | 358 ------------------ .../chronicle/map/FilePerKeyMapTest.java | 166 -------- 4 files changed, 820 deletions(-) delete mode 100644 src/main/java/net/openhft/chronicle/map/FPMEvent.java delete mode 100644 src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java delete mode 100644 src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java delete mode 100644 src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java diff --git a/src/main/java/net/openhft/chronicle/map/FPMEvent.java b/src/main/java/net/openhft/chronicle/map/FPMEvent.java deleted file mode 100644 index c2153b050..000000000 --- a/src/main/java/net/openhft/chronicle/map/FPMEvent.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.openhft.chronicle.map; - -/** - * Created by daniel on 23/04/15. - */ -public class FPMEvent { - private EventType eventType; - private String key; - private String value; - private String lastValue; - - public FPMEvent(EventType eventType, String key, String lastValue, String value) { - this.eventType = eventType; - this.key = key; - this.value = value; - this.lastValue = lastValue; - } - - public String getLastValue() { - return lastValue; - } - - public void setLastValue(String lastValue) { - this.lastValue = lastValue; - } - - public EventType getEventType() { - return eventType; - } - - public void setEventType(EventType eventType) { - this.eventType = eventType; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @Override - public String toString() { - return "FPMEvent{" + - "eventType=" + eventType + - ", key='" + key + '\'' + - ", value='" + value + '\'' + - ", lastValue='" + lastValue + '\'' + - '}'; - } - - public enum EventType {NEW, UPDATE, DELETE} - - -} diff --git a/src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java b/src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java deleted file mode 100644 index a7b5bfed0..000000000 --- a/src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java +++ /dev/null @@ -1,232 +0,0 @@ -package net.openhft.chronicle.map; - -import net.openhft.chronicle.hash.Value; -import net.openhft.chronicle.hash.function.SerializableFunction; -import net.openhft.lang.Jvm; -import org.jetbrains.annotations.NotNull; -import org.xerial.snappy.SnappyInputStream; -import org.xerial.snappy.SnappyOutputStream; - -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -/** - * Created by daniel on 22/04/15. - */ -public class FilePerKeyChronicleMap implements ChronicleMap { - // private final ChronicleMap chMap; - private final FilePerKeyMap fpMap; - - public FilePerKeyChronicleMap(String dir) throws IOException { - fpMap = new FilePerKeyMap(dir); - fpMap.putReturnsNull(true); -// fpMap.valueMarshaller(SnappyInputStream::new, SnappyOutputStream::new); -// fpMap.valueMarshaller(GZIPInputStream::new, GZIPOutputStream::new); -// chMap = ChronicleMapBuilder.of(String.class, String.class) -// .entries(500).averageValueSize(2_000_000).create(); - } - - public void registerForEvents(Consumer listener) { - fpMap.registerForEvents(listener); - } - - @Override - public int size() { - return fpMap.size(); - } - - @Override - public boolean isEmpty() { - return fpMap.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return fpMap.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return fpMap.containsValue(value); - } - - @Override - public String get(Object key) { - return fpMap.get(key); - } - - @Override - public String put(String key, String value) { - return fpMap.put(key, value); -// return chMap.put(key,value); - } - - @Override - public String remove(Object key) { -// chMap.remove(key); - return fpMap.remove(key); - } - - @Override - public void putAll(Map m) { - fpMap.putAll(m); -// chMap.putAll(m); - } - - @Override - public void clear() { - fpMap.clear(); - } - - @NotNull - @Override - public Set keySet() { - return fpMap.keySet(); - } - - @NotNull - @Override - public Collection values() { - return fpMap.values(); - } - - @NotNull - @Override - public Set> entrySet() { - return fpMap.entrySet(); - } - - @Override - public String getUsing(String key, String usingValue) { - throw new UnsupportedOperationException(); -// return chMap.getUsing(key, usingValue); - } - - @Override - public String acquireUsing(@NotNull String key, String usingValue) { - throw new UnsupportedOperationException(); - //@todo ADD THE LOGIC FOR FPMAP -// return chMap.acquireUsing(key, usingValue); - } - - @NotNull - @Override - public MapKeyContext acquireContext(@NotNull String key, @NotNull String usingValue) { - throw new UnsupportedOperationException(); -// return chMap.acquireContext(key,usingValue); - } - - @Override - public R getMapped(String key, @NotNull SerializableFunction function) { - throw new UnsupportedOperationException(); -// return chMap.getMapped(key, function); - } - - @Override - public String putMapped(String key, @NotNull UnaryOperator unaryOperator) { - throw new UnsupportedOperationException(); - } - - @Override - public void getAll(File toFile) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void putAll(File fromFile) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public String newValueInstance() { - return new String(); - } - - @Override - public String newKeyInstance() { - return new String(); - } - - @Override - public Class valueClass() { - return String.class; - } - - @Override - public File file() { - throw new UnsupportedOperationException(); - } - - @Override - public long longSize() { - return size(); - } - - @Override - public MapKeyContext context(String key) { - throw new UnsupportedOperationException(); - // return chMap.context(key); - } - - @Override - public Class keyClass() { - return String.class; - } - - @NotNull - @Override - public ExternalMapQueryContext queryContext(String key) { - throw new UnsupportedOperationException(); - } - - @NotNull - @Override - public ExternalMapQueryContext queryContext(Value key) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean forEachEntryWhile(Predicate> predicate) { - throw new UnsupportedOperationException(); - - // return chMap.forEachEntryWhile(predicate); - } - - @Override - public void forEachEntry(Consumer> action) { - throw new UnsupportedOperationException(); -// chMap.forEachEntry(action); - } - - @Override - public void close() { - fpMap.close(); - } - - @Override - public String putIfAbsent(String key, String value) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean replace(String key, String oldValue, String newValue) { - throw new UnsupportedOperationException(); - } - - @Override - public String replace(String key, String value) { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java b/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java deleted file mode 100644 index 758c6b291..000000000 --- a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java +++ /dev/null @@ -1,358 +0,0 @@ -package net.openhft.chronicle.map; - -import com.sun.nio.file.SensitivityWatchEventModifier; -import net.openhft.chronicle.core.util.ThrowingFunction; -import org.jetbrains.annotations.NotNull; - -import java.io.*; -import java.nio.file.*; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * A {@link Map} implementation that stores each entry as a file in a - * directory. The key is the file name and the value - * is the contents of the file. This map will only handle String's. - *

- * The class is effectively an abstraction over a directory in the file system. - * Therefore when the underlying files are changed an event will be fired to those - * registered for notifications. - * Since every write to this map will cause a change to underlying - * file system the event will distinguish between a programmatic event - * (i.e one caused my the actions of the map itself) and an event that - * has been triggered as a direct result of a file being manipulated outside - * this class. - *

- * Updates will be fired every time the file is saved but will be suppressed - * if the value has not changed. To avoid temporary files (e.g. if edited in vi) - * being included in the map, any file starting with a '.' will be ignored. - *

- * Note the {@link WatchService} is extremely OS dependant. Mas OSX registers - * very few events if they are done quickly and there is a significant delay - * between the event and the event being triggered. - */ -public class FilePerKeyMap implements Map, Closeable { - private final Path dirPath; - private final Map lastFile = new ConcurrentHashMap<>(); - - private final List> listeners = new ArrayList<>(); - private final Thread fileFpmWatcher; - private volatile boolean closed = false; - private boolean putReturnsNull; - private boolean snappyValues; - private ThrowingFunction reading = i -> i; - private ThrowingFunction writing = o -> o; - - public FilePerKeyMap(String dir) throws IOException { - this.dirPath = Paths.get(dir); - Files.createDirectories(dirPath); - WatchService watcher = FileSystems.getDefault().newWatchService(); - dirPath.register(watcher, new WatchEvent.Kind[]{ - StandardWatchEventKinds.ENTRY_CREATE, - StandardWatchEventKinds.ENTRY_DELETE, - StandardWatchEventKinds.ENTRY_MODIFY}, - SensitivityWatchEventModifier.HIGH - ); - - fileFpmWatcher = new Thread(new FPMWatcher(watcher), dir + "-watcher"); - fileFpmWatcher.start(); - } - - public void registerForEvents(Consumer listener) { - listeners.add(listener); - } - - public void unregisterForEvents(Consumer listener) { - listeners.remove(listener); - } - - public void valueMarshaller(ThrowingFunction reading, - ThrowingFunction writing) { - this.reading = reading; - this.writing = writing; - } - - private void fireEvent(FPMEvent event) { - for (Consumer listener : listeners) { - listener.accept(event); - } - } - - @Override - public int size() { - return (int) getFiles().count(); - } - - @Override - public boolean isEmpty() { - return size() == 0; - } - - @Override - public boolean containsKey(Object key) { - return getFiles().anyMatch(p -> p.getFileName().toString().equals(key)); - } - - @Override - public boolean containsValue(Object value) { - return getFiles().anyMatch(p -> getFileContents(p).equals(value)); - } - - @Override - public String get(Object key) { - Path path = dirPath.resolve((String) key); - return getFileContents(path); - } - - @Override - public String put(String key, String value) { - if (closed) throw new IllegalStateException("closed"); - Path path = dirPath.resolve(key); - String existingValue = putReturnsNull ? null : getFileContents(path); - writeToFile(path, value); - - return existingValue; - } - - @Override - public String remove(Object key) { - if (closed) throw new IllegalStateException("closed"); - String existing = get(key); - if (existing != null) { - deleteFile(dirPath.resolve((String) key)); - } - return existing; - } - - @Override - public void putAll(Map m) { - m.entrySet().stream().forEach(e -> put(e.getKey(), e.getValue())); - } - - @Override - public void clear() { - getFiles().forEach(this::deleteFile); - } - - @NotNull - @Override - public Set keySet() { - return getFiles().map(p -> p.getFileName().toString()) - .collect(Collectors.toSet()); - } - - @NotNull - @Override - public Collection values() { - return getFiles().map(p -> getFileContents(p)) - .collect(Collectors.toSet()); - - } - - @NotNull - @Override - public Set> entrySet() { - return getFiles().map(p -> - (Entry) new FPMEntry(p.getFileName().toString(), getFileContents(p))) - .collect(Collectors.toSet()); - } - - - private Stream getFiles() { - try { - return Files.walk(dirPath).filter(p -> !Files.isDirectory(p)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - String getFileContents(Path path) { - try { - File file = path.toFile(); - FileRecord last = lastFile.get(file); - if (last != null && file.lastModified() == last.timestamp) - return last.contents; - return getFileContents0(path); - } catch (IOException ioe) { - throw new IllegalStateException(ioe); - } - } - - String getFileContents0(Path path) throws IOException { - if (!Files.exists(path)) return null; - File file = path.toFile(); - ByteArrayOutputStream baos = new ByteArrayOutputStream((int) file.length()); - byte[] bytes = new byte[1024]; - try (InputStream fis = reading.apply(new FileInputStream(file))) { - for (int len; (len = fis.read(bytes)) > 0; ) - baos.write(bytes, 0, len); - } - return baos.toString(); - } - - private void writeToFile(Path path, String value) { - File file = path.toFile(); - File tmpFile = new File(file.getParentFile(), "." + file.getName()); - try (PrintWriter pw = new PrintWriter(new BufferedOutputStream(writing.apply(new FileOutputStream(tmpFile))))) { - pw.write(value); - } catch (IOException e) { - throw new AssertionError(e); - } - tmpFile.renameTo(file); - } - - private void deleteFile(Path path) { - File key = path.toFile(); - key.delete(); - } - - public void close() { - closed = true; - fileFpmWatcher.interrupt(); - } - - public void putReturnsNull(boolean putReturnsNull) { - this.putReturnsNull = putReturnsNull; - } - - public void snappyValues(boolean snappyValues) { - this.snappyValues = snappyValues; - } - - private static class FPMEntry implements Entry { - private String key; - private String value; - - public FPMEntry(String key, String value) { - this.key = key; - this.value = value; - } - - @Override - public String getKey() { - return key; - } - - @Override - public String getValue() { - return value; - } - - @Override - public String setValue(String value) { - String lastValue = this.value; - this.value = value; - return lastValue; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - FPMEntry fpmEntry = (FPMEntry) o; - - if (key != null ? !key.equals(fpmEntry.key) : fpmEntry.key != null) return false; - return !(value != null ? !value.equals(fpmEntry.value) : fpmEntry.value != null); - } - - @Override - public int hashCode() { - int result = key != null ? key.hashCode() : 0; - result = 31 * result + (value != null ? value.hashCode() : 0); - return result; - } - } - - private class FPMWatcher implements Runnable { - private final WatchService watcher; - - public FPMWatcher(WatchService watcher) { - this.watcher = watcher; - } - - @Override - public void run() { - try { - while (true) { - WatchKey key = null; - try { - key = watcher.take(); - for (WatchEvent event : key.pollEvents()) { - WatchEvent.Kind kind = event.kind(); - - if (kind == StandardWatchEventKinds.OVERFLOW) { - // todo log a warning. - continue; - } - - // get file name - WatchEvent ev = (WatchEvent) event; - Path fileName = ev.context(); - String mapKey = fileName.toString(); - - if (mapKey.startsWith(".")) { - //this avoids temporary files being added to the map - continue; - } - - if (kind == StandardWatchEventKinds.ENTRY_CREATE) { - Path p = dirPath.resolve(fileName); - try { - String mapVal = getFileContents0(p); - lastFile.put(p.toFile(), new FileRecord(p.toFile().lastModified(), mapVal)); - fireEvent(new FPMEvent(FPMEvent.EventType.NEW, mapKey, null, mapVal)); - } catch (FileNotFoundException ignored) { - } - } else if (kind == StandardWatchEventKinds.ENTRY_DELETE) { - Path p = dirPath.resolve(fileName); - - FileRecord lastVal = lastFile.remove(p.toFile()); - String lastContent = lastVal == null ? null : lastVal.contents; - fireEvent(new FPMEvent(FPMEvent.EventType.DELETE, mapKey, lastContent, null)); - } else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { - try { - Path p = dirPath.resolve(fileName); - String mapVal = getFileContents0(p); - String lastVal = null; - if (mapVal != null) { - FileRecord rec = lastFile.put(p.toFile(), new FileRecord(p.toFile().lastModified(), mapVal)); - if (rec != null) lastVal = rec.contents; - } - - if (lastVal != null && lastVal.equals(mapVal)) { - //Nothing has changed don't fire an event - continue; - } - - fireEvent(new FPMEvent(FPMEvent.EventType.UPDATE, mapKey, lastVal, mapVal)); - } catch (FileNotFoundException ignored) { - } - } - } - } catch (InterruptedException e) { - return; - } finally { - if (key != null) key.reset(); - } - } - } catch (Throwable e) { - if (!closed) - e.printStackTrace(); - } - } - } -} - -class FileRecord { - final long timestamp; - final String contents; - - FileRecord(long timestamp, String contents) { - this.timestamp = timestamp; - this.contents = contents; - } -} diff --git a/src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java b/src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java deleted file mode 100644 index 262b357cb..000000000 --- a/src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java +++ /dev/null @@ -1,166 +0,0 @@ -package net.openhft.chronicle.map; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.IOException; -import java.util.*; -import java.util.function.Consumer; - -import static org.junit.Assert.*; - -/** - * JUnit test class to support {@link FilePerKeyMapTest} - */ -public class FilePerKeyMapTest { - private static FilePerKeyMap map; - @BeforeClass - public static void createMap() throws IOException { - map = new FilePerKeyMap("/tmp/filepermaptests"); - //just in case it hasn't been cleared up last time - map.clear(); - } - /** - * Testing all the methods of the map with simple tests. - */ - @Test - @Ignore - public void testMapMethods() { - String val = map.put("one", "test1"); - assertEquals(val, null); - - //After the entry has been written the value returned should be - //the previous value - val = map.put("one", "test2"); - assertEquals(val, "test1"); - - //Check that get returns the latest value - val = map.get("one"); - assertEquals("test2", val); - - assertTrue(map.containsKey("one")); - assertFalse(map.containsKey("two")); - assertTrue(map.containsValue("test2")); - assertFalse(map.containsValue("test5")); - - //Check the size is one - int size = map.size(); - assertEquals(1, size); - assertFalse(map.isEmpty()); - - map.clear(); - //Check the size is now 0 - size = map.size(); - assertEquals(0, size); - - assertTrue(map.isEmpty()); - - map.put("one", "test1"); - map.put("two", "test2"); - map.put("three", "test3"); - assertEquals(3, map.size()); - - val = map.remove("two"); - assertEquals("test2", val); - - assertEquals(2, map.size()); - - val = map.remove("four");//doesn't exist - assertEquals(null, val); - - map.clear(); - - Map copyFrom = new HashMap<>(); - copyFrom.put("five", "test5"); - copyFrom.put("six", "test6"); - copyFrom.put("seven", "test7"); - map.putAll(copyFrom); - assertEquals(3, map.size()); - - Set set = map.keySet(); - assertEquals(3, set.size()); - assertTrue(set.contains("five")); - assertTrue(set.contains("six")); - assertTrue(set.contains("seven")); - - set = (Set) map.values(); - assertEquals(3, set.size()); - assertTrue(set.contains("test5")); - assertTrue(set.contains("test6")); - assertTrue(set.contains("test7")); - - Set entryset = (Set) map.entrySet(); - assertEquals(3, entryset.size()); - for (Iterator it = entryset.iterator(); it.hasNext(); ) { - Map.Entry entry = it.next(); - if (entry.getKey().equals("five")) { - assertEquals(entry.getValue(), "test5"); - } else if (entry.getKey().equals("six")) { - assertEquals(entry.getValue(), "test6"); - } else if (entry.getKey().equals("seven")) { - assertEquals(entry.getValue(), "test7"); - } else { - //should never get here!! - assertTrue(false); - } - } - - map.clear(); - } - - @Test - public void perfTest(){ - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 2_000_000; i++) { - sb.append('x'); - } - String value = sb.toString(); - - //small warm-up - for (int i = 0; i < 10; i++) { - map.put("big file", value); - } - - - long time = System.currentTimeMillis(); - int iterations = 50; - for (int i = 0; i < iterations; i++) { - map.put("big file", value); - } - System.out.println("Time to update " + iterations + " iterations " + (System.currentTimeMillis() - time)); - - map.clear(); - } - - @Ignore //This doesn't work on all OS - @Test - public void eventTest() throws InterruptedException { - final List events = new ArrayList<>(); - - Consumer fpmEventConsumer = (FPMEvent e) -> { - System.out.println(e); - events.add(e); - }; - map.registerForEvents(fpmEventConsumer); - - map.put("one", "one"); - map.put("one", "two"); - map.remove("one"); - map.put("one", "one"); - - //Allow all events to be played through - Thread.sleep(3000); - //Check the events - assertEquals(4, events.size()); - - assertEquals(FPMEvent.EventType.NEW,events.get(0).getEventType()); - assertEquals(FPMEvent.EventType.UPDATE, events.get(1).getEventType()); - assertEquals(FPMEvent.EventType.DELETE, events.get(2).getEventType()); - assertEquals(FPMEvent.EventType.NEW, events.get(3).getEventType()); - - - map.unregisterForEvents(fpmEventConsumer); - map.clear(); - } -} From 9c8a9067df6e3810ef0d1fc4efd1304704d2de04 Mon Sep 17 00:00:00 2001 From: danielshaya Date: Wed, 3 Jun 2015 10:40:13 +0100 Subject: [PATCH 3/5] Last compiling version. --- .../CompiledReplicatedMapQueryContext.java | 2743 ++++++++--------- 1 file changed, 1296 insertions(+), 1447 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java index 02b722fb5..c300f0196 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java @@ -19,10 +19,8 @@ import net.openhft.chronicle.hash.replication.TimeProvider; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; import net.openhft.chronicle.map.*; -import net.openhft.chronicle.map.TcpReplicator.TcpSocketChannelEntryWriter; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; -import net.openhft.chronicle.map.impl.stage.query.MapAbsentEntryHolder; import net.openhft.chronicle.map.impl.value.instance.ValueInitableValue; import net.openhft.chronicle.map.replication.MapRemoteQueryContext; import net.openhft.chronicle.map.replication.MapReplicableEntry; @@ -45,24 +43,23 @@ import java.util.ConcurrentModificationException; import java.util.List; import java.util.concurrent.TimeUnit; -public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , ReplicatedChronicleMapHolder , MapAbsentEntryHolder , MapRemoteQueryContext , MapReplicableEntry { +public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , ReplicatedChronicleMapHolder , MapRemoteQueryContext , MapReplicableEntry { public void close() { - CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); - CompiledReplicatedMapQueryContext.this.closeReplicationInput(); - CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.closeInputKey(); + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeNext(); CompiledReplicatedMapQueryContext.this.closeUsed(); - CompiledReplicatedMapQueryContext.this.closeInputKey(); - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledReplicatedMapQueryContext.this.bytesReturnValue.closeOutput(); - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); CompiledReplicatedMapQueryContext.this.closeInputBytes(); + CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); - CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); CompiledReplicatedMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); + CompiledReplicatedMapQueryContext.this.innerUpdateLock.closeUpdateLockForbiddenUpgradeDependants(); + CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); @@ -117,36 +114,34 @@ public class CompiledReplicatedMapQueryContext)(entryBytesAccessor.access(entryBytes))); - this.bytesReturnValue = new BytesReturnValue(); - this.innerWriteLock = new WriteLock(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.innerReadLock = new ReadLock(); this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); + this.inputValueInstanceValue = new InputValueInstanceValue(); + this.inputKeyBytesValue = new InputKeyBytesValue(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.entryKey = new EntryKeyBytesValue(); + this.usingReturnValue = new UsingReturnValue(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesValue(); + this.dummyValue = new DummyValueZeroValue(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.absentDelegating = new ReplicatedMapAbsentDelegating(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); - this.usingReturnValue = new UsingReturnValue(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryKey = new EntryKeyBytesValue(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); - this.dummyValue = new DummyValueZeroValue(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerWriteLock = new WriteLock(); } public CompiledReplicatedMapQueryContext(CompiledReplicatedMapQueryContext c) { @@ -154,39 +149,42 @@ public class CompiledReplicatedMapQueryContext)(c.m)); - this.innerUpdateLock = new UpdateLock(); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.bytesReturnValue = new BytesReturnValue(); - this.innerWriteLock = new WriteLock(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.innerReadLock = new ReadLock(); this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); + this.inputValueInstanceValue = new InputValueInstanceValue(); + this.inputKeyBytesValue = new InputKeyBytesValue(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.entryKey = new EntryKeyBytesValue(); + this.usingReturnValue = new UsingReturnValue(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesValue(); + this.dummyValue = new DummyValueZeroValue(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.absentDelegating = new ReplicatedMapAbsentDelegating(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); - this.usingReturnValue = new UsingReturnValue(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryKey = new EntryKeyBytesValue(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); - this.dummyValue = new DummyValueZeroValue(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerWriteLock = new WriteLock(); } public class InputKeyBytesValue extends AbstractValue { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + @Override public ReadAccess access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); @@ -201,6 +199,11 @@ public class CompiledReplicatedMapQueryContext { + @Override + public T handle() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; + } + @Override public ReadAccess access() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -281,12 +280,6 @@ public class CompiledReplicatedMapQueryContext { - @NotNull - @Override - public Value defaultValue() { - return CompiledReplicatedMapQueryContext.this.defaultValue(); - } - - @NotNull - @Override - public MapContext context() { - return CompiledReplicatedMapQueryContext.this.context(); - } - - @NotNull - @Override - public Value absentKey() { - return CompiledReplicatedMapQueryContext.this.absentKey(); - } - - @Override - public void doInsert(Value value) { - CompiledReplicatedMapQueryContext.this.doInsert(value); - } } public class EntryValueBytesValue extends AbstractValue { @@ -648,6 +624,12 @@ public class CompiledReplicatedMapQueryContext { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + @Override public long size() { return CompiledReplicatedMapQueryContext.this.firstInputValueSize(); @@ -765,20 +751,10 @@ public class CompiledReplicatedMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); - } - @Override public long offset() { return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.firstInputValueOffset()); } - - @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); - } } public class InputSecondValueBytesValue extends AbstractValue { @@ -792,11 +768,6 @@ public class CompiledReplicatedMapQueryContext)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); } - @Override - public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.secondInputValueOffset()); - } - @Override public long size() { return CompiledReplicatedMapQueryContext.this.secondInputValueSize(); @@ -847,6 +818,11 @@ public class CompiledReplicatedMapQueryContext { @@ -865,6 +841,18 @@ public class CompiledReplicatedMapQueryContext { - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledReplicatedMapQueryContext.this.writeLock(); - } - @NotNull @Override public InterProcessLock readLock() { @@ -976,6 +946,31 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); - if (entry != null) { - CompiledReplicatedMapQueryContext.this.remove(entry); - return true; - } else { - return false; - } + return CompiledReplicatedMapQueryContext.this.entryBytes; } @Override @@ -1030,30 +1019,17 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); + if (entry != null) { + CompiledReplicatedMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } } @Override @@ -1088,6 +1064,18 @@ public class CompiledReplicatedMapQueryContext { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + } + + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + } + @Override public long size() { return CompiledReplicatedMapQueryContext.this.riKeySize(); @@ -1193,11 +1179,6 @@ public class CompiledReplicatedMapQueryContext { + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + } + @Override public T handle() { return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public long offset() { + return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).offset(CompiledReplicatedMapQueryContext.this.replicatedInputBytes(), CompiledReplicatedMapQueryContext.this.riValueOffset()); } - } - public class ReplicatedInputValueBytesValue extends AbstractValue { @Override public long size() { return CompiledReplicatedMapQueryContext.this.riValueSize(); @@ -1262,11 +1253,6 @@ public class CompiledReplicatedMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); - } - @Override public V getUsing(V usingValue) { Bytes inputBytes = CompiledReplicatedMapQueryContext.this.replicatedInputBytes(); @@ -1309,24 +1295,9 @@ public class CompiledReplicatedMapQueryContext { - @Override - public V getUsing(V usingInstance) { - throw new UnsupportedOperationException(); - } - @Override public long offset() { return 0; @@ -1337,6 +1308,16 @@ public class CompiledReplicatedMapQueryContext access() { return ReadAccess.zeros(); } - - @Override - public Void handle() { - return null; - } } public enum SearchState { @@ -1592,6 +1568,11 @@ public class CompiledReplicatedMapQueryContext { - long startOutputPos; - - TcpSocketChannelEntryWriter output = null; - - public boolean outputInit() { - return (this.output) != null; - } - - public void initOutput(TcpSocketChannelEntryWriter output) { - this.output = output; - startOutputPos = output.in().position(); - } - - public long startOutputPos() { - assert this.outputInit() : "Output should be init"; - return this.startOutputPos; - } - - public TcpSocketChannelEntryWriter output() { - assert this.outputInit() : "Output should be init"; - return this.output; - } - - public void closeOutput() { - if (!(this.outputInit())) - return ; - - this.output = null; - } - - @Override - public void close() { - if ((output().in().position()) == (startOutputPos())) { - output().ensureBufferSize(1L); - output().in().writeBoolean(true); - } - } - - @Override - public void returnValue(@NotNull - Value value) { - long valueSize = value.size(); - long totalSize = (1L + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize))) + valueSize; - output().ensureBufferSize(totalSize); - Bytes out = output().in(); - out.writeBoolean(false); - CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(out, valueSize); - Full outAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(out); - long outPosition = out.position(); - out.skip(valueSize); - value.writeTo(outAccessor, out, outPosition); - } } public class DefaultReturnValue implements InstanceReturnValue { @@ -1889,12 +1810,6 @@ public class CompiledReplicatedMapQueryContext absent() { - return CompiledReplicatedMapQueryContext.this; - } - - public void checkAccessingFromOwnerThread() { - if ((owner) != (Thread.currentThread())) { - throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); + public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { + if (CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry) { + return CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (CompiledReplicatedMapQueryContext.this.m().worstAlignment)) + valueSize; + } else { + return (CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; } } - public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { - CompiledReplicatedMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - @Override public ReplicatedChronicleMap m() { return m; @@ -2077,16 +1981,60 @@ public class CompiledReplicatedMapQueryContextT contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + + private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { + return (((CompiledReplicatedMapQueryContext.this.m().metaDataBytes) + (CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); + } + + long sizeOfEverythingBeforeValue(long keySize, long valueSize) { + return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + } + + @NotNull + @Override + public MapContext context() { + return this; + } + + public MVI valueMetaInterop(V value) { + return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); + } + + public MKI keyMetaInterop(K key) { + return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); + } + + public void closeKeyBytesInteropKeyMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); + } + private CompiledReplicatedMapQueryContext _Chaining_createChaining() { return new CompiledReplicatedMapQueryContext(this); } @@ -2108,42 +2056,33 @@ public class CompiledReplicatedMapQueryContextT contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); + public Bytes replicatedInputBytes = null; + + public boolean replicatedInputBytesInit() { + return (this.replicatedInputBytes) != null; } - public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + public void initReplicatedInputBytes(Bytes replicatedInputBytes) { + this.replicatedInputBytes = replicatedInputBytes; + this.closeReplicatedInputBytesDependants(); } - public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); + public Bytes replicatedInputBytes() { + assert this.replicatedInputBytesInit() : "ReplicatedInputBytes should be init"; + return this.replicatedInputBytes; } - public void closeKeyBytesInteropKeyMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); + public void closeReplicatedInputBytes() { + if (!(this.replicatedInputBytesInit())) + return ; + + this.closeReplicatedInputBytesDependants(); + this.replicatedInputBytes = null; } - private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledReplicatedMapQueryContext.this.m().metaDataBytes) + (CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - - public MVI valueMetaInterop(V value) { - return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); + public void closeReplicatedInputBytesDependants() { + CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesValueGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesValueGetUsingDependants(); } public Bytes inputBytes = null; @@ -2174,9 +2113,9 @@ public class CompiledReplicatedMapQueryContext inputKey = null; public boolean inputKeyInit() { @@ -2333,6 +2311,7 @@ public class CompiledReplicatedMapQueryContext 0; - } - - void initSegment() { - VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); - long hashLookupOffset = h.segmentOffset(segmentIndex()); - long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); - freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); - freeList.reuse(freeListBytes); - entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); - this.closeSegmentDependants(); - } - - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.entrySpaceOffset; - } - - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.freeList; - } - - void closeSegment() { - if (!(this.segmentInit())) - return ; - - this.closeSegmentDependants(); - entrySpaceOffset = 0; - } - - public void closeSegmentDependants() { - CompiledReplicatedMapQueryContext.this.closeEntry(); - } - - public long pos = -1; - - public long keySizeOffset; - - public long keySize; - - public long keyOffset; - - public boolean entryInit() { - return (this.pos) >= 0; - } - - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntryCopying(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset; - initKeySizeOffset(newPos); - long oldKeyOffset = keyOffset; - keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); - pos = newPos; - this.closeEntryDependants(); - } - - public long keyOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keyOffset; - } - - public long keySize() { - assert this.entryInit() : "Entry should be init"; - return this.keySize; - } - - public long keySizeOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keySizeOffset; - } - - public long pos() { - assert this.entryInit() : "Entry should be init"; - return this.pos; - } - - public void closeEntry() { - if (!(this.entryInit())) - return ; - - this.closeEntryDependants(); - this.pos = -1; - } - - public void closeEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateDropChangeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationState(); - } - - private long _MapEntryStages_countValueSizeOffset() { - return keyEnd(); - } - - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeValue(); - } - - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - } - - void initReplicationState(long timestamp, byte identifier) { - replicationBytesOffset = keyEnd(); - entryBytes.position(replicationBytesOffset); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.replicationBytesOffset = -1; - } - - private long timestampOffset() { - return replicationBytesOffset(); - } - - long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - public void dropChange() { - CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); - } - - public void closeReplicationUpdateDropChangeDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); - } - - int hashLookupEntrySize; - - int keyBits; - - long address = -1; - - long capacityMask; - - long capacityMask2; - - long keyMask; - - long valueMask; - - long entryMask; - - public boolean segmentHashLookupInit() { - return (this.address) >= 0; - } - - public void initSegmentHashLookup() { - long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); - innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); - this.closeSegmentHashLookupDependants(); - } - - public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { - innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); - this.closeSegmentHashLookupDependants(); - } - - public int hashLookupEntrySize() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.hashLookupEntrySize; - } - - public int keyBits() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyBits; - } - - public long address() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.address; - } - - public long capacityMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask; - } - - public long capacityMask2() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask2; - } - - public long entryMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.entryMask; - } - - public long keyMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyMask; - } - - public long valueMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.valueMask; - } - - public void closeSegmentHashLookup() { - if (!(this.segmentHashLookupInit())) - return ; - - this.closeSegmentHashLookupDependants(); - this.address = -1; - } - - public void closeSegmentHashLookupDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); - } - - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; - } - - public void closeHashLookupStepDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - public void closeHashLookupReadEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void closeHashLookupEmptyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public void checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - - long entry(long key, long value) { - return key | (value << (keyBits())); - } - - public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public void closeHashLookupIndexToPosDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); - } - - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); - } - - public void closeHashLookupHlPosDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); - } - - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public void putValueVolatile(long pos, long value) { - checkValueForPut(value); - long currentEntry = readEntry(pos); - writeEntryVolatile(pos, currentEntry, key(currentEntry), value); - } - - void forEach(EntryConsumer action) { - for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { - long entry = readEntry(pos); - if (!(empty(entry))) - action.accept(key(entry), value(entry)); - - } - } - - String hashLookupToString() { - final StringBuilder sb = new StringBuilder("{"); - forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); - } - - public void writeEntry(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long remove(long posToRemove) { - long entryToRemove = readEntry(posToRemove); - long posToShift = posToRemove; - while (true) { - posToShift = step(posToShift); - long entryToShift = readEntry(posToShift); - if (empty(entryToShift)) - break; - - long insertPos = hlPos(key(entryToShift)); - boolean cond1 = insertPos <= posToRemove; - boolean cond2 = posToRemove <= posToShift; - if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { - writeEntry(posToRemove, entryToRemove, entryToShift); - posToRemove = posToShift; - entryToRemove = entryToShift; - } - } - clearEntry(posToRemove, entryToRemove); - return posToRemove; - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void closeHashLookupMaskUnsetKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); } long segmentHeaderAddress; @@ -2923,25 +2424,31 @@ public class CompiledReplicatedMapQueryContext h = CompiledReplicatedMapQueryContext.this.h(); - if (chunks > (h.maxChunksPerEntry)) - throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); - - long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - ret = freeList().setNextNContinuousClearBits(0L, chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - if (chunks == 1) { - throw new IllegalStateException("Segment is full, no free entries found"); - } else { - throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); - } - } - updateNextPosToSearchFrom(ret, chunks); - } else { - if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { - updateNextPosToSearchFrom(ret, chunks); - } - } - return ret; - } - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { CompiledReplicatedMapQueryContext c = CompiledReplicatedMapQueryContext.this.contextAtIndexInChain(index); if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { @@ -2995,6 +2472,10 @@ public class CompiledReplicatedMapQueryContext= 0; } - public void clear() { - clearSegment(); + public void initSegmentHashLookup() { + long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); + innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); + this.closeSegmentHashLookupDependants(); } - public void deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); + public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { + innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); + this.closeSegmentHashLookupDependants(); } - public long entries() { - return segmentHeader().size(segmentHeaderAddress()); + public int hashLookupEntrySize() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.hashLookupEntrySize; } - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); + public int keyBits() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyBits; } - public long size() { - return (entries()) - (deleted()); + public long address() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.address; + } + + public long capacityMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask; + } + + public long capacityMask2() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask2; + } + + public long entryMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.entryMask; + } + + public long keyMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyMask; + } + + public long valueMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.valueMask; + } + + public void closeSegmentHashLookup() { + if (!(this.segmentHashLookupInit())) + return ; + + this.closeSegmentHashLookupDependants(); + this.address = -1; + } + + public void closeSegmentHashLookupDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); + } + + public long stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); + } + + public void closeHashLookupStepBackDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + + long entry(long key, long value) { + return key | (value << (keyBits())); + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public void closeHashLookupIndexToPosDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void closeHashLookupMaskUnsetKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeSearchKey(); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public void closeHashLookupStepDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + public long key(long entry) { + return entry & (keyMask()); + } + + public void closeHashLookupKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); + } + + public void closeHashLookupEmptyDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + public void closeHashLookupReadEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public void writeEntry(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public void closeHashLookupHlPosDependants() { + CompiledReplicatedMapQueryContext.this.closeSearchKey(); + } + + public long remove(long posToRemove) { + long entryToRemove = readEntry(posToRemove); + long posToShift = posToRemove; + while (true) { + posToShift = step(posToShift); + long entryToShift = readEntry(posToShift); + if (empty(entryToShift)) + break; + + long insertPos = hlPos(key(entryToShift)); + boolean cond1 = insertPos <= posToRemove; + boolean cond2 = posToRemove <= posToShift; + if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { + writeEntry(posToRemove, entryToRemove, entryToShift); + posToRemove = posToShift; + entryToRemove = entryToShift; + } + } + clearEntry(posToRemove, entryToRemove); + return posToRemove; } long searchKey = UNSET_KEY; @@ -3161,8 +2837,8 @@ public class CompiledReplicatedMapQueryContext>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + public long nextPos() { long pos = CompiledReplicatedMapQueryContext.this.hashLookupPos(); while (true) { @@ -3270,6 +2957,188 @@ public class CompiledReplicatedMapQueryContext sb.append(key).append('=').append(value).append(',')); + sb.append('}'); + return sb.toString(); + } + + public boolean checkSlotContainsExpectedKeyAndValue(long value) { + long entry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); + return ((CompiledReplicatedMapQueryContext.this.key(entry)) == (searchKey())) && ((CompiledReplicatedMapQueryContext.this.value(entry)) == value); + } + + public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + long entrySpaceOffset = 0; + + MultiStoreBytes freeListBytes = new MultiStoreBytes(); + + public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); + + boolean segmentInit() { + return (entrySpaceOffset) > 0; + } + + void initSegment() { + VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + long hashLookupOffset = h.segmentOffset(segmentIndex()); + long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); + freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); + freeList.reuse(freeListBytes); + entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); + this.closeSegmentDependants(); + } + + public long entrySpaceOffset() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.entrySpaceOffset; + } + + public SingleThreadedDirectBitSet freeList() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.freeList; + } + + void closeSegment() { + if (!(this.segmentInit())) + return ; + + this.closeSegmentDependants(); + entrySpaceOffset = 0; + } + + public void closeSegmentDependants() { + CompiledReplicatedMapQueryContext.this.closeEntry(); + } + + public long alloc(int chunks) { + VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + if (chunks > (h.maxChunksPerEntry)) + throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); + + long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + ret = freeList().setNextNContinuousClearBits(0L, chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + if (chunks == 1) { + throw new IllegalStateException("Segment is full, no free entries found"); + } else { + throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); + } + } + updateNextPosToSearchFrom(ret, chunks); + } else { + if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { + updateNextPosToSearchFrom(ret, chunks); + } + } + return ret; + } + + public long pos = -1; + + public long keySizeOffset; + + public long keySize; + + public long keyOffset; + + public boolean entryInit() { + return (this.pos) >= 0; + } + + public void initEntry(long pos) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); + keyOffset = entryBytes.position(); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntry(long pos, Value key) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = key.size(); + CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); + keyOffset = entryBytes.position(); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntryCopying(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset; + initKeySizeOffset(newPos); + long oldKeyOffset = keyOffset; + keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); + pos = newPos; + this.closeEntryDependants(); + } + + public long keyOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keyOffset; + } + + public long keySize() { + assert this.entryInit() : "Entry should be init"; + return this.keySize; + } + + public long keySizeOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keySizeOffset; + } + + public long pos() { + assert this.entryInit() : "Entry should be init"; + return this.pos; + } + + public void closeEntry() { + if (!(this.entryInit())) + return ; + + this.closeEntryDependants(); + this.pos = -1; + } + + public void closeEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdateDropChangeDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + boolean keyEquals() { return ((inputKey().size()) == (CompiledReplicatedMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledReplicatedMapQueryContext.this.entryBytesAccess)), CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle, CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()))); } @@ -3317,10 +3186,6 @@ public class CompiledReplicatedMapQueryContext entry, Value newValue) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); } @NotNull @Override - public InterProcessLock readLock() { + public Value defaultValue() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerReadLock; + return wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); } + @NotNull @Override - public long originTimestamp() { + public Value key() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - @Override - public Value wrapValueAsValue(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; + return CompiledReplicatedMapQueryContext.this.entryKey; } @Override @@ -3407,6 +3278,39 @@ public class CompiledReplicatedMapQueryContext queriedKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Value value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerWriteLock; + } + + @NotNull + @Override + public Value value() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryValue; + } + @NotNull @Override public InterProcessLock updateLock() { @@ -3414,26 +3318,115 @@ public class CompiledReplicatedMapQueryContext _MapQuery_absentEntry() { + @Override + public Value wrapValueAsValue(V value) { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : CompiledReplicatedMapQueryContext.this.absent(); + WrappedValueInstanceValue wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + protected boolean searchStateDeleted() { + return (((searchState()) == (SearchState.DELETED)) && (!(CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + } + + protected boolean searchStateAbsent() { + return (!(searchStatePresent())) && (!(searchStateDeleted())); + } + + private void putPrefix() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + boolean underUpdatedLockIsHeld = !(CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + if (underUpdatedLockIsHeld) + CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); + + boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()); + if (((CompiledReplicatedMapQueryContext.this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) + CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); + + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeReplicatedMapEntryStagesKeyEndDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicationState(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; + } + + void initReplicationState() { + replicationBytesOffset = keyEnd(); + } + + void initReplicationState(long timestamp, byte identifier) { + replicationBytesOffset = keyEnd(); + entryBytes.position(replicationBytesOffset); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.replicationBytesOffset = -1; + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + @Override + public long originTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return timestamp(); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); + } + + private boolean _MapQuery_entryPresent() { + return searchStatePresent(); + } + + protected boolean entryPresent() { + return (_MapQuery_entryPresent()) && (!(CompiledReplicatedMapQueryContext.this.entryDeleted())); } @Nullable @Override public MapAbsentEntry absentEntry() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - if (entryPresent()) { - return null; - } else { - if (!(searchStatePresent())) { - return CompiledReplicatedMapQueryContext.this.absentDelegating; - } else { - assert CompiledReplicatedMapQueryContext.this.entryDeleted(); - return CompiledReplicatedMapQueryContext.this.absent(); - } - } + return entryPresent() ? null : this; } private MapEntry _MapQuery_entry() { @@ -3446,65 +3439,16 @@ public class CompiledReplicatedMapQueryContext)(_MapQuery_entry())); } - @NotNull - @Override - public Value defaultValue() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); } - @NotNull - @Override - public Value value() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryValue; + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; } - public Value queriedKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerWriteLock; - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Value value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Value newValue) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @NotNull - @Override - public Value key() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryKey; - } - - @NotNull - @Override - public MapContext context() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return this; + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); } @Override @@ -3513,40 +3457,50 @@ public class CompiledReplicatedMapQueryContext absentKey() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.inputKey(); - } - - protected void putPrefix() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - boolean underUpdatedLockIsHeld = !(CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); - if (underUpdatedLockIsHeld) - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - - boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()); - if (((CompiledReplicatedMapQueryContext.this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) - CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); - - } - - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; + return inputKey(); } public long riKeySize = -1; @@ -3557,12 +3511,6 @@ public class CompiledReplicatedMapQueryContext= 0; } @@ -3571,25 +3519,41 @@ public class CompiledReplicatedMapQueryContext newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); } private long _HashEntryStages_entryEnd() { @@ -3842,88 +3792,6 @@ public class CompiledReplicatedMapQueryContext newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - @Override - public long remoteTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newTimestamp(); - } - - @Override - public byte remoteIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newIdentifier(); - } - - private boolean testTimeStampInSensibleRange() { - if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { - long currentTime = TimeProvider.SYSTEM.currentTime(); - assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); - assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.newTimestamp())))) <= 100000000 : "unrealistic newTimestamp: " + (CompiledReplicatedMapQueryContext.this.newTimestamp()); - } - return true; - } - - public Bytes replicatedInputBytes = null; - - public boolean replicatedInputBytesInit() { - return (this.replicatedInputBytes) != null; - } - - public void initReplicatedInputBytes(Bytes replicatedInputBytes) { - this.replicatedInputBytes = replicatedInputBytes; - this.closeReplicatedInputBytesDependants(); - } - - public Bytes replicatedInputBytes() { - assert this.replicatedInputBytesInit() : "ReplicatedInputBytes should be init"; - return this.replicatedInputBytes; - } - - public void closeReplicatedInputBytes() { - if (!(this.replicatedInputBytesInit())) - return ; - - this.closeReplicatedInputBytesDependants(); - this.replicatedInputBytes = null; - } - - public void closeReplicatedInputBytesDependants() { - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesValueGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesValueGetUsingDependants(); - } - - public int allocatedChunks = 0; - - public boolean allocatedChunksInit() { - return (this.allocatedChunks) != 0; - } - - public void initAllocatedChunks(int allocatedChunks) { - this.allocatedChunks = allocatedChunks; - } - - public int allocatedChunks() { - assert this.allocatedChunksInit() : "AllocatedChunks should be init"; - return this.allocatedChunks; - } - - public void closeAllocatedChunks() { - if (!(this.allocatedChunksInit())) - return ; - - this.allocatedChunks = 0; - } - public final void freeExtraAllocatedChunks() { if (((!(CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapQueryContext.this.allocatedChunks()))) { CompiledReplicatedMapQueryContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapQueryContext.this.allocatedChunks()) - (entrySizeInChunks()))); @@ -3932,31 +3800,90 @@ public class CompiledReplicatedMapQueryContext value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); - } - - public void initEntryAndKey(long entrySize) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); - incrementSegmentEntriesIfNeeded(); - } - void putEntry(Value value) { - assert CompiledReplicatedMapQueryContext.this.searchStateAbsent(); - long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(CompiledReplicatedMapQueryContext.this.inputKey().size(), value.size()); + assert searchStateAbsent(); + long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(inputKey().size(), value.size()); CompiledReplicatedMapQueryContext.this.initEntryAndKey(entrySize); CompiledReplicatedMapQueryContext.this.initValue(value); CompiledReplicatedMapQueryContext.this.freeExtraAllocatedChunks(); CompiledReplicatedMapQueryContext.this.putNewVolatile(CompiledReplicatedMapQueryContext.this.pos()); } - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntryCopying(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); - incrementSegmentEntriesIfNeeded(); + public void writeValueAndPutPos(Value value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + } + + private void _MapEntryStages_putValueDeletedEntry(Value newValue) { + assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = CompiledReplicatedMapQueryContext.this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); + } + if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapQueryContext.this.freeList().size())) && (CompiledReplicatedMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + CompiledReplicatedMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); + CompiledReplicatedMapQueryContext.this.incrementSegmentEntriesIfNeeded(); + if (newValueSizeIsDifferent) { + initValueAgain(newValue); + } else { + writeValueGuarded(newValue); + } + } else { + if (newValueSizeIsDifferent) { + assert newSizeOfEverythingBeforeValue >= 0; + } else { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + } + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + if (newValueSizeIsDifferent) { + CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + } + + public void putValueDeletedEntry(Value newValue) { + throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); + } + + @Override + public void doInsert(Value value) { + putPrefix(); + if (!(searchStatePresent())) { + if (searchStateDeleted()) { + CompiledReplicatedMapQueryContext.this.putValueDeletedEntry(value); + } else { + putEntry(value); + } + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + setSearchStateGuarded(SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is present in the map when doInsert() is called"); + } + } + + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); + CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); } private void _MapEntryStages_relocation(Value newValue, long newSizeOfEverythingBeforeValue) { @@ -4030,47 +3957,12 @@ public class CompiledReplicatedMapQueryContext newValue) { putPrefix(); @@ -4083,85 +3975,42 @@ public class CompiledReplicatedMapQueryContext newValue) { - assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); - int newSizeInChunks; - long entryStartOffset = keySizeOffset(); - long newSizeOfEverythingBeforeValue = -1; - boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); - if (newValueSizeIsDifferent) { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledReplicatedMapQueryContext.this.m().inChunks(newEntrySize); - } else { - newSizeInChunks = entrySizeInChunks(); - } - if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapQueryContext.this.freeList().size())) && (CompiledReplicatedMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledReplicatedMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - CompiledReplicatedMapQueryContext.this.incrementSegmentEntriesIfNeeded(); - if (newValueSizeIsDifferent) { - initValueAgain(newValue); - } else { - writeValueGuarded(newValue); - } - } else { - if (newValueSizeIsDifferent) { - assert newSizeOfEverythingBeforeValue >= 0; - } else { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - } - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - if (newValueSizeIsDifferent) { - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + @Override + public byte remoteIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return newIdentifier(); } - public void putValueDeletedEntry(Value newValue) { - throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); - } - - private void _MapAbsent_doInsert(Value value) { - CompiledReplicatedMapQueryContext.this.putPrefix(); - if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { - if (CompiledReplicatedMapQueryContext.this.searchStateDeleted()) { - CompiledReplicatedMapQueryContext.this.putValueDeletedEntry(value); - } else { - putEntry(value); - } - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - CompiledReplicatedMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is present in the map when doInsert() is called"); + private boolean testTimeStampInSensibleRange() { + if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.newTimestamp())))) <= 100000000 : "unrealistic newTimestamp: " + (CompiledReplicatedMapQueryContext.this.newTimestamp()); } + return true; } @Override - public void doInsert(Value value) { - CompiledReplicatedMapQueryContext.this.putPrefix(); - if (!(CompiledReplicatedMapQueryContext.this.entryPresent())) { - if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { - putEntry(value); - CompiledReplicatedMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); - } else { - CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(value); - CompiledReplicatedMapQueryContext.this.deleted(((CompiledReplicatedMapQueryContext.this.deleted()) - 1)); - } - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - CompiledReplicatedMapQueryContext.this.writeEntryPresent(); - } else { - throw new IllegalStateException("Entry is absent in the map when doInsert() is called"); - } + public long remoteTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return newTimestamp(); + } + + private boolean updatedReplicationState = false; + + public boolean updatedReplicationStateInit() { + return (this.updatedReplicationState) != false; + } + + public void initUpdatedReplicationState() { + initReplicationState(CompiledReplicatedMapQueryContext.this.newTimestamp(), CompiledReplicatedMapQueryContext.this.newIdentifier()); + updatedReplicationState = true; + } + + public void closeUpdatedReplicationState() { + if (!(this.updatedReplicationStateInit())) + return ; + + this.updatedReplicationState = false; } } From 4540513766b21a8610a55fbeb56b080a2e56211c Mon Sep 17 00:00:00 2001 From: danielshaya Date: Wed, 3 Jun 2015 13:06:04 +0100 Subject: [PATCH 4/5] Commented out line to make it compile. --- .../java/net/openhft/chronicle/map/ReplicatedChronicleMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 62e3992fa..4db152a22 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -447,7 +447,7 @@ public class ReplicatedChronicleMap remoteOpContext = mapContext()) { remoteOpContext.initReplicationInput(source); - remoteOpContext.processReplicatedEvent(); + //remoteOpContext.processReplicatedEvent(); } } From fda7e1cd38be86d83ec1eacce7d72894681ec4e4 Mon Sep 17 00:00:00 2001 From: danielshaya Date: Wed, 3 Jun 2015 17:18:22 +0100 Subject: [PATCH 5/5] Move Engine from Map 3 to Map 2 --- .../java/net/openhft/chronicle/map/ChronicleMapBuilder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index c29e21864..fd0412127 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -1360,7 +1360,9 @@ public final class ChronicleMapBuilder implements try { // pushingToMapEventListener(); VanillaChronicleMap map = newMap(singleHashReplication, channel); - OS.warnOnWindows(map.sizeInBytes()); + if(OS.warnOnWindows(map.sizeInBytes())){ + throw new IllegalStateException("Windows cannot support this configuration"); + } BytesStore bytesStore = new DirectStore(JDKObjectSerializer.INSTANCE, map.sizeInBytes(), true); map.createMappedStoreAndSegments(bytesStore);