Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d61decb7
提交
d61decb7
authored
7月 07, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A concurrent linked list, to replace the array list of old roots (work in progress)
上级
82b73a05
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
41 行增加
和
81 行删除
+41
-81
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+37
-81
Page.java
h2/src/main/org/h2/mvstore/Page.java
+1
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+1
-0
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
d61decb7
...
...
@@ -53,7 +53,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
private
long
createVersion
;
private
final
DataType
keyType
;
private
final
DataType
valueType
;
private
ArrayList
<
Page
>
oldRoots
=
new
ArrayList
<
Page
>();
private
ConcurrentLinkedList
<
Page
>
oldRootsList
=
new
ConcurrentLinkedList
<
Page
>();
private
boolean
closed
;
private
boolean
readOnly
;
...
...
@@ -718,22 +720,9 @@ public class MVMap<K, V> extends AbstractMap<K, V>
if
(
root
!=
newRoot
)
{
removeUnusedOldVersions
();
if
(
root
.
getVersion
()
!=
newRoot
.
getVersion
())
{
// directly append to the list, modifying the list
// (if somebody concurrently replaces the oldRoots
// field, the change is lost, but in many cases this is
// detected at the end of this method)
ArrayList
<
Page
>
roots
=
oldRoots
;
if
(
roots
.
size
()
>
0
)
{
Page
last
=
roots
.
get
(
roots
.
size
()
-
1
);
if
(
last
.
getVersion
()
!=
root
.
getVersion
())
{
roots
.
add
(
root
);
}
}
else
{
roots
.
add
(
root
);
}
if
(
roots
!=
oldRoots
)
{
throw
DataUtils
.
newConcurrentModificationException
(
getName
());
Page
last
=
oldRootsList
.
peekLast
();
if
(
last
==
null
||
last
.
getVersion
()
!=
root
.
getVersion
())
{
oldRootsList
.
add
(
root
);
}
}
root
=
newRoot
;
...
...
@@ -977,23 +966,21 @@ public class MVMap<K, V> extends AbstractMap<K, V>
void
rollbackTo
(
long
version
)
{
beforeWrite
();
try
{
removeUnusedOldVersions
();
if
(
version
<=
createVersion
)
{
// the map is removed later
}
else
if
(
root
.
getVersion
()
>=
version
)
{
// iterating in descending order -
// this is not terribly efficient if there are many versions
ArrayList
<
Page
>
roots
=
new
ArrayList
<
Page
>(
oldRoots
);
while
(
roots
.
size
()
>
0
)
{
int
i
=
roots
.
size
()
-
1
;
Page
p
=
roots
.
get
(
i
);
root
=
p
;
root
s
.
remove
(
i
)
;
if
(
p
.
getVersion
()
<
version
)
{
while
(
true
)
{
Page
last
=
oldRootsList
.
peekLast
();
if
(
last
==
null
)
{
break
;
}
// slow, but rollback is not a common operation
oldRootsList
.
removeLast
(
last
)
;
root
=
last
;
if
(
root
.
getVersion
()
<
version
)
{
break
;
}
}
oldRoots
=
roots
;
}
}
finally
{
afterWrite
();
...
...
@@ -1008,35 +995,20 @@ public class MVMap<K, V> extends AbstractMap<K, V>
if
(
oldest
==
-
1
)
{
return
;
}
// operate on a stable array
// (items might be appended concurrently,
// but not removed)
ArrayList
<
Page
>
roots
=
oldRoots
;
int
i
=
searchRoot
(
roots
,
oldest
);
if
(
i
<
0
)
{
i
=
-
i
-
1
;
}
i
--;
if
(
i
<=
0
)
{
if
(
oldRootsList
.
peekFirst
()
==
oldRootsList
.
peekLast
())
{
// do nothing if there is no or only one entry
return
;
}
// create a new instance
// because another thread might iterate over it
int
size
=
roots
.
size
()
-
i
;
ArrayList
<
Page
>
list
=
new
ArrayList
<
Page
>(
size
);
list
.
addAll
(
roots
.
subList
(
i
,
roots
.
size
()));
if
(
roots
!=
oldRoots
)
{
throw
DataUtils
.
newConcurrentModificationException
(
getName
());
}
;
// TODO work in progress
if
(
oldRoots
.
size
()
-
list
.
size
()
>
1
)
{
// System.out.println("reduced! from " +
// oldRoots.size() + " to " + list.size() +" " + getClass());
// TODO why is this?
oldest
--;
while
(
true
)
{
Page
p
=
oldRootsList
.
peekFirst
();
if
(
p
==
null
||
p
.
getVersion
()
>=
oldest
)
{
break
;
}
oldRootsList
.
removeFirst
(
p
);
}
oldRoots
=
list
;
}
public
boolean
isReadOnly
()
{
...
...
@@ -1197,20 +1169,20 @@ public class MVMap<K, V> extends AbstractMap<K, V>
store
.
getFileStore
()
==
null
))
{
newest
=
r
;
}
else
{
// operate on a stable array
// (items might be appended concurrently)
ArrayList
<
Page
>
roots
=
oldRoots
;
// find the newest page that has a getVersion() <= version
int
i
=
searchRoot
(
roots
,
version
);
if
(
i
<
0
)
{
// not found
if
(
i
==
-
1
)
{
// smaller than all in-memory versions
return
store
.
openMapVersion
(
version
,
id
,
this
)
;
Page
last
=
oldRootsList
.
peekFirst
();
if
(
last
==
null
||
version
<
last
.
getVersion
())
{
// smaller than all in-memory versions
return
store
.
openMapVersion
(
version
,
id
,
this
);
}
Iterator
<
Page
>
it
=
oldRootsList
.
iterator
();
while
(
it
.
hasNext
())
{
Page
p
=
it
.
next
();
if
(
p
.
getVersion
()
>
version
)
{
break
;
}
i
=
-
i
-
2
;
last
=
p
;
}
newest
=
roots
.
get
(
i
)
;
newest
=
last
;
}
MVMap
<
K
,
V
>
m
=
openReadOnly
();
m
.
root
=
newest
;
...
...
@@ -1233,22 +1205,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return
m
;
}
private
static
int
searchRoot
(
ArrayList
<
Page
>
roots
,
long
version
)
{
int
low
=
0
,
high
=
roots
.
size
()
-
1
;
while
(
low
<=
high
)
{
int
x
=
(
low
+
high
)
>>>
1
;
long
v
=
roots
.
get
(
x
).
getVersion
();
if
(
v
<
version
)
{
low
=
x
+
1
;
}
else
if
(
version
<
v
)
{
high
=
x
-
1
;
}
else
{
return
x
;
}
}
return
-(
low
+
1
);
}
public
long
getVersion
()
{
return
root
.
getVersion
();
}
...
...
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
d61decb7
...
...
@@ -313,6 +313,7 @@ public class Page {
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"id: "
).
append
(
System
.
identityHashCode
(
this
)).
append
(
'\n'
);
buff
.
append
(
"version: "
).
append
(
Long
.
toHexString
(
version
)).
append
(
"\n"
);
buff
.
append
(
"pos: "
).
append
(
Long
.
toHexString
(
pos
)).
append
(
"\n"
);
if
(
pos
!=
0
)
{
int
chunkId
=
DataUtils
.
getPageChunkId
(
pos
);
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
d61decb7
...
...
@@ -113,6 +113,7 @@ import org.h2.test.store.TestCacheConcurrentLIRS;
import
org.h2.test.store.TestCacheLIRS
;
import
org.h2.test.store.TestCacheLongKeyLIRS
;
import
org.h2.test.store.TestConcurrent
;
import
org.h2.test.store.TestConcurrentLinkedList
;
import
org.h2.test.store.TestDataUtils
;
import
org.h2.test.store.TestFreeSpace
;
import
org.h2.test.store.TestKillProcessWhileWriting
;
...
...
@@ -741,6 +742,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new
TestCacheLIRS
().
runTest
(
this
);
new
TestCacheLongKeyLIRS
().
runTest
(
this
);
new
TestConcurrent
().
runTest
(
this
);
new
TestConcurrentLinkedList
().
runTest
(
this
);
new
TestDataUtils
().
runTest
(
this
);
new
TestFreeSpace
().
runTest
(
this
);
new
TestKillProcessWhileWriting
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
d61decb7
...
...
@@ -1444,6 +1444,7 @@ public class TestMVStore extends TestBase {
String
fileName
=
getBaseDir
()
+
"/testRollback.h3"
;
FileUtils
.
delete
(
fileName
);
MVStore
s
=
openStore
(
fileName
,
5
);
s
.
setAutoCommitDelay
(
0
);
assertEquals
(
0
,
s
.
getCurrentVersion
());
MVMap
<
String
,
String
>
m
=
s
.
openMap
(
"data"
);
s
.
rollbackTo
(
0
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论