Use Jvm.{level}() handlers instead of calling loggers directly, and unit tests cleanup esp use of @After, https://github.com/OpenHFT/Chronicle-Core/issues/233

This commit is contained in:
Peter Lawrey
2021-06-28 12:49:39 +01:00
parent d5461708fb
commit 125577b96e
40 changed files with 110 additions and 180 deletions
@@ -59,7 +59,6 @@ public interface ChronicleHashBuilderPrivateAPI<K, RO> {
* <p>Default value is {@code true} -- old removed entries are erased with 1 second timeout.
*
* @param cleanupRemovedEntries if stale removed entries should be purged from Chronicle Hash
* @return this builder back
* @see #removedEntryCleanupTimeout(long, TimeUnit)
* @see ReplicableEntry#doRemoveCompletely()
*/
@@ -81,7 +80,6 @@ public interface ChronicleHashBuilderPrivateAPI<K, RO> {
* @param removedEntryCleanupTimeout timeout, after which stale removed entries could be erased
* from Chronicle Hash data store completely
* @param unit time unit, in which the timeout is given
* @return this builder back
* @throws IllegalArgumentException is the specified timeout is less than 1 millisecond
* @see #cleanupRemovedEntries(boolean)
* @see ReplicableEntry#doRemoveCompletely()
@@ -16,6 +16,7 @@
package net.openhft.chronicle.hash.impl;
import net.openhft.chronicle.core.Jvm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,7 +24,6 @@ import java.util.TreeMap;
import java.util.WeakHashMap;
final class ChronicleHashCloseOnExitHook {
private static final Logger LOG = LoggerFactory.getLogger(ChronicleHashCloseOnExitHook.class);
private static WeakHashMap<VanillaChronicleHash.Identity, Long> maps = new WeakHashMap<>();
private static long order = 0;
@@ -66,7 +66,8 @@ final class ChronicleHashCloseOnExitHook {
preShutdownAction.run();
} catch (Throwable throwable) {
try {
LOG.error("Error running pre-shutdown action for " + h.toIdentityString() +
Jvm.error().on(ChronicleHashCloseOnExitHook.class,
"Error running pre-shutdown action for " + h.toIdentityString() +
" :", throwable);
} catch (Throwable t2) {
throwable.addSuppressed(t2);
@@ -77,7 +78,8 @@ final class ChronicleHashCloseOnExitHook {
h.close();
} catch (Throwable throwable) {
try {
LOG.error("Error while closing " + h.toIdentityString() +
Jvm.error().on(ChronicleHashCloseOnExitHook.class,
"Error while closing " + h.toIdentityString() +
" during shutdown hook:", throwable);
} catch (Throwable t2) {
// This may occur if the log service has already been shut down. Try to fall
@@ -89,7 +91,8 @@ final class ChronicleHashCloseOnExitHook {
});
} catch (Throwable throwable) {
try {
LOG.error("Error while closing maps during shutdown hook:", throwable);
Jvm.error().on(ChronicleHashCloseOnExitHook.class,
"Error while closing maps during shutdown hook:", throwable);
} catch (Throwable t2) {
throwable.addSuppressed(t2);
throwable.printStackTrace();
@@ -16,6 +16,7 @@
package net.openhft.chronicle.hash.impl;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.hash.ChronicleHashClosedException;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.hash.impl.util.Throwables;
@@ -32,7 +33,6 @@ import java.util.List;
* ChronicleHashResources is Runnable to be passed as "hunk" to {@link sun.misc.Cleaner}.
*/
public abstract class ChronicleHashResources implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(ChronicleHashResources.class);
private static final int OPEN = 0;
private static final int PARTIALLY_CLOSED = 1;
@@ -123,22 +123,21 @@ public abstract class ChronicleHashResources implements Runnable {
if (state == COMPLETELY_CLOSED)
return;
try {
LOG.error("{} is not closed manually, cleaned up from Cleaner",
chronicleHashIdentityString);
Jvm.error().on(getClass(), chronicleHashIdentityString+" is not closed manually, cleaned up from Cleaner" );
} catch (Throwable t) {
thrown = t;
} finally {
synchronized (this) {
if (state == COMPLETELY_CLOSED) {
LOG.error("Somebody closed {} while it is processed by Cleaner, " +
"this should be impossible", chronicleHashIdentityString);
Jvm.error().on(getClass(), "Somebody closed "+chronicleHashIdentityString+" while it is processed by Cleaner, " +
"this should be impossible");
} else {
thrown = Throwables.returnOrSuppress(thrown, releaseEverything(true));
}
}
if (thrown != null) {
try {
LOG.error("Error on releasing resources of " + chronicleHashIdentityString,
Jvm.error().on(getClass(), "Error on releasing resources of " + chronicleHashIdentityString,
thrown);
} catch (Throwable t) {
// This may occur if we are in shutdown hooks, and the log service has
@@ -25,8 +25,7 @@ import net.openhft.chronicle.core.OS;
* are stateful - so need to keep an instance in thread local that seems to be overall more pain
* than gain.
*/
public enum TierCountersArea {
;
public enum TierCountersArea {;
public static final long NEXT_TIER_INDEX_OFFSET = 0L;
public static final long PREV_TIER_INDEX_OFFSET = NEXT_TIER_INDEX_OFFSET + 8L;
@@ -16,8 +16,7 @@
package net.openhft.chronicle.hash.impl.stage.entry;
public enum ChecksumHashing {
;
public enum ChecksumHashing {;
/**
* A smart procedure copied from CityHash/FarmHash, see the full implementation in
@@ -22,6 +22,7 @@ import net.openhft.chronicle.algo.bytes.Access;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.PointerBytesStore;
import net.openhft.chronicle.bytes.VanillaBytes;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.SegmentLock;
@@ -97,8 +98,6 @@ public abstract class SegmentStages implements SegmentLock, LocksInterface {
@Stage("Segment")
public long entrySpaceOffset = 0;
@StageRef
LogHolder log;
@StageRef
Chaining chaining;
// chain
@Stage("Locks")
@@ -607,7 +606,7 @@ public abstract class SegmentStages implements SegmentLock, LocksInterface {
VanillaChronicleHash<?, ?, ?, ?> h = hh.h();
long nextTierIndex = nextTierIndex();
if (nextTierIndex == 0) {
log.LOG.debug("Allocate tier for segment # {}, tier {}", segmentIndex, tier + 1);
Jvm.debug().on(getClass(), "Allocate tier for segment # " + segmentIndex + " tier " +( tier + 1));
nextTierIndex = h.allocateTier();
nextTierIndex(nextTierIndex);
long prevTierIndex = tierIndex;
@@ -22,5 +22,4 @@ import org.slf4j.LoggerFactory;
@Staged
public class LogHolder {
public static final Logger LOG = LoggerFactory.getLogger(LogHolder.class);
}
@@ -96,7 +96,7 @@ public abstract class SegmentsRecovery implements IterationContext {
long finalActualExtraTiersInUse = actualExtraTiersInUse;
report(corruptionListener, corruption, -1, () ->
format("wrong number of actual tiers in use in global mutable state, stored: {}, " +
"should be: {}", storedExtraTiersInUse, finalActualExtraTiersInUse)
"should be: " + storedExtraTiersInUse, finalActualExtraTiersInUse)
);
globalMutableState.setExtraTiersInUse(actualExtraTiersInUse);
}
@@ -119,7 +119,7 @@ public abstract class SegmentsRecovery implements IterationContext {
if (storedFirstFreeTierIndex != firstFreeTierIndex) {
report(corruptionListener, corruption, -1, () ->
format("wrong first free tier index in global mutable state, stored: {}, " +
"should be: {}", storedFirstFreeTierIndex, firstFreeTierIndex)
"should be: " + storedFirstFreeTierIndex, firstFreeTierIndex)
);
globalMutableState.setFirstFreeTierIndex(firstFreeTierIndex);
}
@@ -233,7 +233,7 @@ public class TierRecovery {
if (s.tierEntries() != entries) {
report(corruptionListener, corruption, s.segmentIndex, () ->
format("Wrong number of entries counter for tier with index {}, " +
"stored: {}, should be: {}", s.tierIndex, s.tierEntries(), entries)
"stored: {}, should be: " + s.tierIndex, s.tierEntries(), entries)
);
s.tierEntries(entries);
}
@@ -277,7 +277,7 @@ public class TierRecovery {
}
if (e.keyEnd() > s.segmentBytes.capacity()) {
report(corruptionListener, corruption, segmentIndex, () ->
format("Wrong key size: {}", e.keySize)
format("Wrong key size: " + e.keySize)
);
return -1;
}
@@ -309,7 +309,7 @@ public class TierRecovery {
long entryAndChecksumEnd = e.entryEnd() + e.checksumStrategy.extraEntryBytes();
if (entryAndChecksumEnd > s.segmentBytes.capacity()) {
report(corruptionListener, corruption, segmentIndex, () ->
format("Wrong value size: {}, key: {}", e.valueSize, e.key())
format("Wrong value size: {}, key: " + e.valueSize, e.key())
);
return -1;
}
@@ -25,8 +25,6 @@ import java.lang.reflect.Method;
public class CleanerUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(CleanerUtils.class);
private static final Method CREATE_METHOD;
private static final Method CLEAN_METHOD;
@@ -38,7 +36,7 @@ public class CleanerUtils {
CLEAN_METHOD = cleanerClass.getDeclaredMethod("clean");
Jvm.setAccessible(CLEAN_METHOD);
} catch (ClassNotFoundException | NoSuchMethodException e) {
LOGGER.error("Unable to initialise CleanerUtils", e);
Jvm.error().on(CleanerUtils.class, "Unable to initialise CleanerUtils", e);
throw new RuntimeException(e);
}
}
@@ -48,7 +46,7 @@ public class CleanerUtils {
Object cleanerInstance = CREATE_METHOD.invoke(null, ob, thunk);
return () -> doClean(cleanerInstance);
} catch (IllegalAccessException | InvocationTargetException e) {
LOGGER.error("Unable to create cleaner", e);
Jvm.error().on(CleanerUtils.class, "Unable to create cleaner", e);
throw new RuntimeException(e);
}
}
@@ -57,7 +55,7 @@ public class CleanerUtils {
try {
CLEAN_METHOD.invoke(cleanerInstance);
} catch (IllegalAccessException | InvocationTargetException e) {
LOGGER.warn("Failed to clean buffer", e);
Jvm.warn().on(CleanerUtils.class, "Failed to clean buffer", e);
}
}
}
@@ -11,9 +11,6 @@ import java.lang.reflect.Field;
public final class PosixFallocate {
private static final Logger LOG =
LoggerFactory.getLogger(PosixFallocate.class.getName());
static {
Native.register(Platform.C_LIBRARY_NAME);
}
@@ -26,7 +23,7 @@ public final class PosixFallocate {
if (fd != -1) {
int ret = posix_fallocate(getNativeFileDescriptor(descriptor), offset, length);
if (ret != 0) {
LOG.warn("posix_fallocate() returned {}", ret);
Jvm.warn().on(PosixFallocate.class, "posix_fallocate() returned " + ret);
}
}
}
@@ -39,7 +36,7 @@ public final class PosixFallocate {
Jvm.setAccessible(field);
return (int) field.get(descriptor);
} catch (final Exception e) {
LOG.warn("unsupported FileDescriptor implementation: e={}", e.getLocalizedMessage());
Jvm.warn().on(PosixFallocate.class, "unsupported FileDescriptor implementation: e=" + e.getLocalizedMessage());
return -1;
}
}
@@ -155,18 +155,12 @@ public final class ChronicleMapBuilder<K, V> implements
* Anyway, unlikely anyone ever need more than 1 billion segments.
*/
private static final int MAX_SEGMENTS = (1 << 30);
private static final Logger LOG = LoggerFactory.getLogger(ChronicleMapBuilder.class.getName());
private static final double UNDEFINED_DOUBLE_CONFIG = Double.NaN;
private static final ConcurrentHashMap<File, Void> FILE_LOCKING_CONTROL = new ConcurrentHashMap<>(128);
private static final Logger CHRONICLE_MAP_LOGGER = LoggerFactory.getLogger(ChronicleMap.class);
private static final ChronicleHashCorruption.Listener DEFAULT_CHRONICLE_MAP_CORRUPTION_LISTENER =
corruption -> {
if (corruption.exception() != null) {
CHRONICLE_MAP_LOGGER.error(corruption.message(), corruption.exception());
} else {
CHRONICLE_MAP_LOGGER.error(corruption.message());
}
Jvm.error().on(ChronicleMapBuilder.class, corruption.message(), corruption.exception());
};
private static final int MAX_BOOTSTRAPPING_HEADER_SIZE = (int) MemoryUnit.KILOBYTES.toBytes(16);
private static final boolean MAP_CREATION_DEBUG = Jvm.getBoolean("chronicle.map.creation.debug");
@@ -678,7 +672,7 @@ public final class ChronicleMapBuilder<K, V> implements
if (BytesMarshallable.class.isAssignableFrom(valueClass) &&
(valueBuilder.tClass.isInterface() && valueBuilder.tClass != Marshallable.class)) {
if (Serializable.class.isAssignableFrom(valueClass))
LOG.warn("BytesMarshallable " + valueClass + " will be serialized as Serializable as the value class is an interface");
Jvm.warn().on(getClass(), "BytesMarshallable " + valueClass + " will be serialized as Serializable as the value class is an interface");
else
throw new IllegalArgumentException("Using BytesMarshallable and an interface value type not supported");
}
@@ -1714,9 +1708,8 @@ public final class ChronicleMapBuilder<K, V> implements
else {
try {
pauser.pause(10, TimeUnit.SECONDS);
}
catch (TimeoutException e) {
LOG.warn("Failed to write header: can't acquire exclusive file lock on empty file [" + canonicalFile + "] for 10 seconds", e);
} catch (TimeoutException e) {
Jvm.warn().on(getClass(), "Failed to write header: can't acquire exclusive file lock on empty file [" + canonicalFile + "] for 10 seconds", e);
Jvm.rethrow(e);
}
@@ -1874,7 +1867,7 @@ public final class ChronicleMapBuilder<K, V> implements
if (MAP_CREATION_DEBUG) {
Jvm.warn().on(getClass(), "<map creation debug> Read header from file [canonizedMapDataFile=" +
file.getAbsolutePath() + "]: " + wire.toString());
file.getAbsolutePath() + "]: " + wire);
}
final VanillaChronicleMap<K, V, ?> map = wire.getValueIn().typedMarshallable();
@@ -18,6 +18,7 @@ package net.openhft.chronicle.map;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import net.openhft.chronicle.core.Jvm;
import net.openhft.xstream.converters.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,7 +50,6 @@ final class JsonSerializer {
" <artifactId>jettison</artifactId>\n" +
" <version>1.3.6</version>\n" +
"</dependency>\n";
private static final Logger LOG = LoggerFactory.getLogger(JsonSerializer.class);
static synchronized <K, V> void getAll(final File toFile,
final Map<K, V> map,
@@ -57,7 +57,7 @@ final class JsonSerializer {
final XStream xstream = xStream(map, jsonConverters);
try (OutputStream outputStream = createOutputStream(toFile)) {
xstream.toXML(map, outputStream);
xstream.toXML(map, outputStream);
}
}
@@ -101,9 +101,10 @@ final class JsonSerializer {
if (c instanceof Converter) {
xstream.registerConverter((Converter) c);
} else {
LOG.warn("Skipping Converter of type class=" + c.getClass().getName() + " as " +
" expecting an object of type com.thoughtworks.xstream.converters" +
".Converter");
Jvm.warn().on(JsonSerializer.class,
"Skipping Converter of type class=" + c.getClass().getName() + " as " +
" expecting an object of type com.thoughtworks.xstream.converters" +
".Converter");
}
}
@@ -16,6 +16,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.hash.ChronicleHashBuilderPrivateAPI;
import net.openhft.chronicle.hash.ReplicatedHashSegmentContext;
import net.openhft.chronicle.hash.replication.ReplicableEntry;
@@ -33,7 +34,6 @@ import static net.openhft.chronicle.hash.replication.TimeProvider.systemTimeInte
class OldDeletedEntriesCleanupThread extends Thread
implements MapClosable, Predicate<ReplicableEntry> {
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
@@ -134,7 +134,7 @@ class OldDeletedEntriesCleanupThread extends Thread
long currentTime = currentTime();
long mapScanTime = systemTimeIntervalBetween(
prevSegment0ScanStart, currentTime, cleanupTimeoutUnit);
LOG.debug("Old deleted entries scan time: {} {}", mapScanTime, cleanupTimeoutUnit);
Jvm.debug().on(getClass(), "Old deleted entries scan time: " + mapScanTime + " " + cleanupTimeoutUnit);
if (mapScanTime < cleanupTimeout) {
long timeToSleep = cleanupTimeoutUnit.toMillis(cleanupTimeout - mapScanTime);
if (timeToSleep > 0) {
@@ -162,8 +162,9 @@ class OldDeletedEntriesCleanupThread extends Thread
removedCompletely = 0;
if (((ReplicatedHashSegmentContext<?, ?>) context)
.forEachSegmentReplicableEntryWhile(this)) {
LOG.debug("Removed {} old deleted entries in the segment {}",
removedCompletely, segmentIndex);
Jvm.debug().on(getClass(),
"Removed " + removedCompletely + " old deleted entries " +
"in the segment " + segmentIndex);
nextSegmentIndex = nextSegmentIndex(segmentIndex);
map.globalMutableState().setCurrentCleanupSegmentIndex(nextSegmentIndex);
return nextSegmentIndex;
@@ -19,6 +19,7 @@ package net.openhft.chronicle.map;
import net.openhft.chronicle.algo.bitset.BitSetFrame;
import net.openhft.chronicle.algo.bitset.SingleThreadedFlatBitSetFrame;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.threads.EventHandler;
import net.openhft.chronicle.core.threads.EventLoop;
import net.openhft.chronicle.core.threads.HandlerPriority;
@@ -107,7 +108,6 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public static final int ADDITIONAL_ENTRY_BYTES = 10;
static final byte ENTRY_HUNK = 1;
static final byte BOOTSTRAP_TIME_HUNK = 2;
private static final Logger LOG = LoggerFactory.getLogger(ReplicatedChronicleMap.class);
public transient boolean cleanupRemovedEntries;
public transient long cleanupTimeout;
@@ -608,12 +608,12 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
key.writeTo(destination, destination.writePosition());
destination.writeSkip(key.size());
final boolean traceEnabled = LOG.isTraceEnabled();
final boolean traceEnabled = Jvm.isDebugEnabled(getClass());
String message = null;
if (traceEnabled) {
if (isDeleted) {
LOG.trace("WRITING ENTRY TO DEST - into local-id={}, remove(key={})",
identifier(), key);
Jvm.debug().on(getClass(),
"WRITING ENTRY TO DEST - into local-id=identifier(), remove(key=" + key + ")");
} else {
message = String.format(
"WRITING ENTRY TO DEST - into local-id=%d, put(key=%s,",
@@ -630,7 +630,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
destination.writeSkip(value.size());
if (traceEnabled) {
LOG.debug(message + "value=" + value + ")");
Jvm.debug().on(getClass(), message + "value=" + value + ")");
}
}
@@ -1005,7 +1005,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
return true;
}
final boolean debugEnabled = LOG.isDebugEnabled();
final boolean debugEnabled = Jvm.isDebugEnabled(getClass());
try {
throwExceptionIfClosed();
@@ -1016,16 +1016,19 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
iterationContext.initSegmentIndex(segmentIndex);
iterationContext.forEachSegmentReplicableEntry(e -> {
if (debugEnabled) {
LOG.debug("Bootstrap entry: id {}, key {}, value {}", localIdentifier,
iterationContext.key(), iterationContext.value());
Jvm.debug().on(getClass(), "Bootstrap entry: " +
"id " + localIdentifier + ", " +
"key " + iterationContext.key() + ", " +
"value " + iterationContext.value());
}
// Bizarrely the next line line cause NPE in JDT compiler
//assert re.originTimestamp() > 0L;
if (debugEnabled) {
LOG.debug("Bootstrap decision: bs ts: {}, entry ts: {}, " +
"entry id: {}, local id: {}",
fromTimeStamp, e.originTimestamp(),
e.originIdentifier(), localIdentifier);
Jvm.debug().on(getClass(), "Bootstrap decision: " +
"bs ts: " + fromTimeStamp + ", " +
"entry ts: " + e.originTimestamp() + ", " +
"entry id: " + e.originIdentifier() + ", " +
"local id: " + localIdentifier);
}
// TODO currently, all entries, originating not from the current node,
// are bootstrapped. This could be optimized, but requires to generate
@@ -1060,10 +1063,9 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
try {
for (int i = 0; i < actualSegments + 1; i++) // Call [actualSegments + 1] times to trigger context close
syncHandler.action();
}
catch (InvalidEventHandlerException e) {
} catch (InvalidEventHandlerException e) {
if (e.getCause() instanceof ChronicleHashClosedException)
throw (ChronicleHashClosedException)e.getCause();
throw (ChronicleHashClosedException) e.getCause();
}
}
@@ -39,8 +39,6 @@ import net.openhft.sg.Staged;
OwnerThreadHolder.class,
VanillaChronicleMapHolderImpl.class,
LogHolder.class,
MapSegmentIteration.class,
KeyBytesInterop.class,
@@ -43,8 +43,6 @@ import net.openhft.sg.Staged;
CompilationAnchor.class,
OwnerThreadHolder.class,
LogHolder.class,
VanillaChronicleMapHolderImpl.class,
KeyBytesInterop.class,
@@ -43,8 +43,6 @@ import net.openhft.sg.Staged;
OwnerThreadHolder.class,
ReplicatedChronicleMapHolderImpl.class,
LogHolder.class,
ReplicatedMapSegmentIteration.class,
KeyBytesInterop.class,
@@ -46,8 +46,6 @@ import net.openhft.sg.Staged;
CompilationAnchor.class,
OwnerThreadHolder.class,
LogHolder.class,
ReplicatedChronicleMapHolderImpl.class,
KeyBytesInterop.class,
@@ -1,5 +1,6 @@
package net.openhft.chronicle.map.locks;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.values.LongValue;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ChronicleMapBuilder;
@@ -25,9 +26,6 @@ import static net.openhft.chronicle.values.Values.newNativeReference;
*/
public class ChronicleStampedLock extends StampedLock {
private static final Logger lg = Logger.getLogger(
"net.openhft.chronicle.map.fromdocs.acid.revelations.ChonicleStampedLock"
);
ChronicleMap<String, ChronicleStampedLockVOInterface> chm; //custody of StampedLock semantics
ChronicleMap<String, LongValue> chmR; //Chronicle AtomicLong re: Reader set custody
ChronicleMap<String, LongValue> chmW; //Chronicle AtomicLong re: Reader set custody
@@ -55,7 +53,7 @@ public class ChronicleStampedLock extends StampedLock {
chm.acquireUsing("LastWriterTime ", lastWriterT); //needed for validate
chmR.acquireUsing("ReaderCount ", readLockHolderCount);
chmW.acquireUsing("WriterCount ", readLockHolderCount);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock constructed" +
","
@@ -104,7 +102,7 @@ public class ChronicleStampedLock extends StampedLock {
(offHeapLock = chm.get("Stamp ")).setEntryLockState(0L);
long t = System.currentTimeMillis();
chm.put("Stamp ", offHeapLock);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock saw stamp=[" + 0L + "]" +
" tryOptmisticRead() returning stamp=" +
@@ -119,7 +117,7 @@ public class ChronicleStampedLock extends StampedLock {
offHeapLock = chm.get("Stamp ");
lastWriterT = chm.get("LastWriterTime ");
boolean ret = false;
/**
/*
* If *any* Writer interacted with the offHeapLock,
* since event=tryOptimisticRead(),
* then FAIL the validate() invoke.
@@ -134,14 +132,14 @@ public class ChronicleStampedLock extends StampedLock {
} else {
ret = Boolean.TRUE;
}
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock validate(" +
stamp + ") returned =[" +
ret + "] " +
","
);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock LastWriterT=[" +
lastWriterT.getEntryLockState() + "] " +
@@ -186,7 +184,7 @@ public class ChronicleStampedLock extends StampedLock {
return 0L;
do {
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock tryWriteLock() ?WAITING " +
" on offHeapLock.unlock(" +
@@ -218,13 +216,13 @@ public class ChronicleStampedLock extends StampedLock {
writeLockHolderCount.addAtomicValue(+1);
chmW.put("WriterCount ", writeLockHolderCount);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock trywriteLock() ++ writeSeekers=[" +
+writeLockHolderCount.getVolatileValue() + "] " +
"..,"
);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock tryWriteLock() PROCEEDING " +
" ,"
@@ -234,7 +232,7 @@ public class ChronicleStampedLock extends StampedLock {
lastWriterT.setEntryLockState(t);
chm.put("Stamp ", offHeapLock);
chm.put("LastWriterTime ", lastWriterT);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + t +
" ChronicleStampedLock tryWriteLock() returned stamp=" +
offHeapLock.getEntryLockState() +
@@ -254,7 +252,7 @@ public class ChronicleStampedLock extends StampedLock {
if (l < 0L)
return (0);
do {
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock tryReadLock() ?WAITING " +
" on offHeapLock.unlock(" +
@@ -274,7 +272,7 @@ public class ChronicleStampedLock extends StampedLock {
}
} while (l < 0L);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock tryReadLock() PROCEEDING " +
//" readerCount=[" + readerCount.getReaderCount() + "]" +
@@ -292,7 +290,7 @@ public class ChronicleStampedLock extends StampedLock {
); // assign the Lock to most-recent Reader
chm.put("Stamp ", offHeapLock); // make it IPC visible
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock tryReadLock() returned stamp=" +
offHeapLock.getEntryLockState() +
@@ -312,7 +310,7 @@ public class ChronicleStampedLock extends StampedLock {
writeLockHolderCount = chmW.get("WriterCount ");
do {
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock writeLock() ?WAITING " +
" on offHeapLock.unlock(" +
@@ -343,14 +341,14 @@ public class ChronicleStampedLock extends StampedLock {
writeLockHolderCount.addAtomicValue(+1);
chmW.put("WriterCount ", writeLockHolderCount);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock writeLock() ++ writeSeekers=[" +
+writeLockHolderCount.getVolatileValue() + "] " +
"..,"
);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock writeLock() PROCEEDING " +
" ,"
@@ -360,7 +358,7 @@ public class ChronicleStampedLock extends StampedLock {
lastWriterT.setEntryLockState(t);
chm.put("Stamp ", offHeapLock);
chm.put("LastWriterTime ", lastWriterT);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + t +
" ChronicleStampedLock writeLock() returned stamp=" +
offHeapLock.getEntryLockState() +
@@ -377,7 +375,7 @@ public class ChronicleStampedLock extends StampedLock {
readLockHolderCount = chmR.get("ReaderCount ");
do {
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock readLock() ?WAITING " +
" on offHeapLock.unlock(" +
@@ -397,7 +395,7 @@ public class ChronicleStampedLock extends StampedLock {
}
} while (l < 0L);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock readLock() PROCEEDING " +
//" readerCount=[" + Count.getReaderCount() + "]" +
@@ -416,7 +414,7 @@ public class ChronicleStampedLock extends StampedLock {
chm.put("Stamp ", offHeapLock); // make it IPC visible
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock readLock() returned stamp=" +
offHeapLock.getEntryLockState() +
@@ -443,7 +441,7 @@ public class ChronicleStampedLock extends StampedLock {
offHeapLock = chm.get("Stamp ");
readLockHolderCount = chmR.get("ReaderCount ");
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock unlockRead(" + stamp + ") unlocking.." +
"ReaderCount=[" +
@@ -453,7 +451,7 @@ public class ChronicleStampedLock extends StampedLock {
);
readLockHolderCount.addAtomicValue(-1); // DECREMENT the cardinality of the Reader set
chmR.put("ReaderCount ", readLockHolderCount); // make it IPC visible
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock unlockRead(" + stamp + ") unlocking.." +
"ReaderCount=[" +
@@ -464,7 +462,7 @@ public class ChronicleStampedLock extends StampedLock {
offHeapLock.setEntryLockState(
(readLockHolderCount = chmR.get("ReaderCount ")).getVolatileValue()
);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
"offHeapLock=[" + offHeapLock.getEntryLockState() + "]" +
","
@@ -475,7 +473,7 @@ public class ChronicleStampedLock extends StampedLock {
@Override
public void unlockWrite(long stamp) {
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock unlockWrite(" + stamp + ") unlocking..,"
);
@@ -486,14 +484,14 @@ public class ChronicleStampedLock extends StampedLock {
writeLockHolderCount = chmW.get("WriterCount ");
writeLockHolderCount.addAtomicValue(-1);
chmW.put("WriterCount ", writeLockHolderCount);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock unlockWrite(" + stamp + ") -- writeSeekers=[" +
+writeLockHolderCount.getVolatileValue() + "] " +
"..,"
);
lg.log(Level.FINE,
Jvm.debug().on(getClass(),
" ,@t=" + System.currentTimeMillis() +
" ChronicleStampedLock unlockWrite(" +
(offHeapLock = chm.get("Stamp ")).getEntryLockState() +
@@ -16,6 +16,7 @@
package net.openhft.chronicle.set;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.hash.ChronicleHashBuilder;
import net.openhft.chronicle.hash.ChronicleHashBuilderPrivateAPI;
import net.openhft.chronicle.hash.ChronicleHashCorruption;
@@ -44,15 +45,8 @@ import java.io.IOException;
public final class ChronicleSetBuilder<K>
implements ChronicleHashBuilder<K, ChronicleSet<K>, ChronicleSetBuilder<K>> {
private static final Logger chronicleSetLogger = LoggerFactory.getLogger(ChronicleSet.class);
private static final ChronicleHashCorruption.Listener defaultChronicleSetCorruptionListener =
corruption -> {
if (corruption.exception() != null) {
chronicleSetLogger.error(corruption.message(), corruption.exception());
} else {
chronicleSetLogger.error(corruption.message());
}
};
corruption -> Jvm.error().on(ChronicleSetBuilder.class, corruption.message(), corruption.exception());
private ChronicleMapBuilder<K, DummyValue> chronicleMapBuilder;
private final ChronicleSetBuilderPrivateAPI<K> privateAPI;
@@ -21,6 +21,7 @@ import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.values.ArrayFieldModel;
import net.openhft.chronicle.values.FieldModel;
import net.openhft.chronicle.values.ValueModel;
@@ -36,7 +37,6 @@ import java.lang.reflect.Method;
*/
public class ValueConverter implements Converter {
private static final Logger LOG = LoggerFactory.getLogger(ValueConverter.class);
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext context) {
@@ -77,7 +77,7 @@ public class ValueConverter implements Converter {
writer.endNode();
} catch (Exception e) {
LOG.error("class=" + fieldModel.name(), e);
Jvm.error().on(getClass(), "class=" + fieldModel.name(), e);
}
});