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

Documentation

上级 060abfca
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -358,8 +358,8 @@ public class AlterTableAddConstraint extends SchemaCommand {
for (IndexColumn col : cols) {
// all columns of the list must be part of the index,
// but not all columns of the index need to be part of the list
// holes are not allowed (index=a,b,c & list=a,b is ok; but list=a,c
// is not)
// holes are not allowed (index=a,b,c & list=a,b is ok;
// but list=a,c is not)
int idx = existingIndex.getColumnIndex(col.column);
if (idx < 0 || idx >= cols.length) {
return false;
......
......@@ -205,7 +205,7 @@ public class CreateTable extends SchemaCommand {
"with a higher ID: " + t +
", this is currently not supported, " +
"as it would prevent the database from " +
"beeing re-opened");
"being re-opened");
}
}
}
......
......@@ -1341,6 +1341,11 @@ public class MVStore {
return true;
}
/**
* Compact by moving all chunks next to each other.
*
* @return if anything was written
*/
public synchronized boolean compactMoveChunks() {
return compactMoveChunks(Long.MAX_VALUE);
}
......@@ -2467,8 +2472,8 @@ public class MVStore {
}
/**
* Get the estimated memory (in bytes) of unsaved data. If the value exceeds the
* auto-commit memory, the changes are committed.
* Get the estimated memory (in bytes) of unsaved data. If the value exceeds
* the auto-commit memory, the changes are committed.
* <p>
* The returned value is an estimation only.
*
......
......@@ -222,6 +222,12 @@ public class Page {
return p != null ? p : map.readPage(children[index]);
}
/**
* Get the position of the child.
*
* @param index the index
* @return the position
*/
public long getChildPagePos(int index) {
return children[index];
}
......
......@@ -226,6 +226,8 @@ public class MVTableEngine implements TableEngine {
/**
* Remove all temporary maps.
*
* @param objectIds the ids of the objects to keep
*/
public void removeTemporaryMaps(BitField objectIds) {
for (String mapName : store.getMapNames()) {
......
......@@ -155,8 +155,8 @@ CREATE AGGREGATE [ IF NOT EXISTS ] newAggregateName FOR className
","
Creates a new user-defined aggregate function."
"Commands (DDL)","CREATE ALIAS","
CREATE ALIAS [ IF NOT EXISTS ] newFunctionAliasName [ DETERMINISTIC ] [ NOBUFFER ]
{ FOR classAndMethodName | AS sourceCodeString }
CREATE ALIAS [ IF NOT EXISTS ] newFunctionAliasName [ DETERMINISTIC ]
[ NOBUFFER ] { FOR classAndMethodName | AS sourceCodeString }
","
Creates a new function alias."
"Commands (DDL)","CREATE CONSTANT","
......@@ -171,13 +171,14 @@ CREATE DOMAIN [ IF NOT EXISTS ] newDomainName AS dataType
Creates a new data type (domain)."
"Commands (DDL)","CREATE INDEX","
CREATE
{ [ UNIQUE ] [ HASH ] [ SPATIAL] INDEX [ [ IF NOT EXISTS ] newIndexName ]
{ [ UNIQUE ] [ HASH | SPATIAL] INDEX [ [ IF NOT EXISTS ] newIndexName ]
| PRIMARY KEY [ HASH ] }
ON tableName ( indexColumn [,...] )
","
Creates a new index."
"Commands (DDL)","CREATE LINKED TABLE","
CREATE [ FORCE ] [ [ GLOBAL | LOCAL ] TEMPORARY ] LINKED TABLE [ IF NOT EXISTS ]
CREATE [ FORCE ] [ [ GLOBAL | LOCAL ] TEMPORARY ]
LINKED TABLE [ IF NOT EXISTS ]
name ( driverString, urlString, userString, passwordString,
[ originalSchemaString, ] originalTableString ) [ EMIT UPDATES | READONLY ]
","
......
......@@ -90,11 +90,11 @@ public class ResultTempTable implements ResultExternal {
private void createIndex() {
IndexColumn[] indexCols = null;
if (sort != null) {
int[] colInd = sort.getQueryColumnIndexes();
indexCols = new IndexColumn[colInd.length];
for (int i = 0; i < colInd.length; i++) {
int[] colIndex = sort.getQueryColumnIndexes();
indexCols = new IndexColumn[colIndex.length];
for (int i = 0; i < colIndex.length; i++) {
IndexColumn indexColumn = new IndexColumn();
indexColumn.column = table.getColumn(colInd[i]);
indexColumn.column = table.getColumn(colIndex[i]);
indexColumn.sortType = sort.getSortTypes()[i];
indexColumn.columnName = COLUMN_NAME + i;
indexCols[i] = indexColumn;
......
......@@ -239,8 +239,9 @@ public class TableView extends Table {
return item;
}
}
// We cannot hold the lock during the ViewIndex creation or we risk ABBA deadlocks
// if the view creation calls back into H2 via something like a FunctionTable.
// We cannot hold the lock during the ViewIndex creation or we risk ABBA
// deadlocks if the view creation calls back into H2 via something like
// a FunctionTable.
ViewIndex i2 = new ViewIndex(this, index, session, masks);
synchronized (this) {
// have to check again in case another session has beat us to it
......
......@@ -28,13 +28,22 @@ public class AbbaDetector {
};
/**
* Map of (object A) -> ( map of (object locked before object A) -> (stacktrace where locked) )
* Map of (object A) -> (
* map of (object locked before object A) ->
* (stack trace where locked) )
*/
private static final Map<Object, Map<Object, Exception>> LOCK_ORDERING =
new WeakHashMap<Object, Map<Object, Exception>>();
private static final Set<String> KNOWN_DEADLOCKS = new HashSet<String>();
/**
* This method is called just before or just after an object is
* synchronized.
*
* @param o the object, or null for the current class
* @return the object that was passed
*/
public static Object begin(Object o) {
if (o == null) {
o = new SecurityManager() {
......@@ -59,8 +68,8 @@ public class AbbaDetector {
}
if (TRACE) {
String thread = "[thread " + Thread.currentThread().getId() + "]";
String ident = new String(new char[stack.size() * 2]).replace((char) 0, ' ');
System.out.println(thread + " " + ident +
String indent = new String(new char[stack.size() * 2]).replace((char) 0, ' ');
System.out.println(thread + " " + indent +
"sync " + getObjectName(o));
}
if (stack.size() > 0) {
......@@ -79,7 +88,7 @@ public class AbbaDetector {
return o.getClass().getSimpleName() + "@" + System.identityHashCode(o);
}
public static synchronized void markHigher(Object o, Deque<Object> older) {
private static synchronized void markHigher(Object o, Deque<Object> older) {
Object test = getTest(o);
Map<Object, Exception> map = LOCK_ORDERING.get(test);
if (map == null) {
......@@ -118,19 +127,4 @@ public class AbbaDetector {
}
}
public static void main(String... args) {
Integer a = 1;
Float b = 2.0f;
synchronized (a) {
synchronized (b) {
System.out.println("a, then b");
}
}
synchronized (b) {
synchronized (a) {
System.out.println("b, then a");
}
}
}
}
......@@ -23,18 +23,20 @@ import java.util.WeakHashMap;
*/
public class AbbaLockingDetector implements Runnable {
private int tickInterval_ms = 2;
private int tickIntervalMs = 2;
private volatile boolean stop;
private final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
private final ThreadMXBean threadMXBean =
ManagementFactory.getThreadMXBean();
private Thread thread;
/**
* Map of (object A) -> ( map of (object locked before object A) ->
* (stacktrace where locked) )
* (stack trace where locked) )
*/
private final Map<String, Map<String, String>> LOCK_ORDERING = new WeakHashMap<String, Map<String, String>>();
private final Set<String> KNOWN_DEADLOCKS = new HashSet<String>();
private final Map<String, Map<String, String>> lockOrdering =
new WeakHashMap<String, Map<String, String>>();
private final Set<String> knownDeadlocks = new HashSet<String>();
/**
* Start collecting locking data.
......@@ -48,9 +50,12 @@ public class AbbaLockingDetector implements Runnable {
return this;
}
/**
* Reset the state.
*/
public synchronized void reset() {
LOCK_ORDERING.clear();
KNOWN_DEADLOCKS.clear();
lockOrdering.clear();
knownDeadlocks.clear();
}
/**
......@@ -83,15 +88,19 @@ public class AbbaLockingDetector implements Runnable {
}
private void tick() {
if (tickInterval_ms > 0) {
if (tickIntervalMs > 0) {
try {
Thread.sleep(tickInterval_ms);
Thread.sleep(tickIntervalMs);
} catch (InterruptedException ex) {
// ignore
}
}
ThreadInfo[] list = threadMXBean.dumpAllThreads(true/* lockedMonitors */, false/* lockedSynchronizers */);
ThreadInfo[] list = threadMXBean.dumpAllThreads(
// lockedMonitors
true,
// lockedSynchronizers
false);
processThreadList(list);
}
......@@ -110,7 +119,8 @@ public class AbbaLockingDetector implements Runnable {
* We cannot simply call getLockedMonitors because it is not guaranteed to
* return the locks in the correct order.
*/
private static void generateOrdering(final List<String> lockOrder, ThreadInfo info) {
private static void generateOrdering(final List<String> lockOrder,
ThreadInfo info) {
final MonitorInfo[] lockedMonitors = info.getLockedMonitors();
Arrays.sort(lockedMonitors, new Comparator<MonitorInfo>() {
@Override
......@@ -132,28 +142,30 @@ public class AbbaLockingDetector implements Runnable {
}
}
private synchronized void markHigher(List<String> lockOrder, ThreadInfo threadInfo) {
private synchronized void markHigher(List<String> lockOrder,
ThreadInfo threadInfo) {
String topLock = lockOrder.get(lockOrder.size() - 1);
Map<String, String> map = LOCK_ORDERING.get(topLock);
Map<String, String> map = lockOrdering.get(topLock);
if (map == null) {
map = new WeakHashMap<String, String>();
LOCK_ORDERING.put(topLock, map);
lockOrdering.put(topLock, map);
}
String oldException = null;
for (int i = 0; i < lockOrder.size() - 1; i++) {
String olderLock = lockOrder.get(i);
Map<String, String> oldMap = LOCK_ORDERING.get(olderLock);
Map<String, String> oldMap = lockOrdering.get(olderLock);
boolean foundDeadLock = false;
if (oldMap != null) {
String e = oldMap.get(topLock);
if (e != null) {
foundDeadLock = true;
String deadlockType = topLock + " " + olderLock;
if (!KNOWN_DEADLOCKS.contains(deadlockType)) {
if (!knownDeadlocks.contains(deadlockType)) {
System.out.println(topLock + " synchronized after \n " + olderLock
+ ", but in the past before\n" + "AFTER\n" + getStackTraceForThread(threadInfo)
+ ", but in the past before\n" + "AFTER\n" +
getStackTraceForThread(threadInfo)
+ "BEFORE\n" + e);
KNOWN_DEADLOCKS.add(deadlockType);
knownDeadlocks.add(deadlockType);
}
}
}
......@@ -172,13 +184,15 @@ public class AbbaLockingDetector implements Runnable {
* stack frames)
*/
private static String getStackTraceForThread(ThreadInfo info) {
StringBuilder sb = new StringBuilder("\"" + info.getThreadName() + "\"" + " Id=" + info.getThreadId() + " "
+ info.getThreadState());
StringBuilder sb = new StringBuilder("\"" +
info.getThreadName() + "\"" + " Id=" +
info.getThreadId() + " " + info.getThreadState());
if (info.getLockName() != null) {
sb.append(" on " + info.getLockName());
}
if (info.getLockOwnerName() != null) {
sb.append(" owned by \"" + info.getLockOwnerName() + "\" Id=" + info.getLockOwnerId());
sb.append(" owned by \"" + info.getLockOwnerName() +
"\" Id=" + info.getLockOwnerId());
}
if (info.isSuspended()) {
sb.append(" (suspended)");
......@@ -191,9 +205,9 @@ public class AbbaLockingDetector implements Runnable {
final MonitorInfo[] lockedMonitors = info.getLockedMonitors();
boolean startDumping = false;
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i];
StackTraceElement e = stackTrace[i];
if (startDumping) {
dumpStackTraceElement(info, sb, i, ste);
dumpStackTraceElement(info, sb, i, e);
}
for (MonitorInfo mi : lockedMonitors) {
......@@ -202,7 +216,7 @@ public class AbbaLockingDetector implements Runnable {
// something.
// Removes a lot of unnecessary noise from the output.
if (!startDumping) {
dumpStackTraceElement(info, sb, i, ste);
dumpStackTraceElement(info, sb, i, e);
startDumping = true;
}
sb.append("\t- locked " + mi);
......@@ -213,8 +227,9 @@ public class AbbaLockingDetector implements Runnable {
return sb.toString();
}
private static void dumpStackTraceElement(ThreadInfo info, StringBuilder sb, int i, StackTraceElement ste) {
sb.append("\tat " + ste.toString());
private static void dumpStackTraceElement(ThreadInfo info,
StringBuilder sb, int i, StackTraceElement e) {
sb.append('\t').append("at ").append(e.toString());
sb.append('\n');
if (i == 0 && info.getLockInfo() != null) {
Thread.State ts = info.getThreadState();
......@@ -237,7 +252,8 @@ public class AbbaLockingDetector implements Runnable {
}
private static String getObjectName(MonitorInfo info) {
return info.getClassName() + "@" + Integer.toHexString(info.getIdentityHashCode());
return info.getClassName() + "@" +
Integer.toHexString(info.getIdentityHashCode());
}
}
......@@ -52,7 +52,8 @@ public class DateTimeUtils {
private static final int[] DAYS_OFFSET = { 0, 31, 61, 92, 122, 153, 184,
214, 245, 275, 306, 337, 366 };
private static final ThreadLocal<Calendar> cachedCalendar = new ThreadLocal<Calendar>() {
private static final ThreadLocal<Calendar> CACHED_CALENDAR =
new ThreadLocal<Calendar>() {
@Override
protected Calendar initialValue() {
return Calendar.getInstance();
......@@ -67,7 +68,7 @@ public class DateTimeUtils {
* Reset the calendar, for example after changing the default timezone.
*/
public static void resetCalendar() {
cachedCalendar.remove();
CACHED_CALENDAR.remove();
}
/**
......@@ -379,7 +380,7 @@ public class DateTimeUtils {
int millis) {
Calendar c;
if (tz == TimeZone.getDefault()) {
c = cachedCalendar.get();
c = CACHED_CALENDAR.get();
} else {
c = Calendar.getInstance(tz);
}
......@@ -416,7 +417,7 @@ public class DateTimeUtils {
* @return the value
*/
public static int getDatePart(java.util.Date d, int field) {
Calendar c = cachedCalendar.get();
Calendar c = CACHED_CALENDAR.get();
c.setTime(d);
if (field == Calendar.YEAR) {
return getYear(c);
......@@ -450,7 +451,7 @@ public class DateTimeUtils {
* @return the milliseconds
*/
public static long getTimeLocalWithoutDst(java.util.Date d) {
return d.getTime() + cachedCalendar.get().get(Calendar.ZONE_OFFSET);
return d.getTime() + CACHED_CALENDAR.get().get(Calendar.ZONE_OFFSET);
}
/**
......@@ -461,7 +462,7 @@ public class DateTimeUtils {
* @return the number of milliseconds in UTC
*/
public static long getTimeUTCWithoutDst(long millis) {
return millis - cachedCalendar.get().get(Calendar.ZONE_OFFSET);
return millis - CACHED_CALENDAR.get().get(Calendar.ZONE_OFFSET);
}
/**
......@@ -731,7 +732,7 @@ public class DateTimeUtils {
* @return the date value
*/
public static long dateValueFromDate(long ms) {
Calendar cal = cachedCalendar.get();
Calendar cal = CACHED_CALENDAR.get();
cal.clear();
cal.setTimeInMillis(ms);
return dateValueFromCalendar(cal);
......@@ -759,7 +760,7 @@ public class DateTimeUtils {
* @return the nanoseconds
*/
public static long nanosFromDate(long ms) {
Calendar cal = cachedCalendar.get();
Calendar cal = CACHED_CALENDAR.get();
cal.clear();
cal.setTimeInMillis(ms);
return nanosFromCalendar(cal);
......
......@@ -40,7 +40,8 @@ public class ValueTimestamp extends Value {
static final int DEFAULT_SCALE = 10;
/**
* A bit field with bits for the year, month, and day (see DateTimeUtils for encoding)
* A bit field with bits for the year, month, and day (see DateTimeUtils for
* encoding)
*/
private final long dateValue;
/**
......@@ -56,7 +57,8 @@ public class ValueTimestamp extends Value {
/**
* Get or create a date value for the given date.
*
* @param dateValue the date value, a bit field with bits for the year, month, and day
* @param dateValue the date value, a bit field with bits for the year,
* month, and day
* @param timeNanos the nanoseconds since midnight
* @return the value
*/
......@@ -81,6 +83,8 @@ public class ValueTimestamp extends Value {
/**
* Get or create a timestamp value for the given date/time in millis.
*
* @param ms the milliseconds
* @param nanos the nanoseconds
* @return the value
*/
public static ValueTimestamp fromMillisNanos(long ms, int nanos) {
......@@ -92,6 +96,7 @@ public class ValueTimestamp extends Value {
/**
* Get or create a timestamp value for the given date/time in millis.
*
* @param ms the milliseconds
* @return the value
*/
public static ValueTimestamp fromMillis(long ms) {
......@@ -193,7 +198,10 @@ public class ValueTimestamp extends Value {
}
/**
* A bit field with bits for the year, month, and day (see DateTimeUtils for encoding)
* A bit field with bits for the year, month, and day (see DateTimeUtils for
* encoding).
*
* @return the data value
*/
public long getDateValue() {
return dateValue;
......@@ -201,6 +209,8 @@ public class ValueTimestamp extends Value {
/**
* The nanoseconds since midnight.
*
* @return the nanoseconds
*/
public long getTimeNanos() {
return timeNanos;
......
......@@ -362,6 +362,9 @@ java org.h2.test.TestAll timer
*/
String cacheType;
/**
* The AB-BA locking detector.
*/
AbbaLockingDetector abbaLockingDetector;
private Server server;
......
......@@ -840,7 +840,8 @@ public class TestSpatial extends TestBase {
try {
Statement stat = conn.createStatement();
stat.execute("drop table if exists test");
stat.execute("create table test(id serial primary key, value double, the_geom geometry)");
stat.execute("create table test(id serial primary key, " +
"value double, the_geom geometry)");
stat.execute("create spatial index spatial on test(the_geom)");
ResultSet rs = stat.executeQuery("explain select * from test where _ROWID_ = 5");
assertTrue(rs.next());
......
......@@ -85,11 +85,15 @@ public class AbbaDetect {
// the word synchronized within single line comments comments
source = source.replaceAll("(// .* synchronized )([^ ])", "$1 $2");
source = source.replaceAll("synchronized \\((.*)\\(\\)\\)", "synchronized \\(org.h2.util.AbbaDetector.begin\\($1\\(\\)\\)\\)");
source = source.replaceAll("synchronized \\((.*)\\)", "synchronized \\(org.h2.util.AbbaDetector.begin\\($1\\)\\)");
source = source.replaceAll("synchronized \\((.*)\\(\\)\\)",
"synchronized \\(org.h2.util.AbbaDetector.begin\\($1\\(\\)\\)\\)");
source = source.replaceAll("synchronized \\((.*)\\)",
"synchronized \\(org.h2.util.AbbaDetector.begin\\($1\\)\\)");
source = source.replaceAll("static synchronized ([^ (].*)\\{", "static synchronized $1{org.h2.util.AbbaDetector.begin\\(null\\);");
source = source.replaceAll("synchronized ([^ (].*)\\{", "synchronized $1{org.h2.util.AbbaDetector.begin\\(this\\);");
source = source.replaceAll("static synchronized ([^ (].*)\\{",
"static synchronized $1{org.h2.util.AbbaDetector.begin\\(null\\);");
source = source.replaceAll("synchronized ([^ (].*)\\{",
"synchronized $1{org.h2.util.AbbaDetector.begin\\(this\\);");
return source;
}
......
......@@ -755,4 +755,8 @@ predicted prediction wojtek hops jurczyk cbtree predict vast assumption upside
adjusted lastly sgtatham cleaning gillet prevented
angus bernd chatellier macdonald eckenfels granting moreover exponential transferring
dedup megabyte breadth traversal affine tucc jentsch yyyymmdd vertica graf
mutate shard shards
mutate shard shards succession recipients provisionally contributor statutory
inaccuracies detector logos launcher rewrite monitors equivalents trademarks
reinstated uninteresting dead defendant doctrines beat factual fair suspended
exploit noise ongoing disclaimers shrinks remedy party desirable timely construe
deque synchronizers affero
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论