Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8e2b0b24
提交
8e2b0b24
authored
9月 06, 2016
作者:
Nick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Synchronized on database when remove from lockSharedSessions, add test
上级
d78c3fbe
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
99 行增加
和
11 行删除
+99
-11
Session.java
h2/src/main/org/h2/engine/Session.java
+5
-7
RegularTable.java
h2/src/main/org/h2/table/RegularTable.java
+3
-3
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+6
-1
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+5
-0
TestReleaseSelectLock.java
h2/src/test/org/h2/test/synth/TestReleaseSelectLock.java
+80
-0
没有找到文件。
h2/src/main/org/h2/engine/Session.java
浏览文件 @
8e2b0b24
...
...
@@ -923,14 +923,12 @@ public class Session extends SessionWithState {
}
}
if
(
locks
.
size
()
>
0
)
{
synchronized
(
database
)
{
// don't use the enhanced for loop to save memory
for
(
int
i
=
0
,
size
=
locks
.
size
();
i
<
size
;
i
++)
{
Table
t
=
locks
.
get
(
i
);
t
.
unlock
(
this
);
}
locks
.
clear
();
// don't use the enhanced for loop to save memory
for
(
int
i
=
0
,
size
=
locks
.
size
();
i
<
size
;
i
++)
{
Table
t
=
locks
.
get
(
i
);
t
.
unlock
(
this
);
}
locks
.
clear
();
}
savepoints
=
null
;
sessionStateChanged
=
true
;
...
...
h2/src/main/org/h2/table/RegularTable.java
浏览文件 @
8e2b0b24
...
...
@@ -670,10 +670,10 @@ public class RegularTable extends TableBase {
if
(
lockExclusiveSession
==
s
)
{
lockExclusiveSession
=
null
;
}
if
(
lockSharedSessions
.
size
()
>
0
)
{
lockSharedSessions
.
remove
(
s
);
}
synchronized
(
database
)
{
if
(
lockSharedSessions
.
size
()
>
0
)
{
lockSharedSessions
.
remove
(
s
);
}
if
(!
waitingSessions
.
isEmpty
())
{
database
.
notifyAll
();
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
8e2b0b24
...
...
@@ -266,7 +266,7 @@ java org.h2.test.TestAll timer
/**
* Whether the MVStore storage is used.
*/
public
final
boolean
mvStore
=
Constants
.
VERSION_MINOR
>=
4
;
public
boolean
mvStore
=
Constants
.
VERSION_MINOR
>=
4
;
/**
* If the test should run with many rows.
...
...
@@ -298,6 +298,11 @@ java org.h2.test.TestAll timer
*/
public
boolean
mvcc
=
mvStore
;
/**
* If the multi-threaded mode should be used.
*/
public
boolean
multiThreaded
;
/**
* The cipher to use (null for unencrypted).
*/
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
8e2b0b24
...
...
@@ -280,6 +280,8 @@ public abstract class TestBase {
if
(
config
.
mvStore
)
{
url
=
addOption
(
url
,
"MV_STORE"
,
"true"
);
// url = addOption(url, "MVCC", "true");
}
else
{
url
=
addOption
(
url
,
"MV_STORE"
,
"false"
);
}
if
(!
config
.
memory
)
{
if
(
config
.
smallLog
&&
admin
)
{
...
...
@@ -310,6 +312,9 @@ public abstract class TestBase {
if
(
config
.
mvcc
)
{
url
=
addOption
(
url
,
"MVCC"
,
"TRUE"
);
}
if
(
config
.
multiThreaded
)
{
url
=
addOption
(
url
,
"MULTI_THREADED"
,
"TRUE"
);
}
if
(
config
.
cacheType
!=
null
&&
admin
)
{
url
=
addOption
(
url
,
"CACHE_TYPE"
,
config
.
cacheType
);
}
...
...
h2/src/test/org/h2/test/synth/TestReleaseSelectLock.java
0 → 100644
浏览文件 @
8e2b0b24
package
org
.
h2
.
test
.
synth
;
import
org.h2.test.TestBase
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
java.util.concurrent.CountDownLatch
;
/**
* Tests lock releasing for concurrent select statements
*/
public
class
TestReleaseSelectLock
extends
TestBase
{
private
static
final
String
TEST_DB_NAME
=
"releaseSelectLock"
;
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
Exception
{
config
.
mvStore
=
false
;
config
.
mvcc
=
false
;
config
.
multiThreaded
=
true
;
deleteDb
(
TEST_DB_NAME
);
Connection
conn
=
getConnection
(
TEST_DB_NAME
);
final
Statement
statement
=
conn
.
createStatement
();
statement
.
execute
(
"create table test(id int primary key)"
);
runConcurrentSelects
();
// check that all locks have been released by dropping the test table
statement
.
execute
(
"drop table test"
);
statement
.
close
();
conn
.
close
();
deleteDb
(
TEST_DB_NAME
);
}
private
void
runConcurrentSelects
()
throws
InterruptedException
{
int
tryCount
=
500
;
int
threadsCount
=
getSize
(
2
,
4
);
for
(
int
tryNumber
=
0
;
tryNumber
<
tryCount
;
tryNumber
++)
{
final
CountDownLatch
allFinished
=
new
CountDownLatch
(
threadsCount
);
for
(
int
i
=
0
;
i
<
threadsCount
;
i
++)
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
Connection
conn
=
getConnection
(
TEST_DB_NAME
);
PreparedStatement
stmt
=
conn
.
prepareStatement
(
"select id from test"
);
ResultSet
rs
=
stmt
.
executeQuery
();
while
(
rs
.
next
())
{
rs
.
getInt
(
1
);
}
stmt
.
close
();
conn
.
close
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
allFinished
.
countDown
();
}
}
}).
start
();
}
allFinished
.
await
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论