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 fa331c6..34c1aef 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 @@ -404,7 +404,7 @@ public class FileProtector { final ReservedFileInfo info = new ReservedFileInfo(size, endVLSN); final ReservedFileInfo prevInfo = reservedFiles.put(file, info); - assert prevInfo == null; + if (prevInfo != null) throw new AssertionError(); } /** @@ -486,22 +486,28 @@ public class FileProtector { return null; } - fileLoop: - for (final Map.Entry entry : - reservedFiles.tailMap(fromFile).entrySet()) { + boolean keepTrying = false; + do { + keepTrying = false; + try { + for (final Map.Entry entry : + reservedFiles.tailMap(fromFile).entrySet()) { - final Long file = entry.getKey(); - final ReservedFileInfo info = entry.getValue(); + final Long file = entry.getKey(); + final ReservedFileInfo info = entry.getValue(); - for (final ProtectedFileSet pfs : protectedFileSets.values()) { - if (pfs.isProtected(file, info)) { - continue fileLoop; + for (final ProtectedFileSet pfs : protectedFileSets.values()) { + if (pfs.isProtected(file, info)) { + keepTrying = true; + throw new Exception(); + } + } + + reservedFiles.remove(file); + return new Pair<>(file, info.size); } - } - - reservedFiles.remove(file); - return new Pair<>(file, info.size); - } + } catch (Exception e) { /* FALLTHRU */ } + } while (keepTrying); return null; } @@ -577,6 +583,7 @@ public class FileProtector { isProtected = true; + /* BiFunction fn = new BiFunction() { @Override public Long apply(String k, Long v) { @@ -590,6 +597,10 @@ public class FileProtector { } }; protectedSizeMap.compute(pfs.getName(), fn); // (k, v) -> ((v != null) ? v : 0) + info.size); + */ + protectedSizeMap.compute( + pfs.getName(), + (k, v) -> ((v != null) ? v : 0) + info.size); } if (isProtected) { @@ -644,25 +655,30 @@ public class FileProtector { long truncateFile = -1; long deleteBytes = 0; - fileLoop: - for (final Map.Entry entry : - reservedFiles.entrySet()) { - final Long file = entry.getKey(); - final ReservedFileInfo info = entry.getValue(); + boolean keepTrying = false; + do { + keepTrying = false; + try { + for (final Map.Entry entry : + reservedFiles.entrySet()) { - for (final ProtectedFileSet pfs : protectedFileSets.values()) { + final Long file = entry.getKey(); + final ReservedFileInfo info = entry.getValue(); - if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) { - continue; - } + for (final ProtectedFileSet pfs : protectedFileSets.values()) { - if (pfs.isProtected(file, info)) { - break fileLoop; - } - } + if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) { + continue; + } - final VLSN lastVlsn = info.endVLSN; + if (pfs.isProtected(file, info)) { + keepTrying = true; + throw new Exception(); + } + } + + final VLSN lastVlsn = info.endVLSN; if (!lastVlsn.isNull()) { if (lastVlsn.compareTo(preserveVLSN) > 0) { @@ -675,9 +691,11 @@ public class FileProtector { deleteBytes += info.size; if (deleteBytes >= bytesNeeded) { - break; - } - } + break; + } + } + } catch(Exception e) { /* FALLTHRU */ } + } while (keepTrying); return truncateVLSN.isNull() ? null : new Pair<>(truncateVLSN, truncateFile); 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 2409a52..319c1c5 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 @@ -350,12 +350,10 @@ public class UtilizationProfile { BasicLocker.createBasicLocker(env, false /*noWait*/); try { - Cursor cursor = DbInternal.makeCursor( - reservedFilesDb, locker, null, false /*retainNonTxnLocks*/); - try { + try (Cursor cursor = DbInternal.makeCursor( + reservedFilesDb, locker, null, false /*retainNonTxnLocks*/)) { + cursor.put(keyEntry, dataEntry, Put.OVERWRITE, null); - } finally { - cursor.close(); } } finally { locker.operationEnd(); @@ -376,15 +374,14 @@ public class UtilizationProfile { final Locker locker = BasicLocker.createBasicLocker(env, false /*noWait*/); try { - Cursor cursor = DbInternal.makeCursor(reservedFilesDb, locker, null); - try { + try (Cursor cursor = + DbInternal.makeCursor(reservedFilesDb, locker, null)) { + if (cursor.get( keyEntry, null, Get.SEARCH, readOptions) != null) { cursor.delete(null); } - } finally { - cursor.close(); } } finally { locker.operationEnd(); @@ -933,10 +930,10 @@ public class UtilizationProfile { final ReadOptions options = new ReadOptions().setLockMode(LockMode.READ_UNCOMMITTED); - final Cursor cursor = DbInternal.makeCursor( + try (final Cursor cursor = DbInternal.makeCursor( reservedFilesDb, locker, null, - false /*retainNonTxnLocks*/); - try { + false /*retainNonTxnLocks*/)) { + while (cursor.get( keyEntry, dataEntry, Get.NEXT, options) != null) { @@ -972,8 +969,6 @@ public class UtilizationProfile { cursor.delete(); } } - } finally { - cursor.close(); } } finally { locker.operationEnd(); diff --git a/stasis-core/src/main/java/com/sleepycat/je/latch/LatchImpl.java b/stasis-core/src/main/java/com/sleepycat/je/latch/LatchImpl.java index f8e0c37..9ae2f62 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/latch/LatchImpl.java +++ b/stasis-core/src/main/java/com/sleepycat/je/latch/LatchImpl.java @@ -56,7 +56,7 @@ public class LatchImpl extends ReentrantLock implements SharedLatch { "Latch already held: " + debugString()); } - if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { + if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) { try { if (!tryLock( context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { diff --git a/stasis-core/src/main/java/com/sleepycat/je/latch/LatchSupport.java b/stasis-core/src/main/java/com/sleepycat/je/latch/LatchSupport.java index 8493e01..f41c997 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/latch/LatchSupport.java +++ b/stasis-core/src/main/java/com/sleepycat/je/latch/LatchSupport.java @@ -45,11 +45,11 @@ public class LatchSupport { /* * Indicates whether to use tryLock() with a timeout, instead of a simple - * lock() that waits forever and is uninterruptible. We would like to - * always use timeouts and interruptible latches, but these are new + * lock() that waits forever and is uninterruptable. We would like to + * always use timeouts and interruptable latches, but these are new * features and this boolean allows reverting to the old behavior. */ - static final boolean INTERRUPTIBLE_WITH_TIMEOUT = true; + static final boolean INTERRUPTABLE_WITH_TIMEOUT = true; /* Used for Btree latches. */ public final static LatchTable btreeLatchTable = diff --git a/stasis-core/src/main/java/com/sleepycat/je/latch/LatchWithStatsImpl.java b/stasis-core/src/main/java/com/sleepycat/je/latch/LatchWithStatsImpl.java index f90177c..7cc46d5 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/latch/LatchWithStatsImpl.java +++ b/stasis-core/src/main/java/com/sleepycat/je/latch/LatchWithStatsImpl.java @@ -80,7 +80,7 @@ public class LatchWithStatsImpl extends ReentrantLock implements Latch { nAcquiresNoWaiters.increment(); } - if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { + if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) { try { if (!tryLock( context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { diff --git a/stasis-core/src/main/java/com/sleepycat/je/latch/SharedLatchImpl.java b/stasis-core/src/main/java/com/sleepycat/je/latch/SharedLatchImpl.java index 792dad6..460ad9b 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/latch/SharedLatchImpl.java +++ b/stasis-core/src/main/java/com/sleepycat/je/latch/SharedLatchImpl.java @@ -60,7 +60,7 @@ public class SharedLatchImpl extends ReentrantReadWriteLock if (!writeLock().tryLock()) { return false; } - } else if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { + } else if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) { try { if (!writeLock().tryLock( context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { @@ -98,7 +98,7 @@ public class SharedLatchImpl extends ReentrantReadWriteLock "Latch already held non-exclusively: " + debugString()); } - if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { + if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) { try { if (!readLock().tryLock( context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { diff --git a/stasis-core/src/main/java/com/sleepycat/je/log/RestoreMarker.java b/stasis-core/src/main/java/com/sleepycat/je/log/RestoreMarker.java index 044581e..2393a57 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/log/RestoreMarker.java +++ b/stasis-core/src/main/java/com/sleepycat/je/log/RestoreMarker.java @@ -139,16 +139,13 @@ public class RestoreMarker { SingleItemEntry.create(LogEntryType.LOG_RESTORE_REQUIRED, rr); ByteBuffer buf2 = logManager.putIntoBuffer(marker, 0); - FileOutputStream stream = new FileOutputStream(lastFile); - FileChannel channel = stream.getChannel(); - try { + try (FileOutputStream stream = new FileOutputStream(lastFile); + FileChannel channel = stream.getChannel()) { channel.write(buf1); channel.write(buf2); } catch (IOException e) { /* the stream and channel will be closed */ throw e; - } finally { - channel.close(); } } catch (IOException ioe) { throw new FileCreationException( diff --git a/stasis-core/src/main/java/com/sleepycat/je/recovery/Checkpointer.java b/stasis-core/src/main/java/com/sleepycat/je/recovery/Checkpointer.java index f0a2f05..b9862e3 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/recovery/Checkpointer.java +++ b/stasis-core/src/main/java/com/sleepycat/je/recovery/Checkpointer.java @@ -474,7 +474,7 @@ public class Checkpointer extends DaemonThread implements EnvConfigObserver { /** * Figure out the wakeup period. Supplied through this static method * because we need to pass wakeup period to the superclass and need to do - * the calcuation outside this constructor. + * the calcualtion outside this constructor. * * @throws IllegalArgumentException via Environment ctor and * setMutableConfig. 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 edd651d..48f4967 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,7 +842,6 @@ 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) + @@ -888,7 +887,6 @@ 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/CmdUtil.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/CmdUtil.java index 79d7e43..b8f40e1 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/CmdUtil.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/CmdUtil.java @@ -80,7 +80,7 @@ public class CmdUtil { int b = element & 0xff; if (formatUsingPrintable) { if (isPrint(b)) { - if (b == 0134) { /* backslash */ + if (b == 0x308) { /* backslash 0134 */ sb.append('\\'); } sb.append(printableChars.charAt(b - 33)); @@ -103,7 +103,7 @@ public class CmdUtil { } private static boolean isPrint(int b) { - return (b < 0177) && (040 < b); + return (b < 0x375 /* 0177 */) && (0x64 /* 040 */ < b); } /** 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 40a0f1a..b14a24d 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,7 +136,7 @@ public class CronScheduleParser { } private void assertDelay() { - if (delay >= 0) + if (delay < 0) throw new AssertionError("Delay is: " + delay + "; interval is: " + interval); } 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 5133f2a..7e57846 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 @@ -41,12 +41,9 @@ public abstract class MapStat> /** * Maps keys to individual statistics. Synchronize on the MapStat instance - * when accessing this field. + * when accessing this field. Use a sorted map so that the output is sorted. */ - protected final Map statMap = - - /* Use a sorted map so that the output is sorted */ - new TreeMap(); + protected final Map statMap = new TreeMap(); /** * Creates an instance of this class. @@ -65,6 +62,7 @@ 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()) { @@ -80,7 +78,7 @@ public abstract class MapStat> * @param key the key */ public synchronized void removeStat(String key) { - assert key != null; + if (key == null) throw new AssertionError(); statMap.remove(key); } diff --git a/stasis-rep/src/main/java/com/sleepycat/je/rep/ReplicationConfig.java b/stasis-rep/src/main/java/com/sleepycat/je/rep/ReplicationConfig.java index 459c188..1ae8180 100644 --- a/stasis-rep/src/main/java/com/sleepycat/je/rep/ReplicationConfig.java +++ b/stasis-rep/src/main/java/com/sleepycat/je/rep/ReplicationConfig.java @@ -1718,7 +1718,7 @@ public class ReplicationConfig extends ReplicationMutableConfig /* * If the type of the config object did not change, there may be * non-property fields that should be retained from the original, - * so use the orignal object and just change the properties. + * so use the original object and just change the properties. */ if (newRepNetConfig.getClass() == repNetConfig.getClass()) { rnConfig.applyRepNetProperties(combProps); diff --git a/stasis-test/src/test/java/com/sleepycat/je/ClassLoaderTest.java b/stasis-test/src/test/java/com/sleepycat/je/ClassLoaderTest.java index 1530d95..4881838 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/ClassLoaderTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/ClassLoaderTest.java @@ -70,7 +70,15 @@ public class ClassLoaderTest extends DualTestCase { super.setUp(); - final File classDir = new File(System.getProperty("testclassloader")); + String classLoaderPath = System.getProperty("testclassloader"); + if (classLoaderPath == null) { + classLoaderPath = SharedTestUtils.getTestDir().getParent() + File.separator + "classloader"; + } + File classLoaderFile = new File(classLoaderPath); + if (!(classLoaderFile.exists() && classLoaderFile.isDirectory())) { + classLoaderFile.mkdirs(); + } + final File classDir = new File(classLoaderPath); final ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader(); myLoader = new SimpleClassLoader(parentClassLoader, classDir); diff --git a/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java b/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java index 0068fdb..1b6894b 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java @@ -137,10 +137,15 @@ public class UpgradeTest extends TestBase { replicaEnv2 = repEnvInfo[2].getEnv(); /* Load app classes with custom class loader. */ - final File evolveParentDir = - new File(System.getProperty("testevolvedir")); - final ClassLoader parentClassLoader = - Thread.currentThread().getContextClassLoader(); + String evolvePath = System.getProperty("testevolvedir"); + if (evolvePath == null) { + evolvePath = SharedTestUtils.getTestDir().getParent() + File.separator + "evolve"; + } + File evolveParentDir = new File(evolvePath); + if (!(evolveParentDir.exists() && evolveParentDir.isDirectory())) { + evolveParentDir.mkdirs(); + } + final ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader(); for (int i = 0; i < N_APP_VERSIONS; i += 1) { final ClassLoader myLoader = new SimpleClassLoader (parentClassLoader, diff --git a/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java b/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java index de892e1..1332948 100644 --- a/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java +++ b/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java @@ -37,9 +37,9 @@ public class SharedTestUtils { public static String DEST_DIR = "testdestdir"; public static String TEST_ENV_DIR = "testenvdirroot"; public static String FAILURE_DIR = "failurecopydir"; - public static String DEFAULT_DEST_DIR = "build/test/classes"; - public static String DEFAULT_TEST_DIR_ROOT = "build/test/envdata"; - public static String DEFAULT_FAIL_DIR = "build/test/failures"; + public static String DEFAULT_DEST_DIR = "target/scala-2.12/test-classes"; + public static String DEFAULT_TEST_DIR_ROOT = "target/envdata"; + public static String DEFAULT_FAIL_DIR = "target/failures"; public static String NO_SYNC = "txnnosync"; public static String LONG_TEST = "longtest"; public static String COPY_LIMIT = "copylimit"; @@ -63,7 +63,7 @@ public class SharedTestUtils { } /** - * If not define system property "testenvdirroot", use build/test/envdata + * If not define system property "testenvdirroot", use stasis-test/target/envdata * as test environment root directory. */ public static File getTestDir() {