Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
670d256c
提交
670d256c
authored
11月 06, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A persistent multi-version map: compact based on estimated size, not page count
上级
3a92ea32
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
166 行增加
和
166 行删除
+166
-166
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+1
-1
Chunk.java
h2/src/tools/org/h2/dev/store/btree/Chunk.java
+38
-12
Dump.java
h2/src/tools/org/h2/dev/store/btree/Dump.java
+6
-2
MVStore.java
h2/src/tools/org/h2/dev/store/btree/MVStore.java
+109
-126
Page.java
h2/src/tools/org/h2/dev/store/btree/Page.java
+12
-25
没有找到文件。
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
670d256c
...
...
@@ -577,7 +577,7 @@ public class TestMVStore extends TestBase {
m
.
put
(
j
+
i
,
"Hello "
+
j
);
}
s
.
store
();
s
.
compact
(
80
);
//
s.compact(80);
s
.
close
();
long
len
=
FileUtils
.
size
(
fileName
);
// System.out.println(" len:" + len);
...
...
h2/src/tools/org/h2/dev/store/btree/Chunk.java
浏览文件 @
670d256c
...
...
@@ -6,6 +6,7 @@
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.nio.ByteBuffer
;
import
java.util.HashMap
;
/**
...
...
@@ -19,6 +20,7 @@ import java.util.HashMap;
* 4 bytes: length
* 4 bytes: chunk id (an incrementing number)
* 8 bytes: metaRootPos
* 8 bytes: maxLengthLive
* [ Page ] *
*/
public
class
Chunk
{
...
...
@@ -34,19 +36,19 @@ public class Chunk {
long
start
;
/**
* The length in bytes
(may be larger than the actual value)
.
* The length in bytes.
*/
long
length
;
int
length
;
/**
* The
entry count
.
* The
sum of the max length of all pages
.
*/
int
entryCount
;
long
maxLength
;
/**
* The
number of life (non-garbage) objects
.
* The
sum of the max length of all pages that are in use
.
*/
int
liveCount
;
long
maxLengthLive
;
/**
* The garbage collection priority.
...
...
@@ -67,6 +69,30 @@ public class Chunk {
this
.
id
=
id
;
}
public
static
Chunk
fromHeader
(
ByteBuffer
buff
,
long
start
)
{
if
(
buff
.
get
()
!=
'c'
)
{
throw
new
RuntimeException
(
"File corrupt"
);
}
int
length
=
buff
.
getInt
();
int
chunkId
=
buff
.
getInt
();
long
metaRootPos
=
buff
.
getLong
();
long
maxLengthLive
=
buff
.
getLong
();
Chunk
c
=
new
Chunk
(
chunkId
);
c
.
length
=
length
;
c
.
start
=
start
;
c
.
metaRootPos
=
metaRootPos
;
c
.
maxLengthLive
=
maxLengthLive
;
return
c
;
}
void
writeHeader
(
ByteBuffer
buff
)
{
buff
.
put
((
byte
)
'c'
);
buff
.
putInt
(
length
);
buff
.
putInt
(
id
);
buff
.
putLong
(
metaRootPos
);
buff
.
putLong
(
maxLengthLive
);
}
/**
* Build a block from the given string.
*
...
...
@@ -78,16 +104,16 @@ public class Chunk {
int
id
=
Integer
.
parseInt
(
map
.
get
(
"id"
));
Chunk
c
=
new
Chunk
(
id
);
c
.
start
=
Long
.
parseLong
(
map
.
get
(
"start"
));
c
.
length
=
Long
.
parseLong
(
map
.
get
(
"length"
));
c
.
entryCount
=
Integer
.
parseInt
(
map
.
get
(
"entryCount
"
));
c
.
liveCount
=
Integer
.
parseInt
(
map
.
get
(
"liveCount
"
));
c
.
length
=
Integer
.
parseInt
(
map
.
get
(
"length"
));
c
.
maxLength
=
Long
.
parseLong
(
map
.
get
(
"maxLength
"
));
c
.
maxLengthLive
=
Long
.
parseLong
(
map
.
get
(
"maxLengthLive
"
));
c
.
metaRootPos
=
Long
.
parseLong
(
map
.
get
(
"metaRoot"
));
c
.
version
=
Long
.
parseLong
(
map
.
get
(
"version"
));
return
c
;
}
public
int
getFillRate
()
{
return
entryCount
==
0
?
0
:
100
*
liveCount
/
entryCount
;
return
(
int
)
(
maxLength
==
0
?
0
:
100
*
maxLengthLive
/
maxLength
)
;
}
public
int
hashCode
()
{
...
...
@@ -103,8 +129,8 @@ public class Chunk {
"id:"
+
id
+
","
+
"start:"
+
start
+
","
+
"length:"
+
length
+
","
+
"
entryCount:"
+
entryCount
+
","
+
"
liveCount:"
+
liveCount
+
","
+
"
maxLength:"
+
maxLength
+
","
+
"
maxLengthLive:"
+
maxLengthLive
+
","
+
"metaRoot:"
+
metaRootPos
+
","
+
"version:"
+
version
;
}
...
...
h2/src/tools/org/h2/dev/store/btree/Dump.java
浏览文件 @
670d256c
...
...
@@ -80,8 +80,12 @@ public class Dump {
int
chunkLength
=
block
.
getInt
();
int
chunkId
=
block
.
getInt
();
long
metaRootPos
=
block
.
getLong
();
writer
.
println
(
" chunk "
+
chunkId
+
" at "
+
pos
+
" length "
+
chunkLength
+
" root "
+
metaRootPos
);
long
maxLengthLive
=
block
.
getLong
();
writer
.
println
(
" chunk "
+
chunkId
+
" at "
+
pos
+
" length "
+
chunkLength
+
" root "
+
metaRootPos
+
" maxLengthLive "
+
maxLengthLive
);
ByteBuffer
chunk
=
ByteBuffer
.
allocate
(
chunkLength
);
file
.
position
(
pos
);
FileUtils
.
readFully
(
file
,
chunk
);
...
...
h2/src/tools/org/h2/dev/store/btree/MVStore.java
浏览文件 @
670d256c
差异被折叠。
点击展开。
h2/src/tools/org/h2/dev/store/btree/Page.java
浏览文件 @
670d256c
...
...
@@ -57,7 +57,7 @@ public class Page {
private
Page
[]
childrenPages
;
private
long
[]
counts
;
private
Page
(
MVMap
<?,
?>
map
,
long
version
)
{
Page
(
MVMap
<?,
?>
map
,
long
version
)
{
this
.
map
=
map
;
this
.
version
=
version
;
}
...
...
@@ -596,7 +596,7 @@ public class Page {
}
}
private
void
read
(
ByteBuffer
buff
,
int
chunkId
,
int
offset
,
int
maxLength
)
{
void
read
(
ByteBuffer
buff
,
int
chunkId
,
int
offset
,
int
maxLength
)
{
int
start
=
buff
.
position
();
int
pageLength
=
buff
.
getInt
();
if
(
pageLength
>
maxLength
)
{
...
...
@@ -661,10 +661,10 @@ public class Page {
/**
* Store the page and update the position.
*
* @param chunk the chunk
* @param buff the target buffer
* @param chunkId the chunk id
*/
private
void
write
(
ByteBuffer
buff
,
int
chunkId
)
{
private
void
write
(
Chunk
chunk
,
ByteBuffer
buff
)
{
int
start
=
buff
.
position
();
buff
.
putInt
(
0
);
buff
.
putShort
((
byte
)
0
);
...
...
@@ -707,11 +707,15 @@ public class Page {
}
int
pageLength
=
buff
.
position
()
-
start
;
buff
.
putInt
(
start
,
pageLength
);
int
chunkId
=
chunk
.
id
;
int
check
=
DataUtils
.
getCheckValue
(
chunkId
)
^
DataUtils
.
getCheckValue
(
start
)
^
DataUtils
.
getCheckValue
(
pageLength
);
buff
.
putShort
(
start
+
4
,
(
short
)
check
);
this
.
pos
=
DataUtils
.
getPagePos
(
chunkId
,
start
,
pageLength
,
type
);
long
max
=
DataUtils
.
getPageMaxLength
(
pos
);
chunk
.
maxLength
+=
max
;
chunk
.
maxLengthLive
+=
max
;
}
/**
...
...
@@ -748,42 +752,25 @@ public class Page {
* Store this page and all children that are changed, in reverse order, and
* update the position and the children.
*
* @param chunk the chunk
* @param buff the target buffer
* @param chunkId the chunk id
* @return the page id
*/
long
writeTempRecursive
(
ByteBuffer
buff
,
int
chunkId
)
{
long
writeTempRecursive
(
Chunk
chunk
,
ByteBuffer
buff
)
{
if
(!
isLeaf
())
{
int
len
=
children
.
length
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Page
p
=
childrenPages
[
i
];
if
(
p
!=
null
)
{
children
[
i
]
=
p
.
writeTempRecursive
(
buff
,
chunkId
);
children
[
i
]
=
p
.
writeTempRecursive
(
chunk
,
buff
);
childrenPages
[
i
]
=
null
;
}
}
}
write
(
buff
,
chunkId
);
write
(
chunk
,
buff
);
return
pos
;
}
/**
* Count the temporary pages recursively.
*
* @return the number of temporary pages
*/
int
countTempRecursive
()
{
int
count
=
1
;
if
(!
isLeaf
())
{
for
(
Page
p
:
childrenPages
)
{
if
(
p
!=
null
)
{
count
+=
p
.
countTempRecursive
();
}
}
}
return
count
;
}
long
getVersion
()
{
return
version
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论