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 34c1aef..7f35601 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); - if (prevInfo != null) throw new AssertionError(); + assert prevInfo == null; } /** @@ -486,28 +486,22 @@ public class FileProtector { return null; } - boolean keepTrying = false; - do { - keepTrying = false; - try { - for (final Map.Entry entry : - reservedFiles.tailMap(fromFile).entrySet()) { + fileLoop: + 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)) { - keepTrying = true; - throw new Exception(); - } - } - - reservedFiles.remove(file); - return new Pair<>(file, info.size); + for (final ProtectedFileSet pfs : protectedFileSets.values()) { + if (pfs.isProtected(file, info)) { + continue fileLoop; } - } catch (Exception e) { /* FALLTHRU */ } - } while (keepTrying); + } + + reservedFiles.remove(file); + return new Pair<>(file, info.size); + } return null; } @@ -583,21 +577,6 @@ public class FileProtector { isProtected = true; - /* - 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); - */ protectedSizeMap.compute( pfs.getName(), (k, v) -> ((v != null) ? v : 0) + info.size); @@ -655,30 +634,25 @@ public class FileProtector { long truncateFile = -1; long deleteBytes = 0; + fileLoop: + for (final Map.Entry entry : + reservedFiles.entrySet()) { - boolean keepTrying = false; - do { - keepTrying = false; - try { - for (final Map.Entry entry : - reservedFiles.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()) { - for (final ProtectedFileSet pfs : protectedFileSets.values()) { + if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) { + continue; + } - if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) { - continue; - } + if (pfs.isProtected(file, info)) { + break fileLoop; + } + } - if (pfs.isProtected(file, info)) { - keepTrying = true; - throw new Exception(); - } - } - - final VLSN lastVlsn = info.endVLSN; + final VLSN lastVlsn = info.endVLSN; if (!lastVlsn.isNull()) { if (lastVlsn.compareTo(preserveVLSN) > 0) { @@ -691,11 +665,9 @@ public class FileProtector { deleteBytes += info.size; if (deleteBytes >= bytesNeeded) { - break; - } - } - } catch(Exception e) { /* FALLTHRU */ } - } while (keepTrying); + break; + } + } return truncateVLSN.isNull() ? null : new Pair<>(truncateVLSN, truncateFile); 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 b14a24d..8de8312 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() { - if (delay < 0) - throw new AssertionError("Delay is: " + delay + "; interval is: " + interval); + assert delay >= 0 : + "Delay is: " + delay + "; interval is: " + interval; } private void parser(final String cronSchedule) { 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 7e57846..1c49310 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 @@ -78,7 +78,7 @@ public abstract class MapStat> * @param key the key */ public synchronized void removeStat(String key) { - if (key == null) throw new AssertionError(); + assert key != null; statMap.remove(key); } 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 db79d3f..b94552d 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); - if ((prev != null)) throw new AssertionError("prev = " + prev + " oneStat=" + - oneStat.getDefinition()); + assert (prev == null) : "prev = " + prev + " oneStat=" + + oneStat.getDefinition(); } /** @@ -236,8 +236,9 @@ public class StatGroup implements Serializable { } else if (s instanceof AtomicIntStat) { retval = ((AtomicIntStat) s).get(); } else { - throw new AssertionError("Internal error calling getInt with" + - " unexpected stat type: " + s.getClass().getName()); + assert false : "Internal error calling getInt with" + + " unexpected stat type: " + s.getClass().getName(); + retval = 0; } return retval; } @@ -258,7 +259,8 @@ public class StatGroup implements Serializable { } else if (s instanceof IntegralLongAvgStat) { retval = ((IntegralLongAvgStat)s).get().compute(); } else { - throw new AssertionError("Internal error calling getLong() with " + "unknown stat type."); + assert false: "Internal error calling getLong() with "+ + "unknown stat type."; } return retval; }