This commit is contained in:
Greg Burd 2019-07-29 11:28:26 -04:00
parent 3a1c374088
commit 85f2c790f4
4 changed files with 41 additions and 67 deletions

View file

@ -404,7 +404,7 @@ public class FileProtector {
final ReservedFileInfo info = new ReservedFileInfo(size, endVLSN); final ReservedFileInfo info = new ReservedFileInfo(size, endVLSN);
final ReservedFileInfo prevInfo = reservedFiles.put(file, info); 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; return null;
} }
boolean keepTrying = false; fileLoop:
do { for (final Map.Entry<Long, ReservedFileInfo> entry :
keepTrying = false; reservedFiles.tailMap(fromFile).entrySet()) {
try {
for (final Map.Entry<Long, ReservedFileInfo> entry :
reservedFiles.tailMap(fromFile).entrySet()) {
final Long file = entry.getKey(); 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.isProtected(file, info)) { if (pfs.isProtected(file, info)) {
keepTrying = true; continue fileLoop;
throw new Exception();
}
}
reservedFiles.remove(file);
return new Pair<>(file, info.size);
} }
} catch (Exception e) { /* FALLTHRU */ } }
} while (keepTrying);
reservedFiles.remove(file);
return new Pair<>(file, info.size);
}
return null; return null;
} }
@ -583,21 +577,6 @@ public class FileProtector {
isProtected = true; isProtected = true;
/*
BiFunction<String, Long, Long> fn = new BiFunction<String, Long, Long>() {
@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( protectedSizeMap.compute(
pfs.getName(), pfs.getName(),
(k, v) -> ((v != null) ? v : 0) + info.size); (k, v) -> ((v != null) ? v : 0) + info.size);
@ -655,30 +634,25 @@ public class FileProtector {
long truncateFile = -1; long truncateFile = -1;
long deleteBytes = 0; long deleteBytes = 0;
fileLoop:
for (final Map.Entry<Long, ReservedFileInfo> entry :
reservedFiles.entrySet()) {
boolean keepTrying = false; final Long file = entry.getKey();
do { final ReservedFileInfo info = entry.getValue();
keepTrying = false;
try {
for (final Map.Entry<Long, ReservedFileInfo> entry :
reservedFiles.entrySet()) {
final Long file = entry.getKey(); for (final ProtectedFileSet pfs : protectedFileSets.values()) {
final ReservedFileInfo info = entry.getValue();
for (final ProtectedFileSet pfs : protectedFileSets.values()) { if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) {
continue;
}
if (pfs == vlsnIndexRange || !pfs.protectVlsnIndex) { if (pfs.isProtected(file, info)) {
continue; break fileLoop;
} }
}
if (pfs.isProtected(file, info)) { final VLSN lastVlsn = info.endVLSN;
keepTrying = true;
throw new Exception();
}
}
final VLSN lastVlsn = info.endVLSN;
if (!lastVlsn.isNull()) { if (!lastVlsn.isNull()) {
if (lastVlsn.compareTo(preserveVLSN) > 0) { if (lastVlsn.compareTo(preserveVLSN) > 0) {
@ -691,11 +665,9 @@ public class FileProtector {
deleteBytes += info.size; deleteBytes += info.size;
if (deleteBytes >= bytesNeeded) { if (deleteBytes >= bytesNeeded) {
break; break;
} }
} }
} catch(Exception e) { /* FALLTHRU */ }
} while (keepTrying);
return truncateVLSN.isNull() ? null : return truncateVLSN.isNull() ? null :
new Pair<>(truncateVLSN, truncateFile); new Pair<>(truncateVLSN, truncateFile);

View file

@ -136,8 +136,8 @@ public class CronScheduleParser {
} }
private void assertDelay() { private void assertDelay() {
if (delay < 0) assert delay >= 0 :
throw new AssertionError("Delay is: " + delay + "; interval is: " + interval); "Delay is: " + delay + "; interval is: " + interval;
} }
private void parser(final String cronSchedule) { private void parser(final String cronSchedule) {

View file

@ -78,7 +78,7 @@ public abstract class MapStat<T, C extends MapStatComponent<T, C>>
* @param key the key * @param key the key
*/ */
public synchronized void removeStat(String key) { public synchronized void removeStat(String key) {
if (key == null) throw new AssertionError(); assert key != null;
statMap.remove(key); statMap.remove(key);
} }

View file

@ -99,8 +99,8 @@ public class StatGroup implements Serializable {
*/ */
void register(Stat<?> oneStat) { void register(Stat<?> oneStat) {
Stat<?> prev = stats.put(oneStat.getDefinition(), oneStat); Stat<?> prev = stats.put(oneStat.getDefinition(), oneStat);
if ((prev != null)) throw new AssertionError("prev = " + prev + " oneStat=" + assert (prev == null) : "prev = " + prev + " oneStat=" +
oneStat.getDefinition()); oneStat.getDefinition();
} }
/** /**
@ -236,8 +236,9 @@ public class StatGroup implements Serializable {
} else if (s instanceof AtomicIntStat) { } else if (s instanceof AtomicIntStat) {
retval = ((AtomicIntStat) s).get(); retval = ((AtomicIntStat) s).get();
} else { } else {
throw new AssertionError("Internal error calling getInt with" + assert false : "Internal error calling getInt with" +
" unexpected stat type: " + s.getClass().getName()); " unexpected stat type: " + s.getClass().getName();
retval = 0;
} }
return retval; return retval;
} }
@ -258,7 +259,8 @@ public class StatGroup implements Serializable {
} else if (s instanceof IntegralLongAvgStat) { } else if (s instanceof IntegralLongAvgStat) {
retval = ((IntegralLongAvgStat)s).get().compute(); retval = ((IntegralLongAvgStat)s).get().compute();
} else { } else {
throw new AssertionError("Internal error calling getLong() with " + "unknown stat type."); assert false: "Internal error calling getLong() with "+
"unknown stat type.";
} }
return retval; return retval;
} }