improvement to map (#266) and (#265)

* added AbstractClosable

* added Jvm.init()

* added disable.thread.safety

* ignore thread safety check

* disabled threadSafetyCheck for chronicle map

* removed init()

* changed isOpen() to be !isClosed()

* throwExceptionIfClosed() now creates a new ChronicleHashClosedException()

* added  test testRemainingAutoResizesAfterClose

Co-authored-by: Rob Austin <rob.austin@boundedbuffer.co.uk>
This commit is contained in:
Rob Austin
2021-01-27 18:23:07 +00:00
committed by GitHub
co-authored by Rob Austin
parent f921c40819
commit addfc1481f
4 changed files with 49 additions and 14 deletions
@@ -20,8 +20,10 @@ import net.openhft.chronicle.algo.locks.*;
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.bytes.MappedBytesStoreFactory;
import net.openhft.chronicle.bytes.NativeBytesStore;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.io.AbstractCloseable;
import net.openhft.chronicle.core.io.ReferenceOwner;
import net.openhft.chronicle.hash.*;
import net.openhft.chronicle.hash.impl.util.BuildVersion;
@@ -69,7 +71,7 @@ import static net.openhft.chronicle.map.ChronicleHashCorruptionImpl.report;
public abstract class VanillaChronicleHash<K,
C extends HashEntry<K>, SC extends HashSegmentContext<K, ?>,
ECQ extends ExternalHashQueryContext<K>>
ECQ extends ExternalHashQueryContext<K>> extends AbstractCloseable
implements ChronicleHash<K, C, SC, ECQ>, Marshallable {
public static final long TIER_COUNTERS_AREA_SIZE = 64;
@@ -680,7 +682,13 @@ public abstract class VanillaChronicleHash<K,
}
@Override
public final void close() {
protected boolean threadSafetyCheck(boolean isUsed) {
// disabled for chronicle map
return true;
}
@Override
protected void performClose() {
if (resources != null && resources.releaseManually()) {
cleanupOnClose();
}
@@ -698,11 +706,14 @@ public abstract class VanillaChronicleHash<K,
keyDataAccess = null;
}
/**
* @return !isClosed()
* @Deprecated use !isClosed() instead
*/
@Deprecated(/*remove in x.23*/)
@Override
public boolean isOpen() {
throwExceptionIfClosed();
return !resources.closed();
return !isClosed();
}
public final void checkKey(final Object key) {
@@ -715,6 +726,12 @@ public abstract class VanillaChronicleHash<K,
}
}
@Override
public void throwExceptionIfClosed() throws IllegalStateException {
if (this.isClosed())
throw new ChronicleHashClosedException(this.getClass().getName() + " closed", Jvm.getValue(this, "closedHere"));
}
public final long segmentHeaderAddress(final int segmentIndex) {
return bsAddress() + segmentHeadersOffset + ((long) segmentIndex) * segmentHeaderSize;
}