Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
128619d2
提交
128619d2
authored
12月 25, 2018
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
@katzyn suggested: moving classes around to keep client jar small
上级
f66a645a
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
287 行增加
和
243 行删除
+287
-243
Session.java
h2/src/main/org/h2/engine/Session.java
+1
-1
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+3
-2
CommitDecisionMaker.java
h2/src/main/org/h2/mvstore/tx/CommitDecisionMaker.java
+2
-1
RollbackDecisionMaker.java
h2/src/main/org/h2/mvstore/tx/RollbackDecisionMaker.java
+1
-0
Transaction.java
h2/src/main/org/h2/mvstore/tx/Transaction.java
+1
-0
TransactionMap.java
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
+3
-2
TransactionStore.java
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
+4
-3
TxDecisionMaker.java
h2/src/main/org/h2/mvstore/tx/TxDecisionMaker.java
+5
-4
VersionedValue.java
h2/src/main/org/h2/mvstore/tx/VersionedValue.java
+0
-229
VersionedValueCommitted.java
h2/src/main/org/h2/mvstore/tx/VersionedValueCommitted.java
+45
-0
VersionedValueType.java
h2/src/main/org/h2/mvstore/tx/VersionedValueType.java
+132
-0
VersionedValueUncommitted.java
h2/src/main/org/h2/mvstore/tx/VersionedValueUncommitted.java
+54
-0
Value.java
h2/src/main/org/h2/value/Value.java
+0
-1
VersionedValue.java
h2/src/main/org/h2/value/VersionedValue.java
+36
-0
没有找到文件。
h2/src/main/org/h2/engine/Session.java
浏览文件 @
128619d2
...
...
@@ -34,7 +34,7 @@ import org.h2.mvstore.db.MVTable;
import
org.h2.mvstore.db.MVTableEngine
;
import
org.h2.mvstore.tx.Transaction
;
import
org.h2.mvstore.tx.TransactionStore
;
import
org.h2.
mvstore.tx
.VersionedValue
;
import
org.h2.
value
.VersionedValue
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.result.SortOrder
;
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
128619d2
...
...
@@ -28,7 +28,8 @@ import org.h2.mvstore.rtree.MVRTreeMap.RTreeCursor;
import
org.h2.mvstore.rtree.SpatialKey
;
import
org.h2.mvstore.tx.Transaction
;
import
org.h2.mvstore.tx.TransactionMap
;
import
org.h2.mvstore.tx.VersionedValue
;
import
org.h2.mvstore.tx.VersionedValueType
;
import
org.h2.value.VersionedValue
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
...
...
@@ -98,7 +99,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
String
mapName
=
"index."
+
getId
();
ValueDataType
vt
=
new
ValueDataType
(
db
,
null
);
VersionedValue
.
Type
valueType
=
new
VersionedValue
.
Type
(
vt
);
VersionedValue
Type
valueType
=
new
VersionedValue
Type
(
vt
);
MVRTreeMap
.
Builder
<
VersionedValue
>
mapBuilder
=
new
MVRTreeMap
.
Builder
<
VersionedValue
>().
valueType
(
valueType
);
...
...
h2/src/main/org/h2/mvstore/tx/CommitDecisionMaker.java
浏览文件 @
128619d2
...
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.mvstore.MVMap
;
import
org.h2.value.VersionedValue
;
/**
* Class CommitDecisionMaker makes a decision during post-commit processing
...
...
@@ -49,7 +50,7 @@ final class CommitDecisionMaker extends MVMap.DecisionMaker<VersionedValue> {
public
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
assert
decision
==
MVMap
.
Decision
.
PUT
;
assert
existingValue
!=
null
;
return
VersionedValue
.
getInstance
(
existingValue
.
getCurrentValue
());
return
VersionedValue
Committed
.
getInstance
(
existingValue
.
getCurrentValue
());
}
@Override
...
...
h2/src/main/org/h2/mvstore/tx/RollbackDecisionMaker.java
浏览文件 @
128619d2
...
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.mvstore.MVMap
;
import
org.h2.value.VersionedValue
;
/**
* Class RollbackDecisionMaker process undo log record during transaction rollback.
...
...
h2/src/main/org/h2/mvstore/tx/Transaction.java
浏览文件 @
128619d2
...
...
@@ -9,6 +9,7 @@ import org.h2.mvstore.DataUtils;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.value.VersionedValue
;
import
java.util.Iterator
;
import
java.util.concurrent.atomic.AtomicLong
;
...
...
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
浏览文件 @
128619d2
...
...
@@ -10,6 +10,7 @@ import org.h2.mvstore.DataUtils;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.Page
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.value.VersionedValue
;
import
java.util.AbstractMap
;
import
java.util.AbstractSet
;
...
...
@@ -264,7 +265,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
*/
public
V
putCommitted
(
K
key
,
V
value
)
{
DataUtils
.
checkArgument
(
value
!=
null
,
"The value may not be null"
);
VersionedValue
newValue
=
VersionedValue
.
getInstance
(
value
);
VersionedValue
newValue
=
VersionedValue
Committed
.
getInstance
(
value
);
VersionedValue
oldValue
=
map
.
put
(
key
,
newValue
);
@SuppressWarnings
(
"unchecked"
)
V
result
=
(
V
)
(
oldValue
==
null
?
null
:
oldValue
.
getCurrentValue
());
...
...
@@ -712,7 +713,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
// current value comes from another uncommitted transaction
// take committed value instead
Object
committedValue
=
data
.
getCommittedValue
();
data
=
committedValue
==
null
?
null
:
VersionedValue
.
getInstance
(
committedValue
);
data
=
committedValue
==
null
?
null
:
VersionedValue
Committed
.
getInstance
(
committedValue
);
}
}
}
...
...
h2/src/main/org/h2/mvstore/tx/TransactionStore.java
浏览文件 @
128619d2
...
...
@@ -20,6 +20,7 @@ import org.h2.mvstore.WriteBuffer;
import
org.h2.mvstore.type.DataType
;
import
org.h2.mvstore.type.ObjectDataType
;
import
org.h2.util.StringUtils
;
import
org.h2.value.VersionedValue
;
/**
* A store that supports concurrent MVCC read-committed transactions.
...
...
@@ -128,14 +129,14 @@ public class TransactionStore {
this
.
timeoutMillis
=
timeoutMillis
;
preparedTransactions
=
store
.
openMap
(
"openTransactions"
,
new
MVMap
.
Builder
<
Integer
,
Object
[]>());
DataType
oldValueType
=
new
VersionedValue
.
Type
(
dataType
);
DataType
oldValueType
=
new
VersionedValueType
(
dataType
);
ArrayType
undoLogValueType
=
new
ArrayType
(
new
DataType
[]{
new
ObjectDataType
(),
dataType
,
oldValueType
});
undoLogBuilder
=
new
MVMap
.
Builder
<
Long
,
Object
[]>()
.
singleWriter
()
.
valueType
(
undoLogValueType
);
DataType
vt
=
new
VersionedValue
.
Type
(
dataType
);
DataType
vt
=
new
VersionedValueType
(
dataType
);
mapBuilder
=
new
MVMap
.
Builder
<
Object
,
VersionedValue
>()
.
keyType
(
dataType
).
valueType
(
vt
);
}
...
...
@@ -494,7 +495,7 @@ public class TransactionStore {
if
(
valueType
==
null
)
{
valueType
=
new
ObjectDataType
();
}
VersionedValue
.
Type
vt
=
new
VersionedValue
.
Type
(
valueType
);
VersionedValue
Type
vt
=
new
VersionedValue
Type
(
valueType
);
MVMap
<
K
,
VersionedValue
>
map
;
MVMap
.
Builder
<
K
,
VersionedValue
>
builder
=
new
MVMap
.
Builder
<
K
,
VersionedValue
>().
...
...
h2/src/main/org/h2/mvstore/tx/TxDecisionMaker.java
浏览文件 @
128619d2
...
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.mvstore.MVMap
;
import
org.h2.value.VersionedValue
;
/**
* Class TxDecisionMaker.
...
...
@@ -47,7 +48,7 @@ abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue> {
// 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,
// because a tree root has definitely been changed.
logIt
(
existingValue
.
getCurrentValue
()
==
null
?
null
:
VersionedValue
.
getInstance
(
existingValue
.
getCurrentValue
()));
logIt
(
existingValue
.
getCurrentValue
()
==
null
?
null
:
VersionedValue
Committed
.
getInstance
(
existingValue
.
getCurrentValue
()));
decision
=
MVMap
.
Decision
.
PUT
;
}
else
if
(
getBlockingTransaction
()
!=
null
)
{
// this entry comes from a different transaction, and this
...
...
@@ -63,7 +64,7 @@ abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue> {
// was written but not undo log), and will effectively roll it back
// (just assume committed value and overwrite).
Object
committedValue
=
existingValue
.
getCommittedValue
();
logIt
(
committedValue
==
null
?
null
:
VersionedValue
.
getInstance
(
committedValue
));
logIt
(
committedValue
==
null
?
null
:
VersionedValue
Committed
.
getInstance
(
committedValue
));
decision
=
MVMap
.
Decision
.
PUT
;
}
else
{
// transaction has been committed/rolled back and is closed by now, so
...
...
@@ -138,7 +139,7 @@ abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue> {
@SuppressWarnings
(
"unchecked"
)
@Override
public
final
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
return
VersionedValue
.
getInstance
(
undoKey
,
value
,
return
VersionedValue
Uncommitted
.
getInstance
(
undoKey
,
value
,
existingValue
==
null
?
null
:
existingValue
.
getCommittedValue
());
}
}
...
...
@@ -228,7 +229,7 @@ abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue> {
@SuppressWarnings
(
"unchecked"
)
@Override
public
VersionedValue
selectValue
(
VersionedValue
existingValue
,
VersionedValue
providedValue
)
{
return
VersionedValue
.
getInstance
(
undoKey
,
return
VersionedValue
Uncommitted
.
getInstance
(
undoKey
,
existingValue
==
null
?
null
:
existingValue
.
getCurrentValue
(),
existingValue
==
null
?
null
:
existingValue
.
getCommittedValue
());
}
...
...
h2/src/main/org/h2/mvstore/tx/VersionedValue.java
deleted
100644 → 0
浏览文件 @
f66a645a
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.engine.Constants
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.WriteBuffer
;
import
org.h2.mvstore.type.DataType
;
import
java.nio.ByteBuffer
;
/**
* A versioned value (possibly null).
* 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
{
static
final
VersionedValue
DUMMY
=
new
VersionedValue
();
static
VersionedValue
getInstance
(
Object
value
)
{
assert
value
!=
null
;
return
value
instanceof
VersionedValue
?
(
VersionedValue
)
value
:
new
Committed
(
value
);
}
public
static
VersionedValue
getInstance
(
long
operationId
,
Object
value
,
Object
committedValue
)
{
return
new
Uncommitted
(
operationId
,
value
,
committedValue
);
}
protected
VersionedValue
()
{}
public
boolean
isCommitted
()
{
return
true
;
}
public
long
getOperationId
()
{
return
0L
;
}
public
Object
getCurrentValue
()
{
return
this
;
}
public
Object
getCommittedValue
()
{
return
this
;
}
private
static
class
Committed
extends
VersionedValue
{
/**
* The current value.
*/
public
final
Object
value
;
Committed
(
Object
value
)
{
this
.
value
=
value
;
}
public
Object
getCurrentValue
()
{
return
value
;
}
public
Object
getCommittedValue
()
{
return
value
;
}
@Override
public
String
toString
()
{
return
String
.
valueOf
(
value
);
}
}
private
static
class
Uncommitted
extends
Committed
{
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
()
{
return
operationId
;
}
@Override
public
Object
getCommittedValue
()
{
return
committedValue
;
}
@Override
public
String
toString
()
{
return
super
.
toString
()
+
" "
+
TransactionStore
.
getTransactionId
(
operationId
)
+
"/"
+
TransactionStore
.
getLogId
(
operationId
)
+
" "
+
committedValue
;
}
}
/**
* The value type for a versioned value.
*/
public
static
class
Type
implements
DataType
{
private
final
DataType
valueType
;
public
Type
(
DataType
valueType
)
{
this
.
valueType
=
valueType
;
}
@Override
public
int
getMemory
(
Object
obj
)
{
if
(
obj
==
null
)
return
0
;
VersionedValue
v
=
(
VersionedValue
)
obj
;
int
res
=
Constants
.
MEMORY_OBJECT
+
8
+
2
*
Constants
.
MEMORY_POINTER
+
getValMemory
(
v
.
getCurrentValue
());
if
(
v
.
getOperationId
()
!=
0
)
{
res
+=
getValMemory
(
v
.
getCommittedValue
());
}
return
res
;
}
private
int
getValMemory
(
Object
obj
)
{
return
obj
==
null
?
0
:
valueType
.
getMemory
(
obj
);
}
@Override
public
int
compare
(
Object
aObj
,
Object
bObj
)
{
if
(
aObj
==
bObj
)
{
return
0
;
}
else
if
(
aObj
==
null
)
{
return
-
1
;
}
else
if
(
bObj
==
null
)
{
return
1
;
}
VersionedValue
a
=
(
VersionedValue
)
aObj
;
VersionedValue
b
=
(
VersionedValue
)
bObj
;
long
comp
=
a
.
getOperationId
()
-
b
.
getOperationId
();
if
(
comp
==
0
)
{
return
valueType
.
compare
(
a
.
getCurrentValue
(),
b
.
getCurrentValue
());
}
return
Long
.
signum
(
comp
);
}
@Override
public
void
read
(
ByteBuffer
buff
,
Object
[]
obj
,
int
len
,
boolean
key
)
{
if
(
buff
.
get
()
==
0
)
{
// fast path (no op ids or null entries)
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
obj
[
i
]
=
getInstance
(
valueType
.
read
(
buff
));
}
}
else
{
// slow path (some entries may be null)
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
obj
[
i
]
=
read
(
buff
);
}
}
}
@Override
public
Object
read
(
ByteBuffer
buff
)
{
long
operationId
=
DataUtils
.
readVarLong
(
buff
);
if
(
operationId
==
0
)
{
return
getInstance
(
valueType
.
read
(
buff
));
}
else
{
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
);
}
}
@Override
public
void
write
(
WriteBuffer
buff
,
Object
[]
obj
,
int
len
,
boolean
key
)
{
boolean
fastPath
=
true
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
VersionedValue
v
=
(
VersionedValue
)
obj
[
i
];
if
(
v
.
getOperationId
()
!=
0
||
v
.
getCurrentValue
()
==
null
)
{
fastPath
=
false
;
}
}
if
(
fastPath
)
{
buff
.
put
((
byte
)
0
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
VersionedValue
v
=
(
VersionedValue
)
obj
[
i
];
valueType
.
write
(
buff
,
v
.
getCurrentValue
());
}
}
else
{
// slow path:
// store op ids, and some entries may be null
buff
.
put
((
byte
)
1
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
write
(
buff
,
obj
[
i
]);
}
}
}
@Override
public
void
write
(
WriteBuffer
buff
,
Object
obj
)
{
VersionedValue
v
=
(
VersionedValue
)
obj
;
long
operationId
=
v
.
getOperationId
();
buff
.
putVarLong
(
operationId
);
if
(
operationId
==
0
)
{
valueType
.
write
(
buff
,
v
.
getCurrentValue
());
}
else
{
Object
committedValue
=
v
.
getCommittedValue
();
int
flags
=
(
v
.
getCurrentValue
()
==
null
?
0
:
1
)
|
(
committedValue
==
null
?
0
:
2
);
buff
.
put
((
byte
)
flags
);
if
(
v
.
getCurrentValue
()
!=
null
)
{
valueType
.
write
(
buff
,
v
.
getCurrentValue
());
}
if
(
committedValue
!=
null
)
{
valueType
.
write
(
buff
,
committedValue
);
}
}
}
}
}
h2/src/main/org/h2/mvstore/tx/VersionedValueCommitted.java
0 → 100644
浏览文件 @
128619d2
/*
* Copyright 2004-2017 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.value.VersionedValue
;
/**
* Class CommittedVersionedValue.
* <UL>
* <LI> 12/24/18 8:48 PM initial creation
* </UL>
*
* @author <a href='mailto:andrei.tokar@gmail.com'>Andrei Tokar</a>
*/
class
VersionedValueCommitted
extends
VersionedValue
{
/**
* The current value.
*/
public
final
Object
value
;
VersionedValueCommitted
(
Object
value
)
{
this
.
value
=
value
;
}
static
VersionedValue
getInstance
(
Object
value
)
{
assert
value
!=
null
;
return
value
instanceof
VersionedValue
?
(
VersionedValue
)
value
:
new
VersionedValueCommitted
(
value
);
}
public
Object
getCurrentValue
()
{
return
value
;
}
public
Object
getCommittedValue
()
{
return
value
;
}
@Override
public
String
toString
()
{
return
String
.
valueOf
(
value
);
}
}
h2/src/main/org/h2/mvstore/tx/VersionedValueType.java
0 → 100644
浏览文件 @
128619d2
/*
* Copyright 2004-2017 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.engine.Constants
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.WriteBuffer
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.value.VersionedValue
;
import
java.nio.ByteBuffer
;
/**
* The value type for a versioned value.
*/
public
class
VersionedValueType
implements
DataType
{
private
final
DataType
valueType
;
public
VersionedValueType
(
DataType
valueType
)
{
this
.
valueType
=
valueType
;
}
@Override
public
int
getMemory
(
Object
obj
)
{
if
(
obj
==
null
)
return
0
;
VersionedValue
v
=
(
VersionedValue
)
obj
;
int
res
=
Constants
.
MEMORY_OBJECT
+
8
+
2
*
Constants
.
MEMORY_POINTER
+
getValMemory
(
v
.
getCurrentValue
());
if
(
v
.
getOperationId
()
!=
0
)
{
res
+=
getValMemory
(
v
.
getCommittedValue
());
}
return
res
;
}
private
int
getValMemory
(
Object
obj
)
{
return
obj
==
null
?
0
:
valueType
.
getMemory
(
obj
);
}
@Override
public
int
compare
(
Object
aObj
,
Object
bObj
)
{
if
(
aObj
==
bObj
)
{
return
0
;
}
else
if
(
aObj
==
null
)
{
return
-
1
;
}
else
if
(
bObj
==
null
)
{
return
1
;
}
VersionedValue
a
=
(
VersionedValue
)
aObj
;
VersionedValue
b
=
(
VersionedValue
)
bObj
;
long
comp
=
a
.
getOperationId
()
-
b
.
getOperationId
();
if
(
comp
==
0
)
{
return
valueType
.
compare
(
a
.
getCurrentValue
(),
b
.
getCurrentValue
());
}
return
Long
.
signum
(
comp
);
}
@Override
public
void
read
(
ByteBuffer
buff
,
Object
[]
obj
,
int
len
,
boolean
key
)
{
if
(
buff
.
get
()
==
0
)
{
// fast path (no op ids or null entries)
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
obj
[
i
]
=
VersionedValueCommitted
.
getInstance
(
valueType
.
read
(
buff
));
}
}
else
{
// slow path (some entries may be null)
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
obj
[
i
]
=
read
(
buff
);
}
}
}
@Override
public
Object
read
(
ByteBuffer
buff
)
{
long
operationId
=
DataUtils
.
readVarLong
(
buff
);
if
(
operationId
==
0
)
{
return
VersionedValueCommitted
.
getInstance
(
valueType
.
read
(
buff
));
}
else
{
byte
flags
=
buff
.
get
();
Object
value
=
(
flags
&
1
)
!=
0
?
valueType
.
read
(
buff
)
:
null
;
Object
committedValue
=
(
flags
&
2
)
!=
0
?
valueType
.
read
(
buff
)
:
null
;
return
VersionedValueUncommitted
.
getInstance
(
operationId
,
value
,
committedValue
);
}
}
@Override
public
void
write
(
WriteBuffer
buff
,
Object
[]
obj
,
int
len
,
boolean
key
)
{
boolean
fastPath
=
true
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
VersionedValue
v
=
(
VersionedValue
)
obj
[
i
];
if
(
v
.
getOperationId
()
!=
0
||
v
.
getCurrentValue
()
==
null
)
{
fastPath
=
false
;
}
}
if
(
fastPath
)
{
buff
.
put
((
byte
)
0
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
VersionedValue
v
=
(
VersionedValue
)
obj
[
i
];
valueType
.
write
(
buff
,
v
.
getCurrentValue
());
}
}
else
{
// slow path:
// store op ids, and some entries may be null
buff
.
put
((
byte
)
1
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
write
(
buff
,
obj
[
i
]);
}
}
}
@Override
public
void
write
(
WriteBuffer
buff
,
Object
obj
)
{
VersionedValue
v
=
(
VersionedValue
)
obj
;
long
operationId
=
v
.
getOperationId
();
buff
.
putVarLong
(
operationId
);
if
(
operationId
==
0
)
{
valueType
.
write
(
buff
,
v
.
getCurrentValue
());
}
else
{
Object
committedValue
=
v
.
getCommittedValue
();
int
flags
=
(
v
.
getCurrentValue
()
==
null
?
0
:
1
)
|
(
committedValue
==
null
?
0
:
2
);
buff
.
put
((
byte
)
flags
);
if
(
v
.
getCurrentValue
()
!=
null
)
{
valueType
.
write
(
buff
,
v
.
getCurrentValue
());
}
if
(
committedValue
!=
null
)
{
valueType
.
write
(
buff
,
committedValue
);
}
}
}
}
h2/src/main/org/h2/mvstore/tx/VersionedValueUncommitted.java
0 → 100644
浏览文件 @
128619d2
/*
* Copyright 2004-2017 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
.
tx
;
import
org.h2.value.VersionedValue
;
/**
* Class VersionedValueUncommitted.
* <UL>
* <LI> 12/24/18 8:49 PM initial creation
* </UL>
*
* @author <a href='mailto:andrei.tokar@gmail.com'>Andrei Tokar</a>
*/
class
VersionedValueUncommitted
extends
VersionedValueCommitted
{
private
final
long
operationId
;
private
final
Object
committedValue
;
VersionedValueUncommitted
(
long
operationId
,
Object
value
,
Object
committedValue
)
{
super
(
value
);
assert
operationId
!=
0
;
this
.
operationId
=
operationId
;
this
.
committedValue
=
committedValue
;
}
static
VersionedValue
getInstance
(
long
operationId
,
Object
value
,
Object
committedValue
)
{
return
new
VersionedValueUncommitted
(
operationId
,
value
,
committedValue
);
}
@Override
public
boolean
isCommitted
()
{
return
false
;
}
@Override
public
long
getOperationId
()
{
return
operationId
;
}
@Override
public
Object
getCommittedValue
()
{
return
committedValue
;
}
@Override
public
String
toString
()
{
return
super
.
toString
()
+
" "
+
TransactionStore
.
getTransactionId
(
operationId
)
+
"/"
+
TransactionStore
.
getLogId
(
operationId
)
+
" "
+
committedValue
;
}
}
h2/src/main/org/h2/value/Value.java
浏览文件 @
128619d2
...
...
@@ -23,7 +23,6 @@ import org.h2.api.IntervalQualifier;
import
org.h2.engine.Mode
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.tx.VersionedValue
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.SimpleResult
;
import
org.h2.store.DataHandler
;
...
...
h2/src/main/org/h2/value/VersionedValue.java
0 → 100644
浏览文件 @
128619d2
/*
* Copyright 2004-2017 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
value
;
/**
* A versioned value (possibly null).
* 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
static
final
VersionedValue
DUMMY
=
new
VersionedValue
();
protected
VersionedValue
()
{}
public
boolean
isCommitted
()
{
return
true
;
}
public
long
getOperationId
()
{
return
0L
;
}
public
Object
getCurrentValue
()
{
return
this
;
}
public
Object
getCommittedValue
()
{
return
this
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论