diff --git a/Infinispan Data Grid Platform Definitive Guide - Wagner Roberto dos Santos.pdf b/Infinispan Data Grid Platform Definitive Guide - Wagner Roberto dos Santos.pdf deleted file mode 100644 index 5772099e3..000000000 Binary files a/Infinispan Data Grid Platform Definitive Guide - Wagner Roberto dos Santos.pdf and /dev/null differ diff --git a/docs/CM_FAQs.adoc b/docs/CM_FAQs.adoc index b8b1dd225..c890c8e3c 100755 --- a/docs/CM_FAQs.adoc +++ b/docs/CM_FAQs.adoc @@ -24,7 +24,7 @@ Also, is there a reason these `1000` `gets` have be done serially in one thread? ===== Answer -The stateless client has been replaced with Chronicle Engine. The stateless client is not supported in ChronicleMap 3.x. For more information, please refer to Chronicle Engine FAQ's. +The stateless client has been replaced with Chronicle Datagrid. The stateless client is not supported in ChronicleMap 3.x. For more information, please refer to Chronicle Datagrid FAQ's. For `get()s`, parallelizing will reduce costs. For `put()s`, if you have concurrency requirements, that is, multi-key lock before updating all of them, it should be in one thread. @@ -40,13 +40,11 @@ Does Chronicle Map work by using Memory Mapped Files? ===== Answer Yes; Chronicle Map uses memory mapped files see https://en.wikipedia.org/wiki/Memory-mapped_file. This works the same way on both Linux and Windows. - == Is there a difference in performance between Linux and Windows systems? ===== Question Is there a difference in performance between Linux and Windows systems? - ===== Answer The same code is run on both Windows and Linux. However, we encourage all our clients to use Linux, as it has improved handling of memory mapped files over Windows. @@ -80,6 +78,5 @@ For Chronicle Map, it is somewhat more complicated because Chronicle Map reads a It follows that if you have quite a few maps, especially large maps, and your page cache is not large enough to hold all of these maps, then a read, or write, to a random entry may cause a cache miss. This in turn would cause a disk read or write. If you were going to install high-speed SSDs, Chronicle recommends that you use them to store the Chronicle maps and leave the slower cheap disks for the Chronicle queues. In addition, you should avoid using network attached storage, as this usually offers worst performance than local disks. - ''' <<../ReadMe.adoc#,Back to ReadMe>> diff --git a/docs/CM_Features.adoc b/docs/CM_Features.adoc index fd8b0d2ac..7a556a2cf 100755 --- a/docs/CM_Features.adoc +++ b/docs/CM_Features.adoc @@ -129,7 +129,7 @@ Please contact us at mailto:sales@chronicle.software[sales@chronicle.software] i NOTE: For access to commercially available features please contact mailto:sales@chronicle.software[sales@chronicle.software]. == Peer projects - - https://github.com/OpenHFT/Chronicle-Engine[Chronicle Engine]. Reactive processing framework + - Chronicle Datagrid. Reactive processing framework supporting Chronicle Map as a backend. - http://vanillajava.blogspot.com/2015/09/chronicle-journal-customizable-data.html[Chronicle Journal]. Another diff --git a/docs/CM_Replication.adoc b/docs/CM_Replication.adoc index f96fbc350..a41c44058 100755 --- a/docs/CM_Replication.adoc +++ b/docs/CM_Replication.adoc @@ -164,7 +164,6 @@ try (ReplicatedMap clusterOnHost1 = createCluster(CLUSTER_YAML, 1); } .... - This example is available in the repository https://github.com/ChronicleEnterprise/Chronicle-Map-Enterprise-Demo/blob/master/Example1/src/main/java/software/chronicle/enterprise/map/ThreeWayMapReplicationExampleMain.java[here] == Replication event logging diff --git a/docs/CM_Updates.adoc b/docs/CM_Updates.adoc index 1bfbda862..67922413b 100755 --- a/docs/CM_Updates.adoc +++ b/docs/CM_Updates.adoc @@ -18,9 +18,9 @@ Changes between Chronicle Map 3 and the previous Chronicle Map version are detai - "Listeners" mechanism fully reworked; see <>. This has a number of important consequences, most notable is that it is now possible to define "eventual-consistency" replication strategy, different from "last write wins"; any state-based CRDT. - - "Stateless clients" functionality (remote calls) is moved to https://github.com/OpenHFT/Chronicle-Engine[Chronicle Engine]. + - "Stateless clients" functionality (remote calls) is moved to Chronicle Datagrid. - - Replication is performed using https://github.com/OpenHFT/Chronicle-Engine[Chronicle Engine]. + - Replication is performed using Chronicle Datagrid. - Earlier versions of Chronicle Map had hard creation-time limits on the number of entries storable in a Chronicle Map. If the size exceeded this limit, an exception was thrown. + In Chronicle Map 3, this limitation is removed. The number of entries still has to be configured when the Chronicle Map is created, Exceeding this configured limit is possible, but discouraged. + diff --git a/optimistic.csv b/optimistic.csv index 443eaa7e1..1374a93f1 100644 --- a/optimistic.csv +++ b/optimistic.csv @@ -1,21 +1,16 @@ DirtyReadOffender,chrAig[DIRTY_READ_OPTIMISTIC]coupon=3.50,DirtyReadVictim ,Established chrAig, - ,,@t=1588854152251 DirtyReadVictim sleeping 10 seconds - @t=1588854152295 DirtyReadOffender calling chrAig.put('369604101'/3.85) ,, - , @t=1588854152297 Tx=Thread[Thread-4.5.main] inside chrAig.put('369604101'/null) BEGIN, - , @t=1588854152298 Tx=Thread[Thread-4.5.main] inside chrAig.put('369604101'/3.85) DONE, - @t=1588854152299 DirtyReadOffender sleeping 1 minute. ,, - ,,@t=1588854162256 DirtyReadVictim calling chrAig.get('369604101') - , @t=1588854162256 Tx=Thread[Thread-5.5.main] inside chrAig.get('369604101') BEGIN, - , @t=1588854162256 Tx=Thread[Thread-5.5.main] inside chrAig.get() DONE , - ,,@t=1588854162256 DirtyReadVictim got() coupon=3.85 - ,,@t=1588854162256 DirtyReadVictim calling chrAig.commmit() - ,@t=1588854162256 Tx=Thread[Thread-5.5.main] chrAig.commit() BEGIN , - , @t=1588854162256 Tx=Thread[Thread-5.5.main] chrAig.commit() END , -, @t=1588854162256 Tx=Thread[Thread-5.5.main] chrAig.commit() complete notifyAll() to waiting Tx Threads , - ,,@t=1588854162272 DirtyReadVictim COMMITTED - @t=1588854212307 DirtyReadOffender calling chrAig.rollback() ,, - , @t=1588854212307 Tx=Thread[Thread-4.5.main] chrAig.rollback() BEGIN , - ,@t=1588854212307 Tx=Thread[Thread-4.5.main] chrAig.rollback() COMPLETE coupon=3.50, -, @t=1588854212307 Tx=Thread[Thread-4.5.main] chrAig.rollback() completed notifyAll() to waiting Tx Threads, - @t=1588854212307 DirtyReadOffender ROLLED BACK ,, + ,,@t=1593467845991 DirtyReadVictim sleeping 10 seconds + @t=1593467846072 DirtyReadOffender calling chrAig.put('369604101'/3.85) + , @t=1593467846079 Tx=Thread[Thread-2.5.main] inside chrAig.put('369604101'/null) BEGIN, + , @t=1593467846083 Tx=Thread[Thread-2.5.main] inside chrAig.put('369604101'/3.85) DONE, + @t=1593467846083 DirtyReadOffender sleeping 1 minute. + ,,@t=1593467856000 DirtyReadVictim calling chrAig.get('369604101') + , @t=1593467856002 Tx=Thread[Thread-3.5.main] inside chrAig.get('369604101') BEGIN, + , @t=1593467856036 Tx=Thread[Thread-3.5.main] inside chrAig.get() DONE , + ,,@t=1593467856036 DirtyReadVictim OPTIMISTICALLY_READ coupon=3.85 + ,,@t=1593467856036 DirtyReadVictim calling chrAig.rollback() + , @t=1593467856036 Tx=Thread[Thread-3.5.main] chrAig.rollback() BEGIN , + ,@t=1593467856037 Tx=Thread[Thread-3.5.main] chrAig.rollback() COMPLETE coupon=3.50, +, @t=1593467856037 Tx=Thread[Thread-3.5.main] chrAig.rollback() completed notifyAll() to waiting Tx Threads, + ,,@t=1593467856037 DirtyReadVictim ROLLED BACK diff --git a/pom.xml b/pom.xml index 614ed75e0..ed784a869 100755 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,16 @@ - + net.openhft java-parent-pom 1.1.23 - + 4.0.0 chronicle-map - 3.19.5-SNAPSHOT + 3.19.41-SNAPSHOT OpenHFT/Chronicle-Map Chronicle-Map bundle @@ -71,6 +70,7 @@ + com.intellij annotations 12.0 @@ -224,6 +224,24 @@ 1.11 provided + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + org.junit.jupiter + junit-jupiter + RELEASE + test + diff --git a/spec/README.md b/spec/README.md index 596f5cc40..e0dbe4305 100644 --- a/spec/README.md +++ b/spec/README.md @@ -27,7 +27,7 @@ as an implementation bug. - To provide the ability for Chronicle Map adopters, database developers and researchers to study - the Chronicle Map design and possibly draw their own conclusions about it's behaviour, guarantees + the Chronicle Map design and possibly draw their own conclusions about its behaviour, guarantees and efficiency. The reference implementation is quite complex so it's hard to understand how it works by solely reading the code, especially for people who don't know Java. diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java index 17faf9aa9..ecf893395 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java @@ -17,8 +17,8 @@ package net.openhft.chronicle.hash; import net.openhft.chronicle.bytes.BytesStore; -import net.openhft.chronicle.core.io.Closeable; import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.MapClosable; import net.openhft.chronicle.map.MapMethods; import net.openhft.chronicle.map.MapQueryContext; import net.openhft.chronicle.set.ChronicleSet; @@ -35,43 +35,37 @@ import java.util.function.Predicate; * Common base interface for {@link ChronicleMap} and {@link ChronicleSet}. */ public interface ChronicleHash, SC extends HashSegmentContext, - EQC extends ExternalHashQueryContext> extends Closeable { + EQC extends ExternalHashQueryContext> extends MapClosable { /** - * Returns the file this hash container mapped to, i. e. when it is created by - * {@link ChronicleHashBuilder#create()} call, or {@code null} if it is purely in-memory, - * i. e. if it is created by {@link ChronicleHashBuilder#create()} call. + * Returns the file this hash container mapped to, i. e. when it is created by {@link ChronicleHashBuilder#create()} call, or {@code null} if it + * is purely in-memory, i. e. if it is created by {@link ChronicleHashBuilder#create()} call. * - * @return the file this {@link ChronicleMap} or {@link ChronicleSet} is mapped to, - * or {@code null} if it is not mapped to any file + * @return the file this {@link ChronicleMap} or {@link ChronicleSet} is mapped to, or {@code null} if it is not mapped to any file * @see ChronicleHashBuilder#createPersistedTo(File) */ File file(); /** - * Returns the name of this {@code ChronicleHash}, configured by {@link - * ChronicleHashBuilder#name(String)}, or {@code null}, if not configured. + * Returns the name of this {@code ChronicleHash}, configured by {@link ChronicleHashBuilder#name(String)}, or {@code null}, if not configured. * * @return the name of this this {@link ChronicleMap} or {@link ChronicleSet} */ String name(); /** - * Returns a {@code String}, useful for identifying this {@code ChronicleHash} in debugging, - * logging, and error reporting. {@link #toString()} of concrete {@code ChronicleHash} - * subinterfaces, {@link ChronicleMap} and {@link ChronicleSet}, has to follow {@link - * Map#toString()} and {@link Set#toString()} contracts respectively, making it not always - * useful (or even impossible to use, if this {@code ChronicleHash} contains a lot of entries) - * for the purposes listed above. + * Returns a {@code String}, useful for identifying this {@code ChronicleHash} in debugging, logging, and error reporting. {@link #toString()} of + * concrete {@code ChronicleHash} subinterfaces, {@link ChronicleMap} and {@link ChronicleSet}, has to follow {@link Map#toString()} and {@link + * Set#toString()} contracts respectively, making it not always useful (or even impossible to use, if this {@code ChronicleHash} contains a lot of + * entries) for the purposes listed above. *

*

This method return a string of the form:

- * [ChronicleMap|ChronicleSet]{name={@link #name()}, file={@link #file()}, - * identityHashCode={@link System#identityHashCode System.identityHashCode(thisChronicleHash)}} + * [ChronicleMap|ChronicleSet]{name={@link #name()}, file={@link #file()}, identityHashCode={@link System#identityHashCode + * System.identityHashCode(thisChronicleHash)}} *

- * This form could be changed in any subsequent Chronicle Map library release (including patch - * release). The user code shouldn't depend on this form. + * This form could be changed in any subsequent Chronicle Map library release (including patch release). The user code shouldn't depend on this + * form. * - * @return a {@code String}, useful for identifying this {@code ChronicleHash} in debugging, - * logging, and error reporting + * @return a {@code String}, useful for identifying this {@code ChronicleHash} in debugging, logging, and error reporting */ String toIdentityString(); @@ -83,8 +77,8 @@ public interface ChronicleHash, SC extends HashSegment long longSize(); /** - * Returns the amount of off-heap memory (in bytes), allocated by this {@code ChronicleHash} or - * shared with with other ChronicleHashes, persisting to the same {@link #file()}. + * Returns the amount of off-heap memory (in bytes), allocated by this {@code ChronicleHash} or shared with with other ChronicleHashes, persisting + * to the same {@link #file()}. *

*

After {@link #close()} this method returns 0. * @@ -110,8 +104,7 @@ public interface ChronicleHash, SC extends HashSegment * }} *

*

See documentation to {@link HashQueryContext} interface and methods in {@link MapMethods} - * interface for examples of using contexts. Also see + * interface for examples of using contexts. Also see * Working with an entry within a context section in the Chronicle Map tutorial. * * @param key the queried key @@ -125,15 +118,12 @@ public interface ChronicleHash, SC extends HashSegment EQC queryContext(K key); /** - * Returns a context to perform arbitrary operations with the given key, provided in - * {@link Data} form. Equivalent to {@link #queryContext(Object)}, but accepts {@code Data} - * instead of object key. This method is useful, when you already have {@code Data}, calling - * this method instead of {@link #queryContext(Object)} might help to avoid unnecessary - * deserialization. + * Returns a context to perform arbitrary operations with the given key, provided in {@link Data} form. Equivalent to {@link + * #queryContext(Object)}, but accepts {@code Data} instead of object key. This method is useful, when you already have {@code Data}, calling this + * method instead of {@link #queryContext(Object)} might help to avoid unnecessary deserialization. *

*

See documentation to {@link HashQueryContext} interface and methods in {@link MapMethods} - * interface for examples of using contexts. Also see + * interface for examples of using contexts. Also see * Working with an entry within a context section in the Chronicle Map tutorial. * * @param key the queried key as {@code Data} @@ -143,9 +133,8 @@ public interface ChronicleHash, SC extends HashSegment EQC queryContext(Data key); /** - * Returns a context to perform arbitrary operations with the given key, provided in the - * serialized form. See {@link #queryContext(Object)} and {@link #queryContext(Data)} for more - * information on contexts semantics and usage patterns. + * Returns a context to perform arbitrary operations with the given key, provided in the serialized form. See {@link #queryContext(Object)} and + * {@link #queryContext(Data)} for more information on contexts semantics and usage patterns. * * @param keyBytes the bytes store with the key bytes to query * @param offset actual offset of the key bytes within the given BytesStore @@ -156,8 +145,7 @@ public interface ChronicleHash, SC extends HashSegment EQC queryContext(BytesStore keyBytes, long offset, long size); /** - * Returns a context of the segment with the given index. Segments are indexed from 0 to - * {@link #segments()}{@code - 1}. + * Returns a context of the segment with the given index. Segments are indexed from 0 to {@link #segments()}{@code - 1}. * * @see HashSegmentContext */ @@ -172,50 +160,43 @@ public interface ChronicleHash, SC extends HashSegment int segments(); /** - * Checks the given predicate on each entry in this {@code ChronicleHash} until all entries - * have been processed or the predicate returns {@code false} for some entry, or throws - * an {@code Exception}. Exceptions thrown by the predicate are relayed to the caller. + * Checks the given predicate on each entry in this {@code ChronicleHash} until all entries have been processed or the predicate returns {@code + * false} for some entry, or throws an {@code Exception}. Exceptions thrown by the predicate are relayed to the caller. *

*

The order in which the entries will be processed is unspecified. It might differ from - * the order of iteration via {@code Iterator} returned by any method of this - * {@code ChronicleHash} or it's collection view. + * the order of iteration via {@code Iterator} returned by any method of this {@code ChronicleHash} or it's collection view. *

*

If the {@code ChronicleHash} is empty, this method returns {@code true} immediately. * * @param predicate the predicate to be checked for each entry - * @return {@code true} if the predicate returned {@code true} for all entries of - * the {@code ChronicleHash}, {@code false} if it returned {@code false} for the entry + * @return {@code true} if the predicate returned {@code true} for all entries of the {@code ChronicleHash}, {@code false} if it returned {@code + * false} for the entry */ boolean forEachEntryWhile(Predicate predicate); /** - * Performs the given action for each entry in this {@code ChronicleHash} until all entries have - * been processed or the action throws an {@code Exception}. Exceptions thrown by the action are - * relayed to the caller. + * Performs the given action for each entry in this {@code ChronicleHash} until all entries have been processed or the action throws an {@code + * Exception}. Exceptions thrown by the action are relayed to the caller. *

*

The order in which the entries will be processed is unspecified. It might differ from - * the order of iteration via {@code Iterator} returned by any method of this - * {@code ChronicleHash} or it's collection view. + * the order of iteration via {@code Iterator} returned by any method of this {@code ChronicleHash} or it's collection view. * * @param action the action to be performed for each entry */ void forEachEntry(Consumer action); /** - * Releases the off-heap memory, used by this hash container and resources, used by replication, - * if any. However, if hash container (hence off-heap memory, used by it) is mapped to the file - * and there are other instances mapping the same data on the server across JVMs, the memory - * won't be actually freed on operating system level. I. e. this method call doesn't affect - * other {@link ChronicleMap} or {@link ChronicleSet} instances mapping the same data. + * Releases the off-heap memory, used by this hash container and resources, used by replication, if any. However, if hash container (hence + * off-heap memory, used by it) is mapped to the file and there are other instances mapping the same data on the server across JVMs, the memory + * won't be actually freed on operating system level. I. e. this method call doesn't affect other {@link ChronicleMap} or {@link ChronicleSet} + * instances mapping the same data. *

*

If you won't call this method, memory would be held at least until next garbage - * collection. This could be a problem if, for example, you target rare garbage collections, - * but load and drop {@code ChronicleHash}es regularly. + * collection. This could be a problem if, for example, you target rare garbage collections, but load and drop {@code ChronicleHash}es regularly. *

*

After this method call, all methods, querying the {@code ChronicleHash}'s entries, {@link - * #longSize()} and {@code size()}), throw {@link ChronicleHashClosedException}. {@link - * #isOpen()} returns {@code false}, {@code close()} itself returns immediately without effects - * (i. e. repetitive {@code close()}, even from concurrent threads, are safe). + * #longSize()} and {@code size()}), throw {@link ChronicleHashClosedException}. {@link #isOpen()} returns {@code false}, {@code close()} itself + * returns immediately without effects (i. e. repetitive {@code close()}, even from concurrent threads, are safe). */ @Override void close(); diff --git a/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java b/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java index fa3fb1280..425c32d92 100644 --- a/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java +++ b/src/main/java/net/openhft/chronicle/hash/HashSegmentContext.java @@ -16,7 +16,7 @@ package net.openhft.chronicle.hash; -import net.openhft.chronicle.core.io.Closeable; +import net.openhft.chronicle.map.MapClosable; import java.util.function.Consumer; import java.util.function.Predicate; @@ -28,28 +28,25 @@ import java.util.function.Predicate; * @param the entry type * @see ChronicleHash#segmentContext(int) */ -public interface HashSegmentContext> extends HashContext, Closeable { +public interface HashSegmentContext> extends HashContext, MapClosable { /** - * Performs the given action for each present entry in this segment until all entries - * have been processed or the action throws an {@code Exception}. Exceptions thrown by the - * action are relayed to the caller. + * Performs the given action for each present entry in this segment until all entries have been processed or the action throws an {@code + * Exception}. Exceptions thrown by the action are relayed to the caller. * * @param action the action to be performed for each entry in this segment */ void forEachSegmentEntry(Consumer action); /** - * Checks the given predicate on each present entry in this segment until all entries - * have been processed or the predicate returns {@code false} for some entry, or throws - * an {@code Exception}. Exceptions thrown by the predicate are relayed to the caller. + * Checks the given predicate on each present entry in this segment until all entries have been processed or the predicate returns {@code + * false} for some entry, or throws an {@code Exception}. Exceptions thrown by the predicate are relayed to the caller. *

*

If this segment is empty (i. e. {@link #size()} call returns 0), this method returns * {@code true} immediately. * * @param predicate the predicate to be checked for each entry in this segment - * @return {@code true} if the predicate returned {@code true} for all checked entries, - * {@code false} if it returned {@code false} for some entry + * @return {@code true} if the predicate returned {@code true} for all checked entries, {@code false} if it returned {@code false} for some entry */ boolean forEachSegmentEntryWhile(Predicate predicate); diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java index 1d613653b..ebbfd9a63 100755 --- a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java @@ -38,7 +38,6 @@ import net.openhft.chronicle.map.ChronicleMapBuilder; import net.openhft.chronicle.values.Values; import net.openhft.chronicle.wire.Marshallable; import net.openhft.chronicle.wire.WireIn; -import net.openhft.chronicle.wire.WireInternal; import net.openhft.chronicle.wire.WireOut; import org.jetbrains.annotations.NotNull; @@ -233,12 +232,15 @@ public abstract class VanillaChronicleHash "dataFileVersion").text(dataFileVersion); wireOut.write(() -> "keyClass").typeLiteral(keyClass); @@ -338,7 +341,9 @@ public abstract class VanillaChronicleHash 0; + throwExceptionIfClosed(); + + return globalMutableState.getAllocatedExtraTierBulks() > 0; } @Override public long offHeapMemoryUsed() { - return resources.totalMemory(); + throwExceptionIfClosed(); + + return resources.totalMemory(); } public long allocateTier() { - globalMutableStateLock(); + throwExceptionIfClosed(); + + globalMutableStateLock(); try { long tiersInUse = globalMutableState.getExtraTiersInUse(); if (tiersInUse >= maxExtraTiers) { @@ -837,7 +872,9 @@ public abstract class VanillaChronicleHash> allContexts() { - return Collections.unmodifiableList(resources.contexts()); + throwExceptionIfClosed(); + + return Collections.unmodifiableList(resources.contexts()); } public static class TierBulkData { @@ -1056,7 +1107,9 @@ public abstract class VanillaChronicleHash> } public long tierEntriesForIteration() { - return s.tierEntries(); + throwExceptionIfClosed(); + + return s.tierEntries(); } abstract boolean entryRemovedOnThisIterationInit(); @@ -67,14 +69,18 @@ public abstract class HashSegmentIteration> public abstract boolean hashLookupEntryInit(); public void initHashLookupEntry(long entry) { - hashLookupEntry = entry; + throwExceptionIfClosed(); + + hashLookupEntry = entry; } abstract void closeHashLookupEntry(); @Override public boolean forEachSegmentEntryWhile(Predicate predicate) { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); s.innerUpdateLock.lock(); return innerForEachSegmentEntryWhile(predicate); } @@ -174,18 +180,24 @@ public abstract class HashSegmentIteration> } public void hookAfterEachIteration() { - } + throwExceptionIfClosed(); + + } @Override public void forEachSegmentEntry(Consumer action) { - forEachSegmentEntryWhile(e -> { + throwExceptionIfClosed(); + + forEachSegmentEntryWhile(e -> { action.accept(e); return true; }); } public void checkEntryNotRemovedOnThisIteration() { - if (entryRemovedOnThisIterationInit()) { + throwExceptionIfClosed(); + + if (entryRemovedOnThisIterationInit()) { throw new IllegalStateException( hh.h().toIdentityString() + ": Entry was already removed on this iteration"); } @@ -193,7 +205,9 @@ public abstract class HashSegmentIteration> @Override public void doRemove() { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); s.innerWriteLock.lock(); try { iterationRemove(); @@ -204,7 +218,9 @@ public abstract class HashSegmentIteration> } public void iterationRemove() { - // this condition mean -- some other entry taken place of the removed one + throwExceptionIfClosed(); + + // this condition mean -- some other entry taken place of the removed one if (hh.h().hashLookup.remove(s.tierBaseAddr, hlp.hashLookupPos) != hlp.hashLookupPos) { // if so, should make step back, to compensate step forward on the next iteration, // to consume the shifted entry diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/iter/SegmentsRecovery.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/iter/SegmentsRecovery.java index b8ce94f24..a987cf71c 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/iter/SegmentsRecovery.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/iter/SegmentsRecovery.java @@ -44,7 +44,9 @@ public abstract class SegmentsRecovery implements IterationContext { public void recoverSegments( ChronicleHashCorruption.Listener corruptionListener, ChronicleHashCorruptionImpl corruption) { - VanillaChronicleHash h = hh.h(); + throwExceptionIfClosed(); + + VanillaChronicleHash h = hh.h(); for (int segmentIndex = 0; segmentIndex < h.actualSegments; segmentIndex++) { s.initSegmentIndex(segmentIndex); resetSegmentLock(corruptionListener, corruption); diff --git a/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java b/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java index 311815e04..02d2ce273 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java @@ -16,6 +16,7 @@ package net.openhft.chronicle.hash.impl.util; +import net.openhft.chronicle.core.CleaningRandomAccessFile; import net.openhft.chronicle.core.Jvm; import java.io.File; @@ -36,7 +37,7 @@ public final class CanonicalRandomAccessFiles { return canonicalRafs.compute(file, (f, ref) -> { if (ref == null) { try { - return new RafReference(new RandomAccessFile(f, "rw")); + return new RafReference(new CleaningRandomAccessFile(f, "rw")); } catch (FileNotFoundException e) { throw Jvm.rethrow(e); } diff --git a/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java b/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java index e18c524e7..0b10254bf 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/TimeProvider.java @@ -16,6 +16,7 @@ package net.openhft.chronicle.hash.replication; +import net.openhft.chronicle.core.Jvm; import net.openhft.chronicle.hash.ChronicleHash; import net.openhft.chronicle.hash.ChronicleHashBuilderPrivateAPI; @@ -61,6 +62,7 @@ public final class TimeProvider { return lastTime; if (lastTimeHolder.compareAndSet(lastTime, now)) return now; + Jvm.nanoPause(); } } diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index e7e7d81b8..7596127cc 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -330,8 +330,7 @@ public final class ChronicleMapBuilder implements return valueBuilder.sizeIsStaticallyKnown; } - - private static void checkSegments(long segments) { +private static void checkSegments(long segments) { if (segments <= 0) { throw new IllegalArgumentException("segments should be positive, " + segments + " given"); diff --git a/src/main/java/net/openhft/chronicle/map/MapClosable.java b/src/main/java/net/openhft/chronicle/map/MapClosable.java new file mode 100644 index 000000000..d775ea379 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/MapClosable.java @@ -0,0 +1,12 @@ +package net.openhft.chronicle.map; + +import net.openhft.chronicle.core.io.Closeable; + +public interface MapClosable extends Closeable { + + @Override + default boolean isClosed() { + // if we don't know, pretend it is not. + return false; + } +} diff --git a/src/main/java/net/openhft/chronicle/map/OldDeletedEntriesCleanupThread.java b/src/main/java/net/openhft/chronicle/map/OldDeletedEntriesCleanupThread.java index 3a6253b7d..af47f9976 100644 --- a/src/main/java/net/openhft/chronicle/map/OldDeletedEntriesCleanupThread.java +++ b/src/main/java/net/openhft/chronicle/map/OldDeletedEntriesCleanupThread.java @@ -16,7 +16,6 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.core.io.Closeable; import net.openhft.chronicle.hash.ChronicleHashBuilderPrivateAPI; import net.openhft.chronicle.hash.ReplicatedHashSegmentContext; import net.openhft.chronicle.hash.replication.ReplicableEntry; @@ -34,14 +33,13 @@ import static net.openhft.chronicle.hash.replication.TimeProvider.currentTime; import static net.openhft.chronicle.hash.replication.TimeProvider.systemTimeIntervalBetween; class OldDeletedEntriesCleanupThread extends Thread - implements Closeable, Predicate { + implements MapClosable, Predicate { private static final Logger LOG = LoggerFactory.getLogger(OldDeletedEntriesCleanupThread.class); /** - * Don't store a strong ref to a map in order to avoid it's leaking, if the user forgets to - * close() map, from where this thread is shut down explicitly. Dereference map within - * a single method, {@link #cleanupSegment()}. The map has a chance to be collected by GC when - * this thread is sleeping after cleaning up a segment. + * Don't store a strong ref to a map in order to avoid it's leaking, if the user forgets to close() map, from where this thread is shut down + * explicitly. Dereference map within a single method, {@link #cleanupSegment()}. The map has a chance to be collected by GC when this thread is + * sleeping after cleaning up a segment. */ private final WeakReference> mapRef; /** @@ -116,11 +114,20 @@ class OldDeletedEntriesCleanupThread extends Thread @Override public void run() { - if (System.currentTimeMillis() - startTime < 1_000) + throwExceptionIfClosed(); + + if (System.currentTimeMillis() - startTime < 1_000) return; while (!shutdown) { - int nextSegmentIndex = cleanupSegment(); + int nextSegmentIndex; + try { + nextSegmentIndex = cleanupSegment(); + } catch (Exception e) { + if (shutdown) + break; + throw e; + } if (nextSegmentIndex == -1) return; if (nextSegmentIndex == 0) { @@ -170,7 +177,9 @@ class OldDeletedEntriesCleanupThread extends Thread @Override public boolean test(ReplicableEntry e) { - if (shutdown) + throwExceptionIfClosed(); + + if (shutdown) return false; if (e instanceof MapAbsentEntry) { long deleteTimeout = systemTimeIntervalBetween( diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index c1cec0737..cc004d1c6 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -154,6 +154,7 @@ public class ReplicatedChronicleMap extends VanillaChronicleMap "tierModIterBitSetSizeInBits").int64(tierModIterBitSetSizeInBits); @@ -171,12 +172,16 @@ public class ReplicatedChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap raise change for all + throwExceptionIfClosed(); + + // -1 is invalid remoteIdentifier => raise change for all changeCount.incrementAndGet(); raiseChangeForAllExcept(tierIndex, pos, (byte) -1); } public void raiseChangeFor(long tierIndex, long pos, byte remoteIdentifier) { - acquireModificationIterator(remoteIdentifier).raiseChange0(tierIndex, pos); + throwExceptionIfClosed(); + + acquireModificationIterator(remoteIdentifier).raiseChange0(tierIndex, pos); } public void raiseChangeForAllExcept(long tierIndex, long pos, byte remoteIdentifier) { - updateModificationIteratorsArray(); + throwExceptionIfClosed(); + + updateModificationIteratorsArray(); if (tierIndex <= actualSegments) { long segmentIndex = tierIndex - 1; long offsetToTierBitSet = segmentIndex * tierModIterBitSetOuterSize; @@ -373,7 +402,9 @@ public class ReplicatedChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap keys) { - if (payload != null) + throwExceptionIfClosed(); + + if (payload != null) writePayload(payload, destination); if (entry != null) writeExternalEntry0(entry, destination, keys); @@ -524,11 +565,11 @@ public class ReplicatedChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap * Once a change occurs to a map, map replication requires that these changes are picked up * by another thread, this class provides an iterator like interface to poll for such changes. @@ -681,7 +722,9 @@ public class ReplicatedChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap extends VanillaChronicleMap c = iterationContext()) { + throwExceptionIfClosed(); + + try (CompiledReplicatedMapIterationContext c = iterationContext()) { // iterate over all the segments and mark bit in the modification iterator // that correspond to entries with an older timestamp boolean debugEnabled = LOG.isDebugEnabled(); @@ -934,7 +983,9 @@ public class ReplicatedChronicleMap extends VanillaChronicleMap ///////////////////////////////////////////////// private transient String name; /** - * identityString is initialized lazily in {@link #toIdentityString()} rather than in - * {@link #initOwnTransients()} because it depends on {@link #file()} which is set after - * initOwnTransients(). + * identityString is initialized lazily in {@link #toIdentityString()} rather than in {@link #initOwnTransients()} because it depends on {@link + * #file()} which is set after initOwnTransients(). */ private transient String identityString; private transient boolean defaultEntryOperationsAndMethods; @@ -131,11 +129,12 @@ public class VanillaChronicleMap alignment = wireIn.read(() -> "alignment").int32(); worstAlignment = wireIn.read(() -> "worstAlignment").int32(); - maxBloatFactor = wireIn.read(() -> "maxBloatFactor").float64(); + maxBloatFactor = wireIn.read(() -> "maxBloatFactor").float64(); } @Override public void writeMarshallable(@NotNull WireOut wireOut) { + ; super.writeMarshallable(wireOut); wireOut.write(() -> "valueClass").typeLiteral(valueClass); @@ -163,14 +162,18 @@ public class VanillaChronicleMap @Override public void initTransients() { - super.initTransients(); + throwExceptionIfClosed(); + + super.initTransients(); initOwnTransients(); } public void recover( ChronicleHashResources resources, ChronicleHashCorruption.Listener corruptionListener, ChronicleHashCorruptionImpl corruption) throws IOException { - basicRecover(resources, corruptionListener, corruption); + throwExceptionIfClosed(); + + basicRecover(resources, corruptionListener, corruption); try (IterationContext iterationContext = iterationContext()) { iterationContext.recoverSegments(corruptionListener, corruption); } @@ -214,22 +217,30 @@ public class VanillaChronicleMap @Override public Class keyClass() { - return (Class) keyClass; + throwExceptionIfClosed(); + + return (Class) keyClass; } @Override public Type keyType() { - return keyClass; + throwExceptionIfClosed(); + + return keyClass; } @Override public Class valueClass() { - return (Class) valueClass; + throwExceptionIfClosed(); + + return (Class) valueClass; } @Override public Type valueType() { - return valueClass; + throwExceptionIfClosed(); + + return valueClass; } private long tiersUsed() { @@ -242,13 +253,16 @@ public class VanillaChronicleMap @Override public int remainingAutoResizes() { - return (int) (maxTiers() - tiersUsed()); + throwExceptionIfClosed(); + + return (int) (maxTiers() - tiersUsed()); } @Override public short percentageFreeSpace() { + throwExceptionIfClosed(); - double totalUsed = 0; + double totalUsed = 0; double totalSize = 0; try (IterationContext c = iterationContext()) { @@ -270,8 +284,7 @@ public class VanillaChronicleMap totalUsed += freeList0.cardinality(); totalSize += freeList.logicalSize(); } - - } + } } return (short) (100 - (int) (100 * totalUsed / totalSize)); @@ -279,7 +292,7 @@ public class VanillaChronicleMap @NotNull @Override - public final Closeable acquireContext(K key, V usingValue) { + public final MapClosable acquireContext(K key, V usingValue) { QueryContextInterface q = queryContext(key); // TODO optimize to update lock in certain cases try { @@ -312,12 +325,16 @@ public class VanillaChronicleMap @Override public int hashCode() { - return mapHashCode(); + throwExceptionIfClosed(); + + return mapHashCode(); } @Override public boolean equals(Object obj) { - return mapEquals(obj); + throwExceptionIfClosed(); + + return mapEquals(obj); } @Override @@ -332,7 +349,9 @@ public class VanillaChronicleMap @Override public String toIdentityString() { - if (identityString == null) + throwExceptionIfClosed(); + + if (identityString == null) identityString = makeIdentityString(); return identityString; } @@ -349,7 +368,9 @@ public class VanillaChronicleMap @Override public void clear() { - forEachEntry(c -> c.context().remove(c)); + throwExceptionIfClosed(); + + forEachEntry(c -> c.context().remove(c)); } public final long readValueSize(Bytes entry) { @@ -359,7 +380,9 @@ public class VanillaChronicleMap } public void alignReadPosition(Bytes entry) { - long positionAddr = entry.addressForRead(entry.readPosition()); + throwExceptionIfClosed(); + + long positionAddr = entry.addressForRead(entry.readPosition()); long skip = alignAddr(positionAddr, alignment) - positionAddr; if (skip > 0) entry.readSkip(skip); @@ -522,7 +545,9 @@ public class VanillaChronicleMap @Override public V get(Object key) { - return defaultEntryOperationsAndMethods ? optimizedGet(key, null) : defaultGet(key); + throwExceptionIfClosed(); + + return defaultEntryOperationsAndMethods ? optimizedGet(key, null) : defaultGet(key); } final V defaultGet(Object key) { @@ -677,7 +702,7 @@ public class VanillaChronicleMap } long keySizeOffset = entrySpaceOffset + (entryPos * chunkSize); - bs.readLimit(bs.capacity()); + bs.readLimitToCapacity(); bs.readPosition(keySizeOffset); long keySize = keySizeMarshaller.readSize(bs); long keyOffset = bs.readPosition(); @@ -695,7 +720,9 @@ public class VanillaChronicleMap @Override public V getUsing(K key, V usingValue) { - return defaultEntryOperationsAndMethods ? optimizedGet(key, usingValue) : + throwExceptionIfClosed(); + + return defaultEntryOperationsAndMethods ? optimizedGet(key, usingValue) : defaultGetUsing(key, usingValue); } @@ -709,7 +736,9 @@ public class VanillaChronicleMap @Override public V acquireUsing(K key, V usingValue) { - try (QueryContextInterface q = queryContext(key)) { + throwExceptionIfClosed(); + + try (QueryContextInterface q = queryContext(key)) { return acquireUsingBody(q, usingValue); } } @@ -722,7 +751,9 @@ public class VanillaChronicleMap @Override public V putIfAbsent(K key, V value) { - checkValue(value); + throwExceptionIfClosed(); + + checkValue(value); try (QueryContextInterface q = queryContext(key)) { methods.putIfAbsent(q, q.inputValueDataAccess().getData(value), q.defaultReturnValue()); return q.defaultReturnValue().returnValue(); @@ -731,7 +762,9 @@ public class VanillaChronicleMap @Override public boolean remove(Object key, Object value) { - if (value == null) + throwExceptionIfClosed(); + + if (value == null) return false; // ConcurrentHashMap compatibility V v = checkValue(value); try (QueryContextInterface q = queryContext(key)) { @@ -741,7 +774,9 @@ public class VanillaChronicleMap @Override public boolean replace(K key, V oldValue, V newValue) { - checkValue(oldValue); + throwExceptionIfClosed(); + + checkValue(oldValue); checkValue(newValue); try (QueryContextInterface q = queryContext(key)) { return methods.replace( @@ -751,7 +786,9 @@ public class VanillaChronicleMap @Override public V replace(K key, V value) { - checkValue(value); + throwExceptionIfClosed(); + + checkValue(value); try (QueryContextInterface q = queryContext(key)) { methods.replace(q, q.inputValueDataAccess().getData(value), q.defaultReturnValue()); return q.defaultReturnValue().returnValue(); @@ -760,14 +797,18 @@ public class VanillaChronicleMap @Override public boolean containsKey(Object key) { - try (QueryContextInterface q = queryContext(key)) { + throwExceptionIfClosed(); + + try (QueryContextInterface q = queryContext(key)) { return methods.containsKey(q); } } @Override public V put(K key, V value) { - checkValue(value); + throwExceptionIfClosed(); + + checkValue(value); try (QueryContextInterface q = queryContext(key)) { Data valueData = q.inputValueDataAccess().getData(value); InstanceReturnValue returnValue = @@ -779,7 +820,9 @@ public class VanillaChronicleMap @Override public V remove(Object key) { - try (QueryContextInterface q = queryContext(key)) { + throwExceptionIfClosed(); + + try (QueryContextInterface q = queryContext(key)) { InstanceReturnValue returnValue = removeReturnsNull ? NullReturnValue.get() : q.defaultReturnValue(); methods.remove(q, returnValue); @@ -790,7 +833,9 @@ public class VanillaChronicleMap @Override public V merge(K key, V value, BiFunction remappingFunction) { - try (QueryContextInterface q = queryContext(key)) { + throwExceptionIfClosed(); + + try (QueryContextInterface q = queryContext(key)) { methods.merge(q, q.inputValueDataAccess().getData(value), remappingFunction, q.defaultReturnValue()); return q.defaultReturnValue().returnValue(); @@ -799,7 +844,9 @@ public class VanillaChronicleMap @Override public V compute(K key, BiFunction remappingFunction) { - try (QueryContextInterface q = queryContext(key)) { + throwExceptionIfClosed(); + + try (QueryContextInterface q = queryContext(key)) { methods.compute(q, remappingFunction, q.defaultReturnValue()); return q.defaultReturnValue().returnValue(); } @@ -807,7 +854,9 @@ public class VanillaChronicleMap @Override public V computeIfAbsent(K key, Function mappingFunction) { - try (QueryContextInterface q = queryContext(key)) { + throwExceptionIfClosed(); + + try (QueryContextInterface q = queryContext(key)) { methods.computeIfAbsent(q, mappingFunction, q.defaultReturnValue()); return q.defaultReturnValue().returnValue(); } @@ -816,14 +865,18 @@ public class VanillaChronicleMap @Override public V computeIfPresent(K key, BiFunction remappingFunction) { - try (QueryContextInterface q = queryContext(key)) { + throwExceptionIfClosed(); + + try (QueryContextInterface q = queryContext(key)) { methods.computeIfPresent(q, remappingFunction, q.defaultReturnValue()); return q.defaultReturnValue().returnValue(); } } public void verifyTierCountersAreaData() { - for (int i = 0; i < actualSegments; i++) { + throwExceptionIfClosed(); + + for (int i = 0; i < actualSegments; i++) { try (MapSegmentContext c = segmentContext(i)) { Method verifyTierCountersAreaData = c.getClass().getMethod("verifyTierCountersAreaData"); diff --git a/src/main/java/net/openhft/chronicle/map/acid/BondVOInterface.java b/src/main/java/net/openhft/chronicle/map/acid/BondVOInterface.java deleted file mode 100644 index e01c9422b..000000000 --- a/src/main/java/net/openhft/chronicle/map/acid/BondVOInterface.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2012-2018 Chronicle Map Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.openhft.chronicle.map.acid; - -import net.openhft.chronicle.values.Array; -import net.openhft.chronicle.values.Group; -import net.openhft.chronicle.values.MaxUtf8Length; - -public interface BondVOInterface { - - @Group(0) - long getEntryLockState(); - - void setEntryLockState(long entryLockState); - - @Group(1) - long getIssueDate(); - - void setIssueDate(long issueDate); /* time in millis */ - - @Group(1) - long getMaturityDate(); - - void setMaturityDate(long maturityDate); /* time in millis */ - - long addAtomicMaturityDate(long toAdd); - - @Group(1) - boolean compareAndSwapCoupon(double expected, double value); - - double getCoupon(); - - void setCoupon(double coupon); - - double addAtomicCoupon(double toAdd); - - @Group(1) - String getSymbol(); - - void setSymbol(@MaxUtf8Length(20) String symbol); - - // OpenHFT Off-Heap array[ ] processing notice ‘At’ suffix - @Group(1) - @Array(length = 7) - void setMarketPxIntraDayHistoryAt(int tradingDayHour, MarketPx mPx); - - /* 7 Hours in the Trading Day: - * index_0 = 9.30am, - * index_1 = 10.30am, - …, - * index_6 = 4.30pm - */ - - MarketPx getMarketPxIntraDayHistoryAt(int tradingDayHour); - - /* nested interface - empowering an Off-Heap hierarchical “TIER of prices” - as array[ ] value */ - interface MarketPx { - double getCallPx(); - - void setCallPx(double px); - - double getParPx(); - - void setParPx(double px); - - double getMaturityPx(); - - void setMaturityPx(double px); - - double getBidPx(); - - void setBidPx(double px); - - double getAskPx(); - - void setAskPx(double px); - } -} diff --git a/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java b/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java index a951067cd..9ab41ef8c 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java +++ b/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java @@ -17,10 +17,10 @@ package net.openhft.chronicle.map.impl; import net.openhft.chronicle.bytes.BytesStore; -import net.openhft.chronicle.core.io.Closeable; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.serialization.DataAccess; import net.openhft.chronicle.map.ExternalMapQueryContext; +import net.openhft.chronicle.map.MapClosable; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; @@ -38,7 +38,7 @@ public interface QueryContextInterface extends ExternalMapQueryContext< DataAccess inputValueDataAccess(); - Closeable acquireHandle(); + MapClosable acquireHandle(); void initSegmentIndex(int segmentIndex); diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/data/ZeroBytesStore.java b/src/main/java/net/openhft/chronicle/map/impl/stage/data/ZeroBytesStore.java index e79f95870..655b3a8b5 100755 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/data/ZeroBytesStore.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/data/ZeroBytesStore.java @@ -19,6 +19,7 @@ package net.openhft.chronicle.map.impl.stage.data; import net.openhft.chronicle.bytes.BytesStore; import net.openhft.chronicle.bytes.RandomDataInput; import net.openhft.chronicle.core.OS; +import net.openhft.chronicle.core.io.ReferenceOwner; import org.jetbrains.annotations.Nullable; import java.nio.BufferOverflowException; @@ -37,7 +38,7 @@ public enum ZeroBytesStore implements BytesStore { throw new UnsupportedOperationException("Cannot get the address of nothing"); } - @Override +@Override public int peekUnsignedByte(long offset) { return 0; } @@ -155,24 +156,33 @@ public enum ZeroBytesStore implements BytesStore { return true; } - @Override - public void reserve() throws IllegalStateException { +@Override + public void reserve(ReferenceOwner id) throws IllegalStateException { } @Override - public void release() throws IllegalStateException { + public boolean tryReserve(ReferenceOwner id) throws IllegalStateException { + return false; } @Override - public long refCount() { + public boolean reservedBy(ReferenceOwner owner) { + return true; + } + + @Override + public void release(ReferenceOwner id) throws IllegalStateException { + } + + @Override + public void releaseLast(ReferenceOwner id) throws IllegalStateException { + } + + @Override + public int refCount() { return 0; } - @Override - public boolean tryReserve() { - throw new UnsupportedOperationException("todo"); - } - @Override public ZeroBytesStore writeByte(long l, byte b) { throw new UnsupportedOperationException(); diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/iter/MapSegmentIteration.java b/src/main/java/net/openhft/chronicle/map/impl/stage/iter/MapSegmentIteration.java index 4532c782b..fab7faa66 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/iter/MapSegmentIteration.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/iter/MapSegmentIteration.java @@ -40,12 +40,16 @@ public abstract class MapSegmentIteration extends HashSegmentIteration< @Override public void hookAfterEachIteration() { - wrappedValueInstanceDataHolder.closeValue(); + throwExceptionIfClosed(); + + wrappedValueInstanceDataHolder.closeValue(); } @Override public void doReplaceValue(Data newValue) { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); try { entry.innerDefaultReplaceValue(newValue); } finally { diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/iter/ReplicatedMapSegmentIteration.java b/src/main/java/net/openhft/chronicle/map/impl/stage/iter/ReplicatedMapSegmentIteration.java index 46b1a8c55..584a1748a 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/iter/ReplicatedMapSegmentIteration.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/iter/ReplicatedMapSegmentIteration.java @@ -60,22 +60,30 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI @Override public boolean shouldTestEntry() { - return entriesToTest == ALL || !e.entryDeleted(); + throwExceptionIfClosed(); + + return entriesToTest == ALL || !e.entryDeleted(); } @Override public Object entryForIteration() { - return !e.entryDeleted() ? entryDelegating : absentEntryDelegating; + throwExceptionIfClosed(); + + return !e.entryDeleted() ? entryDelegating : absentEntryDelegating; } @Override public long tierEntriesForIteration() { - return entriesToTest == ALL ? s.tierEntries() : s.tierEntries() - s.tierDeleted(); + throwExceptionIfClosed(); + + return entriesToTest == ALL ? s.tierEntries() : s.tierEntries() - s.tierDeleted(); } @Override public void doReplaceValue(Data newValue) { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); try { entry.innerDefaultReplaceValue(newValue); e.updatedReplicationStateOnPresentEntry(); @@ -87,7 +95,9 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI @Override public boolean forEachSegmentEntryWhile(Predicate> predicate) { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); initEntriesToTest(PRESENT); s.innerUpdateLock.lock(); return innerForEachSegmentEntryWhile(predicate); @@ -96,7 +106,9 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI @Override public boolean forEachSegmentReplicableEntryWhile( Predicate predicate) { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); initEntriesToTest(ALL); s.innerUpdateLock.lock(); return innerForEachSegmentEntryWhile(predicate); @@ -104,7 +116,9 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI @Override public void forEachSegmentReplicableEntry(Consumer action) { - forEachSegmentReplicableEntryWhile(e -> { + throwExceptionIfClosed(); + + forEachSegmentReplicableEntryWhile(e -> { action.accept(e); return true; }); @@ -112,7 +126,9 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI @Override public void doRemove() { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); try { if (e.valueSize > dummyValue.size()) e.innerDefaultReplaceValue(dummyValue); @@ -128,7 +144,9 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI @Override public void doRemoveCompletely() { - boolean wasDeleted = e.entryDeleted(); + throwExceptionIfClosed(); + + boolean wasDeleted = e.entryDeleted(); super.doRemove(); ru.dropChange(); if (wasDeleted) @@ -136,7 +154,9 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI } public void doInsert(Data value) { - checkOnEachPublicOperation.checkOnEachPublicOperation(); + throwExceptionIfClosed(); + + checkOnEachPublicOperation.checkOnEachPublicOperation(); if (e.entryDeleted()) { try { s.tierDeleted(s.tierDeleted() - 1); @@ -155,7 +175,9 @@ public abstract class ReplicatedMapSegmentIteration extends MapSegmentI } public void doInsert() { - if (mh.set() == null) + throwExceptionIfClosed(); + + if (mh.set() == null) throw new IllegalStateException(mh.h().toIdentityString() + ": Called SetAbsentEntry.doInsert() from Map context"); doInsert((Data) DummyValueData.INSTANCE); diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/query/AcquireHandle.java b/src/main/java/net/openhft/chronicle/map/impl/stage/query/AcquireHandle.java index f946b6a93..2fcec669b 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/query/AcquireHandle.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/query/AcquireHandle.java @@ -16,14 +16,14 @@ package net.openhft.chronicle.map.impl.stage.query; -import net.openhft.chronicle.core.io.Closeable; import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation; +import net.openhft.chronicle.map.MapClosable; import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue; import net.openhft.sg.StageRef; import net.openhft.sg.Staged; @Staged -public class AcquireHandle implements Closeable { +public class AcquireHandle implements MapClosable { @StageRef CheckOnEachPublicOperation checkOnEachPublicOperation; diff --git a/src/main/java/net/openhft/chronicle/set/SetFromMap.java b/src/main/java/net/openhft/chronicle/set/SetFromMap.java index c31204622..edadc8f7a 100644 --- a/src/main/java/net/openhft/chronicle/set/SetFromMap.java +++ b/src/main/java/net/openhft/chronicle/set/SetFromMap.java @@ -51,35 +51,51 @@ class SetFromMap extends AbstractSet implements ChronicleSet { } public void clear() { - m.clear(); + throwExceptionIfClosed(); + + m.clear(); } public int size() { - return m.size(); + throwExceptionIfClosed(); + + return m.size(); } public boolean isEmpty() { - return m.isEmpty(); + throwExceptionIfClosed(); + + return m.isEmpty(); } public boolean contains(Object o) { - return m.containsKey(o); + throwExceptionIfClosed(); + + return m.containsKey(o); } public boolean remove(Object o) { - return m.remove(o, DUMMY_VALUE); + throwExceptionIfClosed(); + + return m.remove(o, DUMMY_VALUE); } public boolean add(E e) { - return m.putIfAbsent(e, DUMMY_VALUE) == null; + throwExceptionIfClosed(); + + return m.putIfAbsent(e, DUMMY_VALUE) == null; } public Iterator iterator() { - return s.iterator(); + throwExceptionIfClosed(); + + return s.iterator(); } public Object[] toArray() { - return s.toArray(); + throwExceptionIfClosed(); + + return s.toArray(); } public T[] toArray(T[] a) { @@ -92,7 +108,9 @@ class SetFromMap extends AbstractSet implements ChronicleSet { @Override public String toIdentityString() { - return "ChronicleSet{" + + throwExceptionIfClosed(); + + return "ChronicleSet{" + "name=" + name() + ", file=" + file() + ", identityHashCode=" + System.identityHashCode(this) + @@ -100,44 +118,62 @@ class SetFromMap extends AbstractSet implements ChronicleSet { } public int hashCode() { - return s.hashCode(); + throwExceptionIfClosed(); + + return s.hashCode(); } public boolean equals(Object o) { - return o == this || s.equals(o); + throwExceptionIfClosed(); + + return o == this || s.equals(o); } public boolean containsAll(Collection c) { - return s.containsAll(c); + throwExceptionIfClosed(); + + return s.containsAll(c); } public boolean removeAll(Collection c) { - return s.removeAll(c); + throwExceptionIfClosed(); + + return s.removeAll(c); } public boolean retainAll(Collection c) { - return s.retainAll(c); + throwExceptionIfClosed(); + + return s.retainAll(c); } // addAll is the only inherited implementation @Override public long longSize() { - return m.longSize(); + throwExceptionIfClosed(); + + return m.longSize(); } @Override public long offHeapMemoryUsed() { - return m.offHeapMemoryUsed(); + throwExceptionIfClosed(); + + return m.offHeapMemoryUsed(); } @Override public Class keyClass() { - return m.keyClass(); + throwExceptionIfClosed(); + + return m.keyClass(); } @Override public Type keyType() { - return m.keyType(); + throwExceptionIfClosed(); + + return m.keyType(); } // TODO test queryContext methods @@ -171,31 +207,41 @@ class SetFromMap extends AbstractSet implements ChronicleSet { @Override public int segments() { - return m.segments(); + throwExceptionIfClosed(); + + return m.segments(); } // TODO test forEach methods @Override public boolean forEachEntryWhile(Predicate> predicate) { - Objects.requireNonNull(predicate); + throwExceptionIfClosed(); + + Objects.requireNonNull(predicate); return m.forEachEntryWhile(e -> predicate.test(((SetEntry) e))); } @Override public void forEachEntry(Consumer> action) { - Objects.requireNonNull(action); + throwExceptionIfClosed(); + + Objects.requireNonNull(action); m.forEachEntry(e -> action.accept(((SetEntry) e))); } @Override public File file() { - return m.file(); + throwExceptionIfClosed(); + + return m.file(); } @Override public String name() { - return m.name(); + throwExceptionIfClosed(); + + return m.name(); } @Override @@ -205,6 +251,8 @@ class SetFromMap extends AbstractSet implements ChronicleSet { @Override public boolean isOpen() { - return m.isOpen(); + throwExceptionIfClosed(); + + return m.isOpen(); } } diff --git a/src/test/java/examples/portfolio/PortfolioValueTest.java b/src/test/java/examples/portfolio/PortfolioValueTest.java index 3beba449e..64b8c59bd 100644 --- a/src/test/java/examples/portfolio/PortfolioValueTest.java +++ b/src/test/java/examples/portfolio/PortfolioValueTest.java @@ -20,6 +20,7 @@ import net.openhft.chronicle.core.values.LongValue; import net.openhft.chronicle.map.ChronicleMap; import net.openhft.chronicle.map.ChronicleMapBuilder; import net.openhft.chronicle.map.MapSegmentContext; +import net.openhft.chronicle.threads.NamedThreadFactory; import net.openhft.chronicle.values.Values; import org.apache.commons.lang3.mutable.MutableDouble; import org.junit.Test; @@ -42,7 +43,8 @@ public class PortfolioValueTest { private static void computeValueUsingIterator(final ChronicleMap cache) throws ExecutionException, InterruptedException { long startTime = System.currentTimeMillis(); - ExecutorService executor = Executors.newFixedThreadPool(nThreads); + ExecutorService executor = Executors.newFixedThreadPool(nThreads, + new NamedThreadFactory("test")); @SuppressWarnings("unchecked") Future[] futures = new Future[nThreads]; long batchSize = (useIterator ? cache.segments() : nAssets) / nThreads; @@ -118,7 +120,8 @@ public class PortfolioValueTest { private void createData(final ChronicleMap cache) throws ExecutionException, InterruptedException { long startTime = System.currentTimeMillis(); - ExecutorService executor = Executors.newFixedThreadPool(nThreads); + ExecutorService executor = Executors.newFixedThreadPool(nThreads, + new NamedThreadFactory("test")); Future[] futures = new Future[nThreads]; long batchSize = nAssets / nThreads; diff --git a/src/test/java/net/openhft/chronicle/map/AutoResizeTest.java b/src/test/java/net/openhft/chronicle/map/AutoResizeTest.java index 4ca677ffe..657fac2ec 100644 --- a/src/test/java/net/openhft/chronicle/map/AutoResizeTest.java +++ b/src/test/java/net/openhft/chronicle/map/AutoResizeTest.java @@ -43,8 +43,7 @@ public class AutoResizeTest { Assert.assertNotEquals(0.0, map.remainingAutoResizes()); System.out.println(actual); } - - } + } @Test public void testAutoResizeNotZeroUponRestart2() throws IOException { @@ -59,7 +58,6 @@ public class AutoResizeTest { Assert.assertNotEquals(0.0, actual); System.out.println(actual); } - - } + } } diff --git a/src/test/java/net/openhft/chronicle/map/BasicReplicationTest.java b/src/test/java/net/openhft/chronicle/map/BasicReplicationTest.java index 9dc28723b..a22a4bc0b 100644 --- a/src/test/java/net/openhft/chronicle/map/BasicReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/BasicReplicationTest.java @@ -18,6 +18,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.bytes.Bytes; import net.openhft.chronicle.hash.replication.ReplicableEntry; +import net.openhft.chronicle.threads.NamedThreadFactory; import org.hamcrest.CoreMatchers; import org.junit.Test; @@ -65,7 +66,8 @@ public class BasicReplicationTest { processorThree.addDestinationMap(mapThree.acquireModificationIterator(asByte(1)), mapThree, mapOne); processorThree.addDestinationMap(mapThree.acquireModificationIterator(asByte(2)), mapThree, mapTwo); - final ExecutorService executorService = Executors.newFixedThreadPool(3); + final ExecutorService executorService = Executors.newFixedThreadPool(3, + new NamedThreadFactory("test")); executorService.submit(processorOne::processPendingChangesLoop); executorService.submit(processorTwo::processPendingChangesLoop); executorService.submit(processorThree::processPendingChangesLoop); @@ -175,7 +177,8 @@ public class BasicReplicationTest { private final ReplicatedChronicleMap sourceMap; private final ReplicatedChronicleMap destinationMap; private final Bytes buffer = Bytes.elasticByteBuffer(4096); - private final ExecutorService delayedExecutor = Executors.newSingleThreadExecutor(); + private final ExecutorService delayedExecutor = Executors.newSingleThreadExecutor( + new NamedThreadFactory("delayed")); private final AtomicInteger messagesInflight = new AtomicInteger(0); private final ArrayList keys = new ArrayList<>(); diff --git a/src/test/java/net/openhft/chronicle/map/BloatFactorTest.java b/src/test/java/net/openhft/chronicle/map/BloatFactorTest.java index 2b434e01b..3013eae01 100644 --- a/src/test/java/net/openhft/chronicle/map/BloatFactorTest.java +++ b/src/test/java/net/openhft/chronicle/map/BloatFactorTest.java @@ -42,7 +42,6 @@ public class BloatFactorTest { Assert.assertEquals(EXPECTED_MAX_BLOAT_FACTOR, maxBloatFactor,0.0); } - - } + } } diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapSanityCheckTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapSanityCheckTest.java index 28c02ef66..8a12f33f1 100644 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapSanityCheckTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapSanityCheckTest.java @@ -17,6 +17,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.core.Jvm; +import net.openhft.chronicle.threads.NamedThreadFactory; import org.junit.Test; import java.io.File; @@ -47,10 +48,12 @@ public class ChronicleMapSanityCheckTest { file.getAbsolutePath().toString()); ScheduledExecutorService producerExecutor = - Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() - 1); + Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() - 1, + new NamedThreadFactory("producer")); ScheduledExecutorService consumerExecutor = - Executors.newSingleThreadScheduledExecutor(); + Executors.newSingleThreadScheduledExecutor( + new NamedThreadFactory("consumer")); int N = 1000; diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index f6f3d4034..792964e22 100755 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -23,6 +23,7 @@ import net.openhft.chronicle.bytes.BytesStore; import net.openhft.chronicle.core.values.IntValue; import net.openhft.chronicle.core.values.LongValue; import net.openhft.chronicle.set.Builder; +import net.openhft.chronicle.threads.NamedThreadFactory; import net.openhft.chronicle.values.Values; import org.junit.Ignore; import org.junit.Test; @@ -917,7 +918,7 @@ public class ChronicleMapTest { // int runs = Integer.getInteger("runs", 10); int procs = 1; // Runtime.getRuntime().availableProcessors(); int threads = procs * 3; - ExecutorService es = Executors.newFixedThreadPool(procs); + ExecutorService es = Executors.newFixedThreadPool(procs, new NamedThreadFactory("test")); for (int runs : new int[]{1, /*10, 250, 500, 1000, 2500*/}) { for (int entrySize : new int[]{240, 256}) { int valuePadding = entrySize - 16; @@ -1009,7 +1010,7 @@ public class ChronicleMapTest { int procs = Runtime.getRuntime().availableProcessors(); if (procs > 8) procs--; int threads = procs * 3; - ExecutorService es = Executors.newFixedThreadPool(procs); + ExecutorService es = Executors.newFixedThreadPool(procs, new NamedThreadFactory("test")); for (int runs : new int[]{1, 2, 5, 10, 25, 50, 100, 500, 1000, 2500}) { final long entries = runs * 1000 * 1000L; @@ -1106,7 +1107,7 @@ public class ChronicleMapTest { // int runs = Integer.getInteger("runs", 10); int procs = Runtime.getRuntime().availableProcessors(); int threads = procs * 3; // runs > 100 ? procs / 2 : procs; - ExecutorService es = Executors.newFixedThreadPool(procs); + ExecutorService es = Executors.newFixedThreadPool(procs, new NamedThreadFactory("test")); for (int runs : new int[]{10, 50, 100, 250, 500, 1000, 2500}) { // JAVA 8 produces more garbage than previous versions for internal work. // System.gc(); @@ -1185,7 +1186,7 @@ public class ChronicleMapTest { for (int j = 0; j < count; j++) { final ConcurrentMap map = new ConcurrentHashMap((int) (entries * 5 / 4), 1.0f, 1024); long start = System.currentTimeMillis(); - ExecutorService es = Executors.newFixedThreadPool(procs); + ExecutorService es = Executors.newFixedThreadPool(procs, new NamedThreadFactory("test")); for (int i = 0; i < threads; i++) { final int t = i; es.submit(new Runnable() { diff --git a/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java b/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java index 698dc5246..9f4c4236b 100644 --- a/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/EntryCountMapTest.java @@ -17,6 +17,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.core.values.LongValue; +import net.openhft.chronicle.threads.NamedThreadFactory; import org.junit.Ignore; import org.junit.Test; @@ -116,7 +117,7 @@ public class EntryCountMapTest { public void testSmall() throws IOException, ExecutionException, InterruptedException { System.out.print("testSmall seeds"); int procs = Runtime.getRuntime().availableProcessors(); - ExecutorService es = Executors.newFixedThreadPool(procs); + ExecutorService es = Executors.newFixedThreadPool(procs, new NamedThreadFactory("test")); for (int t = 0; t < ecmTests; t++) { List> futures = new ArrayList<>(); { @@ -160,7 +161,7 @@ public class EntryCountMapTest { public void testMedium() throws IOException, ExecutionException, InterruptedException { System.out.print("testMedium seeds"); int procs = Runtime.getRuntime().availableProcessors(); - ExecutorService es = Executors.newFixedThreadPool(procs); + ExecutorService es = Executors.newFixedThreadPool(procs, new NamedThreadFactory("test")); for (int t = 0; t < ecmTests; t++) { // regression test. List> futures = new ArrayList<>(); diff --git a/src/test/java/net/openhft/chronicle/map/ExitHookTest.java b/src/test/java/net/openhft/chronicle/map/ExitHookTest.java index b5003cb8c..eed6bea0e 100644 --- a/src/test/java/net/openhft/chronicle/map/ExitHookTest.java +++ b/src/test/java/net/openhft/chronicle/map/ExitHookTest.java @@ -17,7 +17,6 @@ package net.openhft.chronicle.map; import com.google.common.base.Preconditions; -import net.bytebuddy.implementation.bytecode.Throw; import net.openhft.chronicle.core.OS; import org.junit.Rule; import org.junit.Test; @@ -36,7 +35,7 @@ import static org.junit.Assert.*; public class ExitHookTest { private static final int KEY = 1; - private static final int JVM_STARTUP_WAIT_TIME_MS = 15_000; + private static final int JVM_STARTUP_WAIT_TIME_MS = 5_000; private static final String PRE_SHUTDOWN_ACTION_EXECUTED = "PRE_SHUTDOWN_ACTION_EXECUTED"; private static final String USER_SHUTDOWN_HOOK_EXECUTED = "USER_SHUTDOWN_HOOK_EXECUTED"; @@ -44,64 +43,60 @@ public class ExitHookTest { public TemporaryFolder folder = new TemporaryFolder(); public static void main(String[] args) throws IOException, InterruptedException { + + System.out.println("Other process started, yo"); + File mapFile = new File(args[0]); + System.out.println("1"); + File shutdownActionConfirmationFile = new File(args[1]); + System.out.println("2"); + ChronicleMapBuilder mapBuilder = null; try { - System.out.println("Other process started, yo"); - File mapFile = new File(args[0]); - System.out.println("1"); - File shutdownActionConfirmationFile = new File(args[1]); - System.out.println("2"); - ChronicleMapBuilder mapBuilder = null; - try { - mapBuilder = createMapBuilder(); - } catch (Throwable e) { - e.printStackTrace(); - } - System.out.println("3"); - boolean skipCloseOnExitHook = false; - System.out.println("4"); - if (Boolean.parseBoolean(args[2])) { - skipCloseOnExitHook = true; - } - AtomicReference> mapReference = new AtomicReference<>(); - System.out.println("exit hook" + skipCloseOnExitHook); - if (skipCloseOnExitHook) { - mapBuilder.skipCloseOnExitHook(skipCloseOnExitHook); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - // In practice, do something with map before shutdown - like create a new map using data from this map. - mapReference.get().close(); - try { - System.out.println("Executing user defined shutdown hook"); - Preconditions.checkState(shutdownActionConfirmationFile.exists()); - Files.write(shutdownActionConfirmationFile.toPath(), - USER_SHUTDOWN_HOOK_EXECUTED.getBytes()); - } catch (Exception e) { - throw new RuntimeException(e); - } - })); - } else { - mapBuilder.setPreShutdownAction(() -> { - try { - System.out.println("Executing pre-shutdown action"); - Preconditions.checkState(shutdownActionConfirmationFile.exists()); - Files.write(shutdownActionConfirmationFile.toPath(), - PRE_SHUTDOWN_ACTION_EXECUTED.getBytes()); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - } - mapReference.set(mapBuilder.createPersistedTo(mapFile)); - try (ExternalMapQueryContext c = mapReference.get().queryContext(KEY)) { - c.writeLock().lock(); - Thread.sleep(30_000); - } - } catch (Exception e) { + mapBuilder = createMapBuilder(); + } catch (Throwable e) { e.printStackTrace(); } + System.out.println("3"); + boolean skipCloseOnExitHook = false; + System.out.println("4"); + if (Boolean.parseBoolean(args[2])) { + skipCloseOnExitHook = true; + } + AtomicReference> mapReference = new AtomicReference<>(); + System.out.println("exit hook" + skipCloseOnExitHook); + if (skipCloseOnExitHook) { + mapBuilder.skipCloseOnExitHook(skipCloseOnExitHook); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + // In practice, do something with map before shutdown - like create a new map using data from this map. + mapReference.get().close(); + try { + System.out.println("Executing user defined shutdown hook"); + Preconditions.checkState(shutdownActionConfirmationFile.exists()); + Files.write(shutdownActionConfirmationFile.toPath(), + USER_SHUTDOWN_HOOK_EXECUTED.getBytes()); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + } else { + mapBuilder.setPreShutdownAction(() -> { + try { + System.out.println("Executing pre-shutdown action"); + Preconditions.checkState(shutdownActionConfirmationFile.exists()); + Files.write(shutdownActionConfirmationFile.toPath(), + PRE_SHUTDOWN_ACTION_EXECUTED.getBytes()); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + mapReference.set(mapBuilder.createPersistedTo(mapFile)); + try (ExternalMapQueryContext c = mapReference.get().queryContext(KEY)) { + c.writeLock().lock(); + Thread.sleep(30_000); + } } - private static ChronicleMapBuilder createMapBuilder() - throws IOException { + private static ChronicleMapBuilder createMapBuilder() { return ChronicleMapBuilder .of(Integer.class, Integer.class) .entries(1); @@ -203,7 +198,7 @@ public class ExitHookTest { System.out.println("Classpath: " + classpath); String className = ExitHookTest.class.getCanonicalName(); - String[] command = new String[] {javaBin, "-cp", classpath, className, + String[] command = new String[]{javaBin, "-cp", classpath, className, mapFile.getAbsolutePath(), outputFile.getAbsolutePath(), String.valueOf(skipCloseOnExitHook)}; ProcessBuilder builder = new ProcessBuilder(command); builder.inheritIO(); diff --git a/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java b/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java index c3fb73ee4..fc5b9fe61 100755 --- a/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java +++ b/src/test/java/net/openhft/chronicle/map/LargeEntriesTest.java @@ -16,6 +16,7 @@ package net.openhft.chronicle.map; +import net.openhft.chronicle.threads.NamedThreadFactory; import org.junit.Ignore; import org.junit.Test; @@ -51,7 +52,7 @@ public class LargeEntriesTest { .createPersistedTo(file)) { warmUpCompression(ENTRY_SIZE); int threads = 4; //Runtime.getRuntime().availableProcessors(); - ExecutorService es = Executors.newFixedThreadPool(threads); + ExecutorService es = Executors.newFixedThreadPool(threads, new NamedThreadFactory("test")); final int block = ENTRIES / threads; for (int i = 0; i < 3; i++) { long start = System.currentTimeMillis(); @@ -119,7 +120,8 @@ public class LargeEntriesTest { { // warmUpCompression(ENTRY_SIZE); int threads = Runtime.getRuntime().availableProcessors(); - ExecutorService es = Executors.newFixedThreadPool(threads); + ExecutorService es = Executors.newFixedThreadPool(threads, + new NamedThreadFactory("test")); final int block = ENTRIES / threads; for (int i = 0; i < 3; i++) { long start = System.currentTimeMillis(); diff --git a/src/test/java/net/openhft/chronicle/map/MemoryLeaksTest.java b/src/test/java/net/openhft/chronicle/map/MemoryLeaksTest.java index 26326d6d8..d13d0fa96 100755 --- a/src/test/java/net/openhft/chronicle/map/MemoryLeaksTest.java +++ b/src/test/java/net/openhft/chronicle/map/MemoryLeaksTest.java @@ -18,6 +18,7 @@ package net.openhft.chronicle.map; import com.google.common.collect.Lists; import net.openhft.chronicle.bytes.NoBytesStore; +import net.openhft.chronicle.core.Jvm; import net.openhft.chronicle.core.OS; import net.openhft.chronicle.core.values.IntValue; import net.openhft.chronicle.hash.impl.util.Cleaner; @@ -39,6 +40,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; @RunWith(Parameterized.class) public class MemoryLeaksTest { @@ -56,6 +58,7 @@ public class MemoryLeaksTest { private boolean persisted; private ChronicleMapBuilder builder; private boolean closeWithinContext; + public MemoryLeaksTest(String testType, boolean replicated, boolean persisted, boolean closeWithinContext) { this.persisted = persisted; this.closeWithinContext = closeWithinContext; @@ -92,50 +95,53 @@ public class MemoryLeaksTest { @Before public void resetSerializerCount() { + System.err.println("This test is expect to print 'ChronicleMap ... is not closed manually, cleaned up from Cleaner'"); serializerCount.set(0); } - @Test(timeout = 60_000) + @Test(timeout = 10_000) public void testChronicleMapCollectedAndDirectMemoryReleased() throws IOException, InterruptedException { - if (!OS.isWindows()) { - // This test is flaky in Linux and Mac OS apparently because some native memory from - // running previous/concurrent tests is released during this test, that infers with - // the (*) check below. The aim of this test is to check that native memory is not - // leaked and it is proven if it succeeds at least sometimes at least in some OSes. - // This tests is successful always in Windows and successful in Linux and OS X when run - // alone, rather than along all other Chronicle Map's tests. - return; - } + assertFalse(OS.isMacOSX()); + // This test is flaky in Linux and Mac OS apparently because some native memory from + // running previous/concurrent tests is released during this test, that infers with + // the (*) check below. The aim of this test is to check that native memory is not + // leaked and it is proven if it succeeds at least sometimes at least in some OSes. + // This tests is successful always in Windows and successful in Linux and OS X when run + // alone, rather than along all other Chronicle Map's tests. + + System.gc(); + Jvm.pause(100); + long nativeMemoryUsedBeforeMap = nativeMemoryUsed(); int serializersBeforeMap = serializerCount.get(); - try (ChronicleMap map = getMap()) { - long expectedNativeMemory = nativeMemoryUsedBeforeMap + map.offHeapMemoryUsed(); - assertEquals(expectedNativeMemory, nativeMemoryUsed()); - tryCloseFromContext(map); - WeakReference> ref = new WeakReference<>(map); - Assert.assertNotNull(ref.get()); - // map = null; + // the purpose of the test is to find maps which are not closed properly. + ChronicleMap map = getMap(); + long expectedNativeMemory = nativeMemoryUsedBeforeMap + map.offHeapMemoryUsed(); + assertEquals(expectedNativeMemory, nativeMemoryUsed()); + tryCloseFromContext(map); + WeakReference> ref = new WeakReference<>(map); + Assert.assertNotNull(ref.get()); + //noinspection UnusedAssignment + map = null; - // Wait until Map is collected by GC - while (ref.get() != null) { - System.gc(); - byte[] garbage = new byte[10_000_000]; - Thread.yield(); + // Wait until Map is collected by GC + // Wait until Cleaner is called and memory is returned to the system + for (int i = 1; i <= 10; i++) { + if (ref.get() == null && + nativeMemoryUsedBeforeMap >= nativeMemoryUsed() && // (*) + serializerCount.get() == serializersBeforeMap) { + break; } - // Wait until Cleaner is called and memory is returned to the system - for (int i = 0; i < 6_000; i++) { - if (nativeMemoryUsedBeforeMap == nativeMemoryUsed() && // (*) - serializerCount.get() == serializersBeforeMap) { - break; - } - System.gc(); - byte[] garbage = new byte[10_000_000]; - Thread.sleep(10); - } - Assert.assertEquals(nativeMemoryUsedBeforeMap, nativeMemoryUsed()); - Assert.assertEquals(serializersBeforeMap, serializerCount.get()); + System.gc(); + Jvm.pause(i * 10); + System.out.println("ref.get()=" + (ref.get() == null)); + System.out.println(nativeMemoryUsedBeforeMap + " <=> " + nativeMemoryUsed()); + System.out.println(serializerCount.get() + " <=> " + serializersBeforeMap); } + if (nativeMemoryUsedBeforeMap < nativeMemoryUsed()) + Assert.assertEquals(nativeMemoryUsedBeforeMap, nativeMemoryUsed()); + Assert.assertEquals(serializersBeforeMap, serializerCount.get()); } private long nativeMemoryUsed() { diff --git a/src/test/java/net/openhft/chronicle/map/RecoverTest.java b/src/test/java/net/openhft/chronicle/map/RecoverTest.java index abf39dece..f6c986d41 100644 --- a/src/test/java/net/openhft/chronicle/map/RecoverTest.java +++ b/src/test/java/net/openhft/chronicle/map/RecoverTest.java @@ -20,6 +20,7 @@ import net.openhft.chronicle.core.values.LongValue; import net.openhft.chronicle.hash.ChecksumEntry; import net.openhft.chronicle.hash.ChronicleHashBuilderPrivateAPI; import net.openhft.chronicle.hash.ChronicleHashCorruption; +import net.openhft.chronicle.threads.NamedThreadFactory; import net.openhft.chronicle.values.Values; import org.junit.Assert; import org.junit.Ignore; @@ -69,7 +70,8 @@ public class RecoverTest { // acquires read lock successfully assertNull(map.get(0)); - ExecutorService executorService = Executors.newSingleThreadExecutor(); + ExecutorService executorService = Executors.newSingleThreadExecutor( + new NamedThreadFactory("recoverTest")); executorService.submit(() -> { ExternalMapQueryContext c = map.queryContext(0); diff --git a/src/test/java/net/openhft/chronicle/map/TrickyContextCasesTest.java b/src/test/java/net/openhft/chronicle/map/TrickyContextCasesTest.java index f194c6a5d..82210538d 100644 --- a/src/test/java/net/openhft/chronicle/map/TrickyContextCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/TrickyContextCasesTest.java @@ -17,6 +17,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.core.values.IntValue; +import net.openhft.chronicle.threads.NamedThreadFactory; import net.openhft.chronicle.values.Values; import org.junit.Test; @@ -65,14 +66,16 @@ public class TrickyContextCasesTest { try (ExternalMapQueryContext q = map.queryContext(1)) { MapEntry entry = q.entry(); // acquires read lock implicitly assertNotNull(entry); - Executors.newFixedThreadPool(1).submit(() -> { - // this call should try to acquire write lock, that should lead to dead lock - // but if not... - // relocates the entry for the key 1 after the entry for 2, under update lock - map.put(1, new byte[]{1, 2, 3, 4, 5}); - // puts the entry for 3 at the place of the entry for the key 1, under update lock - map.put(3, new byte[]{3}); - }).get(); + Executors.newFixedThreadPool(1, + new NamedThreadFactory("test")) + .submit(() -> { + // this call should try to acquire write lock, that should lead to dead lock + // but if not... + // relocates the entry for the key 1 after the entry for 2, under update lock + map.put(1, new byte[]{1, 2, 3, 4, 5}); + // puts the entry for 3 at the place of the entry for the key 1, under update lock + map.put(3, new byte[]{3}); + }).get(); // prints [3] System.out.println(Arrays.toString(entry.value().get())); } diff --git a/src/test/java/net/openhft/chronicle/map/example/LotsOfEntriesMain.java b/src/test/java/net/openhft/chronicle/map/example/LotsOfEntriesMain.java index 4d57453d1..a33bb60ca 100755 --- a/src/test/java/net/openhft/chronicle/map/example/LotsOfEntriesMain.java +++ b/src/test/java/net/openhft/chronicle/map/example/LotsOfEntriesMain.java @@ -18,6 +18,7 @@ package net.openhft.chronicle.map.example; import net.openhft.chronicle.map.ChronicleMap; import net.openhft.chronicle.map.ChronicleMapBuilder; +import net.openhft.chronicle.threads.NamedThreadFactory; import net.openhft.chronicle.values.Array; import net.openhft.chronicle.values.Values; @@ -59,7 +60,8 @@ public class LotsOfEntriesMain { .averageKeySize((Math.log(1.024) - Math.log(0.024)) * 24 + 2) .createPersistedTo(file); int threads = Runtime.getRuntime().availableProcessors(); - ExecutorService es = Executors.newFixedThreadPool(threads); + ExecutorService es = Executors.newFixedThreadPool(threads, + new NamedThreadFactory("test")); long block = (entries + threads - 1) / threads; final long start = System.nanoTime(); diff --git a/src/test/java/net/openhft/chronicle/map/example/StringArrayExample.java b/src/test/java/net/openhft/chronicle/map/example/StringArrayExample.java index 3f027bbb2..c495af995 100644 --- a/src/test/java/net/openhft/chronicle/map/example/StringArrayExample.java +++ b/src/test/java/net/openhft/chronicle/map/example/StringArrayExample.java @@ -52,8 +52,7 @@ public class StringArrayExample { // to string all the values System.out.println(map.getUsing(1, charSequenceArray).toString()); } - - } + } private CharSequenceArray setToHello(final Integer integer, final CharSequenceArray charSequenceArray) { charSequenceArray.getCharSequenceWrapperAt(1).setCharSequence("hello"); diff --git a/src/main/java/net/openhft/chronicle/map/acid/ChronicleAcidIsolation.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleAcidIsolation.java similarity index 84% rename from src/main/java/net/openhft/chronicle/map/acid/ChronicleAcidIsolation.java rename to src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleAcidIsolation.java index 380066313..cc827a738 100644 --- a/src/main/java/net/openhft/chronicle/map/acid/ChronicleAcidIsolation.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleAcidIsolation.java @@ -1,7 +1,4 @@ -package net.openhft.chronicle.map.acid; - -import net.openhft.chronicle.map.ChronicleMap; - +package net.openhft.chronicle.map.fromdocs.acid; public interface ChronicleAcidIsolation extends java.sql.Connection{ diff --git a/src/main/java/net/openhft/chronicle/map/acid/ChronicleAcidIsolationGovernor.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleAcidIsolationGovernor.java similarity index 97% rename from src/main/java/net/openhft/chronicle/map/acid/ChronicleAcidIsolationGovernor.java rename to src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleAcidIsolationGovernor.java index ef966d26a..e5b52ccbe 100644 --- a/src/main/java/net/openhft/chronicle/map/acid/ChronicleAcidIsolationGovernor.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/ChronicleAcidIsolationGovernor.java @@ -1,14 +1,10 @@ -package net.openhft.chronicle.map.acid; +package net.openhft.chronicle.map.fromdocs.acid; //import net.openhft.affinity.AffinitySupport; import net.openhft.chronicle.map.ChronicleMap; -import net.openhft.chronicle.map.ChronicleMapBuilder; -import net.openhft.chronicle.map.acid.BondVOInterface; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; -import java.io.File; -import java.io.IOException; -import java.math.BigDecimal; import java.sql.*; import java.util.Map; import java.util.Properties; @@ -30,7 +26,7 @@ public class ChronicleAcidIsolationGovernor implements ChronicleAcidIsolation { " inside chrAig.put('"+cusip+"'/"+aCoupon+") BEGIN"+ ", " ); - ChronicleMap cMap = this.getCompositeChronicleMap(); + ChronicleMap cMap = this.getCompositeChronicleMap(); this.aCoupon = cMap.get(cusip).getCoupon(); bond.setCoupon(aCoupon); diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadOffender.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadOffender.java deleted file mode 100644 index c12fbc78f..000000000 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadOffender.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.openhft.chronicle.map.fromdocs.acid; - -import net.openhft.chronicle.map.acid.ChronicleAcidIsolation; -import net.openhft.chronicle.map.acid.ChronicleAcidIsolationGovernor; -import net.openhft.chronicle.map.acid.BondVOInterface; - -import java.sql.SQLException; -import java.util.Scanner; - -import static net.openhft.chronicle.values.Values.newNativeReference; - -public class DirtyReadOffender implements Runnable { - - ChronicleAcidIsolationGovernor chrAig; - - public ChronicleAcidIsolationGovernor getCraig() { - return chrAig; - } - - public void setCraig(ChronicleAcidIsolationGovernor craig) { - this.chrAig = craig; - } - - @Override - public void run() { - Scanner sc = new Scanner(System.in); - - try { - BondVOInterface bond = newNativeReference(BondVOInterface.class); - chrAig.getCompositeChronicleMap().acquireUsing("369604101", bond); - System.out.println( - " @t=" + System.currentTimeMillis() + - " DirtyReadOffender calling chrAig.put('369604101'/3.85) " - ); - //sc.nextLine(); - chrAig.setTransactionIsolation(ChronicleAcidIsolation.LOWEST_LATENCY); - bond.setCoupon(3.85); - chrAig.put("369604101", bond); - - System.out.println( - " @t=" + System.currentTimeMillis() + - " DirtyReadOffender sleeping 1 minute. " - ); - Thread.sleep(60 * 1_000); - System.out.println( - " @t=" + System.currentTimeMillis() + - " DirtyReadOffender calling chrAig.rollback() " - ); - //sc.nextLine(); - //chrAig.commit(); Normally, app would be coded like this. demo the ROLLBACK - chrAig.rollback(); //forced to accommodate demo to Peter - System.out.println( - " @t=" + System.currentTimeMillis() + - " DirtyReadOffender ROLLED BACK " - ); - } catch (Exception throwables) { - try { - System.out.println( - " @t=" + System.currentTimeMillis() + - " DirtyReadOffender calling chrAig.rollback " - ); - chrAig.rollback(); - System.out.println( - " @t=" + System.currentTimeMillis() + - " DirtyReadOffender ROLLED BACK " - ); - } catch (SQLException e) { - e.printStackTrace(); - } - throwables.printStackTrace(); - } - - } - -} diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadTolerance.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadTolerance.java deleted file mode 100644 index 41aea4eaf..000000000 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadTolerance.java +++ /dev/null @@ -1,82 +0,0 @@ -package net.openhft.chronicle.map.fromdocs.acid; - -import com.sun.org.apache.xpath.internal.operations.Bool; -import net.openhft.affinity.AffinitySupport; -import net.openhft.chronicle.map.ChronicleMap; -import net.openhft.chronicle.map.ChronicleMapBuilder; -import net.openhft.chronicle.map.acid.ChronicleAcidIsolation; -import net.openhft.chronicle.map.acid.ChronicleAcidIsolationGovernor; -import net.openhft.chronicle.map.acid.BondVOInterface; -import net.openhft.chronicle.map.fromdocs.pingpong_latency.PingPongCASLeft; -import java.io.File; -import java.io.IOException; -import java.sql.SQLException; -import java.util.Arrays; -import static net.openhft.chronicle.values.Values.newNativeReference; - - -public class DirtyReadTolerance { - - public static void main(String args[]) throws Exception { - - System.out.println("DirtyReadOffender,chrAig["+args[0]+"]coupon=3.50,DirtyReadVictim"); - String isoLevel = args[0]; - - ChronicleMap operand = - DirtyReadTolerance.acquireChronicleMapOperand( - "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" - ); - ChronicleMap operator = - DirtyReadTolerance.acquireChronicleMapOperator( - "C:\\Users\\buddy\\dev\\shm\\OPERATOR_CHRONICLE_MAP" - ); - ChronicleAcidIsolationGovernor chrAig = new ChronicleAcidIsolationGovernor(); - chrAig.setCompositeChronicleMap(operand); - chrAig.setAutoCommit(Boolean.FALSE); - chrAig.setTransactionIsolationMap(operator); - System.out.println(",Established chrAig,"); - - DirtyReadOffender offender = new DirtyReadOffender(); - offender.setCraig(chrAig); - - DirtyReadVictim victim = new DirtyReadVictim(isoLevel); - victim.setCraig(chrAig); - - (new Thread(offender)).start(); - (new Thread(victim)).start(); - - - } - - static ChronicleMap acquireChronicleMapOperand(String operand) - throws IOException { - // ensure thread ids are globally unique. - AffinitySupport.setThreadId(); - return ChronicleMapBuilder.of(String.class, BondVOInterface.class) - .entries(16) - .averageKeySize("123456789".length()) - .createPersistedTo( - new File( - operand - // "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" - ) - ); - //.create(); - } - - static ChronicleMap acquireChronicleMapOperator(String operator) - throws IOException { - // ensure thread ids are globally unique. - AffinitySupport.setThreadId(); - return ChronicleMapBuilder.of(String.class, Integer.class) - .entries(16) - .averageKeySize("123456789".length()) - .createPersistedTo( - new File( - operator - // "C:\\Users\\buddy\\dev\\shm\\OPERATOR_CHRONICLE_MAP" - ) - ); - //.create(); - } -} \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadVictim.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadVictim.java deleted file mode 100644 index b78ffedc2..000000000 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/DirtyReadVictim.java +++ /dev/null @@ -1,87 +0,0 @@ -package net.openhft.chronicle.map.fromdocs.acid; - - -import net.openhft.chronicle.map.acid.BondVOInterface; -import net.openhft.chronicle.map.acid.ChronicleAcidIsolation; -import net.openhft.chronicle.map.acid.ChronicleAcidIsolationGovernor; -import java.sql.SQLException; -import java.util.Scanner; -import static net.openhft.chronicle.values.Values.newNativeReference; - -public class DirtyReadVictim implements Runnable { - int isoLevel = ChronicleAcidIsolation.LOWEST_LATENCY; - - DirtyReadVictim(String isoL) { - if (isoL.equals("DIRTY_READ_INTOLERANT")) - this.isoLevel = ChronicleAcidIsolation.DIRTY_READ_INTOLERANT; - else if (isoL.equals("DIRTY_READ_OPTIMISTIC")) - this.isoLevel = ChronicleAcidIsolation.DIRTY_READ_OPTIMISTIC; - } - - ChronicleAcidIsolationGovernor chrAig; - - public ChronicleAcidIsolationGovernor getCraig() { - - return this.chrAig; - } - - public void setCraig(ChronicleAcidIsolationGovernor craig) { - - this.chrAig = craig; - } - - @Override - public void run() { - Scanner sc= new Scanner(System.in); - try { - System.out.println( - " ,,@t="+System.currentTimeMillis()+ - " DirtyReadVictim sleeping 10 seconds" - ); - Thread.sleep(10_000); - BondVOInterface bond = newNativeReference(BondVOInterface.class); - chrAig.getCompositeChronicleMap().acquireUsing("369604101", bond); - System.out.println( - " ,,@t="+System.currentTimeMillis()+ - " DirtyReadVictim calling chrAig.get('369604101')" - ); - //sc.nextLine(); - chrAig.setTransactionIsolation(this.isoLevel); - //chrAig.setTransactionIsolation(ChronicleAcidIsolation.DIRTY_READ_INTOLERANT); - //chrAig.setTransactionIsolation(ChronicleAcidIsolation.DIRTY_READ_OPTIMISTIC); - bond = chrAig.get("369604101"); - Double coupon = bond.getCoupon(); - System.out.println( - " ,,@t="+System.currentTimeMillis()+ - " DirtyReadVictim got() coupon="+coupon+" " - ); - System.out.println( - " ,,@t="+System.currentTimeMillis()+ - " DirtyReadVictim calling chrAig.commmit()" - ); - //sc.nextLine(); - chrAig.commit(); - System.out.println( - " ,,@t="+System.currentTimeMillis()+ - " DirtyReadVictim COMMITTED" - ); - } catch (Exception throwables) { - try { - System.out.println( - " ,,@t="+System.currentTimeMillis()+ - " DirtyReadVictim calling chrAig.rollback()" - ); - //sc.nextLine(); - chrAig.rollback(); - System.out.println( - " ,,@t="+System.currentTimeMillis()+ - " DirtyReadVictim ROLLED BACK" - ); - } catch (SQLException e) { - e.printStackTrace(); - } - throwables.printStackTrace(); - } - } -} - diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadOffender.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadOffender.java new file mode 100644 index 000000000..0920ebe35 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadOffender.java @@ -0,0 +1,105 @@ +package net.openhft.chronicle.map.fromdocs.acid.exodus; + + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; + +import java.util.Scanner; +import java.util.concurrent.locks.StampedLock; + +import static net.openhft.chronicle.values.Values.newNativeReference; + +public class DirtyReadOffender implements Runnable { + private int isoLevel; + private ChronicleMap chm; + private StampedLock offHeapLock; + + @Override + public void run() { + Scanner sc = new Scanner(System.in); + + try { + BondVOInterface bond = newNativeReference(BondVOInterface.class); + this.chm.acquireUsing("369604101", bond); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender sleeping 10 seconds " + ); + Thread.sleep(10 * 1_000); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender awakening " + ); + /** + * ben.cotton@rutgers.edu ... anticipate Chronicle (www.OpenHFT.net) + * providing a j.u.c.l.StampedLock API for off-heap enthusiasts + * + * START + * + */ + + long stamp = 0; + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender ACQUIRING offHeapLock.writeLock();" + ); + while ((stamp = this.offHeapLock.writeLock()) == 0) { + ; + } + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender ACQUIRED offHeapLock.writeLock();" + ); + try { + double newCoupon = 3.5 + Math.random(); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender "+ + " calling chm.put('369604101',"+newCoupon+") " + ); + bond.setCoupon(newCoupon); + chm.put("369604101", bond); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender coupon=["+ + bond.getCoupon()+ + "] written. " + ); + } finally { + this.offHeapLock.unlockWrite(stamp); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender called offHeapLock.unlockWrite(stamp);" + ); + } + /** + * ben.cotton@rutgers.edu + * + * END + * + */ + } catch (Exception throwables) { + throwables.printStackTrace(); + } + } + + public ChronicleMap getCraig() { + return this.chm; + } + + public void setCraig(ChronicleMap craig) { + this.chm = craig; + } + + public int getIsoLevel() { + return isoLevel; + } + + public void setIsoLevel(int isoLevel) { + this.isoLevel = isoLevel; + } + + public void setStampedLock(StampedLock _sLock) { + this.offHeapLock = _sLock; + } +} diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadTolerance.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadTolerance.java new file mode 100644 index 000000000..6b5a77e2b --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadTolerance.java @@ -0,0 +1,52 @@ +package net.openhft.chronicle.map.fromdocs.acid.exodus; + +import net.openhft.affinity.AffinitySupport; +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.ChronicleMapBuilder; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.locks.StampedLock; + + +public class DirtyReadTolerance { + + public static void main(String args[]) throws Exception { + System.out.println("DirtyReadOffender,chrAig["+args[0]+"]coupon=3.50,DirtyReadVictim"); + String isoLevel = args[0]; + + ChronicleMap chm = + DirtyReadTolerance.offHeap( + "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ); + System.out.println(",Established chm,"); + + StampedLock sLock = new StampedLock(); + DirtyReadOffender offender = new DirtyReadOffender(); + offender.setCraig(chm); + offender.setStampedLock(sLock); + + DirtyReadVictim victim = new DirtyReadVictim(isoLevel); + victim.setCraig(chm); + victim.setStampedLock(sLock); + + (new Thread(offender)).start(); + (new Thread(victim)).start(); + } + + static ChronicleMap offHeap(String operand) throws IOException { + // ensure thread ids are globally unique. + AffinitySupport.setThreadId(); + return ChronicleMapBuilder.of(String.class, BondVOInterface.class) + .entries(16) + .averageKeySize("123456789".length()) + .createPersistedTo( + new File( + operand + // "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ) + ); + //.create(); + } +} \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadVictim.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadVictim.java new file mode 100644 index 000000000..c3dfe2d6c --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/exodus/DirtyReadVictim.java @@ -0,0 +1,115 @@ +package net.openhft.chronicle.map.fromdocs.acid.exodus; + + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; +import net.openhft.chronicle.map.fromdocs.acid.ChronicleAcidIsolation; + +import java.util.Scanner; +import java.util.concurrent.locks.StampedLock; + +import static net.openhft.chronicle.values.Values.newNativeReference; + +public class DirtyReadVictim implements Runnable { + private int isoLevel = ChronicleAcidIsolation.LOWEST_LATENCY; + private ChronicleMap chm; + private StampedLock offHeapLock; + + DirtyReadVictim(String isoL) { + if (isoL.equals("DIRTY_READ_INTOLERANT")) + this.isoLevel = ChronicleAcidIsolation.DIRTY_READ_INTOLERANT; + else if (isoL.equals("DIRTY_READ_OPTIMISTIC")) + this.isoLevel = ChronicleAcidIsolation.DIRTY_READ_OPTIMISTIC; + } + + @Override + public void run() { + Scanner sc = new Scanner(System.in); + try { + + + /** + * ben.cotton@rutgers.edu START + */ + Double coupon = 0.00; + BondVOInterface bond = newNativeReference(BondVOInterface.class); + long stamp = 0; + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLING offHeapLock.tryOptimisticRead()" + ); + while ((stamp = this.offHeapLock.tryOptimisticRead()) == 0) { + ; + } + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLED offHeapLock.tryOptimisticRead()" + ); + + try { + chm.acquireUsing("369604101", bond); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim calling chm.get('369604101').getCoupon()" + ); + bond = (BondVOInterface) chm.get("369604101"); + coupon = bond.getCoupon(); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim coupon=[" +coupon+"] read." + ); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim sleeping 60 seconds" + ); + Thread.sleep( 60_000); + } finally { + if (this.offHeapLock.validate(stamp)) { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim OPTIMISTICALLY_READ coupon=" + + coupon + " " + ); + } else { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim FAILED offHeapLock.validate(stamp) " + + " must apply PESSIMISTIC_POLICY (dirty read endured)" + + " coupon=[" + coupon + "] is *DIRTY*. " + ); + } + } + + /** + * ben.cotton@rutgers.edu END + */ + + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim got() coupon=" + + coupon + " " + ); + + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim COMMITTED" + ); + } catch (Exception throwables) { + throwables.printStackTrace(); + } + } + + + public ChronicleMap getCraig() { + return this.chm; + } + + public void setCraig(ChronicleMap craig) { + this.chm = craig; + } + + public void setStampedLock(StampedLock _sLock) { + this.offHeapLock = _sLock; + } +} + diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadOffender.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadOffender.java new file mode 100644 index 000000000..2e5125267 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadOffender.java @@ -0,0 +1,105 @@ +package net.openhft.chronicle.map.fromdocs.acid.genesis; + + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; + +import java.util.Scanner; +import java.util.concurrent.locks.StampedLock; + +import static net.openhft.chronicle.values.Values.newNativeReference; + +public class DirtyReadOffender implements Runnable { + private int isoLevel; + private ChronicleMap chm; + private StampedLock offHeapLock; + + @Override + public void run() { + Scanner sc = new Scanner(System.in); + + try { + BondVOInterface bond = newNativeReference(BondVOInterface.class); + this.chm.acquireUsing("369604101", bond); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender sleeping 60 seconds " + ); + Thread.sleep(60 * 1_000); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender awakening " + ); + /** + * ben.cotton@rutgers.edu ... anticipate Chronicle (www.OpenHFT.net) + * providing a j.u.c.l.StampedLock API for off-heap enthusiasts + * + * START + * + */ + + long stamp = 0; + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender ACQUIRING offHeapLock.writeLock();" + ); + while ((stamp = this.offHeapLock.writeLock()) == 0) { + ; + } + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender ACQUIRED offHeapLock.writeLock();" + ); + try { + double newCoupon = 3.5 + Math.random(); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender "+ + " calling chm.put('369604101',"+newCoupon+") " + ); + bond.setCoupon(newCoupon); + chm.put("369604101", bond); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender coupon=["+ + bond.getCoupon()+ + "] written. " + ); + } finally { + this.offHeapLock.unlockWrite(stamp); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender called offHeapLock.unlockWrite(stamp);" + ); + } + /** + * ben.cotton@rutgers.edu + * + * END + * + */ + } catch (Exception throwables) { + throwables.printStackTrace(); + } + } + + public ChronicleMap getCraig() { + return this.chm; + } + + public void setCraig(ChronicleMap craig) { + this.chm = craig; + } + + public int getIsoLevel() { + return isoLevel; + } + + public void setIsoLevel(int isoLevel) { + this.isoLevel = isoLevel; + } + + public void setStampedLock(StampedLock _sLock) { + this.offHeapLock = _sLock; + } +} diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadTolerance.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadTolerance.java new file mode 100644 index 000000000..4fbd115a8 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadTolerance.java @@ -0,0 +1,52 @@ +package net.openhft.chronicle.map.fromdocs.acid.genesis; + +import net.openhft.affinity.AffinitySupport; +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.ChronicleMapBuilder; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.locks.StampedLock; + + +public class DirtyReadTolerance { + + public static void main(String args[]) throws Exception { + System.out.println("DirtyReadOffender,chrAig["+args[0]+"]coupon=3.50,DirtyReadVictim"); + String isoLevel = args[0]; + + ChronicleMap chm = + DirtyReadTolerance.offHeap( + "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ); + System.out.println(",Established chm,"); + + StampedLock sLock = new StampedLock(); + DirtyReadOffender offender = new DirtyReadOffender(); + offender.setCraig(chm); + offender.setStampedLock(sLock); + + DirtyReadVictim victim = new DirtyReadVictim(isoLevel); + victim.setCraig(chm); + victim.setStampedLock(sLock); + + (new Thread(offender)).start(); + (new Thread(victim)).start(); + } + + static ChronicleMap offHeap(String operand) throws IOException { + // ensure thread ids are globally unique. + AffinitySupport.setThreadId(); + return ChronicleMapBuilder.of(String.class, BondVOInterface.class) + .entries(16) + .averageKeySize("123456789".length()) + .createPersistedTo( + new File( + operand + // "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ) + ); + //.create(); + } +} \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadVictim.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadVictim.java new file mode 100644 index 000000000..753d8de94 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/genesis/DirtyReadVictim.java @@ -0,0 +1,115 @@ +package net.openhft.chronicle.map.fromdocs.acid.genesis; + + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; +import net.openhft.chronicle.map.fromdocs.acid.ChronicleAcidIsolation; + +import java.util.Scanner; +import java.util.concurrent.locks.StampedLock; + +import static net.openhft.chronicle.values.Values.newNativeReference; + +public class DirtyReadVictim implements Runnable { + private int isoLevel = ChronicleAcidIsolation.LOWEST_LATENCY; + private ChronicleMap chm; + private StampedLock offHeapLock; + + DirtyReadVictim(String isoL) { + if (isoL.equals("DIRTY_READ_INTOLERANT")) + this.isoLevel = ChronicleAcidIsolation.DIRTY_READ_INTOLERANT; + else if (isoL.equals("DIRTY_READ_OPTIMISTIC")) + this.isoLevel = ChronicleAcidIsolation.DIRTY_READ_OPTIMISTIC; + } + + @Override + public void run() { + Scanner sc = new Scanner(System.in); + try { + + + /** + * ben.cotton@rutgers.edu START + */ + Double coupon = 0.00; + BondVOInterface bond = newNativeReference(BondVOInterface.class); + long stamp = 0; + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLING offHeapLock.tryOptimisticRead()" + ); + while ((stamp = this.offHeapLock.tryOptimisticRead()) == 0) { + ; + } + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLED offHeapLock.tryOptimisticRead()" + ); + + try { + chm.acquireUsing("369604101", bond); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim calling chm.get('369604101').getCoupon()" + ); + bond = (BondVOInterface) chm.get("369604101"); + coupon = bond.getCoupon(); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim coupon=[" +coupon+"] read." + ); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim sleeping 10 seconds" + ); + Thread.sleep( 10_000); + } finally { + if (this.offHeapLock.validate(stamp)) { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim OPTIMISTICALLY_READ coupon=" + + coupon + " " + ); + } else { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim FAILED offHeapLock.validate(stamp) " + + " must apply PESSIMISTIC_POLICY (dirty read endured)" + + " coupon=[" + coupon + "] is *DIRTY*. " + ); + } + } + + /** + * ben.cotton@rutgers.edu END + */ + + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim got() coupon=" + + coupon + " " + ); + + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim COMMITTED" + ); + } catch (Exception throwables) { + throwables.printStackTrace(); + } + } + + + public ChronicleMap getCraig() { + return this.chm; + } + + public void setCraig(ChronicleMap craig) { + this.chm = craig; + } + + public void setStampedLock(StampedLock _sLock) { + this.offHeapLock = _sLock; + } +} + diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/ChronicleStampedLock.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/ChronicleStampedLock.java new file mode 100644 index 000000000..3304d3929 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/ChronicleStampedLock.java @@ -0,0 +1,6 @@ +package net.openhft.chronicle.map.fromdocs.acid.revelations; + +import java.util.concurrent.locks.StampedLock; + +public class ChronicleStampedLock extends StampedLock { +} diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadOffender.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadOffender.java new file mode 100644 index 000000000..7ab0a59df --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadOffender.java @@ -0,0 +1,94 @@ +package net.openhft.chronicle.map.fromdocs.acid.revelations; + + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; +import net.openhft.chronicle.map.fromdocs.acid.revelations.DirtyReadTolerance; + +import java.util.Scanner; +import java.util.concurrent.locks.StampedLock; + +import static net.openhft.chronicle.values.Values.newNativeReference; + +public class DirtyReadOffender { + + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + + try { + String isoLevel = args[0]; + + ChronicleMap chm = + DirtyReadTolerance.offHeap( + "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender established chm " + ); + BondVOInterface bond = newNativeReference(BondVOInterface.class); + chm.acquireUsing("369604101", bond); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender sleeping 10 seconds " + ); + Thread.sleep(10 * 1_000); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender awakening " + ); + /** + * ben.cotton@rutgers.edu ... anticipate Chronicle (www.OpenHFT.net) + * providing a j.u.c.l.StampedLock API for off-heap enthusiasts + * + * START + * + */ + + long stamp = 0; + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender ACQUIRING offHeapLock.writeLock();" + ); + ChronicleStampedLock offHeapLock = new ChronicleStampedLock(); + while ((stamp = offHeapLock.writeLock()) == 0) { + ; + } + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender ACQUIRED offHeapLock.writeLock();" + ); + try { + double newCoupon = 3.5 + Math.random(); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender "+ + " calling chm.put('369604101',"+newCoupon+") " + ); + bond.setCoupon(newCoupon); + chm.put("369604101", bond); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender coupon=["+ + bond.getCoupon()+ + "] written. " + ); + } finally { + offHeapLock.unlockWrite(stamp); + System.out.println( + " @t=" + System.currentTimeMillis() + + " DirtyReadOffender called offHeapLock.unlockWrite(stamp);" + ); + } + /** + * ben.cotton@rutgers.edu + * + * END + * + */ + } catch (Exception throwables) { + throwables.printStackTrace(); + } + } + +} diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadTolerance.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadTolerance.java new file mode 100644 index 000000000..16dbc97c7 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadTolerance.java @@ -0,0 +1,44 @@ +package net.openhft.chronicle.map.fromdocs.acid.revelations; + +import net.openhft.affinity.AffinitySupport; +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.ChronicleMapBuilder; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; +import net.openhft.chronicle.map.fromdocs.acid.exodus.DirtyReadOffender; +import net.openhft.chronicle.map.fromdocs.acid.exodus.DirtyReadVictim; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.locks.StampedLock; + + +public class DirtyReadTolerance { + + public static void main(String args[]) throws Exception { + System.out.println("DirtyReadOffender,chrAig["+args[0]+"]coupon=3.50,DirtyReadVictim"); + String isoLevel = args[0]; + + ChronicleMap chm = + DirtyReadTolerance.offHeap( + "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ); + System.out.println(",Established chm,"); + + + } + + static ChronicleMap offHeap(String operand) throws IOException { + // ensure thread ids are globally unique. + AffinitySupport.setThreadId(); + return ChronicleMapBuilder.of(String.class, BondVOInterface.class) + .entries(16) + .averageKeySize("123456789".length()) + .createPersistedTo( + new File( + operand + // "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ) + ); + //.create(); + } +} \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadVictim.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadVictim.java new file mode 100644 index 000000000..a75803383 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadVictim.java @@ -0,0 +1,85 @@ +package net.openhft.chronicle.map.fromdocs.acid.revelations; + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; +import net.openhft.chronicle.map.fromdocs.acid.ChronicleAcidIsolation; +import static net.openhft.chronicle.values.Values.newNativeReference; + +public class DirtyReadVictim { + + public static void main(String args[]) { + try { + /** + * ben.cotton@rutgers.edu START + */ + ChronicleMap chm = + DirtyReadTolerance.offHeap( + "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ); + Double coupon = 0.00; + BondVOInterface bond = newNativeReference(BondVOInterface.class); + long stamp = 0; + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLING offHeapLock.tryOptimisticRead()" + ); + ChronicleStampedLock offHeapLock = new ChronicleStampedLock(); + while ((stamp = offHeapLock.tryOptimisticRead()) == 0) { + ; + } + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLED offHeapLock.tryOptimisticRead()" + ); + try { + chm.acquireUsing("369604101", bond); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim calling chm.get('369604101').getCoupon()" + ); + bond = (BondVOInterface) chm.get("369604101"); + coupon = bond.getCoupon(); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim coupon=[" + coupon + "] read." + ); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim sleeping 60 seconds" + ); + Thread.sleep(60_000); + } finally { + if (offHeapLock.validate(stamp)) { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim OPTIMISTICALLY_READ coupon=" + + coupon + " " + ); + + } else { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim FAILED offHeapLock.validate(stamp) " + + " must apply PESSIMISTIC_POLICY (dirty read endured)" + + " coupon=[" + coupon + "] is *DIRTY*. " + ); + } + } + /** + * ben.cotton@rutgers.edu END + */ + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim got() coupon=" + + coupon + " " + ); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim COMMITTED" + ); + } catch (Exception throwables) { + throwables.printStackTrace(); + } + } +} + diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadVictimTest.java b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadVictimTest.java new file mode 100644 index 000000000..f06db23c8 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/acid/revelations/DirtyReadVictimTest.java @@ -0,0 +1,100 @@ +package net.openhft.chronicle.map.fromdocs.acid.revelations; + +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.fromdocs.BondVOInterface; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static net.openhft.chronicle.values.Values.newNativeReference; +import static org.junit.Assert.*; + +public class DirtyReadVictimTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void main() { + try { + /** + * ben.cotton@rutgers.edu START + */ + ChronicleMap chm = + DirtyReadTolerance.offHeap( + "C:\\Users\\buddy\\dev\\shm\\OPERAND_CHRONICLE_MAP" + ); + Double coupon = 0.00; + BondVOInterface bond = newNativeReference(BondVOInterface.class); + long stamp = 0; + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLING offHeapLock.tryOptimisticRead()" + ); + ChronicleStampedLock offHeapLock = new ChronicleStampedLock(); + while ((stamp = offHeapLock.tryOptimisticRead()) == 0) { + ; + } + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim CALLED offHeapLock.tryOptimisticRead()" + ); + try { + chm.acquireUsing("369604101", bond); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim calling chm.get('369604101').getCoupon()" + ); + bond = (BondVOInterface) chm.get("369604101"); + coupon = bond.getCoupon(); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim coupon=[" + coupon + "] read." + ); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim sleeping 60 seconds" + ); + Thread.sleep(60_000); + } finally { + if (offHeapLock.validate(stamp)) { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim OPTIMISTICALLY_READ coupon=" + + coupon + " " + ); + + Assert.assertFalse(Boolean.TRUE); + } else { + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim FAILED offHeapLock.validate(stamp) " + + " must apply PESSIMISTIC_POLICY (dirty read endured)" + + " coupon=[" + coupon + "] is *DIRTY*. " + ); + Assert.assertFalse(Boolean.FALSE); + } + } + /** + * ben.cotton@rutgers.edu END + */ + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim got() coupon=" + + coupon + " " + ); + System.out.println( + " ,,@t=" + System.currentTimeMillis() + + " DirtyReadVictim COMMITTED" + ); + } catch (Exception throwables) { + throwables.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASLeft.java b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASLeft.java index af9e1ea48..4475b0934 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASLeft.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASLeft.java @@ -21,7 +21,6 @@ import net.openhft.chronicle.map.ChronicleMap; import net.openhft.chronicle.map.ChronicleMapBuilder; import net.openhft.chronicle.map.fromdocs.BondVOInterface; -import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -29,7 +28,7 @@ import static net.openhft.chronicle.values.Values.newNativeReference; /* on an i7-4500 laptop. -PingPongLEFT: Timing 1 x off-heap operations on /dev/shm/RDR_DIM_Mock +PingPongLEFT: Timing 1 x off-heap operations on /dev/chm/RDR_DIM_Mock #0: compareAndSwapCoupon() 50/90/99%tile was 41 / 52 / 132 #1: compareAndSwapCoupon() 50/90/99%tile was 40 / 56 / 119 #2: compareAndSwapCoupon() 50/90/99%tile was 39 / 48 / 54 @@ -46,17 +45,11 @@ public class PingPongCASLeft { public static void main(String... ignored) throws IOException { ChronicleMap chm = PingPongCASLeft.acquireCHM(); - playPingPong(chm, 4, 5, true, "PingPongCASLeft"); + playPingPong(chm, 4, 5, true, "PingPongCASLEFT"); } - static void playPingPong( - ChronicleMap chm, - double _coupon, - double _coupon2, - boolean setFirst, - final String desc - ) { - + static void playPingPong(ChronicleMap chm, double _coupon, + double _coupon2, boolean setFirst, final String desc) { BondVOInterface bond1 = newNativeReference(BondVOInterface.class); BondVOInterface bond2 = newNativeReference(BondVOInterface.class); BondVOInterface bond3 = newNativeReference(BondVOInterface.class); @@ -66,7 +59,7 @@ public class PingPongCASLeft { chm.acquireUsing("369604102", bond2); chm.acquireUsing("369604103", bond3); chm.acquireUsing("369604104", bond4); - System.out.printf("\n\n" + desc + ": Timing 1 x off-heap operations on /dev/shm/RDR_DIM_Mock\n"); + System.out.printf("\n\n" + desc + ": Timing 1 x off-heap operations on /dev/chm/RDR_DIM_Mock\n"); if (setFirst) { bond1.setCoupon(_coupon); bond2.setCoupon(_coupon); @@ -80,9 +73,9 @@ public class PingPongCASLeft { for (int i = 0; i < runs; i++) { long _start = System.nanoTime(); // while (!bond1.compareAndSwapCoupon(_coupon, _coupon2)) ; - //while (!bond2.compareAndSwapCoupon(_coupon, _coupon2)) ; - //while (!bond3.compareAndSwapCoupon(_coupon, _coupon2)) ; - //while (!bond4.compareAndSwapCoupon(_coupon, _coupon2)) ; + while (!bond2.compareAndSwapCoupon(_coupon, _coupon2)) ; + while (!bond3.compareAndSwapCoupon(_coupon, _coupon2)) ; + while (!bond4.compareAndSwapCoupon(_coupon, _coupon2)) ; timings[i] = (System.nanoTime() - _start - timeToCallNanoTime) / 4; } @@ -97,8 +90,6 @@ public class PingPongCASLeft { AffinitySupport.setThreadId(); return ChronicleMapBuilder.of(String.class, BondVOInterface.class) .entries(16) - .averageKeySize("369604101".length()) - .createPersistedTo(new File("C:\\Users\\buddy\\dev\\shm\\RDR_DIM_MOCK")); - //.create(); + .averageKeySize("369604101".length()).create(); } } \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASRight.java b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASRight.java index 2432f04a6..ef4eaa886 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASRight.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongCASRight.java @@ -27,6 +27,6 @@ public class PingPongCASRight { public static void main(String... ignored) throws IOException { ChronicleMap chm = PingPongCASLeft.acquireCHM(); - playPingPong(chm, 5, 4, false, "PingPongCASRight"); + playPingPong(chm, 5, 4, false, "PingPongCASLEFT"); } } \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockLeft.java b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockLeft.java index 675c547b3..f4266a414 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockLeft.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockLeft.java @@ -32,68 +32,68 @@ import static net.openhft.chronicle.algo.bytes.Access.checkedBytesStoreAccess; import static net.openhft.chronicle.values.Values.newNativeReference; public class PingPongLockLeft { - public static void main(String... ignored) throws IOException, InterruptedException { - ChronicleMap chm = PingPongCASLeft.acquireCHM(); - - playPingPong(chm, 4, 5, true, "PingPongLockLEFT"); - } - - static void playPingPong(ChronicleMap chm, double _coupon, double _coupon2, boolean setFirst, final String desc) throws InterruptedException { - BondVOInterface bond1 = newNativeReference(BondVOInterface.class); - BondVOInterface bond2 = newNativeReference(BondVOInterface.class); - BondVOInterface bond3 = newNativeReference(BondVOInterface.class); - BondVOInterface bond4 = newNativeReference(BondVOInterface.class); - - chm.acquireUsing("369604101", bond1); - chm.acquireUsing("369604102", bond2); - chm.acquireUsing("369604103", bond3); - chm.acquireUsing("369604104", bond4); - System.out.printf("\n\n" + desc + ": Timing 1 x off-heap operations on " + chm.file() + "\n"); - if (setFirst) { - bond1.setCoupon(_coupon); - bond2.setCoupon(_coupon); - bond3.setCoupon(_coupon); - bond4.setCoupon(_coupon); - } - int timeToCallNanoTime = 30; - int runs = 1000000; - long[] timings = new long[runs]; - for (int j = 0; j < 10; j++) { - for (int i = 0; i < runs; i++) { - long _start = System.nanoTime(); - toggleCoupon(bond1, _coupon, _coupon2); - toggleCoupon(bond2, _coupon, _coupon2); - toggleCoupon(bond3, _coupon, _coupon2); - toggleCoupon(bond4, _coupon, _coupon2); - - timings[i] = (System.nanoTime() - _start - timeToCallNanoTime) / 4; - } - Arrays.sort(timings); - System.out.printf("#%d: lock,compare,set,unlock 50/90/99%%tile was %,d / %,d / %,d%n", - j, timings[runs / 2], timings[runs * 9 / 10], timings[runs * 99 / 100]); - } - } - - private static void toggleCoupon(BondVOInterface bond, double _coupon, double _coupon2) - throws InterruptedException { - for (int i = 0; ; i++) { - AcquisitionStrategies.spinLoopOrFail(5, TimeUnit.SECONDS) - .acquire(TryAcquireOperations.writeLock(), - VanillaReadWriteWithWaitsLockingStrategy.instance(), - checkedBytesStoreAccess(), - ((Byteable) bond).bytesStore(), ((Byteable) bond).offset()); - try { - if (bond.getCoupon() == _coupon) { - bond.setCoupon(_coupon2); - return; - } - if (i > 1000) - Thread.yield(); - } finally { - VanillaReadWriteWithWaitsLockingStrategy.instance() - .writeUnlock(checkedBytesStoreAccess(), - ((Byteable) bond).bytesStore(), ((Byteable) bond).offset()); - } - } - } +// public static void main(String... ignored) throws IOException, InterruptedException { +// ChronicleMap chm = PingPongCASLeft.acquireCHM(); +// +// playPingPong(chm, 4, 5, true, "PingPongLockLEFT"); +// } +// +// static void playPingPong(ChronicleMap chm, double _coupon, double _coupon2, boolean setFirst, final String desc) throws InterruptedException { +// BondVOInterface bond1 = newNativeReference(BondVOInterface.class); +// BondVOInterface bond2 = newNativeReference(BondVOInterface.class); +// BondVOInterface bond3 = newNativeReference(BondVOInterface.class); +// BondVOInterface bond4 = newNativeReference(BondVOInterface.class); +// +// chm.acquireUsing("369604101", bond1); +// chm.acquireUsing("369604102", bond2); +// chm.acquireUsing("369604103", bond3); +// chm.acquireUsing("369604104", bond4); +// System.out.printf("\n\n" + desc + ": Timing 1 x off-heap operations on " + chm.file() + "\n"); +// if (setFirst) { +// bond1.setCoupon(_coupon); +// bond2.setCoupon(_coupon); +// bond3.setCoupon(_coupon); +// bond4.setCoupon(_coupon); +// } +// int timeToCallNanoTime = 30; +// int runs = 1000000; +// long[] timings = new long[runs]; +// for (int j = 0; j < 10; j++) { +// for (int i = 0; i < runs; i++) { +// long _start = System.nanoTime(); +// toggleCoupon(bond1, _coupon, _coupon2); +// toggleCoupon(bond2, _coupon, _coupon2); +// toggleCoupon(bond3, _coupon, _coupon2); +// toggleCoupon(bond4, _coupon, _coupon2); +// +// timings[i] = (System.nanoTime() - _start - timeToCallNanoTime) / 4; +// } +// Arrays.sort(timings); +// System.out.printf("#%d: lock,compare,set,unlock 50/90/99%%tile was %,d / %,d / %,d%n", +// j, timings[runs / 2], timings[runs * 9 / 10], timings[runs * 99 / 100]); +// } +// } +// +// private static void toggleCoupon(BondVOInterface bond, double _coupon, double _coupon2) +// throws InterruptedException { +// for (int i = 0; ; i++) { +// AcquisitionStrategies.spinLoopOrFail(5, TimeUnit.SECONDS) +// .acquire(TryAcquireOperations.writeLock(), +// VanillaReadWriteWithWaitsLockingStrategy.instance(), +// checkedBytesStoreAccess(), +// ((Byteable) bond).bytesStore(), ((Byteable) bond).offset()); +// try { +// if (bond.getCoupon() == _coupon) { +// bond.setCoupon(_coupon2); +// return; +// } +// if (i > 1000) +// Thread.yield(); +// } finally { +// VanillaReadWriteWithWaitsLockingStrategy.instance() +// .writeUnlock(checkedBytesStoreAccess(), +// ((Byteable) bond).bytesStore(), ((Byteable) bond).offset()); +// } +// } +// } } \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockRight.java b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockRight.java index 41684f614..7e5884fc2 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockRight.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/pingpong_latency/PingPongLockRight.java @@ -25,6 +25,6 @@ public class PingPongLockRight { public static void main(String... ignored) throws IOException, InterruptedException { ChronicleMap chm = PingPongCASLeft.acquireCHM(); - PingPongLockLeft.playPingPong(chm, 5, 4, false, "PingPongLockRIGHT"); + //PingPongLockLeft.playPingPong(chm, 5, 4, false, "PingPongLockRIGHT"); } } \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java index 8ce65c4ba..e721e60ba 100644 --- a/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/jsr166/map/ChronicleMapTest.java @@ -699,8 +699,7 @@ public class ChronicleMapTest extends JSR166TestCase { } Assert.fail(); } - - } + } } } diff --git a/src/test/java/net/openhft/chronicle/map/watcher/MapFileManager.java b/src/test/java/net/openhft/chronicle/map/watcher/MapFileManager.java index 63fc2c33c..f05e9b21e 100755 --- a/src/test/java/net/openhft/chronicle/map/watcher/MapFileManager.java +++ b/src/test/java/net/openhft/chronicle/map/watcher/MapFileManager.java @@ -104,8 +104,7 @@ public class MapFileManager extends JMXFileManager implements MapFileManagerMBea map.createMappedStoreAndSegments( new PersistedChronicleHashResources(file)); - - keyClass = map.keyType(); +keyClass = map.keyType(); valueClass = map.valueType(); size = map.longSize(); name = map.name(); @@ -116,7 +115,7 @@ public class MapFileManager extends JMXFileManager implements MapFileManagerMBea Jvm.warn().on(getClass(), "Unable to update", e); header = e.toString(); } finally { - mf.release(); + mf.releaseLast(); assert mf.refCount() == 0; } } diff --git a/src/test/java/net/openhft/chronicle/set/Builder.java b/src/test/java/net/openhft/chronicle/set/Builder.java index bed10ca9e..2edde079c 100644 --- a/src/test/java/net/openhft/chronicle/set/Builder.java +++ b/src/test/java/net/openhft/chronicle/set/Builder.java @@ -44,8 +44,9 @@ public class Builder { This will only work if the user is an admin on windows. */ file.setWritable(true);//just in case relative path was used. - RandomAccessFile raf = new RandomAccessFile(file, "rw"); - raf.close();//allows closing the file access on windows. forcing to close access. Only works for admin-access. + try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) { + //allows closing the file access on windows. forcing to close access. Only works for admin-access. + } } //file.delete(); //isnt guaranteed on windows. diff --git a/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java b/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java index eb8a1b2e3..48b76c5f6 100644 --- a/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java +++ b/src/test/java/net/openhft/chronicle/set/Issue24ChronicleSetTest.java @@ -18,6 +18,7 @@ package net.openhft.chronicle.set; import net.openhft.chronicle.hash.ChronicleHash; import net.openhft.chronicle.hash.ChronicleHashBuilder; +import net.openhft.chronicle.threads.NamedThreadFactory; import org.junit.Test; import java.io.File; @@ -55,7 +56,8 @@ public class Issue24ChronicleSetTest { @Test public void issue24ChronicleSetTest() throws IOException { ChronicleSet set = initSet(String.class, 1_000_000, 30); - ExecutorService executor = Executors.newFixedThreadPool(5); + ExecutorService executor = Executors.newFixedThreadPool(5, + new NamedThreadFactory("test")); for (int i = 0; i < 10; i++) { Runnable worker = new WorkerThread(set); executor.execute(worker); diff --git a/src/test/java/net/openhft/lang/values/DoubleArrayTest.java b/src/test/java/net/openhft/lang/values/DoubleArrayTest.java index 2c91b0e35..e0438bf4c 100755 --- a/src/test/java/net/openhft/lang/values/DoubleArrayTest.java +++ b/src/test/java/net/openhft/lang/values/DoubleArrayTest.java @@ -62,7 +62,7 @@ public class DoubleArrayTest { // expected } // free the memory. - da.bytesStore().release(); + da.bytesStore().releaseLast(); } @Test