diff --git a/NOTES b/NOTES index d8e19b6..ad0b771 100644 --- a/NOTES +++ b/NOTES @@ -1,5 +1,7 @@ + * s/System.out.println/log()/g * Migrate to Scala * mvn com.mysema.scalagen:scalagen-maven-plugin:0.2.2:main -DtargetFolder=/home/gburd/ws/stasis/stasis-core/src/main/scala + * /usr/lib/jvm/zulu-8-amd64/bin/java -cp /home/gburd/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.6.jar:/home/gburd/src/scalagen/scalagen/target/dependencies/*:/home/gburd/src/scalagen/scalagen/target/classes/ com.mysema.scalagen.Cli /home/gburd/ws/stasis/stasis-core/src/main/java /tmp/stasis-foo * Fix @Ignore'ed JUnit tests * TODO/XXX/FIXME/JE_TEST * begin/end JE only @@ -19,5 +21,6 @@ * multiple private constructors * @BeanProperty * copyright + * assert * http://dbmsmusings.blogspot.com/2019/06/correctness-anomalies-under.html diff --git a/stasis-core/src/main/java/com/sleepycat/je/cleaner/Cleaner.java b/stasis-core/src/main/java/com/sleepycat/je/cleaner/Cleaner.java index b218072..8f2f627 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/cleaner/Cleaner.java +++ b/stasis-core/src/main/java/com/sleepycat/je/cleaner/Cleaner.java @@ -339,7 +339,7 @@ public class Cleaner implements DaemonRunner, EnvConfigObserver { new LongStat(statGroup, CLEANER_REPEAT_ITERATOR_READS); logSizeStats = - new FileProtector.LogSizeStats(0, 0, 0, new HashMap<>()); + new FileProtector.LogSizeStats(0, 0, 0, new HashMap()); if (env.isMemOnly()) { fileStoreInfo = null; @@ -898,7 +898,7 @@ public class Cleaner implements DaemonRunner, EnvConfigObserver { throws EnvLockedException { final FileManager fileManager = env.getFileManager(); - final SortedSet deletedFiles = new TreeSet<>(); + final SortedSet deletedFiles = new TreeSet(); if (!fileManager.lockEnvironment(false, true)) { throw new EnvLockedException(); diff --git a/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProcessor.java b/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProcessor.java index 25158f4..f702f2e 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProcessor.java +++ b/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProcessor.java @@ -167,7 +167,7 @@ public class FileProcessor extends DaemonThread { private int nLNsExpiredThisRun = 0; /* - * Number of LN logrecs that were not known apriory to be obsolete, and as + * Number of LN logrecs that were not known a priori to be obsolete, and as * a result, needed further processing. These include LNs that had to be * searched-for in the tree as well as the nLNQueueHitsThisRun (see below). */ @@ -190,8 +190,8 @@ public class FileProcessor extends DaemonThread { /* * Number of LN logrecs whose LSN had to be locked in order to check their - * obsoleteness, and this non-blocking lock request was denied (and as a - * result, the logrec was placed in the "pending LNs" queue. + * how obsolete they are, and this non-blocking lock request was denied (and + * as a result, the logrec was placed in the "pending LNs" queue. */ private int nLNsLockedThisRun = 0; @@ -301,7 +301,7 @@ public class FileProcessor extends DaemonThread { /** * Selects files to clean and cleans them. It returns the number of * successfully cleaned files. May be called by the daemon thread or - * programatically. + * programmatically. * * @param invokedFromDaemon currently has no effect. * @@ -410,7 +410,7 @@ public class FileProcessor extends DaemonThread { final long runId = cleaner.totalRuns.incrementAndGet(); final MemoryBudget budget = envImpl.getMemoryBudget(); - nFilesCleaned += 1; + nFilesCleaned = nFilesCleaned + 1; try { TestHookExecute.doHookIfSet(cleaner.fileChosenHook); @@ -712,14 +712,14 @@ public class FileProcessor extends DaemonThread { * all DB IDs encountered and do the check once per DB at the end. */ final Set checkPendingDbSet = - countOnly ? null : new HashSet<>(); + countOnly ? null : new HashSet(); /* * Use local caching to reduce DbTree.getDb overhead. Do not call * releaseDb after getDb with the dbCache, since the entire dbCache * will be released at the end of this method. */ - final Map dbCache = new HashMap<>(); + final Map dbCache = new HashMap(); final DbTree dbMapTree = envImpl.getDbTree(); /* @@ -731,7 +731,7 @@ public class FileProcessor extends DaemonThread { countOnly ? null : new LocalUtilizationTracker(envImpl); /* Keep track of all database IDs encountered. */ - final Set databases = new HashSet<>(); + final Set databases = new HashSet(); /* Create the file reader. */ final CleanerFileReader reader = new CleanerFileReader( @@ -1170,7 +1170,7 @@ public class FileProcessor extends DaemonThread { processFoundLN(info, logLsn, bin.getLsn(index), bin, index); if (pendingLN != null) { - pendingLNs = new HashMap<>(); + pendingLNs = new HashMap(); pendingLNs.put(logLsn, pendingLN); } @@ -1202,7 +1202,7 @@ public class FileProcessor extends DaemonThread { if (pendingLN != null) { if (pendingLNs == null) { - pendingLNs = new HashMap<>(); + pendingLNs = new HashMap(); } pendingLNs.put(binLsn, pendingLN); } @@ -1955,7 +1955,7 @@ public class FileProcessor extends DaemonThread { private int usedMem; LookAheadCache(int lookAheadCacheSize) { - map = new TreeMap<>(); + map = new TreeMap(); maxMem = lookAheadCacheSize; usedMem = MemoryBudget.TREEMAP_OVERHEAD; } diff --git a/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProtector.java b/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProtector.java index b98f1ec..fa331c6 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProtector.java +++ b/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileProtector.java @@ -13,14 +13,6 @@ package com.sleepycat.je.cleaner; -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import java.util.NavigableMap; -import java.util.NavigableSet; -import java.util.TreeMap; -import java.util.TreeSet; - import com.sleepycat.je.EnvironmentFailureException; import com.sleepycat.je.dbi.EnvironmentImpl; import com.sleepycat.je.log.FileManager; @@ -28,6 +20,10 @@ import com.sleepycat.je.utilint.DbLsn; import com.sleepycat.je.utilint.Pair; import com.sleepycat.je.utilint.VLSN; +import java.io.File; +import java.util.*; +import java.util.function.BiFunction; + /** * The FileProtector is primarily responsible for protecting files from being * deleted due to log cleaning, when they are needed for other purposes. As @@ -197,15 +193,15 @@ public class FileProtector { private final EnvironmentImpl envImpl; /* Access active files only via getActiveFiles. */ - private final NavigableMap activeFiles = new TreeMap<>(); + private final NavigableMap activeFiles = new TreeMap(); private final NavigableMap reservedFiles = - new TreeMap<>(); + new TreeMap(); - private final NavigableMap condemnedFiles = new TreeMap<>(); + private final NavigableMap condemnedFiles = new TreeMap(); private final Map protectedFileSets = - new HashMap<>(); + new HashMap(); /* Is null if the env is not replicated. */ private ProtectedFileRange vlsnIndexRange; @@ -308,7 +304,7 @@ public class FileProtector { final NavigableMap activeFiles = getActiveFiles(); final NavigableSet protectedFiles = - new TreeSet<>(activeFiles.keySet()); + new TreeSet(activeFiles.keySet()); if (nReservedFiles > 0) { int n = nReservedFiles; @@ -443,7 +439,7 @@ public class FileProtector { for (final ReservedFileInfo info : reservedFiles.values()) { size += info.size; } - return new Pair<>(size, new TreeSet<>(reservedFiles.keySet())); + return new Pair>(size, new TreeSet(reservedFiles.keySet())); } /** @@ -483,7 +479,7 @@ public class FileProtector { if (!condemnedFiles.isEmpty()) { final Long file = condemnedFiles.firstKey(); final Long size = condemnedFiles.remove(file); - return new Pair<>(file, size); + return new Pair(file, size); } if (reservedFiles.isEmpty()) { @@ -563,7 +559,7 @@ public class FileProtector { /* Calculate reserved and protected sizes. */ long reservedSize = 0; long protectedSize = 0; - final Map protectedSizeMap = new HashMap<>(); + final Map protectedSizeMap = new HashMap(); for (final Map.Entry entry : reservedFiles.entrySet()) { @@ -581,9 +577,19 @@ public class FileProtector { isProtected = true; - protectedSizeMap.compute( - pfs.getName(), - (k, v) -> ((v != null) ? v : 0) + info.size); + BiFunction fn = new BiFunction() { + @Override + public Long apply(String k, Long v) { + Long r = 0L; + if (v != null) { + r = v + info.size; + } else { + r = info.size; + } + return r; + } + }; + protectedSizeMap.compute(pfs.getName(), fn); // (k, v) -> ((v != null) ? v : 0) + info.size); } if (isProtected) { @@ -643,12 +649,12 @@ public class FileProtector { reservedFiles.entrySet()) { final Long file = entry.getKey(); - final ReservedFileInfo info = entry.getValue(); + final ReservedFileInfo info = entry.getValue(); - for (final ProtectedFileSet pfs : protectedFileSets.values()) { + for (final ProtectedFileSet pfs : protectedFileSets.values()) { - if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) { - continue; + if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) { + continue; } if (pfs.isProtected(file, info)) { @@ -658,17 +664,17 @@ public class FileProtector { final VLSN lastVlsn = info.endVLSN; - if (!lastVlsn.isNull()) { - if (lastVlsn.compareTo(preserveVLSN) > 0) { - break; - } - truncateVLSN = lastVlsn; - truncateFile = file; - } + if (!lastVlsn.isNull()) { + if (lastVlsn.compareTo(preserveVLSN) > 0) { + break; + } + truncateVLSN = lastVlsn; + truncateFile = file; + } - deleteBytes += info.size; + deleteBytes += info.size; - if (deleteBytes >= bytesNeeded) { + if (deleteBytes >= bytesNeeded) { break; } } @@ -822,7 +828,7 @@ public class FileProtector { * new files. */ public synchronized NavigableSet getProtectedFiles() { - return new TreeSet<>(protectedFiles); + return new TreeSet(protectedFiles); } /** diff --git a/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileSelector.java b/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileSelector.java index e8d4c1a..9f9e2fb 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileSelector.java +++ b/stasis-core/src/main/java/com/sleepycat/je/cleaner/FileSelector.java @@ -152,9 +152,9 @@ public class FileSelector { private boolean anyPendingDuringCheckpoint; FileSelector() { - fileInfoMap = new TreeMap<>(); - pendingLNs = new HashMap<>(); - pendingDBs = new HashSet<>(); + fileInfoMap = new TreeMap(); + pendingLNs = new HashMap(); + pendingDBs = new HashSet(); } /** @@ -177,7 +177,7 @@ public class FileSelector { if (!toBeCleaned.isEmpty()) { final Long fileNum = toBeCleaned.iterator().next(); final FileInfo info = setStatus(fileNum, FileStatus.BEING_CLEANED); - return new Pair<>(fileNum, info.requiredUtil); + return new Pair(fileNum, info.requiredUtil); } final Pair result = calculator.getBestFile( @@ -215,7 +215,7 @@ public class FileSelector { * Returns a sorted set of files having the given status. */ private synchronized NavigableSet getFiles(FileStatus status) { - final NavigableSet set = new TreeSet<>(); + final NavigableSet set = new TreeSet(); for (Map.Entry entry : fileInfoMap.entrySet()) { if (entry.getValue().status == status) { set.add(entry.getKey()); @@ -403,7 +403,7 @@ public class FileSelector { return Collections.emptyMap(); } - final Map reservedFiles = new HashMap<>(); + final Map reservedFiles = new HashMap(); final Set previouslyCleanedFiles = info.getCleanedFiles(); final Set previouslyProcessedFiles = info.getFullyProcessedFiles(); @@ -465,7 +465,7 @@ public class FileSelector { synchronized Map getPendingLNs() { if (pendingLNs.size() > 0) { - return new HashMap<>(pendingLNs); + return new HashMap(pendingLNs); } else { return null; } @@ -527,7 +527,7 @@ public class FileSelector { * none. */ public synchronized NavigableSet getInProgressFiles() { - return new TreeSet<>(fileInfoMap.keySet()); + return new TreeSet(fileInfoMap.keySet()); } /** diff --git a/stasis-core/src/main/java/com/sleepycat/je/cleaner/ReservedFileInfo.java b/stasis-core/src/main/java/com/sleepycat/je/cleaner/ReservedFileInfo.java index 367834d..899b4c9 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/cleaner/ReservedFileInfo.java +++ b/stasis-core/src/main/java/com/sleepycat/je/cleaner/ReservedFileInfo.java @@ -52,7 +52,7 @@ public class ReservedFileInfo { input.readByte(); /* Future flags. */ final VLSN firstVLSN = new VLSN(input.readPackedLong()); final VLSN lastVLSN = new VLSN(input.readPackedLong()); - final Set dbIds = new HashSet<>(); + final Set dbIds = new HashSet(); final int nDbs = input.readPackedInt(); for (int i = 0; i < nDbs; i += 1) { dbIds.add(new DatabaseId(input.readPackedLong())); diff --git a/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationCalculator.java b/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationCalculator.java index 7be352d..d308242 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationCalculator.java +++ b/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationCalculator.java @@ -476,7 +476,7 @@ public class UtilizationCalculator implements EnvConfigObserver { } return (fileChosen != null) ? - new Pair<>(fileChosen, pass1RequiredUtil) : + new Pair(fileChosen, pass1RequiredUtil) : null; } diff --git a/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationProfile.java b/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationProfile.java index 6788e69..2409a52 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationProfile.java +++ b/stasis-core/src/main/java/com/sleepycat/je/cleaner/UtilizationProfile.java @@ -112,7 +112,7 @@ public class UtilizationProfile { UtilizationTracker tracker) { this.env = env; this.tracker = tracker; - fileSummaryMap = new TreeMap<>(); + fileSummaryMap = new TreeMap(); logger = LoggerUtils.getLogger(getClass()); } @@ -218,7 +218,7 @@ public class UtilizationProfile { * Copy the fileSummaryMap to a new map, adding in the tracked * summary information for each entry. */ - TreeMap map = new TreeMap<>(); + TreeMap map = new TreeMap(); for (Long file : fileSummaryMap.keySet()) { FileSummary summary = getFileSummary(file); map.put(file, summary); @@ -233,7 +233,7 @@ public class UtilizationProfile { } return map; } else { - return new TreeMap<>(fileSummaryMap); + return new TreeMap(fileSummaryMap); } } @@ -260,7 +260,7 @@ public class UtilizationProfile { */ public synchronized SortedMap getFileSizeSummaryMap() { - TreeMap map = new TreeMap<>(); + TreeMap map = new TreeMap(); for (Long fileNum : fileSummaryMap.keySet()) { int totalSize = getFileSize(fileNum); @@ -294,7 +294,7 @@ public class UtilizationProfile { MemoryBudget mb = env.getMemoryBudget(); mb.updateAdminMemoryUsage(0 - memorySize); - fileSummaryMap = new TreeMap<>(); + fileSummaryMap = new TreeMap(); cachePopulated = false; } @@ -310,7 +310,7 @@ public class UtilizationProfile { */ void reserveFiles(final Map reservedFiles) { - final Set dbIds = new HashSet<>(); + final Set dbIds = new HashSet(); for (final Map.Entry entry : reservedFiles.entrySet()) { @@ -350,10 +350,12 @@ public class UtilizationProfile { BasicLocker.createBasicLocker(env, false /*noWait*/); try { - try (Cursor cursor = DbInternal.makeCursor( - reservedFilesDb, locker, null, false /*retainNonTxnLocks*/)) { - + Cursor cursor = DbInternal.makeCursor( + reservedFilesDb, locker, null, false /*retainNonTxnLocks*/); + try { cursor.put(keyEntry, dataEntry, Put.OVERWRITE, null); + } finally { + cursor.close(); } } finally { locker.operationEnd(); @@ -374,14 +376,15 @@ public class UtilizationProfile { final Locker locker = BasicLocker.createBasicLocker(env, false /*noWait*/); try { - try (Cursor cursor = - DbInternal.makeCursor(reservedFilesDb, locker, null)) { - + Cursor cursor = DbInternal.makeCursor(reservedFilesDb, locker, null); + try { if (cursor.get( keyEntry, null, Get.SEARCH, readOptions) != null) { cursor.delete(null); } + } finally { + cursor.close(); } } finally { locker.operationEnd(); @@ -718,7 +721,7 @@ public class UtilizationProfile { assert cachePopulated; final long fileNumVal = fileNum; - final List list = new ArrayList<>(); + final List list = new ArrayList(); /* * Get a TrackedFileSummary that cannot be flushed (evicted) while we @@ -899,7 +902,7 @@ public class UtilizationProfile { } final Long[] existingFiles = env.getFileManager().getAllFileNumbers(); - final Set reservedFileRecords = new HashSet<>(); + final Set reservedFileRecords = new HashSet(); final DatabaseEntry keyEntry = new DatabaseEntry(); final DatabaseEntry dataEntry = new DatabaseEntry(); final FileProtector fileProtector = env.getFileProtector(); @@ -930,10 +933,10 @@ public class UtilizationProfile { final ReadOptions options = new ReadOptions().setLockMode(LockMode.READ_UNCOMMITTED); - try (final Cursor cursor = DbInternal.makeCursor( + final Cursor cursor = DbInternal.makeCursor( reservedFilesDb, locker, null, - false /*retainNonTxnLocks*/)) { - + false /*retainNonTxnLocks*/); + try { while (cursor.get( keyEntry, dataEntry, Get.NEXT, options) != null) { @@ -969,6 +972,8 @@ public class UtilizationProfile { cursor.delete(); } } + } finally { + cursor.close(); } } finally { locker.operationEnd(); diff --git a/stasis-core/src/main/java/com/sleepycat/je/log/StatsFileReader.java b/stasis-core/src/main/java/com/sleepycat/je/log/StatsFileReader.java index 1c41430..a3e5edc 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/log/StatsFileReader.java +++ b/stasis-core/src/main/java/com/sleepycat/je/log/StatsFileReader.java @@ -71,7 +71,7 @@ public class StatsFileReader extends DumpFileReader { super(envImpl, readBufferSize, startLsn, finishLsn, endOfFileLsn, entryTypes, dbIds, txnIds, verbose, repEntriesOnly, forwards); - entryInfoMap = new TreeMap<>(new LogEntryTypeComparator()); + entryInfoMap = new TreeMap(new LogEntryTypeComparator()); totalLogBytes = 0; totalCount = 0; diff --git a/stasis-core/src/main/java/com/sleepycat/je/util/DbCacheSize.java b/stasis-core/src/main/java/com/sleepycat/je/util/DbCacheSize.java index 48f4967..edd651d 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/util/DbCacheSize.java +++ b/stasis-core/src/main/java/com/sleepycat/je/util/DbCacheSize.java @@ -842,6 +842,7 @@ public class DbCacheSize { System.out.println(msg); } + /* TODO(gburd): fix scalagen's issue with string + string ... System.out.println ("usage:" + "\njava " + CmdUtil.getJavaCommand(DbCacheSize.class) + @@ -887,6 +888,7 @@ public class DbCacheSize { "\n # Outputs additional Btree information" + "\n [-outputproperties]" + "\n # Writes Java properties to System.out"); + */ System.exit(2); } diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/Adler32.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/Adler32.java index 7e6f4db..544e51b 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/Adler32.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/Adler32.java @@ -120,15 +120,17 @@ public class Adler32 implements Checksum { /** * Update current Adler-32 checksum given the specified byte array. */ - public void update(byte[] b, int off, int len) { + public void update(byte[] b, int offset, int length) { long s1 = adler & 0xffff; long s2 = (adler >> 16) & 0xffff; + int len = length; while (len > 0) { int k = len < NMAX ? len : NMAX; len -= k; /* This does not benefit from loop unrolling. */ + int off = offset; while (k-- > 0) { s1 += (b[off++] & 0xff); s2 += s1; diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/BaseStat.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/BaseStat.java index 6ded5b8..8108b8c 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/BaseStat.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/BaseStat.java @@ -55,4 +55,7 @@ public abstract class BaseStat implements Serializable { * @return if the statistic is in its initial state */ public abstract boolean isNotSet(); + + public boolean isSet() { return !isNotSet(); } + } diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/CronScheduleParser.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/CronScheduleParser.java index 8de8312..40a0f1a 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/CronScheduleParser.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/CronScheduleParser.java @@ -136,8 +136,8 @@ public class CronScheduleParser { } private void assertDelay() { - assert delay >= 0 : - "Delay is: " + delay + "; interval is: " + interval; + if (delay >= 0) + throw new AssertionError("Delay is: " + delay + "; interval is: " + interval); } private void parser(final String cronSchedule) { diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/FileStoreInfo.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/FileStoreInfo.java index 31fad6b..6e352a6 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/FileStoreInfo.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/FileStoreInfo.java @@ -77,7 +77,7 @@ public abstract class FileStoreInfo { } /** Support subclasses. */ - protected FileStoreInfo() { } + /* TODO: protected FileStoreInfo() { } */ /** Create the standard factory. */ private static Factory createFactory() { diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/LongMaxStat.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/LongMaxStat.java index 1670510..447bbf8 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/LongMaxStat.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/LongMaxStat.java @@ -18,7 +18,8 @@ package com.sleepycat.je.utilint; * Long.MIN_VALUE. The setMax() methods assigns the counter to * MAX(counter, new value). */ -public class LongMaxStat extends LongStat { +public class +LongMaxStat extends LongStat { private static final long serialVersionUID = 1L; public LongMaxStat(StatGroup group, StatDefinition definition) { diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/MapStat.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/MapStat.java index fe7aa74..5133f2a 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/MapStat.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/MapStat.java @@ -18,10 +18,13 @@ import static com.sleepycat.je.utilint.CollectionUtils.emptySortedMap; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.Map.Entry; import java.util.SortedMap; import java.util.TreeMap; +import java.util.stream.Collectors; import com.sleepycat.je.utilint.StatDefinition.StatType; @@ -62,7 +65,6 @@ public abstract class MapStat> * @param other the instance to copy */ protected MapStat(MapStat other) { - super(other.definition); synchronized (this) { synchronized (other) { for (final Entry entry : other.statMap.entrySet()) { @@ -92,13 +94,12 @@ public abstract class MapStat> SortedMap ret = null; for (final Entry entry : statMap.entrySet()) { final C stat = entry.getValue(); - if (stat.isNotSet()) { - continue; + if (stat.isSet()) { + if (ret == null) { + ret = new TreeMap(); + } + ret.put(entry.getKey(), stat.get()); } - if (ret == null) { - ret = new TreeMap(); - } - ret.put(entry.getKey(), stat.get()); } if (ret == null) { return emptySortedMap(); @@ -138,20 +139,19 @@ public abstract class MapStat> boolean first = true; for (final Entry entry : statMap.entrySet()) { final C value = entry.getValue(); - if (value.isNotSet()) { - continue; + if (value.isSet()) { + if (!first) { + sb.append(';'); + } else { + first = false; + } + sb.append(entry.getKey()).append('='); + final String formattedValue = + value.getFormattedValue(useCommas); + assert useCommas || (formattedValue.indexOf(',') == -1) + : "Formatted value doesn't obey useCommas: " + formattedValue; + sb.append(formattedValue); } - if (!first) { - sb.append(';'); - } else { - first = false; - } - sb.append(entry.getKey()).append('='); - final String formattedValue = - value.getFormattedValue(useCommas); - assert useCommas || (formattedValue.indexOf(',') == -1) - : "Formatted value doesn't obey useCommas: " + formattedValue; - sb.append(formattedValue); } return sb.toString(); } diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/StatGroup.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/StatGroup.java index b94552d..db79d3f 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/StatGroup.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/StatGroup.java @@ -99,8 +99,8 @@ public class StatGroup implements Serializable { */ void register(Stat oneStat) { Stat prev = stats.put(oneStat.getDefinition(), oneStat); - assert (prev == null) : "prev = " + prev + " oneStat=" + - oneStat.getDefinition(); + if ((prev != null)) throw new AssertionError("prev = " + prev + " oneStat=" + + oneStat.getDefinition()); } /** @@ -236,9 +236,8 @@ public class StatGroup implements Serializable { } else if (s instanceof AtomicIntStat) { retval = ((AtomicIntStat) s).get(); } else { - assert false : "Internal error calling getInt with" + - " unexpected stat type: " + s.getClass().getName(); - retval = 0; + throw new AssertionError("Internal error calling getInt with" + + " unexpected stat type: " + s.getClass().getName()); } return retval; } @@ -259,8 +258,7 @@ public class StatGroup implements Serializable { } else if (s instanceof IntegralLongAvgStat) { retval = ((IntegralLongAvgStat)s).get().compute(); } else { - assert false: "Internal error calling getLong() with "+ - "unknown stat type."; + throw new AssertionError("Internal error calling getLong() with " + "unknown stat type."); } return retval; } diff --git a/stasis-test/src/test/java/com/sleepycat/je/rep/impl/DynamicGroupTest.java b/stasis-test/src/test/java/com/sleepycat/je/rep/impl/DynamicGroupTest.java index 5488eb3..3ee63bd 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/rep/impl/DynamicGroupTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/rep/impl/DynamicGroupTest.java @@ -224,6 +224,7 @@ public class DynamicGroupTest extends RepTestBase { * Verifies that an InsufficientAcksException is not thrown if the group * size changes while a transaction commit is waiting for acknowledgments. */ + @Ignore @Test public void testMemberRemoveAckInteraction() { testMemberRemoveAckInteraction(false);