Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
038b19b6
提交
038b19b6
authored
1月 13, 2019
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move RootReference to the top level
上级
fad4a812
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
131 行增加
和
119 行删除
+131
-119
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+0
-105
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+8
-8
RootReference.java
h2/src/main/org/h2/mvstore/RootReference.java
+115
-0
MVRTreeMap.java
h2/src/main/org/h2/mvstore/rtree/MVRTreeMap.java
+1
-0
TransactionMap.java
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
+7
-6
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
038b19b6
...
@@ -1420,111 +1420,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -1420,111 +1420,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return
asString
(
null
);
return
asString
(
null
);
}
}
public
static
final
class
RootReference
{
/**
* The root page.
*/
public
final
Page
root
;
/**
* The version used for writing.
*/
public
final
long
version
;
/**
* Indicator that map is locked for update.
*/
final
boolean
lockedForUpdate
;
/**
* Reference to the previous root in the chain.
*/
public
volatile
RootReference
previous
;
/**
* Counter for successful root updates.
*/
public
final
long
updateCounter
;
/**
* Counter for attempted root updates.
*/
public
final
long
updateAttemptCounter
;
/**
* Size of the occupied part of the append buffer.
*/
public
final
byte
appendCounter
;
RootReference
(
Page
root
,
long
version
,
RootReference
previous
,
int
appendCounter
,
long
updateCounter
,
long
updateAttemptCounter
)
{
this
.
root
=
root
;
this
.
version
=
version
;
this
.
previous
=
previous
;
this
.
updateCounter
=
updateCounter
;
this
.
updateAttemptCounter
=
updateAttemptCounter
;
this
.
lockedForUpdate
=
false
;
this
.
appendCounter
=
(
byte
)
appendCounter
;
}
// This one is used for locking
RootReference
(
RootReference
r
,
int
attempt
)
{
this
.
root
=
r
.
root
;
this
.
version
=
r
.
version
;
this
.
previous
=
r
.
previous
;
this
.
updateCounter
=
r
.
updateCounter
+
1
;
this
.
updateAttemptCounter
=
r
.
updateAttemptCounter
+
attempt
;
this
.
lockedForUpdate
=
true
;
this
.
appendCounter
=
r
.
appendCounter
;
}
// This one is used for unlocking
RootReference
(
RootReference
r
,
Page
root
,
int
appendCounter
,
boolean
lockedForUpdate
)
{
this
.
root
=
root
;
this
.
version
=
r
.
version
;
this
.
previous
=
r
.
previous
;
this
.
updateCounter
=
r
.
updateCounter
;
this
.
updateAttemptCounter
=
r
.
updateAttemptCounter
;
this
.
lockedForUpdate
=
lockedForUpdate
;
this
.
appendCounter
=
(
byte
)
appendCounter
;
}
// This one is used for version change
RootReference
(
RootReference
r
,
long
version
,
int
attempt
)
{
RootReference
previous
=
r
;
RootReference
tmp
;
while
((
tmp
=
previous
.
previous
)
!=
null
&&
tmp
.
root
==
r
.
root
)
{
previous
=
tmp
;
}
this
.
root
=
r
.
root
;
this
.
version
=
version
;
this
.
previous
=
previous
;
this
.
updateCounter
=
r
.
updateCounter
+
1
;
this
.
updateAttemptCounter
=
r
.
updateAttemptCounter
+
attempt
;
this
.
lockedForUpdate
=
r
.
lockedForUpdate
;
this
.
appendCounter
=
r
.
appendCounter
;
}
// This one is used for r/o snapshots
RootReference
(
Page
root
,
long
version
)
{
this
.
root
=
root
;
this
.
version
=
version
;
this
.
previous
=
null
;
this
.
updateCounter
=
1
;
this
.
updateAttemptCounter
=
1
;
this
.
lockedForUpdate
=
false
;
this
.
appendCounter
=
0
;
}
public
int
getAppendCounter
()
{
return
appendCounter
&
0xff
;
}
public
long
getTotalCount
()
{
return
root
.
getTotalCount
()
+
getAppendCounter
();
}
@Override
public
String
toString
()
{
return
"RootReference("
+
System
.
identityHashCode
(
root
)+
","
+
version
+
","
+
lockedForUpdate
+
")"
;
}
}
/**
/**
* A builder for maps.
* A builder for maps.
*
*
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
038b19b6
...
@@ -1250,7 +1250,7 @@ public class MVStore implements AutoCloseable {
...
@@ -1250,7 +1250,7 @@ public class MVStore implements AutoCloseable {
ArrayList
<
Page
>
changed
=
new
ArrayList
<>();
ArrayList
<
Page
>
changed
=
new
ArrayList
<>();
for
(
Iterator
<
MVMap
<?,
?>>
iter
=
maps
.
values
().
iterator
();
iter
.
hasNext
();
)
{
for
(
Iterator
<
MVMap
<?,
?>>
iter
=
maps
.
values
().
iterator
();
iter
.
hasNext
();
)
{
MVMap
<?,
?>
map
=
iter
.
next
();
MVMap
<?,
?>
map
=
iter
.
next
();
MVMap
.
RootReference
rootReference
=
map
.
setWriteVersion
(
version
);
RootReference
rootReference
=
map
.
setWriteVersion
(
version
);
if
(
rootReference
==
null
)
{
if
(
rootReference
==
null
)
{
assert
map
.
isClosed
();
assert
map
.
isClosed
();
assert
map
.
getVersion
()
<
getOldestVersionToKeep
();
assert
map
.
getVersion
()
<
getOldestVersionToKeep
();
...
@@ -1289,7 +1289,7 @@ public class MVStore implements AutoCloseable {
...
@@ -1289,7 +1289,7 @@ public class MVStore implements AutoCloseable {
}
}
}
}
applyFreedSpace
();
applyFreedSpace
();
MVMap
.
RootReference
metaRootReference
=
meta
.
setWriteVersion
(
version
);
RootReference
metaRootReference
=
meta
.
setWriteVersion
(
version
);
assert
metaRootReference
!=
null
;
assert
metaRootReference
!=
null
;
assert
metaRootReference
.
version
==
version
:
metaRootReference
.
version
+
" != "
+
version
;
assert
metaRootReference
.
version
==
version
:
metaRootReference
.
version
+
" != "
+
version
;
metaChanged
=
false
;
metaChanged
=
false
;
...
@@ -1445,9 +1445,9 @@ public class MVStore implements AutoCloseable {
...
@@ -1445,9 +1445,9 @@ public class MVStore implements AutoCloseable {
try
{
try
{
ChunkIdsCollector
collector
=
new
ChunkIdsCollector
(
meta
.
getId
());
ChunkIdsCollector
collector
=
new
ChunkIdsCollector
(
meta
.
getId
());
long
oldestVersionToKeep
=
getOldestVersionToKeep
();
long
oldestVersionToKeep
=
getOldestVersionToKeep
();
MVMap
.
RootReference
rootReference
=
meta
.
flushAndGetRoot
();
RootReference
rootReference
=
meta
.
flushAndGetRoot
();
if
(
fast
)
{
if
(
fast
)
{
MVMap
.
RootReference
previous
;
RootReference
previous
;
while
(
rootReference
.
version
>=
oldestVersionToKeep
&&
(
previous
=
rootReference
.
previous
)
!=
null
)
{
while
(
rootReference
.
version
>=
oldestVersionToKeep
&&
(
previous
=
rootReference
.
previous
)
!=
null
)
{
rootReference
=
previous
;
rootReference
=
previous
;
}
}
...
@@ -1482,7 +1482,7 @@ public class MVStore implements AutoCloseable {
...
@@ -1482,7 +1482,7 @@ public class MVStore implements AutoCloseable {
* @param inspectedRoots set of page positions for map's roots already inspected
* @param inspectedRoots set of page positions for map's roots already inspected
* or null if not to be used
* or null if not to be used
*/
*/
private
void
inspectVersion
(
MVMap
.
RootReference
rootReference
,
ChunkIdsCollector
collector
,
private
void
inspectVersion
(
RootReference
rootReference
,
ChunkIdsCollector
collector
,
ThreadPoolExecutor
executorService
,
ThreadPoolExecutor
executorService
,
AtomicInteger
executingThreadCounter
,
AtomicInteger
executingThreadCounter
,
Set
<
Long
>
inspectedRoots
)
{
Set
<
Long
>
inspectedRoots
)
{
...
@@ -2683,7 +2683,7 @@ public class MVStore implements AutoCloseable {
...
@@ -2683,7 +2683,7 @@ public class MVStore implements AutoCloseable {
DataUtils
.
checkArgument
(
map
!=
meta
,
DataUtils
.
checkArgument
(
map
!=
meta
,
"Removing the meta map is not allowed"
);
"Removing the meta map is not allowed"
);
map
.
close
();
map
.
close
();
MVMap
.
RootReference
rootReference
=
map
.
getRoot
();
RootReference
rootReference
=
map
.
getRoot
();
updateCounter
+=
rootReference
.
updateCounter
;
updateCounter
+=
rootReference
.
updateCounter
;
updateAttemptCounter
+=
rootReference
.
updateAttemptCounter
;
updateAttemptCounter
+=
rootReference
.
updateAttemptCounter
;
...
@@ -2983,11 +2983,11 @@ public class MVStore implements AutoCloseable {
...
@@ -2983,11 +2983,11 @@ public class MVStore implements AutoCloseable {
public
double
getUpdateFailureRatio
()
{
public
double
getUpdateFailureRatio
()
{
long
updateCounter
=
this
.
updateCounter
;
long
updateCounter
=
this
.
updateCounter
;
long
updateAttemptCounter
=
this
.
updateAttemptCounter
;
long
updateAttemptCounter
=
this
.
updateAttemptCounter
;
MVMap
.
RootReference
rootReference
=
meta
.
getRoot
();
RootReference
rootReference
=
meta
.
getRoot
();
updateCounter
+=
rootReference
.
updateCounter
;
updateCounter
+=
rootReference
.
updateCounter
;
updateAttemptCounter
+=
rootReference
.
updateAttemptCounter
;
updateAttemptCounter
+=
rootReference
.
updateAttemptCounter
;
for
(
MVMap
<?,
?>
map
:
maps
.
values
())
{
for
(
MVMap
<?,
?>
map
:
maps
.
values
())
{
MVMap
.
RootReference
root
=
map
.
getRoot
();
RootReference
root
=
map
.
getRoot
();
updateCounter
+=
root
.
updateCounter
;
updateCounter
+=
root
.
updateCounter
;
updateAttemptCounter
+=
root
.
updateAttemptCounter
;
updateAttemptCounter
+=
root
.
updateAttemptCounter
;
}
}
...
...
h2/src/main/org/h2/mvstore/RootReference.java
0 → 100644
浏览文件 @
038b19b6
/*
* Copyright 2004-2019 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
;
/**
* Class RootReference.
*
* @author <a href='mailto:andrei.tokar@gmail.com'>Andrei Tokar</a>
*/
public
final
class
RootReference
{
/**
* The root page.
*/
public
final
Page
root
;
/**
* The version used for writing.
*/
public
final
long
version
;
/**
* Indicator that map is locked for update.
*/
final
boolean
lockedForUpdate
;
/**
* Reference to the previous root in the chain.
*/
public
volatile
RootReference
previous
;
/**
* Counter for successful root updates.
*/
public
final
long
updateCounter
;
/**
* Counter for attempted root updates.
*/
public
final
long
updateAttemptCounter
;
/**
* Size of the occupied part of the append buffer.
*/
public
final
byte
appendCounter
;
RootReference
(
Page
root
,
long
version
,
RootReference
previous
,
int
appendCounter
,
long
updateCounter
,
long
updateAttemptCounter
)
{
this
.
root
=
root
;
this
.
version
=
version
;
this
.
previous
=
previous
;
this
.
updateCounter
=
updateCounter
;
this
.
updateAttemptCounter
=
updateAttemptCounter
;
this
.
lockedForUpdate
=
false
;
this
.
appendCounter
=
(
byte
)
appendCounter
;
}
// This one is used for locking
RootReference
(
RootReference
r
,
int
attempt
)
{
this
.
root
=
r
.
root
;
this
.
version
=
r
.
version
;
this
.
previous
=
r
.
previous
;
this
.
updateCounter
=
r
.
updateCounter
+
1
;
this
.
updateAttemptCounter
=
r
.
updateAttemptCounter
+
attempt
;
this
.
lockedForUpdate
=
true
;
this
.
appendCounter
=
r
.
appendCounter
;
}
// This one is used for unlocking
RootReference
(
RootReference
r
,
Page
root
,
int
appendCounter
,
boolean
lockedForUpdate
)
{
this
.
root
=
root
;
this
.
version
=
r
.
version
;
this
.
previous
=
r
.
previous
;
this
.
updateCounter
=
r
.
updateCounter
;
this
.
updateAttemptCounter
=
r
.
updateAttemptCounter
;
this
.
lockedForUpdate
=
lockedForUpdate
;
this
.
appendCounter
=
(
byte
)
appendCounter
;
}
// This one is used for version change
RootReference
(
RootReference
r
,
long
version
,
int
attempt
)
{
RootReference
previous
=
r
;
RootReference
tmp
;
while
((
tmp
=
previous
.
previous
)
!=
null
&&
tmp
.
root
==
r
.
root
)
{
previous
=
tmp
;
}
this
.
root
=
r
.
root
;
this
.
version
=
version
;
this
.
previous
=
previous
;
this
.
updateCounter
=
r
.
updateCounter
+
1
;
this
.
updateAttemptCounter
=
r
.
updateAttemptCounter
+
attempt
;
this
.
lockedForUpdate
=
r
.
lockedForUpdate
;
this
.
appendCounter
=
r
.
appendCounter
;
}
// This one is used for r/o snapshots
RootReference
(
Page
root
,
long
version
)
{
this
.
root
=
root
;
this
.
version
=
version
;
this
.
previous
=
null
;
this
.
updateCounter
=
1
;
this
.
updateAttemptCounter
=
1
;
this
.
lockedForUpdate
=
false
;
this
.
appendCounter
=
0
;
}
public
int
getAppendCounter
()
{
return
appendCounter
&
0xff
;
}
public
long
getTotalCount
()
{
return
root
.
getTotalCount
()
+
getAppendCounter
();
}
@Override
public
String
toString
()
{
return
"RootReference("
+
System
.
identityHashCode
(
root
)
+
","
+
version
+
","
+
lockedForUpdate
+
")"
;
}
}
h2/src/main/org/h2/mvstore/rtree/MVRTreeMap.java
浏览文件 @
038b19b6
...
@@ -13,6 +13,7 @@ import org.h2.mvstore.CursorPos;
...
@@ -13,6 +13,7 @@ import org.h2.mvstore.CursorPos;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.Page
;
import
org.h2.mvstore.Page
;
import
org.h2.mvstore.RootReference
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.mvstore.type.DataType
;
/**
/**
...
...
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
浏览文件 @
038b19b6
...
@@ -9,6 +9,7 @@ import org.h2.mvstore.Cursor;
...
@@ -9,6 +9,7 @@ import org.h2.mvstore.Cursor;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.Page
;
import
org.h2.mvstore.Page
;
import
org.h2.mvstore.RootReference
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.value.VersionedValue
;
import
org.h2.value.VersionedValue
;
...
@@ -100,19 +101,19 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
...
@@ -100,19 +101,19 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
// In order to get such a "snapshot", we wait for a moment of silence,
// In order to get such a "snapshot", we wait for a moment of silence,
// when none of the variables concurrently changes it's value.
// when none of the variables concurrently changes it's value.
BitSet
committingTransactions
;
BitSet
committingTransactions
;
MVMap
.
RootReference
mapRootReference
;
RootReference
mapRootReference
;
MVMap
.
RootReference
[]
undoLogRootReferences
;
RootReference
[]
undoLogRootReferences
;
long
undoLogSize
;
long
undoLogSize
;
do
{
do
{
committingTransactions
=
store
.
committingTransactions
.
get
();
committingTransactions
=
store
.
committingTransactions
.
get
();
mapRootReference
=
map
.
flushAndGetRoot
();
mapRootReference
=
map
.
flushAndGetRoot
();
BitSet
opentransactions
=
store
.
openTransactions
.
get
();
BitSet
opentransactions
=
store
.
openTransactions
.
get
();
undoLogRootReferences
=
new
MVMap
.
RootReference
[
opentransactions
.
length
()];
undoLogRootReferences
=
new
RootReference
[
opentransactions
.
length
()];
undoLogSize
=
0
;
undoLogSize
=
0
;
for
(
int
i
=
opentransactions
.
nextSetBit
(
0
);
i
>=
0
;
i
=
opentransactions
.
nextSetBit
(
i
+
1
))
{
for
(
int
i
=
opentransactions
.
nextSetBit
(
0
);
i
>=
0
;
i
=
opentransactions
.
nextSetBit
(
i
+
1
))
{
MVMap
<
Long
,
Object
[]>
undoLog
=
store
.
undoLogs
[
i
];
MVMap
<
Long
,
Object
[]>
undoLog
=
store
.
undoLogs
[
i
];
if
(
undoLog
!=
null
)
{
if
(
undoLog
!=
null
)
{
MVMap
.
RootReference
rootReference
=
undoLog
.
flushAndGetRoot
();
RootReference
rootReference
=
undoLog
.
flushAndGetRoot
();
undoLogRootReferences
[
i
]
=
rootReference
;
undoLogRootReferences
[
i
]
=
rootReference
;
undoLogSize
+=
rootReference
.
getTotalCount
();
undoLogSize
+=
rootReference
.
getTotalCount
();
}
}
...
@@ -156,7 +157,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
...
@@ -156,7 +157,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
}
else
{
}
else
{
// The undo logs are much smaller than the map - scan all undo logs,
// The undo logs are much smaller than the map - scan all undo logs,
// and then lookup relevant map entry.
// and then lookup relevant map entry.
for
(
MVMap
.
RootReference
undoLogRootReference
:
undoLogRootReferences
)
{
for
(
RootReference
undoLogRootReference
:
undoLogRootReferences
)
{
if
(
undoLogRootReference
!=
null
)
{
if
(
undoLogRootReference
!=
null
)
{
Cursor
<
Long
,
Object
[]>
cursor
=
new
Cursor
<>(
undoLogRootReference
.
root
,
null
);
Cursor
<
Long
,
Object
[]>
cursor
=
new
Cursor
<>(
undoLogRootReference
.
root
,
null
);
while
(
cursor
.
hasNext
())
{
while
(
cursor
.
hasNext
())
{
...
@@ -688,7 +689,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
...
@@ -688,7 +689,7 @@ public class TransactionMap<K, V> extends AbstractMap<K, V> {
// In order to get such a "snapshot", we wait for a moment of silence,
// In order to get such a "snapshot", we wait for a moment of silence,
// when neither of the variables concurrently changes it's value.
// when neither of the variables concurrently changes it's value.
BitSet
committingTransactions
;
BitSet
committingTransactions
;
MVMap
.
RootReference
mapRootReference
;
RootReference
mapRootReference
;
do
{
do
{
committingTransactions
=
store
.
committingTransactions
.
get
();
committingTransactions
=
store
.
committingTransactions
.
get
();
mapRootReference
=
map
.
flushAndGetRoot
();
mapRootReference
=
map
.
flushAndGetRoot
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论