Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3d206afc
提交
3d206afc
authored
2月 20, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix two-phase commit in MVStore
上级
6bde4590
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
46 行增加
和
5 行删除
+46
-5
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+7
-5
TestTransaction.java
h2/src/test/org/h2/test/db/TestTransaction.java
+39
-0
没有找到文件。
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
3d206afc
...
@@ -344,6 +344,7 @@ public class TransactionStore {
...
@@ -344,6 +344,7 @@ public class TransactionStore {
}
}
// TODO could synchronize on blocks (100 at a time or so)
// TODO could synchronize on blocks (100 at a time or so)
rwLock
.
writeLock
().
lock
();
rwLock
.
writeLock
().
lock
();
int
oldStatus
=
t
.
status
;
try
{
try
{
t
.
setStatus
(
Transaction
.
STATUS_COMMITTING
);
t
.
setStatus
(
Transaction
.
STATUS_COMMITTING
);
for
(
long
logId
=
0
;
logId
<
maxLogId
;
logId
++)
{
for
(
long
logId
=
0
;
logId
<
maxLogId
;
logId
++)
{
...
@@ -383,7 +384,7 @@ public class TransactionStore {
...
@@ -383,7 +384,7 @@ public class TransactionStore {
}
finally
{
}
finally
{
rwLock
.
writeLock
().
unlock
();
rwLock
.
writeLock
().
unlock
();
}
}
endTransaction
(
t
);
endTransaction
(
t
,
oldStatus
);
}
}
/**
/**
...
@@ -467,14 +468,15 @@ public class TransactionStore {
...
@@ -467,14 +468,15 @@ public class TransactionStore {
* End this transaction
* End this transaction
*
*
* @param t the transaction
* @param t the transaction
* @param previous status of this transaction
*/
*/
synchronized
void
endTransaction
(
Transaction
t
)
{
synchronized
void
endTransaction
(
Transaction
t
,
int
oldStatus
)
{
if
(
t
.
getStatus
()
==
Transaction
.
STATUS_PREPARED
)
{
if
(
oldStatus
==
Transaction
.
STATUS_PREPARED
)
{
preparedTransactions
.
remove
(
t
.
getId
());
preparedTransactions
.
remove
(
t
.
getId
());
}
}
t
.
setStatus
(
Transaction
.
STATUS_CLOSED
);
t
.
setStatus
(
Transaction
.
STATUS_CLOSED
);
openTransactions
.
clear
(
t
.
transactionId
);
openTransactions
.
clear
(
t
.
transactionId
);
if
(
store
.
getAutoCommitDelay
()
==
0
)
{
if
(
oldStatus
==
Transaction
.
STATUS_PREPARED
||
store
.
getAutoCommitDelay
()
==
0
)
{
store
.
commit
();
store
.
commit
();
return
;
return
;
}
}
...
@@ -825,7 +827,7 @@ public class TransactionStore {
...
@@ -825,7 +827,7 @@ public class TransactionStore {
public
void
rollback
()
{
public
void
rollback
()
{
checkNotClosed
();
checkNotClosed
();
store
.
rollbackTo
(
this
,
logId
,
0
);
store
.
rollbackTo
(
this
,
logId
,
0
);
store
.
endTransaction
(
this
);
store
.
endTransaction
(
this
,
status
);
}
}
/**
/**
...
...
h2/src/test/org/h2/test/db/TestTransaction.java
浏览文件 @
3d206afc
...
@@ -48,6 +48,7 @@ public class TestTransaction extends TestBase {
...
@@ -48,6 +48,7 @@ public class TestTransaction extends TestBase {
testReferential
();
testReferential
();
testSavepoint
();
testSavepoint
();
testIsolation
();
testIsolation
();
testTwoPhaseCommit
();
deleteDb
(
"transaction"
);
deleteDb
(
"transaction"
);
}
}
...
@@ -543,4 +544,42 @@ public class TestTransaction extends TestBase {
...
@@ -543,4 +544,42 @@ public class TestTransaction extends TestBase {
stat
.
execute
(
sql
);
stat
.
execute
(
sql
);
}
}
private
void
testTwoPhaseCommit
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"transaction2pc"
);
Connection
conn
=
getConnection
(
"transaction2pc"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST (ID INT PRIMARY KEY)"
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES (1)"
);
stat
.
execute
(
"PREPARE COMMIT \"#1\""
);
conn
.
commit
();
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
conn
=
getConnection
(
"transaction2pc"
);
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT TRANSACTION, STATE FROM INFORMATION_SCHEMA.IN_DOUBT"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT ID FROM TEST"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES (2)"
);
stat
.
execute
(
"PREPARE COMMIT \"#2\""
);
conn
.
rollback
();
stat
.
execute
(
"SHUTDOWN IMMEDIATELY"
);
conn
=
getConnection
(
"transaction2pc"
);
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"SELECT TRANSACTION, STATE FROM INFORMATION_SCHEMA.IN_DOUBT"
);
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT ID FROM TEST"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
conn
.
close
();
deleteDb
(
"transaction2pc"
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论