This commit is contained in:
Greg Burd 2019-07-29 10:29:37 -04:00
parent 074aeb7b1d
commit 3a1c374088
16 changed files with 98 additions and 79 deletions

View file

@ -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<Long, ReservedFileInfo> entry :
reservedFiles.tailMap(fromFile).entrySet()) {
boolean keepTrying = false;
do {
keepTrying = false;
try {
for (final Map.Entry<Long, ReservedFileInfo> 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<String, Long, Long> fn = new BiFunction<String, Long, Long>() {
@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<Long, ReservedFileInfo> entry :
reservedFiles.entrySet()) {
final Long file = entry.getKey();
final ReservedFileInfo info = entry.getValue();
boolean keepTrying = false;
do {
keepTrying = false;
try {
for (final Map.Entry<Long, ReservedFileInfo> 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);

View file

@ -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();

View file

@ -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)) {

View file

@ -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 =

View file

@ -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)) {

View file

@ -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)) {

View file

@ -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(

View file

@ -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.

View file

@ -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);
}

View file

@ -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);
}
/**

View file

@ -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);
}

View file

@ -41,12 +41,9 @@ public abstract class MapStat<T, C extends MapStatComponent<T, C>>
/**
* 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<String, C> statMap =
/* Use a sorted map so that the output is sorted */
new TreeMap<String, C>();
protected final Map<String, C> statMap = new TreeMap<String, C>();
/**
* Creates an instance of this class.
@ -65,6 +62,7 @@ public abstract class MapStat<T, C extends MapStatComponent<T, C>>
* @param other the instance to copy
*/
protected MapStat(MapStat<T, C> other) {
super(other.definition);
synchronized (this) {
synchronized (other) {
for (final Entry<String, C> entry : other.statMap.entrySet()) {
@ -80,7 +78,7 @@ public abstract class MapStat<T, C extends MapStatComponent<T, C>>
* @param key the key
*/
public synchronized void removeStat(String key) {
assert key != null;
if (key == null) throw new AssertionError();
statMap.remove(key);
}

View file

@ -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);

View file

@ -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);

View file

@ -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,

View file

@ -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() {