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 info = new ReservedFileInfo(size, endVLSN);
final ReservedFileInfo prevInfo = reservedFiles.put(file, info); final ReservedFileInfo prevInfo = reservedFiles.put(file, info);
assert prevInfo == null; if (prevInfo != null) throw new AssertionError();
} }
/** /**
@ -486,7 +486,10 @@ public class FileProtector {
return null; return null;
} }
fileLoop: boolean keepTrying = false;
do {
keepTrying = false;
try {
for (final Map.Entry<Long, ReservedFileInfo> entry : for (final Map.Entry<Long, ReservedFileInfo> entry :
reservedFiles.tailMap(fromFile).entrySet()) { reservedFiles.tailMap(fromFile).entrySet()) {
@ -495,13 +498,16 @@ public class FileProtector {
for (final ProtectedFileSet pfs : protectedFileSets.values()) { for (final ProtectedFileSet pfs : protectedFileSets.values()) {
if (pfs.isProtected(file, info)) { if (pfs.isProtected(file, info)) {
continue fileLoop; keepTrying = true;
throw new Exception();
} }
} }
reservedFiles.remove(file); reservedFiles.remove(file);
return new Pair<>(file, info.size); return new Pair<>(file, info.size);
} }
} catch (Exception e) { /* FALLTHRU */ }
} while (keepTrying);
return null; return null;
} }
@ -577,6 +583,7 @@ public class FileProtector {
isProtected = true; isProtected = true;
/*
BiFunction<String, Long, Long> fn = new BiFunction<String, Long, Long>() { BiFunction<String, Long, Long> fn = new BiFunction<String, Long, Long>() {
@Override @Override
public Long apply(String k, Long v) { 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(), fn); // (k, v) -> ((v != null) ? v : 0) + info.size);
*/
protectedSizeMap.compute(
pfs.getName(),
(k, v) -> ((v != null) ? v : 0) + info.size);
} }
if (isProtected) { if (isProtected) {
@ -644,7 +655,11 @@ public class FileProtector {
long truncateFile = -1; long truncateFile = -1;
long deleteBytes = 0; long deleteBytes = 0;
fileLoop:
boolean keepTrying = false;
do {
keepTrying = false;
try {
for (final Map.Entry<Long, ReservedFileInfo> entry : for (final Map.Entry<Long, ReservedFileInfo> entry :
reservedFiles.entrySet()) { reservedFiles.entrySet()) {
@ -658,7 +673,8 @@ public class FileProtector {
} }
if (pfs.isProtected(file, info)) { if (pfs.isProtected(file, info)) {
break fileLoop; keepTrying = true;
throw new Exception();
} }
} }
@ -678,6 +694,8 @@ public class FileProtector {
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

@ -350,12 +350,10 @@ public class UtilizationProfile {
BasicLocker.createBasicLocker(env, false /*noWait*/); BasicLocker.createBasicLocker(env, false /*noWait*/);
try { try {
Cursor cursor = DbInternal.makeCursor( try (Cursor cursor = DbInternal.makeCursor(
reservedFilesDb, locker, null, false /*retainNonTxnLocks*/); reservedFilesDb, locker, null, false /*retainNonTxnLocks*/)) {
try {
cursor.put(keyEntry, dataEntry, Put.OVERWRITE, null); cursor.put(keyEntry, dataEntry, Put.OVERWRITE, null);
} finally {
cursor.close();
} }
} finally { } finally {
locker.operationEnd(); locker.operationEnd();
@ -376,15 +374,14 @@ public class UtilizationProfile {
final Locker locker = final Locker locker =
BasicLocker.createBasicLocker(env, false /*noWait*/); BasicLocker.createBasicLocker(env, false /*noWait*/);
try { try {
Cursor cursor = DbInternal.makeCursor(reservedFilesDb, locker, null); try (Cursor cursor =
try { DbInternal.makeCursor(reservedFilesDb, locker, null)) {
if (cursor.get( if (cursor.get(
keyEntry, null, Get.SEARCH, readOptions) != null) { keyEntry, null, Get.SEARCH, readOptions) != null) {
cursor.delete(null); cursor.delete(null);
} }
} finally {
cursor.close();
} }
} finally { } finally {
locker.operationEnd(); locker.operationEnd();
@ -933,10 +930,10 @@ public class UtilizationProfile {
final ReadOptions options = final ReadOptions options =
new ReadOptions().setLockMode(LockMode.READ_UNCOMMITTED); new ReadOptions().setLockMode(LockMode.READ_UNCOMMITTED);
final Cursor cursor = DbInternal.makeCursor( try (final Cursor cursor = DbInternal.makeCursor(
reservedFilesDb, locker, null, reservedFilesDb, locker, null,
false /*retainNonTxnLocks*/); false /*retainNonTxnLocks*/)) {
try {
while (cursor.get( while (cursor.get(
keyEntry, dataEntry, Get.NEXT, options) != null) { keyEntry, dataEntry, Get.NEXT, options) != null) {
@ -972,8 +969,6 @@ public class UtilizationProfile {
cursor.delete(); cursor.delete();
} }
} }
} finally {
cursor.close();
} }
} finally { } finally {
locker.operationEnd(); locker.operationEnd();

View file

@ -56,7 +56,7 @@ public class LatchImpl extends ReentrantLock implements SharedLatch {
"Latch already held: " + debugString()); "Latch already held: " + debugString());
} }
if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) {
try { try {
if (!tryLock( if (!tryLock(
context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { 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 * Indicates whether to use tryLock() with a timeout, instead of a simple
* lock() that waits forever and is uninterruptible. We would like to * lock() that waits forever and is uninterruptable. We would like to
* always use timeouts and interruptible latches, but these are new * always use timeouts and interruptable latches, but these are new
* features and this boolean allows reverting to the old behavior. * 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. */ /* Used for Btree latches. */
public final static LatchTable btreeLatchTable = public final static LatchTable btreeLatchTable =

View file

@ -80,7 +80,7 @@ public class LatchWithStatsImpl extends ReentrantLock implements Latch {
nAcquiresNoWaiters.increment(); nAcquiresNoWaiters.increment();
} }
if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) {
try { try {
if (!tryLock( if (!tryLock(
context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) {

View file

@ -60,7 +60,7 @@ public class SharedLatchImpl extends ReentrantReadWriteLock
if (!writeLock().tryLock()) { if (!writeLock().tryLock()) {
return false; return false;
} }
} else if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { } else if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) {
try { try {
if (!writeLock().tryLock( if (!writeLock().tryLock(
context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) {
@ -98,7 +98,7 @@ public class SharedLatchImpl extends ReentrantReadWriteLock
"Latch already held non-exclusively: " + debugString()); "Latch already held non-exclusively: " + debugString());
} }
if (LatchSupport.INTERRUPTIBLE_WITH_TIMEOUT) { if (LatchSupport.INTERRUPTABLE_WITH_TIMEOUT) {
try { try {
if (!readLock().tryLock( if (!readLock().tryLock(
context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) { context.getLatchTimeoutMs(), TimeUnit.MILLISECONDS)) {

View file

@ -139,16 +139,13 @@ public class RestoreMarker {
SingleItemEntry.create(LogEntryType.LOG_RESTORE_REQUIRED, rr); SingleItemEntry.create(LogEntryType.LOG_RESTORE_REQUIRED, rr);
ByteBuffer buf2 = logManager.putIntoBuffer(marker, 0); ByteBuffer buf2 = logManager.putIntoBuffer(marker, 0);
FileOutputStream stream = new FileOutputStream(lastFile); try (FileOutputStream stream = new FileOutputStream(lastFile);
FileChannel channel = stream.getChannel(); FileChannel channel = stream.getChannel()) {
try {
channel.write(buf1); channel.write(buf1);
channel.write(buf2); channel.write(buf2);
} catch (IOException e) { } catch (IOException e) {
/* the stream and channel will be closed */ /* the stream and channel will be closed */
throw e; throw e;
} finally {
channel.close();
} }
} catch (IOException ioe) { } catch (IOException ioe) {
throw new FileCreationException( 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 * Figure out the wakeup period. Supplied through this static method
* because we need to pass wakeup period to the superclass and need to do * 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 * @throws IllegalArgumentException via Environment ctor and
* setMutableConfig. * setMutableConfig.

View file

@ -842,7 +842,6 @@ public class DbCacheSize {
System.out.println(msg); System.out.println(msg);
} }
/* TODO(gburd): fix scalagen's issue with string + string ...
System.out.println System.out.println
("usage:" + ("usage:" +
"\njava " + CmdUtil.getJavaCommand(DbCacheSize.class) + "\njava " + CmdUtil.getJavaCommand(DbCacheSize.class) +
@ -888,7 +887,6 @@ public class DbCacheSize {
"\n # Outputs additional Btree information" + "\n # Outputs additional Btree information" +
"\n [-outputproperties]" + "\n [-outputproperties]" +
"\n # Writes Java properties to System.out"); "\n # Writes Java properties to System.out");
*/
System.exit(2); System.exit(2);
} }

View file

@ -80,7 +80,7 @@ public class CmdUtil {
int b = element & 0xff; int b = element & 0xff;
if (formatUsingPrintable) { if (formatUsingPrintable) {
if (isPrint(b)) { if (isPrint(b)) {
if (b == 0134) { /* backslash */ if (b == 0x308) { /* backslash 0134 */
sb.append('\\'); sb.append('\\');
} }
sb.append(printableChars.charAt(b - 33)); sb.append(printableChars.charAt(b - 33));
@ -103,7 +103,7 @@ public class CmdUtil {
} }
private static boolean isPrint(int b) { 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() { private void assertDelay() {
if (delay >= 0) if (delay < 0)
throw new AssertionError("Delay is: " + delay + "; interval is: " + interval); 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 * 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 = protected final Map<String, C> statMap = new TreeMap<String, C>();
/* Use a sorted map so that the output is sorted */
new TreeMap<String, C>();
/** /**
* Creates an instance of this class. * 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 * @param other the instance to copy
*/ */
protected MapStat(MapStat<T, C> other) { protected MapStat(MapStat<T, C> other) {
super(other.definition);
synchronized (this) { synchronized (this) {
synchronized (other) { synchronized (other) {
for (final Entry<String, C> entry : other.statMap.entrySet()) { 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 * @param key the key
*/ */
public synchronized void removeStat(String key) { public synchronized void removeStat(String key) {
assert key != null; if (key == null) throw new AssertionError();
statMap.remove(key); 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 * If the type of the config object did not change, there may be
* non-property fields that should be retained from the original, * 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()) { if (newRepNetConfig.getClass() == repNetConfig.getClass()) {
rnConfig.applyRepNetProperties(combProps); rnConfig.applyRepNetProperties(combProps);

View file

@ -70,7 +70,15 @@ public class ClassLoaderTest extends DualTestCase {
super.setUp(); 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 = final ClassLoader parentClassLoader =
Thread.currentThread().getContextClassLoader(); Thread.currentThread().getContextClassLoader();
myLoader = new SimpleClassLoader(parentClassLoader, classDir); myLoader = new SimpleClassLoader(parentClassLoader, classDir);

View file

@ -137,10 +137,15 @@ public class UpgradeTest extends TestBase {
replicaEnv2 = repEnvInfo[2].getEnv(); replicaEnv2 = repEnvInfo[2].getEnv();
/* Load app classes with custom class loader. */ /* Load app classes with custom class loader. */
final File evolveParentDir = String evolvePath = System.getProperty("testevolvedir");
new File(System.getProperty("testevolvedir")); if (evolvePath == null) {
final ClassLoader parentClassLoader = evolvePath = SharedTestUtils.getTestDir().getParent() + File.separator + "evolve";
Thread.currentThread().getContextClassLoader(); }
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) { for (int i = 0; i < N_APP_VERSIONS; i += 1) {
final ClassLoader myLoader = new SimpleClassLoader final ClassLoader myLoader = new SimpleClassLoader
(parentClassLoader, (parentClassLoader,

View file

@ -37,9 +37,9 @@ public class SharedTestUtils {
public static String DEST_DIR = "testdestdir"; public static String DEST_DIR = "testdestdir";
public static String TEST_ENV_DIR = "testenvdirroot"; public static String TEST_ENV_DIR = "testenvdirroot";
public static String FAILURE_DIR = "failurecopydir"; public static String FAILURE_DIR = "failurecopydir";
public static String DEFAULT_DEST_DIR = "build/test/classes"; public static String DEFAULT_DEST_DIR = "target/scala-2.12/test-classes";
public static String DEFAULT_TEST_DIR_ROOT = "build/test/envdata"; public static String DEFAULT_TEST_DIR_ROOT = "target/envdata";
public static String DEFAULT_FAIL_DIR = "build/test/failures"; public static String DEFAULT_FAIL_DIR = "target/failures";
public static String NO_SYNC = "txnnosync"; public static String NO_SYNC = "txnnosync";
public static String LONG_TEST = "longtest"; public static String LONG_TEST = "longtest";
public static String COPY_LIMIT = "copylimit"; 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. * as test environment root directory.
*/ */
public static File getTestDir() { public static File getTestDir() {