Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b56c16ef
提交
b56c16ef
authored
5月 17, 2018
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor refactoring between Transaction and TransactionStore
上级
d5478abd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
32 行删除
+58
-32
Transaction.java
h2/src/main/org/h2/mvstore/tx/Transaction.java
+43
-9
TransactionStore.java
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
+15
-23
没有找到文件。
h2/src/main/org/h2/mvstore/tx/Transaction.java
浏览文件 @
b56c16ef
...
...
@@ -230,7 +230,7 @@ public class Transaction {
* @param key the key
* @param oldValue the old value
*/
void
log
(
int
mapId
,
Object
key
,
VersionedValue
oldValue
)
{
long
log
(
int
mapId
,
Object
key
,
VersionedValue
oldValue
)
{
long
currentState
=
statusAndLogId
.
getAndIncrement
();
long
logId
=
getLogId
(
currentState
);
if
(
logId
>=
LOG_ID_LIMIT
)
{
...
...
@@ -239,7 +239,10 @@ public class Transaction {
"Transaction {0} has too many changes"
,
transactionId
);
}
store
.
log
(
this
,
logId
,
mapId
,
key
,
oldValue
);
int
currentStatus
=
getStatus
(
currentState
);
checkOpen
(
currentStatus
);
long
undoKey
=
store
.
addUndoLogRecord
(
transactionId
,
logId
,
new
Object
[]{
mapId
,
key
,
oldValue
});
return
undoKey
;
}
/**
...
...
@@ -254,7 +257,9 @@ public class Transaction {
"Transaction {0} has internal error"
,
transactionId
);
}
store
.
logUndo
(
this
,
logId
);
int
currentStatus
=
getStatus
(
currentState
);
checkOpen
(
currentStatus
);
store
.
removeUndoLogRecord
(
transactionId
,
logId
);
}
/**
...
...
@@ -313,11 +318,29 @@ public class Transaction {
*/
public
void
commit
()
{
assert
store
.
openTransactions
.
get
().
get
(
transactionId
);
long
state
=
setStatus
(
STATUS_COMMITTING
);
long
logId
=
Transaction
.
getLogId
(
state
);
boolean
hasChanges
=
hasChanges
(
state
);
store
.
commit
(
this
,
logId
,
hasChanges
);
Throwable
ex
=
null
;
boolean
hasChanges
=
false
;
try
{
long
state
=
setStatus
(
STATUS_COMMITTING
);
long
logId
=
getLogId
(
state
);
hasChanges
=
hasChanges
(
state
);
if
(
hasChanges
)
{
store
.
commit
(
this
,
logId
);
}
}
catch
(
Throwable
e
)
{
ex
=
e
;
throw
e
;
}
finally
{
try
{
store
.
endTransaction
(
this
,
hasChanges
);
}
catch
(
Throwable
e
)
{
if
(
ex
==
null
)
{
throw
e
;
}
else
{
ex
.
addSuppressed
(
e
);
}
}
}
}
/**
...
...
@@ -376,13 +399,24 @@ public class Transaction {
return
getLogId
(
statusAndLogId
.
get
());
}
/**
* Check whether this transaction is open.
*/
private
void
checkOpen
(
int
status
)
{
if
(
status
!=
STATUS_OPEN
)
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_TRANSACTION_ILLEGAL_STATE
,
"Transaction {0} has status {1}, not open"
,
transactionId
,
status
);
}
}
/**
* Check whether this transaction is open or prepared.
*/
void
checkNotClosed
()
{
if
(
getStatus
()
==
STATUS_CLOSED
)
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_CLOSED
,
"Transaction
is closed"
);
DataUtils
.
ERROR_CLOSED
,
"Transaction
{0} is closed"
,
transactionId
);
}
}
...
...
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
浏览文件 @
b56c16ef
...
...
@@ -366,18 +366,14 @@ public class TransactionStore {
}
/**
*
Log an
entry.
*
Add an undoLog
entry.
*
* @param t the transaction
* @param logId the log id
* @param mapId the map id
* @param key the key
* @param oldValue the old value
*/
long
log
(
Transaction
t
,
long
logId
,
int
mapId
,
Object
key
,
Object
oldValue
)
{
Long
undoKey
=
getOperationId
(
t
.
getId
(),
logId
);
Object
[]
log
=
{
mapId
,
key
,
oldValue
};
* @param transactionId id of the transaction
* @param logId sequential number of the log record within transaction
* @param undoLogRecord Object[]
*/
long
addUndoLogRecord
(
int
transactionId
,
long
logId
,
Object
[]
undoLogRecord
)
{
Long
undoKey
=
getOperationId
(
transactionId
,
logId
);
rwLock
.
writeLock
().
lock
();
try
{
if
(
logId
==
0
)
{
...
...
@@ -386,10 +382,10 @@ public class TransactionStore {
DataUtils
.
ERROR_TOO_MANY_OPEN_TRANSACTIONS
,
"An old transaction with the same id "
+
"is still open: {0}"
,
t
.
getId
()
);
t
ransactionId
);
}
}
undoLog
.
put
(
undoKey
,
log
);
undoLog
.
put
(
undoKey
,
undoLogRecord
);
}
finally
{
rwLock
.
writeLock
().
unlock
();
}
...
...
@@ -399,11 +395,11 @@ public class TransactionStore {
/**
* Remove a log entry.
*
* @param t the transaction
* @param logId
the log id
* @param t
ransactionId id of
the transaction
* @param logId
sequential number of the log record within transaction
*/
public
void
logUndo
(
Transaction
t
,
long
logId
)
{
Long
undoKey
=
getOperationId
(
t
.
getId
()
,
logId
);
public
void
removeUndoLogRecord
(
int
transactionId
,
long
logId
)
{
Long
undoKey
=
getOperationId
(
t
ransactionId
,
logId
);
rwLock
.
writeLock
().
lock
();
try
{
Object
[]
old
=
undoLog
.
remove
(
undoKey
);
...
...
@@ -411,7 +407,7 @@ public class TransactionStore {
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_TRANSACTION_ILLEGAL_STATE
,
"Transaction {0} was concurrently rolled back"
,
t
.
getId
()
);
t
ransactionId
);
}
}
finally
{
rwLock
.
writeLock
().
unlock
();
...
...
@@ -435,11 +431,8 @@ public class TransactionStore {
*
* @param t the transaction
* @param maxLogId the last log id
* @param hasChanges true if there were updates within specified
* transaction (even fully rolled back),
* false if just data access
*/
void
commit
(
Transaction
t
,
long
maxLogId
,
boolean
hasChanges
)
{
void
commit
(
Transaction
t
,
long
maxLogId
)
{
if
(
store
.
isClosed
())
{
return
;
}
...
...
@@ -487,7 +480,6 @@ public class TransactionStore {
rwLock
.
writeLock
().
unlock
();
flipCommittingTransactionsBit
(
transactionId
,
false
);
}
endTransaction
(
t
,
hasChanges
);
}
private
void
flipCommittingTransactionsBit
(
int
transactionId
,
boolean
flag
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论