提交 c6ce63d8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting (spaces instead of tabs and so on)

上级 94312cca
...@@ -36,7 +36,7 @@ public class Engine implements SessionFactory { ...@@ -36,7 +36,7 @@ public class Engine implements SessionFactory {
private Engine() { private Engine() {
// use getInstance() // use getInstance()
ThreadDeadlockDetector.init(); ThreadDeadlockDetector.init();
} }
public static Engine getInstance() { public static Engine getInstance() {
......
...@@ -756,7 +756,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -756,7 +756,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* closed * closed
*/ */
@Deprecated @Deprecated
@Override @Override
public BigDecimal getBigDecimal(String columnLabel, int scale) public BigDecimal getBigDecimal(String columnLabel, int scale)
throws SQLException { throws SQLException {
try { try {
...@@ -786,7 +786,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -786,7 +786,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* closed * closed
*/ */
@Deprecated @Deprecated
@Override @Override
public BigDecimal getBigDecimal(int columnIndex, int scale) public BigDecimal getBigDecimal(int columnIndex, int scale)
throws SQLException { throws SQLException {
try { try {
...@@ -808,7 +808,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -808,7 +808,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* @deprecated since JDBC 2.0, use getCharacterStream * @deprecated since JDBC 2.0, use getCharacterStream
*/ */
@Deprecated @Deprecated
@Override @Override
public InputStream getUnicodeStream(int columnIndex) throws SQLException { public InputStream getUnicodeStream(int columnIndex) throws SQLException {
throw unsupported("unicodeStream"); throw unsupported("unicodeStream");
} }
...@@ -818,7 +818,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -818,7 +818,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* @deprecated since JDBC 2.0, use setCharacterStream * @deprecated since JDBC 2.0, use setCharacterStream
*/ */
@Deprecated @Deprecated
@Override @Override
public InputStream getUnicodeStream(String columnLabel) throws SQLException { public InputStream getUnicodeStream(String columnLabel) throws SQLException {
throw unsupported("unicodeStream"); throw unsupported("unicodeStream");
} }
......
...@@ -49,6 +49,10 @@ import org.h2.value.Value; ...@@ -49,6 +49,10 @@ import org.h2.value.Value;
*/ */
public class MVTable extends TableBase { public class MVTable extends TableBase {
public static final DebuggingThreadLocal<String> WAITING_FOR_LOCK = new DebuggingThreadLocal<String>();
public static final DebuggingThreadLocal<ArrayList<String>> EXCLUSIVE_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
public static final DebuggingThreadLocal<ArrayList<String>> SHARED_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
private MVPrimaryIndex primaryIndex; private MVPrimaryIndex primaryIndex;
private final ArrayList<Index> indexes = New.arrayList(); private final ArrayList<Index> indexes = New.arrayList();
private long lastModificationId; private long lastModificationId;
...@@ -58,10 +62,6 @@ public class MVTable extends TableBase { ...@@ -58,10 +62,6 @@ public class MVTable extends TableBase {
private final ConcurrentHashMap<Session, Session> lockSharedSessions = private final ConcurrentHashMap<Session, Session> lockSharedSessions =
new ConcurrentHashMap<Session, Session>(); new ConcurrentHashMap<Session, Session>();
public static final DebuggingThreadLocal<String> WAITING_FOR_LOCK = new DebuggingThreadLocal<String>();
public static final DebuggingThreadLocal<ArrayList<String>> EXCLUSIVE_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
public static final DebuggingThreadLocal<ArrayList<String>> SHARED_LOCKS = new DebuggingThreadLocal<ArrayList<String>>();
/** /**
* The queue of sessions waiting to lock the table. It is a FIFO queue to * The queue of sessions waiting to lock the table. It is a FIFO queue to
* prevent starvation, since Java's synchronized locking is biased. * prevent starvation, since Java's synchronized locking is biased.
...@@ -261,7 +261,7 @@ public class MVTable extends TableBase { ...@@ -261,7 +261,7 @@ public class MVTable extends TableBase {
session.addLock(this); session.addLock(this);
lockSharedSessions.put(session, session); lockSharedSessions.put(session, session);
if (SHARED_LOCKS.get() == null) { if (SHARED_LOCKS.get() == null) {
SHARED_LOCKS.set(new ArrayList<String>()); SHARED_LOCKS.set(new ArrayList<String>());
} }
SHARED_LOCKS.get().add(getName()); SHARED_LOCKS.get().add(getName());
} }
...@@ -385,7 +385,7 @@ public class MVTable extends TableBase { ...@@ -385,7 +385,7 @@ public class MVTable extends TableBase {
if (lockSharedSessions.size() > 0) { if (lockSharedSessions.size() > 0) {
lockSharedSessions.remove(s); lockSharedSessions.remove(s);
if (SHARED_LOCKS.get() != null) { if (SHARED_LOCKS.get() != null) {
SHARED_LOCKS.get().remove(getName()); SHARED_LOCKS.get().remove(getName());
} }
} }
if (!waitingSessions.isEmpty()) { if (!waitingSessions.isEmpty()) {
......
...@@ -9,7 +9,6 @@ import java.util.ArrayList; ...@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.TableEngine;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -27,7 +26,6 @@ import org.h2.mvstore.db.MVTableEngine; ...@@ -27,7 +26,6 @@ import org.h2.mvstore.db.MVTableEngine;
import org.h2.table.RegularTable; import org.h2.table.RegularTable;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableLink; import org.h2.table.TableLink;
import org.h2.util.JdbcUtils;
import org.h2.util.New; import org.h2.util.New;
/** /**
...@@ -568,9 +566,9 @@ public class Schema extends DbObjectBase { ...@@ -568,9 +566,9 @@ public class Schema extends DbObjectBase {
} }
data.schema = this; data.schema = this;
if (data.tableEngine == null) { if (data.tableEngine == null) {
DbSettings s = database.getSettings(); DbSettings s = database.getSettings();
if (s.defaultTableEngine != null) { if (s.defaultTableEngine != null) {
data.tableEngine = s.defaultTableEngine; data.tableEngine = s.defaultTableEngine;
} else if (s.mvStore) { } else if (s.mvStore) {
data.tableEngine = MVTableEngine.class.getName(); data.tableEngine = MVTableEngine.class.getName();
} }
......
...@@ -150,10 +150,10 @@ public class Sequence extends SchemaObjectBase { ...@@ -150,10 +150,10 @@ public class Sequence extends SchemaObjectBase {
maxValue > minValue && maxValue > minValue &&
increment != 0 && increment != 0 &&
// Math.abs(increment) < maxValue - minValue // Math.abs(increment) < maxValue - minValue
// use BigInteger to avoid overflows when maxValue and minValue // use BigInteger to avoid overflows when maxValue and minValue
// are really big // are really big
BigInteger.valueOf(increment).abs().compareTo( BigInteger.valueOf(increment).abs().compareTo(
BigInteger.valueOf(maxValue).subtract(BigInteger.valueOf(minValue))) < 0; BigInteger.valueOf(maxValue).subtract(BigInteger.valueOf(minValue))) < 0;
} }
private static long getDefaultMinValue(Long startValue, long increment) { private static long getDefaultMinValue(Long startValue, long increment) {
...@@ -248,26 +248,26 @@ public class Sequence extends SchemaObjectBase { ...@@ -248,26 +248,26 @@ public class Sequence extends SchemaObjectBase {
boolean needsFlush = false; boolean needsFlush = false;
long retVal; long retVal;
long flushValueWithMargin = -1; long flushValueWithMargin = -1;
synchronized(this) { synchronized (this) {
if ((increment > 0 && value >= valueWithMargin) || if ((increment > 0 && value >= valueWithMargin) ||
(increment < 0 && value <= valueWithMargin)) { (increment < 0 && value <= valueWithMargin)) {
valueWithMargin += increment * cacheSize; valueWithMargin += increment * cacheSize;
flushValueWithMargin = valueWithMargin; flushValueWithMargin = valueWithMargin;
needsFlush = true; needsFlush = true;
} }
if ((increment > 0 && value > maxValue) || if ((increment > 0 && value > maxValue) ||
(increment < 0 && value < minValue)) { (increment < 0 && value < minValue)) {
if (cycle) { if (cycle) {
value = increment > 0 ? minValue : maxValue; value = increment > 0 ? minValue : maxValue;
valueWithMargin = value + (increment * cacheSize); valueWithMargin = value + (increment * cacheSize);
flushValueWithMargin = valueWithMargin; flushValueWithMargin = valueWithMargin;
needsFlush = true; needsFlush = true;
} else { } else {
throw DbException.get(ErrorCode.SEQUENCE_EXHAUSTED, getName()); throw DbException.get(ErrorCode.SEQUENCE_EXHAUSTED, getName());
} }
} }
retVal = value; retVal = value;
value += increment; value += increment;
} }
if (needsFlush) { if (needsFlush) {
flush(session, flushValueWithMargin); flush(session, flushValueWithMargin);
...@@ -308,15 +308,15 @@ public class Sequence extends SchemaObjectBase { ...@@ -308,15 +308,15 @@ public class Sequence extends SchemaObjectBase {
} }
private void flushInternal(Session session, long flushValueWithMargin) { private void flushInternal(Session session, long flushValueWithMargin) {
final boolean metaWasLocked = database.lockMeta(session); final boolean metaWasLocked = database.lockMeta(session);
synchronized (this) { synchronized (this) {
if (flushValueWithMargin == lastFlushValueWithMargin) { if (flushValueWithMargin == lastFlushValueWithMargin) {
if (!metaWasLocked) { if (!metaWasLocked) {
database.unlockMeta(session); database.unlockMeta(session);
} }
return; return;
} }
} }
// just for this case, use the value with the margin for the script // just for this case, use the value with the margin for the script
long realValue = value; long realValue = value;
try { try {
...@@ -327,12 +327,12 @@ public class Sequence extends SchemaObjectBase { ...@@ -327,12 +327,12 @@ public class Sequence extends SchemaObjectBase {
} finally { } finally {
value = realValue; value = realValue;
} }
synchronized (this) { synchronized (this) {
lastFlushValueWithMargin = flushValueWithMargin; lastFlushValueWithMargin = flushValueWithMargin;
} }
if (!metaWasLocked) { if (!metaWasLocked) {
database.unlockMeta(session); database.unlockMeta(session);
} }
} }
/** /**
......
...@@ -266,11 +266,11 @@ public class Column { ...@@ -266,11 +266,11 @@ public class Column {
* @return the new or converted value * @return the new or converted value
*/ */
public Value validateConvertUpdateSequence(Session session, Value value) { public Value validateConvertUpdateSequence(Session session, Value value) {
// take a local copy of defaultExpression to avoid holding the lock while calling getValue // take a local copy of defaultExpression to avoid holding the lock while calling getValue
final Expression localDefaultExpression; final Expression localDefaultExpression;
synchronized (this) { synchronized (this) {
localDefaultExpression = defaultExpression; localDefaultExpression = defaultExpression;
} }
if (value == null) { if (value == null) {
if (localDefaultExpression == null) { if (localDefaultExpression == null) {
value = ValueNull.INSTANCE; value = ValueNull.INSTANCE;
......
...@@ -23,128 +23,131 @@ import org.h2.mvstore.db.MVTable; ...@@ -23,128 +23,131 @@ import org.h2.mvstore.db.MVTable;
* Detects deadlocks between threads. Prints out data in the same format as the CTRL-BREAK handler, * Detects deadlocks between threads. Prints out data in the same format as the CTRL-BREAK handler,
* but includes information about table locks. * but includes information about table locks.
*/ */
public class ThreadDeadlockDetector public class ThreadDeadlockDetector {
{
private static String INDENT = " "; private static final String INDENT = " ";
private final ThreadMXBean tmbean; private static ThreadDeadlockDetector detector;
private final Timer threadCheck = new Timer("ThreadDeadlockDetector", true/* isDaemon */); private final ThreadMXBean tmbean;
private static ThreadDeadlockDetector detector = null; // a daemon thread
private final Timer threadCheck = new Timer("ThreadDeadlockDetector", true);
public synchronized static void init() {
if (detector == null) { private ThreadDeadlockDetector() {
detector = new ThreadDeadlockDetector(); this.tmbean = ManagementFactory.getThreadMXBean();
} // delay: 10 ms
} // period: 10000 ms (100 seconds)
threadCheck.schedule(new TimerTask() {
private ThreadDeadlockDetector() { @Override
this.tmbean = ManagementFactory.getThreadMXBean(); public void run() {
threadCheck.schedule(new TimerTask() { checkForDeadlocks();
@Override }
public void run() { }, 10, 10000);
checkForDeadlocks(); }
}
}, 10/*delay(ms)*/, 10000/*period(ms)*/); public static synchronized void init() {
} if (detector == null) {
detector = new ThreadDeadlockDetector();
/** }
* Checks if any threads are deadlocked. If any, print the thread dump information. }
*/
private void checkForDeadlocks() { /**
long[] tids = tmbean.findDeadlockedThreads(); * Checks if any threads are deadlocked. If any, print the thread dump information.
if (tids == null) { */
return; void checkForDeadlocks() {
} long[] tids = tmbean.findDeadlockedThreads();
if (tids == null) {
final StringWriter stringWriter = new StringWriter(); return;
final PrintWriter print = new PrintWriter(stringWriter); }
print.println("ThreadDeadlockDetector - deadlock found :"); final StringWriter stringWriter = new StringWriter();
final ThreadInfo[] infos = tmbean.getThreadInfo(tids, true, true); final PrintWriter print = new PrintWriter(stringWriter);
final HashMap<Long,String> mvtableWaitingForLockMap =
MVTable.WAITING_FOR_LOCK.getSnapshotOfAllThreads(); print.println("ThreadDeadlockDetector - deadlock found :");
final HashMap<Long,ArrayList<String>> mvtableExclusiveLocksMap = final ThreadInfo[] infos = tmbean.getThreadInfo(tids, true, true);
MVTable.EXCLUSIVE_LOCKS.getSnapshotOfAllThreads(); final HashMap<Long, String> mvtableWaitingForLockMap =
final HashMap<Long,ArrayList<String>> mvtableSharedLocksMap = MVTable.WAITING_FOR_LOCK.getSnapshotOfAllThreads();
MVTable.SHARED_LOCKS.getSnapshotOfAllThreads(); final HashMap<Long, ArrayList<String>> mvtableExclusiveLocksMap =
for (ThreadInfo ti : infos) { MVTable.EXCLUSIVE_LOCKS.getSnapshotOfAllThreads();
printThreadInfo(print, ti); final HashMap<Long, ArrayList<String>> mvtableSharedLocksMap =
printLockInfo(print, ti.getLockedSynchronizers(), MVTable.SHARED_LOCKS.getSnapshotOfAllThreads();
mvtableWaitingForLockMap.get(ti.getThreadId()), for (ThreadInfo ti : infos) {
mvtableExclusiveLocksMap.get(ti.getThreadId()), printThreadInfo(print, ti);
mvtableSharedLocksMap.get(ti.getThreadId())); printLockInfo(print, ti.getLockedSynchronizers(),
} mvtableWaitingForLockMap.get(ti.getThreadId()),
mvtableExclusiveLocksMap.get(ti.getThreadId()),
print.flush(); mvtableSharedLocksMap.get(ti.getThreadId()));
// Dump it to system.out in one block, so it doesn't get mixed up with other stuff when we're }
// using a logging subsystem.
System.out.println(stringWriter.getBuffer()); print.flush();
} // Dump it to system.out in one block, so it doesn't get mixed up with other stuff when we're
// using a logging subsystem.
private static void printThreadInfo(PrintWriter print, ThreadInfo ti) { System.out.println(stringWriter.getBuffer());
// print thread information }
printThread(print, ti);
private static void printThreadInfo(PrintWriter print, ThreadInfo ti) {
// print stack trace with locks // print thread information
StackTraceElement[] stacktrace = ti.getStackTrace(); printThread(print, ti);
MonitorInfo[] monitors = ti.getLockedMonitors();
for (int i = 0; i < stacktrace.length; i++) { // print stack trace with locks
StackTraceElement ste = stacktrace[i]; StackTraceElement[] stacktrace = ti.getStackTrace();
print.println(INDENT + "at " + ste.toString()); MonitorInfo[] monitors = ti.getLockedMonitors();
for (MonitorInfo mi : monitors) { for (int i = 0; i < stacktrace.length; i++) {
if (mi.getLockedStackDepth() == i) { StackTraceElement ste = stacktrace[i];
print.println(INDENT + " - locked " + mi); print.println(INDENT + "at " + ste.toString());
} for (MonitorInfo mi : monitors) {
} if (mi.getLockedStackDepth() == i) {
} print.println(INDENT + " - locked " + mi);
print.println(); }
} }
}
private static void printThread(PrintWriter print, ThreadInfo ti) { print.println();
print.print("\"" + ti.getThreadName() + "\"" + " Id=" }
+ ti.getThreadId() + " in " + ti.getThreadState());
if (ti.getLockName() != null) { private static void printThread(PrintWriter print, ThreadInfo ti) {
print.append(" on lock=" + ti.getLockName()); print.print("\"" + ti.getThreadName() + "\"" + " Id="
} + ti.getThreadId() + " in " + ti.getThreadState());
if (ti.isSuspended()) { if (ti.getLockName() != null) {
print.append(" (suspended)"); print.append(" on lock=" + ti.getLockName());
} }
if (ti.isInNative()) { if (ti.isSuspended()) {
print.append(" (running in native)"); print.append(" (suspended)");
} }
print.println(); if (ti.isInNative()) {
if (ti.getLockOwnerName() != null) { print.append(" (running in native)");
print.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" }
+ ti.getLockOwnerId()); print.println();
} if (ti.getLockOwnerName() != null) {
} print.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id="
+ ti.getLockOwnerId());
private static void printLockInfo(PrintWriter print, LockInfo[] locks, }
String mvtableWaitingForLock, }
ArrayList<String> mvtableExclusiveLocks,
ArrayList<String> mvtableSharedLocksMap) { private static void printLockInfo(PrintWriter print, LockInfo[] locks,
print.println(INDENT + "Locked synchronizers: count = " + locks.length); String mvtableWaitingForLock,
for (LockInfo li : locks) { ArrayList<String> mvtableExclusiveLocks,
print.println(INDENT + " - " + li); ArrayList<String> mvtableSharedLocksMap) {
} print.println(INDENT + "Locked synchronizers: count = " + locks.length);
if (mvtableWaitingForLock != null) { for (LockInfo li : locks) {
print.println(INDENT + "Waiting for table: " + mvtableWaitingForLock); print.println(INDENT + " - " + li);
} }
if (mvtableExclusiveLocks != null) { if (mvtableWaitingForLock != null) {
print.println(INDENT + "Exclusive table locks: count = " + mvtableExclusiveLocks.size()); print.println(INDENT + "Waiting for table: " + mvtableWaitingForLock);
for (String name : mvtableExclusiveLocks) { }
print.println(INDENT + " - " + name); if (mvtableExclusiveLocks != null) {
} print.println(INDENT + "Exclusive table locks: count = " + mvtableExclusiveLocks.size());
} for (String name : mvtableExclusiveLocks) {
if (mvtableSharedLocksMap != null) { print.println(INDENT + " - " + name);
print.println(INDENT + "Shared table locks: count = " + mvtableSharedLocksMap.size()); }
for (String name : mvtableSharedLocksMap) { }
print.println(INDENT + " - " + name); if (mvtableSharedLocksMap != null) {
} print.println(INDENT + "Shared table locks: count = " + mvtableSharedLocksMap.size());
} for (String name : mvtableSharedLocksMap) {
print.println(); print.println(INDENT + " - " + name);
} }
}
print.println();
}
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论