Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a7b4f8b7
提交
a7b4f8b7
authored
13 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A persistent tree map (work in progress)
上级
756c6fa4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
17 行删除
+51
-17
TestTreeMapStore.java
h2/src/test/org/h2/test/unit/TestTreeMapStore.java
+8
-10
TreeMapStore.java
h2/src/tools/org/h2/dev/store/TreeMapStore.java
+43
-7
没有找到文件。
h2/src/test/org/h2/test/unit/TestTreeMapStore.java
浏览文件 @
a7b4f8b7
...
...
@@ -29,7 +29,7 @@ public class TestTreeMapStore extends TestBase {
}
public
void
test
()
throws
Exception
{
//
testReuseSpace();
testReuseSpace
();
testRandom
();
testKeyValueClasses
();
testIterate
();
...
...
@@ -39,28 +39,26 @@ public class TestTreeMapStore extends TestBase {
private
void
testReuseSpace
()
{
String
fileName
=
getBaseDir
()
+
"/data.h3"
;
FileUtils
.
delete
(
fileName
);
long
initialLength
=
0
;
for
(
int
j
=
0
;
j
<
10
;
j
++)
{
System
.
out
.
println
(
"@@@open"
);
TreeMapStore
s
=
TreeMapStore
.
open
(
fileName
);
StoredMap
<
Integer
,
String
>
m
=
s
.
openMap
(
"data"
,
Integer
.
class
,
String
.
class
);
System
.
out
.
println
(
s
);
System
.
out
.
println
(
"get0: "
+
m
.
get
(
0
));
System
.
out
.
println
(
"@@@add"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
m
.
put
(
i
,
"Hello"
);
}
s
.
store
();
System
.
out
.
println
(
s
);
System
.
out
.
println
(
"@@@remove"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
m
.
remove
(
i
);
}
s
.
store
();
System
.
out
.
println
(
s
);
System
.
out
.
println
(
"@@@close"
);
s
.
close
();
long
len
=
FileUtils
.
size
(
fileName
);
if
(
initialLength
==
0
)
{
initialLength
=
len
;
}
else
{
assertTrue
(
len
<=
initialLength
*
2
);
}
}
if
(
true
)
System
.
exit
(
0
);
}
private
void
testRandom
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/store/TreeMapStore.java
浏览文件 @
a7b4f8b7
...
...
@@ -11,6 +11,7 @@ import java.io.File;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.util.ArrayList
;
import
java.util.BitSet
;
import
java.util.HashMap
;
import
java.util.Iterator
;
...
...
@@ -95,7 +96,7 @@ public class TreeMapStore {
String
root
=
meta
.
get
(
"map."
+
name
);
m
=
StoredMap
.
open
(
this
,
name
,
keyClass
,
valueClass
);
maps
.
put
(
name
,
m
);
if
(
root
!=
null
)
{
if
(
root
!=
null
&&
!
root
.
equals
(
"0"
)
)
{
m
.
setRoot
(
Long
.
parseLong
(
root
));
}
}
...
...
@@ -221,6 +222,20 @@ public class TreeMapStore {
return
offset
;
}
private
int
count
(
Node
n
)
{
if
(
n
==
null
)
{
return
0
;
}
int
count
=
1
;
if
(
n
.
getLeftId
()
<
0
)
{
count
+=
count
(
n
.
getLeft
());
}
if
(
n
.
getRightId
()
<
0
)
{
count
+=
count
(
n
.
getRight
());
}
return
count
;
}
private
void
store
(
ByteBuffer
buff
,
Node
n
)
{
if
(
n
==
null
)
{
return
;
...
...
@@ -264,6 +279,16 @@ public class TreeMapStore {
for
(
Block
x
:
blocks
)
{
if
(
x
.
liveCount
==
0
)
{
meta
.
remove
(
"block."
+
x
.
id
);
}
else
{
meta
.
put
(
"block."
+
x
.
id
,
"temp "
+
x
.
toString
());
}
}
// modifying the meta can itself affect the metadata
// TODO solve this in a better way
for
(
Block
x
:
new
ArrayList
<
Block
>(
blocks
))
{
if
(
x
.
liveCount
==
0
)
{
meta
.
remove
(
"block."
+
x
.
id
);
blocks
.
remove
(
x
);
}
else
{
meta
.
put
(
"block."
+
x
.
id
,
x
.
toString
());
}
...
...
@@ -273,19 +298,27 @@ public class TreeMapStore {
long
storePos
=
allocate
(
lenEstimate
);
int
test
;
// System.out.println("use " + storePos + ".." + (storePos + lenEstimate));
long
end
=
storePos
+
1
+
8
;
for
(
StoredMap
<?,
?>
m
:
mapsChanged
.
values
())
{
meta
.
put
(
"map."
+
m
.
getName
(),
String
.
valueOf
(
end
));
end
=
updateId
(
m
.
getRoot
(),
end
);
Node
r
=
m
.
getRoot
();
long
p
=
r
==
null
?
0
:
end
;
meta
.
put
(
"map."
+
m
.
getName
(),
String
.
valueOf
(
p
));
end
=
updateId
(
r
,
end
);
}
long
metaPos
=
end
;
// add a dummy entry so the count is correct
meta
.
put
(
"block."
+
b
.
id
,
b
.
toString
());
int
count
=
0
;
for
(
StoredMap
<?,
?>
m
:
mapsChanged
.
values
())
{
count
+=
count
(
m
.
getRoot
());
}
count
+=
count
(
meta
.
getRoot
());
b
.
start
=
storePos
;
b
.
entryCount
=
tempNodeId
;
b
.
entryCount
=
count
;
b
.
liveCount
=
b
.
entryCount
;
meta
.
put
(
"block."
+
b
.
id
,
b
.
toString
());
end
=
updateId
(
meta
.
getRoot
(),
end
);
...
...
@@ -430,6 +463,9 @@ public class TreeMapStore {
void
removeNode
(
long
id
)
{
if
(
id
>
0
)
{
if
(
getBlock
(
id
).
liveCount
==
0
)
{
System
.
out
.
println
(
"??"
);
}
getBlock
(
id
).
liveCount
--;
}
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论