Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
74b4db9a
Unverified
提交
74b4db9a
authored
6月 04, 2018
作者:
Andrei Tokar
提交者:
GitHub
6月 04, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1171 from h2database/verval-ext
Introduce last commited value into a VersionedValue
上级
4801c8ba
5b8df111
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
136 行增加
和
69 行删除
+136
-69
CommitDecisionMaker.java
h2/src/main/org/h2/mvstore/tx/CommitDecisionMaker.java
+1
-1
TransactionMap.java
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
+35
-34
TxDecisionMaker.java
h2/src/main/org/h2/mvstore/tx/TxDecisionMaker.java
+5
-3
VersionedValue.java
h2/src/main/org/h2/mvstore/tx/VersionedValue.java
+95
-31
没有找到文件。
h2/src/main/org/h2/mvstore/tx/CommitDecisionMaker.java
浏览文件 @
74b4db9a
...
@@ -49,7 +49,7 @@ final class CommitDecisionMaker extends MVMap.DecisionMaker<VersionedValue> {
...
@@ -49,7 +49,7 @@ final class CommitDecisionMaker extends MVMap.DecisionMaker<VersionedValue> {
public
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
public
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
assert
decision
==
MVMap
.
Decision
.
PUT
;
assert
decision
==
MVMap
.
Decision
.
PUT
;
assert
existingValue
!=
null
;
assert
existingValue
!=
null
;
return
new
VersionedValue
(
0L
,
existingValue
.
value
);
return
VersionedValue
.
getInstance
(
existingValue
.
value
);
}
}
@Override
@Override
...
...
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
浏览文件 @
74b4db9a
...
@@ -226,7 +226,7 @@ public class TransactionMap<K, V> {
...
@@ -226,7 +226,7 @@ public class TransactionMap<K, V> {
*/
*/
public
V
putCommitted
(
K
key
,
V
value
)
{
public
V
putCommitted
(
K
key
,
V
value
)
{
DataUtils
.
checkArgument
(
value
!=
null
,
"The value may not be null"
);
DataUtils
.
checkArgument
(
value
!=
null
,
"The value may not be null"
);
VersionedValue
newValue
=
new
VersionedValue
(
0L
,
value
);
VersionedValue
newValue
=
VersionedValue
.
getInstance
(
value
);
VersionedValue
oldValue
=
map
.
put
(
key
,
newValue
);
VersionedValue
oldValue
=
map
.
put
(
key
,
newValue
);
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
V
result
=
(
V
)
(
oldValue
==
null
?
null
:
oldValue
.
value
);
V
result
=
(
V
)
(
oldValue
==
null
?
null
:
oldValue
.
value
);
...
@@ -442,27 +442,18 @@ public class TransactionMap<K, V> {
...
@@ -442,27 +442,18 @@ public class TransactionMap<K, V> {
*/
*/
VersionedValue
getValue
(
Page
root
,
Page
undoRoot
,
K
key
,
long
maxLog
,
VersionedValue
getValue
(
Page
root
,
Page
undoRoot
,
K
key
,
long
maxLog
,
VersionedValue
data
,
BitSet
committingTransactions
)
{
VersionedValue
data
,
BitSet
committingTransactions
)
{
// TODO: This method is overly complicated and has a bunch of extra parameters
// TODO: to support maxLog feature, which is not really used by H2
long
id
;
int
tx
;
while
(
true
)
{
while
(
true
)
{
if
(
data
==
null
)
{
// If value doesn't exist or it was deleted by a committed transaction,
// doesn't exist or deleted by a committed transaction
// or if value is a committed one, just return it.
return
null
;
if
(
data
!=
null
&&
}
(
id
=
data
.
getOperationId
())
!=
0
)
{
long
id
=
data
.
operationId
;
if
((
tx
=
TransactionStore
.
getTransactionId
(
id
))
==
transaction
.
transactionId
)
{
if
(
id
==
0
)
{
// current value comes from our transaction
// it is committed
if
(
TransactionStore
.
getLogId
(
id
)
>=
maxLog
)
{
return
data
;
}
int
tx
=
TransactionStore
.
getTransactionId
(
id
);
if
(
tx
==
transaction
.
transactionId
)
{
// added by this transaction
if
(
TransactionStore
.
getLogId
(
id
)
<
maxLog
)
{
return
data
;
}
}
else
if
(
committingTransactions
.
get
(
tx
))
{
// transaction which made a change is committed by now
return
data
;
}
// get the value before the uncommitted transaction
Object
d
[]
=
transaction
.
store
.
undoLog
.
get
(
undoRoot
,
id
);
Object
d
[]
=
transaction
.
store
.
undoLog
.
get
(
undoRoot
,
id
);
if
(
d
==
null
)
{
if
(
d
==
null
)
{
if
(
transaction
.
store
.
store
.
isReadOnly
())
{
if
(
transaction
.
store
.
store
.
isReadOnly
())
{
...
@@ -477,6 +468,16 @@ public class TransactionMap<K, V> {
...
@@ -477,6 +468,16 @@ public class TransactionMap<K, V> {
}
else
{
}
else
{
data
=
(
VersionedValue
)
d
[
2
];
data
=
(
VersionedValue
)
d
[
2
];
}
}
continue
;
}
}
else
if
(!
committingTransactions
.
get
(
tx
))
{
// current value comes from another uncommitted transaction
// take committed value instead
Object
committedValue
=
data
.
getCommittedValue
();
data
=
committedValue
==
null
?
null
:
VersionedValue
.
getInstance
(
committedValue
);
}
}
return
data
;
}
}
}
}
...
...
h2/src/main/org/h2/mvstore/tx/TxDecisionMaker.java
浏览文件 @
74b4db9a
...
@@ -46,7 +46,7 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
...
@@ -46,7 +46,7 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
// We assume that we are looking at the final value for this transaction,
// We assume that we are looking at the final value for this transaction,
// and if it's not the case, then it will fail later,
// and if it's not the case, then it will fail later,
// because a tree root has definitely been changed.
// because a tree root has definitely been changed.
logIt
(
existingValue
.
value
==
null
?
null
:
new
VersionedValue
(
0L
,
existingValue
.
value
));
logIt
(
existingValue
.
value
==
null
?
null
:
VersionedValue
.
getInstance
(
existingValue
.
value
));
decision
=
MVMap
.
Decision
.
PUT
;
decision
=
MVMap
.
Decision
.
PUT
;
}
else
if
(
fetchTransaction
(
blockingId
)
==
null
)
{
}
else
if
(
fetchTransaction
(
blockingId
)
==
null
)
{
// condition above means transaction has been committed/rplled back and closed by now
// condition above means transaction has been committed/rplled back and closed by now
...
@@ -113,7 +113,8 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
...
@@ -113,7 +113,8 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Override
@Override
public
final
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
public
final
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
return
new
VersionedValue
(
undoKey
,
value
);
return
VersionedValue
.
getInstance
(
undoKey
,
value
,
existingValue
==
null
?
null
:
existingValue
.
getCommittedValue
());
}
}
}
}
...
@@ -171,7 +172,8 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
...
@@ -171,7 +172,8 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Override
@Override
public
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
public
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
return
new
VersionedValue
(
undoKey
,
existingValue
==
null
?
null
:
existingValue
.
value
);
assert
existingValue
!=
null
;
// otherwise, what's there to lock?
return
VersionedValue
.
getInstance
(
undoKey
,
existingValue
.
value
,
existingValue
.
getCommittedValue
());
}
}
}
}
}
}
h2/src/main/org/h2/mvstore/tx/VersionedValue.java
浏览文件 @
74b4db9a
...
@@ -5,44 +5,90 @@
...
@@ -5,44 +5,90 @@
*/
*/
package
org
.
h2
.
mvstore
.
tx
;
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.engine.Constants
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.WriteBuffer
;
import
org.h2.mvstore.WriteBuffer
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.mvstore.type.DataType
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
/**
/**
* A versioned value (possibly null). It contains a pointer to the old
* A versioned value (possibly null).
* value, and the value itself.
* It contains current value and latest committed value if current one is uncommitted.
* Also for uncommitted values it contains operationId - a combination of
* transactionId and logId.
*/
*/
public
class
VersionedValue
{
public
class
VersionedValue
{
public
static
final
VersionedValue
DUMMY
=
new
VersionedValue
(
0L
,
new
Object
());
public
static
final
VersionedValue
DUMMY
=
new
VersionedValue
(
new
Object
());
/**
/**
* The operation id.
* The current value.
*/
final
long
operationId
;
/**
* The value.
*/
*/
public
final
Object
value
;
public
final
Object
value
;
VersionedValue
(
long
operationId
,
Object
value
)
{
static
VersionedValue
getInstance
(
Object
value
)
{
this
.
operationId
=
operationId
;
assert
value
!=
null
;
return
new
VersionedValue
(
value
);
}
public
static
VersionedValue
getInstance
(
long
operationId
,
Object
value
,
Object
committedValue
)
{
return
new
Uncommitted
(
operationId
,
value
,
committedValue
);
}
private
VersionedValue
(
Object
value
)
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
public
boolean
isCommitted
()
{
return
true
;
}
public
long
getOperationId
()
{
return
0L
;
}
public
Object
getCommittedValue
()
{
return
value
;
}
@Override
public
String
toString
()
{
return
String
.
valueOf
(
value
);
}
private
static
class
Uncommitted
extends
VersionedValue
{
private
final
long
operationId
;
private
final
Object
committedValue
;
Uncommitted
(
long
operationId
,
Object
value
,
Object
committedValue
)
{
super
(
value
);
assert
operationId
!=
0
;
this
.
operationId
=
operationId
;
this
.
committedValue
=
committedValue
;
}
@Override
public
boolean
isCommitted
()
{
return
false
;
}
@Override
public
long
getOperationId
()
{
public
long
getOperationId
()
{
return
operationId
;
return
operationId
;
}
}
@Override
public
Object
getCommittedValue
()
{
return
committedValue
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
value
+
(
operationId
==
0
?
""
:
(
return
super
.
toString
()
+
"
"
+
" "
+
TransactionStore
.
getTransactionId
(
operationId
)
+
"/
"
+
TransactionStore
.
getTransactionId
(
operationId
)
+
"/"
+
TransactionStore
.
getLogId
(
operationId
)
+
" "
+
committedValue
;
TransactionStore
.
getLogId
(
operationId
)));
}
}
}
/**
/**
...
@@ -58,8 +104,18 @@ public class VersionedValue {
...
@@ -58,8 +104,18 @@ public class VersionedValue {
@Override
@Override
public
int
getMemory
(
Object
obj
)
{
public
int
getMemory
(
Object
obj
)
{
if
(
obj
==
null
)
return
0
;
VersionedValue
v
=
(
VersionedValue
)
obj
;
VersionedValue
v
=
(
VersionedValue
)
obj
;
return
valueType
.
getMemory
(
v
.
value
)
+
8
;
int
res
=
Constants
.
MEMORY_OBJECT
+
8
+
2
*
Constants
.
MEMORY_POINTER
+
getValMemory
(
v
.
value
);
if
(
v
.
getOperationId
()
!=
0
)
{
res
+=
getValMemory
(
v
.
getCommittedValue
());
}
return
res
;
}
private
int
getValMemory
(
Object
obj
)
{
return
obj
==
null
?
0
:
valueType
.
getMemory
(
obj
);
}
}
@Override
@Override
...
@@ -69,7 +125,7 @@ public class VersionedValue {
...
@@ -69,7 +125,7 @@ public class VersionedValue {
}
}
VersionedValue
a
=
(
VersionedValue
)
aObj
;
VersionedValue
a
=
(
VersionedValue
)
aObj
;
VersionedValue
b
=
(
VersionedValue
)
bObj
;
VersionedValue
b
=
(
VersionedValue
)
bObj
;
long
comp
=
a
.
operationId
-
b
.
operationId
;
long
comp
=
a
.
getOperationId
()
-
b
.
getOperationId
()
;
if
(
comp
==
0
)
{
if
(
comp
==
0
)
{
return
valueType
.
compare
(
a
.
value
,
b
.
value
);
return
valueType
.
compare
(
a
.
value
,
b
.
value
);
}
}
...
@@ -81,7 +137,7 @@ public class VersionedValue {
...
@@ -81,7 +137,7 @@ public class VersionedValue {
if
(
buff
.
get
()
==
0
)
{
if
(
buff
.
get
()
==
0
)
{
// fast path (no op ids or null entries)
// fast path (no op ids or null entries)
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
obj
[
i
]
=
new
VersionedValue
(
0L
,
valueType
.
read
(
buff
));
obj
[
i
]
=
new
VersionedValue
(
valueType
.
read
(
buff
));
}
}
}
else
{
}
else
{
// slow path (some entries may be null)
// slow path (some entries may be null)
...
@@ -94,13 +150,14 @@ public class VersionedValue {
...
@@ -94,13 +150,14 @@ public class VersionedValue {
@Override
@Override
public
Object
read
(
ByteBuffer
buff
)
{
public
Object
read
(
ByteBuffer
buff
)
{
long
operationId
=
DataUtils
.
readVarLong
(
buff
);
long
operationId
=
DataUtils
.
readVarLong
(
buff
);
Object
value
;
if
(
operationId
==
0
)
{
if
(
buff
.
get
()
==
1
)
{
return
new
VersionedValue
(
valueType
.
read
(
buff
));
value
=
valueType
.
read
(
buff
);
}
else
{
}
else
{
value
=
null
;
byte
flags
=
buff
.
get
();
Object
value
=
(
flags
&
1
)
!=
0
?
valueType
.
read
(
buff
)
:
null
;
Object
committedValue
=
(
flags
&
2
)
!=
0
?
valueType
.
read
(
buff
)
:
null
;
return
new
Uncommitted
(
operationId
,
value
,
committedValue
);
}
}
return
new
VersionedValue
(
operationId
,
value
);
}
}
@Override
@Override
...
@@ -108,7 +165,7 @@ public class VersionedValue {
...
@@ -108,7 +165,7 @@ public class VersionedValue {
boolean
fastPath
=
true
;
boolean
fastPath
=
true
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
VersionedValue
v
=
(
VersionedValue
)
obj
[
i
];
VersionedValue
v
=
(
VersionedValue
)
obj
[
i
];
if
(
v
.
operationId
!=
0
||
v
.
value
==
null
)
{
if
(
v
.
getOperationId
()
!=
0
||
v
.
value
==
null
)
{
fastPath
=
false
;
fastPath
=
false
;
}
}
}
}
...
@@ -131,14 +188,21 @@ public class VersionedValue {
...
@@ -131,14 +188,21 @@ public class VersionedValue {
@Override
@Override
public
void
write
(
WriteBuffer
buff
,
Object
obj
)
{
public
void
write
(
WriteBuffer
buff
,
Object
obj
)
{
VersionedValue
v
=
(
VersionedValue
)
obj
;
VersionedValue
v
=
(
VersionedValue
)
obj
;
buff
.
putVarLong
(
v
.
operationId
);
long
operationId
=
v
.
getOperationId
();
if
(
v
.
value
==
null
)
{
buff
.
putVarLong
(
operationId
);
buff
.
put
((
byte
)
0
);
if
(
operationId
==
0
)
{
valueType
.
write
(
buff
,
v
.
value
);
}
else
{
}
else
{
buff
.
put
((
byte
)
1
);
Object
committedValue
=
v
.
getCommittedValue
();
int
flags
=
(
v
.
value
==
null
?
0
:
1
)
|
(
committedValue
==
null
?
0
:
2
);
buff
.
put
((
byte
)
flags
);
if
(
v
.
value
!=
null
)
{
valueType
.
write
(
buff
,
v
.
value
);
valueType
.
write
(
buff
,
v
.
value
);
}
}
if
(
committedValue
!=
null
)
{
valueType
.
write
(
buff
,
committedValue
);
}
}
}
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论