Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c6ce63d8
提交
c6ce63d8
authored
7月 22, 2015
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Formatting (spaces instead of tabs and so on)
上级
94312cca
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
182 行增加
和
181 行删除
+182
-181
Engine.java
h2/src/main/org/h2/engine/Engine.java
+1
-1
JdbcResultSet.java
h2/src/main/org/h2/jdbc/JdbcResultSet.java
+4
-4
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+6
-6
Schema.java
h2/src/main/org/h2/schema/Schema.java
+2
-4
Sequence.java
h2/src/main/org/h2/schema/Sequence.java
+38
-38
Column.java
h2/src/main/org/h2/table/Column.java
+5
-5
ThreadDeadlockDetector.java
h2/src/main/org/h2/util/ThreadDeadlockDetector.java
+126
-123
没有找到文件。
h2/src/main/org/h2/engine/Engine.java
浏览文件 @
c6ce63d8
...
...
@@ -36,7 +36,7 @@ public class Engine implements SessionFactory {
private
Engine
()
{
// use getInstance()
ThreadDeadlockDetector
.
init
();
ThreadDeadlockDetector
.
init
();
}
public
static
Engine
getInstance
()
{
...
...
h2/src/main/org/h2/jdbc/JdbcResultSet.java
浏览文件 @
c6ce63d8
...
...
@@ -756,7 +756,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* closed
*/
@Deprecated
@Override
@Override
public
BigDecimal
getBigDecimal
(
String
columnLabel
,
int
scale
)
throws
SQLException
{
try
{
...
...
@@ -786,7 +786,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* closed
*/
@Deprecated
@Override
@Override
public
BigDecimal
getBigDecimal
(
int
columnIndex
,
int
scale
)
throws
SQLException
{
try
{
...
...
@@ -808,7 +808,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* @deprecated since JDBC 2.0, use getCharacterStream
*/
@Deprecated
@Override
@Override
public
InputStream
getUnicodeStream
(
int
columnIndex
)
throws
SQLException
{
throw
unsupported
(
"unicodeStream"
);
}
...
...
@@ -818,7 +818,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
* @deprecated since JDBC 2.0, use setCharacterStream
*/
@Deprecated
@Override
@Override
public
InputStream
getUnicodeStream
(
String
columnLabel
)
throws
SQLException
{
throw
unsupported
(
"unicodeStream"
);
}
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
c6ce63d8
...
...
@@ -49,6 +49,10 @@ import org.h2.value.Value;
*/
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
final
ArrayList
<
Index
>
indexes
=
New
.
arrayList
();
private
long
lastModificationId
;
...
...
@@ -58,10 +62,6 @@ public class MVTable extends TableBase {
private
final
ConcurrentHashMap
<
Session
,
Session
>
lockSharedSessions
=
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
* prevent starvation, since Java's synchronized locking is biased.
...
...
@@ -261,7 +261,7 @@ public class MVTable extends TableBase {
session
.
addLock
(
this
);
lockSharedSessions
.
put
(
session
,
session
);
if
(
SHARED_LOCKS
.
get
()
==
null
)
{
SHARED_LOCKS
.
set
(
new
ArrayList
<
String
>());
SHARED_LOCKS
.
set
(
new
ArrayList
<
String
>());
}
SHARED_LOCKS
.
get
().
add
(
getName
());
}
...
...
@@ -385,7 +385,7 @@ public class MVTable extends TableBase {
if
(
lockSharedSessions
.
size
()
>
0
)
{
lockSharedSessions
.
remove
(
s
);
if
(
SHARED_LOCKS
.
get
()
!=
null
)
{
SHARED_LOCKS
.
get
().
remove
(
getName
());
SHARED_LOCKS
.
get
().
remove
(
getName
());
}
}
if
(!
waitingSessions
.
isEmpty
())
{
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
c6ce63d8
...
...
@@ -9,7 +9,6 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.TableEngine
;
import
org.h2.command.ddl.CreateTableData
;
import
org.h2.constraint.Constraint
;
import
org.h2.engine.Database
;
...
...
@@ -27,7 +26,6 @@ import org.h2.mvstore.db.MVTableEngine;
import
org.h2.table.RegularTable
;
import
org.h2.table.Table
;
import
org.h2.table.TableLink
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
/**
...
...
@@ -568,9 +566,9 @@ public class Schema extends DbObjectBase {
}
data
.
schema
=
this
;
if
(
data
.
tableEngine
==
null
)
{
DbSettings
s
=
database
.
getSettings
();
DbSettings
s
=
database
.
getSettings
();
if
(
s
.
defaultTableEngine
!=
null
)
{
data
.
tableEngine
=
s
.
defaultTableEngine
;
data
.
tableEngine
=
s
.
defaultTableEngine
;
}
else
if
(
s
.
mvStore
)
{
data
.
tableEngine
=
MVTableEngine
.
class
.
getName
();
}
...
...
h2/src/main/org/h2/schema/Sequence.java
浏览文件 @
c6ce63d8
...
...
@@ -150,10 +150,10 @@ public class Sequence extends SchemaObjectBase {
maxValue
>
minValue
&&
increment
!=
0
&&
// Math.abs(increment) < maxValue - minValue
// use BigInteger to avoid overflows when maxValue and minValue
// are really big
// use BigInteger to avoid overflows when maxValue and minValue
// are really big
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
)
{
...
...
@@ -248,26 +248,26 @@ public class Sequence extends SchemaObjectBase {
boolean
needsFlush
=
false
;
long
retVal
;
long
flushValueWithMargin
=
-
1
;
synchronized
(
this
)
{
if
((
increment
>
0
&&
value
>=
valueWithMargin
)
||
(
increment
<
0
&&
value
<=
valueWithMargin
))
{
valueWithMargin
+=
increment
*
cacheSize
;
flushValueWithMargin
=
valueWithMargin
;
needsFlush
=
true
;
}
if
((
increment
>
0
&&
value
>
maxValue
)
||
(
increment
<
0
&&
value
<
minValue
))
{
if
(
cycle
)
{
value
=
increment
>
0
?
minValue
:
maxValue
;
valueWithMargin
=
value
+
(
increment
*
cacheSize
);
flushValueWithMargin
=
valueWithMargin
;
needsFlush
=
true
;
}
else
{
throw
DbException
.
get
(
ErrorCode
.
SEQUENCE_EXHAUSTED
,
getName
());
}
}
retVal
=
value
;
value
+=
increment
;
synchronized
(
this
)
{
if
((
increment
>
0
&&
value
>=
valueWithMargin
)
||
(
increment
<
0
&&
value
<=
valueWithMargin
))
{
valueWithMargin
+=
increment
*
cacheSize
;
flushValueWithMargin
=
valueWithMargin
;
needsFlush
=
true
;
}
if
((
increment
>
0
&&
value
>
maxValue
)
||
(
increment
<
0
&&
value
<
minValue
))
{
if
(
cycle
)
{
value
=
increment
>
0
?
minValue
:
maxValue
;
valueWithMargin
=
value
+
(
increment
*
cacheSize
);
flushValueWithMargin
=
valueWithMargin
;
needsFlush
=
true
;
}
else
{
throw
DbException
.
get
(
ErrorCode
.
SEQUENCE_EXHAUSTED
,
getName
());
}
}
retVal
=
value
;
value
+=
increment
;
}
if
(
needsFlush
)
{
flush
(
session
,
flushValueWithMargin
);
...
...
@@ -308,15 +308,15 @@ public class Sequence extends SchemaObjectBase {
}
private
void
flushInternal
(
Session
session
,
long
flushValueWithMargin
)
{
final
boolean
metaWasLocked
=
database
.
lockMeta
(
session
);
synchronized
(
this
)
{
if
(
flushValueWithMargin
==
lastFlushValueWithMargin
)
{
if
(!
metaWasLocked
)
{
database
.
unlockMeta
(
session
);
}
return
;
}
}
final
boolean
metaWasLocked
=
database
.
lockMeta
(
session
);
synchronized
(
this
)
{
if
(
flushValueWithMargin
==
lastFlushValueWithMargin
)
{
if
(!
metaWasLocked
)
{
database
.
unlockMeta
(
session
);
}
return
;
}
}
// just for this case, use the value with the margin for the script
long
realValue
=
value
;
try
{
...
...
@@ -327,12 +327,12 @@ public class Sequence extends SchemaObjectBase {
}
finally
{
value
=
realValue
;
}
synchronized
(
this
)
{
lastFlushValueWithMargin
=
flushValueWithMargin
;
}
if
(!
metaWasLocked
)
{
database
.
unlockMeta
(
session
);
}
synchronized
(
this
)
{
lastFlushValueWithMargin
=
flushValueWithMargin
;
}
if
(!
metaWasLocked
)
{
database
.
unlockMeta
(
session
);
}
}
/**
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
c6ce63d8
...
...
@@ -266,11 +266,11 @@ public class Column {
* @return the new or converted value
*/
public
Value
validateConvertUpdateSequence
(
Session
session
,
Value
value
)
{
// take a local copy of defaultExpression to avoid holding the lock while calling getValue
final
Expression
localDefaultExpression
;
synchronized
(
this
)
{
localDefaultExpression
=
defaultExpression
;
}
// take a local copy of defaultExpression to avoid holding the lock while calling getValue
final
Expression
localDefaultExpression
;
synchronized
(
this
)
{
localDefaultExpression
=
defaultExpression
;
}
if
(
value
==
null
)
{
if
(
localDefaultExpression
==
null
)
{
value
=
ValueNull
.
INSTANCE
;
...
...
h2/src/main/org/h2/util/ThreadDeadlockDetector.java
浏览文件 @
c6ce63d8
...
...
@@ -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,
* but includes information about table locks.
*/
public
class
ThreadDeadlockDetector
{
private
static
String
INDENT
=
" "
;
private
final
ThreadMXBean
tmbean
;
private
final
Timer
threadCheck
=
new
Timer
(
"ThreadDeadlockDetector"
,
true
/* isDaemon */
);
private
static
ThreadDeadlockDetector
detector
=
null
;
public
synchronized
static
void
init
()
{
if
(
detector
==
null
)
{
detector
=
new
ThreadDeadlockDetector
();
}
}
private
ThreadDeadlockDetector
()
{
this
.
tmbean
=
ManagementFactory
.
getThreadMXBean
();
threadCheck
.
schedule
(
new
TimerTask
()
{
@Override
public
void
run
()
{
checkForDeadlocks
();
}
},
10
/*delay(ms)*/
,
10000
/*period(ms)*/
);
}
/**
* Checks if any threads are deadlocked. If any, print the thread dump information.
*/
private
void
checkForDeadlocks
()
{
long
[]
tids
=
tmbean
.
findDeadlockedThreads
();
if
(
tids
==
null
)
{
return
;
}
final
StringWriter
stringWriter
=
new
StringWriter
();
final
PrintWriter
print
=
new
PrintWriter
(
stringWriter
);
print
.
println
(
"ThreadDeadlockDetector - deadlock found :"
);
final
ThreadInfo
[]
infos
=
tmbean
.
getThreadInfo
(
tids
,
true
,
true
);
final
HashMap
<
Long
,
String
>
mvtableWaitingForLockMap
=
MVTable
.
WAITING_FOR_LOCK
.
getSnapshotOfAllThreads
();
final
HashMap
<
Long
,
ArrayList
<
String
>>
mvtableExclusiveLocksMap
=
MVTable
.
EXCLUSIVE_LOCKS
.
getSnapshotOfAllThreads
();
final
HashMap
<
Long
,
ArrayList
<
String
>>
mvtableSharedLocksMap
=
MVTable
.
SHARED_LOCKS
.
getSnapshotOfAllThreads
();
for
(
ThreadInfo
ti
:
infos
)
{
printThreadInfo
(
print
,
ti
);
printLockInfo
(
print
,
ti
.
getLockedSynchronizers
(),
mvtableWaitingForLockMap
.
get
(
ti
.
getThreadId
()),
mvtableExclusiveLocksMap
.
get
(
ti
.
getThreadId
()),
mvtableSharedLocksMap
.
get
(
ti
.
getThreadId
()));
}
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.
System
.
out
.
println
(
stringWriter
.
getBuffer
());
}
private
static
void
printThreadInfo
(
PrintWriter
print
,
ThreadInfo
ti
)
{
// print thread information
printThread
(
print
,
ti
);
// print stack trace with locks
StackTraceElement
[]
stacktrace
=
ti
.
getStackTrace
();
MonitorInfo
[]
monitors
=
ti
.
getLockedMonitors
();
for
(
int
i
=
0
;
i
<
stacktrace
.
length
;
i
++)
{
StackTraceElement
ste
=
stacktrace
[
i
];
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
.
print
(
"\""
+
ti
.
getThreadName
()
+
"\""
+
" Id="
+
ti
.
getThreadId
()
+
" in "
+
ti
.
getThreadState
());
if
(
ti
.
getLockName
()
!=
null
)
{
print
.
append
(
" on lock="
+
ti
.
getLockName
());
}
if
(
ti
.
isSuspended
())
{
print
.
append
(
" (suspended)"
);
}
if
(
ti
.
isInNative
())
{
print
.
append
(
" (running in native)"
);
}
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
)
{
print
.
println
(
INDENT
+
"Locked synchronizers: count = "
+
locks
.
length
);
for
(
LockInfo
li
:
locks
)
{
print
.
println
(
INDENT
+
" - "
+
li
);
}
if
(
mvtableWaitingForLock
!=
null
)
{
print
.
println
(
INDENT
+
"Waiting for table: "
+
mvtableWaitingForLock
);
}
if
(
mvtableExclusiveLocks
!=
null
)
{
print
.
println
(
INDENT
+
"Exclusive table locks: count = "
+
mvtableExclusiveLocks
.
size
());
for
(
String
name
:
mvtableExclusiveLocks
)
{
print
.
println
(
INDENT
+
" - "
+
name
);
}
}
if
(
mvtableSharedLocksMap
!=
null
)
{
print
.
println
(
INDENT
+
"Shared table locks: count = "
+
mvtableSharedLocksMap
.
size
());
for
(
String
name
:
mvtableSharedLocksMap
)
{
print
.
println
(
INDENT
+
" - "
+
name
);
}
}
print
.
println
();
}
public
class
ThreadDeadlockDetector
{
private
static
final
String
INDENT
=
" "
;
private
static
ThreadDeadlockDetector
detector
;
private
final
ThreadMXBean
tmbean
;
// a daemon thread
private
final
Timer
threadCheck
=
new
Timer
(
"ThreadDeadlockDetector"
,
true
);
private
ThreadDeadlockDetector
()
{
this
.
tmbean
=
ManagementFactory
.
getThreadMXBean
();
// delay: 10 ms
// period: 10000 ms (100 seconds)
threadCheck
.
schedule
(
new
TimerTask
()
{
@Override
public
void
run
()
{
checkForDeadlocks
();
}
},
10
,
10000
);
}
public
static
synchronized
void
init
()
{
if
(
detector
==
null
)
{
detector
=
new
ThreadDeadlockDetector
();
}
}
/**
* Checks if any threads are deadlocked. If any, print the thread dump information.
*/
void
checkForDeadlocks
()
{
long
[]
tids
=
tmbean
.
findDeadlockedThreads
();
if
(
tids
==
null
)
{
return
;
}
final
StringWriter
stringWriter
=
new
StringWriter
();
final
PrintWriter
print
=
new
PrintWriter
(
stringWriter
);
print
.
println
(
"ThreadDeadlockDetector - deadlock found :"
);
final
ThreadInfo
[]
infos
=
tmbean
.
getThreadInfo
(
tids
,
true
,
true
);
final
HashMap
<
Long
,
String
>
mvtableWaitingForLockMap
=
MVTable
.
WAITING_FOR_LOCK
.
getSnapshotOfAllThreads
();
final
HashMap
<
Long
,
ArrayList
<
String
>>
mvtableExclusiveLocksMap
=
MVTable
.
EXCLUSIVE_LOCKS
.
getSnapshotOfAllThreads
();
final
HashMap
<
Long
,
ArrayList
<
String
>>
mvtableSharedLocksMap
=
MVTable
.
SHARED_LOCKS
.
getSnapshotOfAllThreads
();
for
(
ThreadInfo
ti
:
infos
)
{
printThreadInfo
(
print
,
ti
);
printLockInfo
(
print
,
ti
.
getLockedSynchronizers
(),
mvtableWaitingForLockMap
.
get
(
ti
.
getThreadId
()),
mvtableExclusiveLocksMap
.
get
(
ti
.
getThreadId
()),
mvtableSharedLocksMap
.
get
(
ti
.
getThreadId
()));
}
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.
System
.
out
.
println
(
stringWriter
.
getBuffer
());
}
private
static
void
printThreadInfo
(
PrintWriter
print
,
ThreadInfo
ti
)
{
// print thread information
printThread
(
print
,
ti
);
// print stack trace with locks
StackTraceElement
[]
stacktrace
=
ti
.
getStackTrace
();
MonitorInfo
[]
monitors
=
ti
.
getLockedMonitors
();
for
(
int
i
=
0
;
i
<
stacktrace
.
length
;
i
++)
{
StackTraceElement
ste
=
stacktrace
[
i
];
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
.
print
(
"\""
+
ti
.
getThreadName
()
+
"\""
+
" Id="
+
ti
.
getThreadId
()
+
" in "
+
ti
.
getThreadState
());
if
(
ti
.
getLockName
()
!=
null
)
{
print
.
append
(
" on lock="
+
ti
.
getLockName
());
}
if
(
ti
.
isSuspended
())
{
print
.
append
(
" (suspended)"
);
}
if
(
ti
.
isInNative
())
{
print
.
append
(
" (running in native)"
);
}
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
)
{
print
.
println
(
INDENT
+
"Locked synchronizers: count = "
+
locks
.
length
);
for
(
LockInfo
li
:
locks
)
{
print
.
println
(
INDENT
+
" - "
+
li
);
}
if
(
mvtableWaitingForLock
!=
null
)
{
print
.
println
(
INDENT
+
"Waiting for table: "
+
mvtableWaitingForLock
);
}
if
(
mvtableExclusiveLocks
!=
null
)
{
print
.
println
(
INDENT
+
"Exclusive table locks: count = "
+
mvtableExclusiveLocks
.
size
());
for
(
String
name
:
mvtableExclusiveLocks
)
{
print
.
println
(
INDENT
+
" - "
+
name
);
}
}
if
(
mvtableSharedLocksMap
!=
null
)
{
print
.
println
(
INDENT
+
"Shared table locks: count = "
+
mvtableSharedLocksMap
.
size
());
for
(
String
name
:
mvtableSharedLocksMap
)
{
print
.
println
(
INDENT
+
" - "
+
name
);
}
}
print
.
println
();
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论