Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7f774520
提交
7f774520
authored
4月 11, 2018
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce overflow bit in tx state and some bit manipulation constants for readability
上级
8e29ff1f
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
46 行增加
和
16 行删除
+46
-16
DataUtils.java
h2/src/main/org/h2/mvstore/DataUtils.java
+5
-0
Transaction.java
h2/src/main/org/h2/mvstore/tx/Transaction.java
+33
-11
TransactionStore.java
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
+8
-5
没有找到文件。
h2/src/main/org/h2/mvstore/DataUtils.java
浏览文件 @
7f774520
...
...
@@ -96,6 +96,11 @@ public final class DataUtils {
*/
public
static
final
int
ERROR_TRANSACTION_ILLEGAL_STATE
=
103
;
/**
* The transaction contains too many changes.
*/
public
static
final
int
ERROR_TRANSACTION_TOO_BIG
=
104
;
/**
* The type for leaf page.
*/
...
...
h2/src/main/org/h2/mvstore/tx/Transaction.java
浏览文件 @
7f774520
...
...
@@ -50,7 +50,7 @@ public class Transaction {
* This transaction's id can not be re-used until all the above is completed
* and transaction is closed.
*/
p
ublic
static
final
int
STATUS_COMMITTED
=
4
;
p
rivate
static
final
int
STATUS_COMMITTED
=
4
;
/**
* The status of a transaction that currently in a process of rolling back
...
...
@@ -68,6 +68,12 @@ public class Transaction {
"CLOSED"
,
"OPEN"
,
"PREPARED"
,
"COMMITTING"
,
"COMMITTED"
,
"ROLLING_BACK"
,
"ROLLED_BACK"
};
static
final
int
LOG_ID_BITS
=
40
;
private
static
final
int
LOG_ID_BITS1
=
LOG_ID_BITS
+
1
;
private
static
final
long
LOG_ID_MASK
=
(
1L
<<
LOG_ID_BITS
)
-
1
;
private
static
final
int
STATUS_BITS
=
4
;
private
static
final
int
STATUS_MASK
=
(
1
<<
STATUS_BITS
)
-
1
;
/**
* The transaction store.
...
...
@@ -81,8 +87,9 @@ public class Transaction {
/*
* Transation state is an atomic composite field:
* bit 44 : flag whether transaction had rollback(s)
* bits 42-40 : status
* bit 45 : flag whether transaction had rollback(s)
* bits 44-41 : status
* bits 40 : overflow control bit, always 0
* bits 39-0 : log id of the last entry in the undo log map
*/
private
final
AtomicLong
statusAndLogId
;
...
...
@@ -202,6 +209,12 @@ public class Transaction {
void
log
(
int
mapId
,
Object
key
,
VersionedValue
oldValue
)
{
long
currentState
=
statusAndLogId
.
getAndIncrement
();
long
logId
=
getLogId
(
currentState
);
if
(
logId
>
LOG_ID_MASK
)
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_TRANSACTION_TOO_BIG
,
"Transaction {0} has too many changes"
,
transactionId
);
}
store
.
log
(
this
,
logId
,
mapId
,
key
,
oldValue
);
}
...
...
@@ -211,6 +224,12 @@ public class Transaction {
void
logUndo
()
{
long
currentState
=
statusAndLogId
.
decrementAndGet
();
long
logId
=
getLogId
(
currentState
);
if
(
logId
==
LOG_ID_MASK
)
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_TRANSACTION_CORRUPT
,
"Transaction {0} has internal error"
,
transactionId
);
}
store
.
logUndo
(
this
,
logId
);
}
...
...
@@ -269,7 +288,7 @@ public class Transaction {
* Commit the transaction. Afterwards, this transaction is closed.
*/
public
void
commit
()
{
long
state
=
setStatus
(
Transaction
.
STATUS_COMMITTING
);
long
state
=
setStatus
(
STATUS_COMMITTING
);
long
logId
=
Transaction
.
getLogId
(
state
);
int
oldStatus
=
Transaction
.
getStatus
(
state
);
store
.
commit
(
this
,
logId
,
oldStatus
);
...
...
@@ -357,16 +376,16 @@ public class Transaction {
}
p
ublic
static
int
getStatus
(
long
state
)
{
return
(
int
)(
state
>>>
40
)
&
15
;
p
rivate
static
int
getStatus
(
long
state
)
{
return
(
int
)(
state
>>>
LOG_ID_BITS1
)
&
STATUS_MASK
;
}
p
ublic
static
long
getLogId
(
long
state
)
{
return
state
&
((
1L
<<
40
)
-
1
)
;
p
rivate
static
long
getLogId
(
long
state
)
{
return
state
&
LOG_ID_MASK
;
}
private
static
boolean
hasRollback
(
long
state
)
{
return
(
state
&
(
1L
<<
44
))
!=
0
;
return
(
state
&
(
1L
<<
(
STATUS_BITS
+
LOG_ID_BITS1
)
))
!=
0
;
}
private
static
boolean
hasChanges
(
long
state
)
{
...
...
@@ -374,9 +393,12 @@ public class Transaction {
}
private
static
long
composeState
(
int
status
,
long
logId
,
boolean
hasRollback
)
{
assert
(
logId
&
~
LOG_ID_MASK
)
==
0
:
logId
;
assert
(
status
&
~
STATUS_MASK
)
==
0
:
status
;
if
(
hasRollback
)
{
status
|=
1
6
;
status
|=
1
<<
STATUS_BITS
;
}
return
((
long
)
status
<<
40
)
|
logId
;
return
((
long
)
status
<<
LOG_ID_BITS1
)
|
logId
;
}
}
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
浏览文件 @
7f774520
...
...
@@ -156,6 +156,9 @@ public class TransactionStore {
return
store
.
hasMap
(
name
);
}
private
static
final
int
LOG_ID_BITS
=
Transaction
.
LOG_ID_BITS
;
private
static
final
long
LOG_ID_MASK
=
(
1L
<<
LOG_ID_BITS
)
-
1
;
/**
* Combine the transaction id and the log id to an operation id.
*
...
...
@@ -164,11 +167,11 @@ public class TransactionStore {
* @return the operation id
*/
static
long
getOperationId
(
int
transactionId
,
long
logId
)
{
DataUtils
.
checkArgument
(
transactionId
>=
0
&&
transactionId
<
(
1
<<
24
),
DataUtils
.
checkArgument
(
transactionId
>=
0
&&
transactionId
<
(
1
<<
(
64
-
LOG_ID_BITS
)
),
"Transaction id out of range: {0}"
,
transactionId
);
DataUtils
.
checkArgument
(
logId
>=
0
&&
logId
<
(
1L
<<
40
)
,
DataUtils
.
checkArgument
(
logId
>=
0
&&
logId
<
=
LOG_ID_MASK
,
"Transaction log id out of range: {0}"
,
logId
);
return
((
long
)
transactionId
<<
40
)
|
logId
;
return
((
long
)
transactionId
<<
LOG_ID_BITS
)
|
logId
;
}
/**
...
...
@@ -178,7 +181,7 @@ public class TransactionStore {
* @return the transaction id
*/
static
int
getTransactionId
(
long
operationId
)
{
return
(
int
)
(
operationId
>>>
40
);
return
(
int
)
(
operationId
>>>
LOG_ID_BITS
);
}
/**
...
...
@@ -188,7 +191,7 @@ public class TransactionStore {
* @return the log id
*/
static
long
getLogId
(
long
operationId
)
{
return
operationId
&
((
1L
<<
40
)
-
1
)
;
return
operationId
&
LOG_ID_MASK
;
}
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论