Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8c0bb119
提交
8c0bb119
authored
2月 11, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore file format documentation.
上级
831e6937
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
80 行增加
和
39 行删除
+80
-39
mvstore.html
h2/src/docsrc/html/mvstore.html
+80
-39
没有找到文件。
h2/src/docsrc/html/mvstore.html
浏览文件 @
8c0bb119
...
...
@@ -478,15 +478,56 @@ it is recommended to use it together with the MVCC mode
<h2
id=
"fileFormat"
>
File Format
</h2>
<p>
The data is stored in one file. The file contains two file headers (to be safe),
and a number of chunks. The file headers are one block each; a block is 4096 bytes.
The data is stored in one file.
The file contains two file headers (for safety), and a number of chunks.
The file headers are one block each; a block is 4096 bytes.
Each chunk is at least one block, but typically 200 blocks or more.
There might be a number of free blocks in front of every chunk.
Data is stored in the chunks in the form of a
<a
href=
"https://en.wikipedia.org/wiki/Log-structured_file_system"
>
log structured storage
</a>
.
There is one chunk for every version.
</p>
<pre>
[ file header 1 ] [ file header 2 ] [ chunk ] [ chunk ] ... [ chunk ]
</pre>
<p>
Each chunk contains a number of B-tree pages.
As an example, the following code:
</p>
<pre>
MVStore s = MVStore.open(fileName);
MVMap
<Integer
,
String
>
map = s.openMap("data");
for (int i = 0; i
<
400
;
i
++)
{
map
.
put
(
i
,
"
Hello
");
}
s
.
commit
();
for
(
int
i =
0;
i
<
100
;
i
++)
{
map
.
put
(
0
,
"
Hi
");
}
s
.
commit
();
s
.
close
();
</
pre
>
<p>
will result in the following two chunks (excluding metadata):
</p>
<p>
<b>
Chunk 1:
</b>
</p>
<ul><li>
Page 1: leaf with 140 entries (keys 0 - 139)
</li><li>
Page 2: leaf with 260 entries (keys 140 - 399)
</li><li>
Page 3: node with 2 entries pointing to page 1 and 2 (the root)
</li></ul>
<p>
<b>
Chunk 2:
</b>
</p>
<ul><li>
Page 4: leaf with 140 entries (keys 0 - 139)
</li><li>
Page 5: node with 2 entries pointing to page 4 and 1 (the root)
</li></ul>
<p>
That means each chunk contains the changes of one version,
that means the new version of the changed pages and the parent pages,
recursively, up to the root page. Pages in subsequent chunks refer to
pages in earlier chunks.
</p>
<h3>
File Header
</h3>
<p>
...
...
@@ -573,11 +614,11 @@ to be stored in the next chunk, and the number of live pages in the old chunk is
This mechanism is called copy-on-write, and is similar to how the
<a
href=
"https://en.wikipedia.org/wiki/Btrfs"
>
Btrfs
</a>
file system works.
Chunks without live pages are marked as free, so the space can be re-used by more recent chunks.
Because not all chunks are of the same size, there can be
some unused space
in front of a chunk
Because not all chunks are of the same size, there can be
a number of free blocks
in front of a chunk
for some time (until a small chunk is written or the chunks are compacted).
There is a
<a
href=
"http://stackoverflow.com/questions/13650134/after-how-many-seconds-are-file-system-write-buffers-typically-flushed"
>
delay of 45 seconds
</a>
(by default) before a free chunk is overwritten,
to ensure new versions are persisted first
, as hard disks sometimes re-order write operations
.
to ensure new versions are persisted first.
</p>
<p>
How the newest chunk is located when opening a store:
...
...
@@ -613,10 +654,10 @@ and <a href="https://en.wikipedia.org/wiki/Variable-length_quantity">variable si
</li><li>
len (variable size int): The number of keys in the page.
</li><li>
type (byte): The page type (0 for leaf page, 1 for internal node;
plus 2 if the page data is compressed).
</li><li>
keys (byte array): All keys, stored depending on the data type.
</li><li>
children (array of long; internal nodes only): The position of the children.
</li><li>
childCounts (array of variable size long; internal nodes only):
The total number of entries for the given child page.
</li><li>
keys (byte array): All keys, stored depending on the data type.
</li><li>
values (byte array; leaf pages only): All values, stored depending on the data type.
</li></ul>
<p>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论