提交 caa572bf authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Replace remaining usages of SysProperties.CHECK2 with check for assertions

上级 20be82db
......@@ -91,6 +91,15 @@ public class Database implements DataHandler {
private static int initialPowerOffCount;
private static final boolean ASSERT;
static {
boolean a = false;
// Intentional side-effect
assert a = true;
ASSERT = a;
}
private static final ThreadLocal<Session> META_LOCK_DEBUGGING = new ThreadLocal<>();
private static final ThreadLocal<Database> META_LOCK_DEBUGGING_DB = new ThreadLocal<>();
private static final ThreadLocal<Throwable> META_LOCK_DEBUGGING_STACK = new ThreadLocal<>();
......@@ -919,7 +928,7 @@ public class Database implements DataHandler {
if (meta == null) {
return true;
}
if (SysProperties.CHECK2) {
if (ASSERT) {
// If we are locking two different databases in the same stack, just ignore it.
// This only happens in TestLinkedTable where we connect to another h2 DB in the
// same process.
......@@ -961,7 +970,7 @@ public class Database implements DataHandler {
* @param session the session
*/
public void unlockMetaDebug(Session session) {
if (SysProperties.CHECK2) {
if (ASSERT) {
if (META_LOCK_DEBUGGING.get() == session) {
META_LOCK_DEBUGGING.set(null);
META_LOCK_DEBUGGING_DB.set(null);
......@@ -1405,7 +1414,7 @@ public class Database implements DataHandler {
unlockMeta(pageStore.getPageStoreSession());
}
} catch (DbException e) {
if (SysProperties.CHECK2) {
if (ASSERT) {
int code = e.getErrorCode();
if (code != ErrorCode.DATABASE_IS_CLOSED &&
code != ErrorCode.LOCK_TIMEOUT_1 &&
......@@ -1415,7 +1424,7 @@ public class Database implements DataHandler {
}
trace.error(e, "close");
} catch (Throwable t) {
if (SysProperties.CHECK2) {
if (ASSERT) {
t.printStackTrace();
}
trace.error(t, "close");
......
......@@ -36,6 +36,15 @@ public class FileStore {
private static final String HEADER =
"-- H2 0.5/B -- ".substring(0, Constants.FILE_BLOCK_SIZE - 1) + "\n";
private static final boolean ASSERT;
static {
boolean a = false;
// Intentional side-effect
assert a = true;
ASSERT = a;
}
/**
* The file name.
*/
......@@ -371,20 +380,20 @@ public class FileStore {
public long length() {
try {
long len = fileLength;
if (SysProperties.CHECK2) {
if (ASSERT) {
len = file.size();
if (len != fileLength) {
DbException.throwInternalError(
"file " + name + " length " + len + " expected " + fileLength);
}
}
if (SysProperties.CHECK2 && len % Constants.FILE_BLOCK_SIZE != 0) {
long newLength = len + Constants.FILE_BLOCK_SIZE -
(len % Constants.FILE_BLOCK_SIZE);
file.truncate(newLength);
fileLength = newLength;
DbException.throwInternalError(
"unaligned file length " + name + " len " + len);
if (len % Constants.FILE_BLOCK_SIZE != 0) {
long newLength = len + Constants.FILE_BLOCK_SIZE -
(len % Constants.FILE_BLOCK_SIZE);
file.truncate(newLength);
fileLength = newLength;
DbException.throwInternalError(
"unaligned file length " + name + " len " + len);
}
}
return len;
} catch (IOException e) {
......@@ -398,7 +407,7 @@ public class FileStore {
* @return the location
*/
public long getFilePointer() {
if (SysProperties.CHECK2) {
if (ASSERT) {
try {
if (file.position() != filePos) {
DbException.throwInternalError(file.position() + " " + filePos);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论