Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cbab3234
提交
cbab3234
authored
10 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: tool to quickly compact a store.
上级
5da4e45c
全部展开
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
120 行增加
和
157 行删除
+120
-157
CursorPos.java
h2/src/main/org/h2/mvstore/CursorPos.java
+1
-1
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+19
-10
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+55
-128
MVStoreTool.java
h2/src/main/org/h2/mvstore/MVStoreTool.java
+20
-8
WriteBuffer.java
h2/src/main/org/h2/mvstore/WriteBuffer.java
+5
-1
MVTableEngine.java
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
+4
-4
TestMVStoreTool.java
h2/src/test/org/h2/test/store/TestMVStoreTool.java
+16
-5
没有找到文件。
h2/src/main/org/h2/mvstore/CursorPos.java
浏览文件 @
cbab3234
...
@@ -13,7 +13,7 @@ public class CursorPos {
...
@@ -13,7 +13,7 @@ public class CursorPos {
/**
/**
* The current page.
* The current page.
*/
*/
public
final
Page
page
;
public
Page
page
;
/**
/**
* The current index.
* The current index.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
cbab3234
...
@@ -995,7 +995,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -995,7 +995,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return
;
return
;
}
}
Page
last
=
oldRoots
.
peekLast
();
Page
last
=
oldRoots
.
peekLast
();
// TODO why is this?
// TODO why is this?
(maybe not needed)
;
;
oldest
--;
oldest
--;
while
(
true
)
{
while
(
true
)
{
...
@@ -1257,23 +1257,32 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -1257,23 +1257,32 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* @param sourceMap the source map
* @param sourceMap the source map
*/
*/
void
copyFrom
(
MVMap
<
K
,
V
>
sourceMap
)
{
void
copyFrom
(
MVMap
<
K
,
V
>
sourceMap
)
{
;
// TODO work in progress
beforeWrite
();
root
=
copy
(
sourceMap
.
root
,
null
);
newRoot
(
copy
(
sourceMap
.
root
,
null
));
afterWrite
();
}
}
private
Page
copy
(
Page
source
,
CursorPos
parent
)
{
private
Page
copy
(
Page
source
,
CursorPos
parent
)
{
Page
target
=
Page
.
create
(
this
,
writeVersion
,
source
);
Page
target
=
Page
.
create
(
this
,
writeVersion
,
source
);
if
(
target
.
isLeaf
())
{
Page
child
=
target
;
for
(
CursorPos
p
=
parent
;
p
!=
null
;
p
=
p
.
parent
)
{
for
(
CursorPos
p
=
parent
;
p
!=
null
;
p
=
p
.
parent
)
{
p
.
page
.
setChild
(
p
.
index
,
target
);
p
.
page
.
setChild
(
p
.
index
,
child
);
p
.
page
=
copyOnWrite
(
p
.
page
,
writeVersion
);
child
=
p
.
page
;
if
(
p
.
parent
==
null
)
{
newRoot
(
p
.
page
);
afterWrite
();
beforeWrite
();
}
}
}
if
(!
target
.
isLeaf
())
{
}
else
{
CursorPos
pos
=
new
CursorPos
(
target
,
0
,
parent
);
CursorPos
pos
=
new
CursorPos
(
target
,
0
,
parent
);
target
=
copyOnWrite
(
target
,
writeVersion
);
for
(
int
i
=
0
;
i
<
target
.
getChildPageCount
();
i
++)
{
for
(
int
i
=
0
;
i
<
target
.
getChildPageCount
();
i
++)
{
Page
sourceChild
=
source
.
getChildPage
(
i
);
pos
.
index
=
i
;
pos
.
index
=
i
;
copy
(
source
Child
,
pos
);
copy
(
source
.
getChildPage
(
i
)
,
pos
);
}
}
target
=
pos
.
page
;
}
}
return
target
;
return
target
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
cbab3234
差异被折叠。
点击展开。
h2/src/main/org/h2/mvstore/MVStoreTool.java
浏览文件 @
cbab3234
...
@@ -45,6 +45,12 @@ public class MVStoreTool {
...
@@ -45,6 +45,12 @@ public class MVStoreTool {
}
else
if
(
"-info"
.
equals
(
args
[
i
]))
{
}
else
if
(
"-info"
.
equals
(
args
[
i
]))
{
String
fileName
=
args
[++
i
];
String
fileName
=
args
[++
i
];
info
(
fileName
,
new
PrintWriter
(
System
.
out
));
info
(
fileName
,
new
PrintWriter
(
System
.
out
));
}
else
if
(
"-compact"
.
equals
(
args
[
i
]))
{
String
fileName
=
args
[++
i
];
compact
(
fileName
,
false
);
}
else
if
(
"-compress"
.
equals
(
args
[
i
]))
{
String
fileName
=
args
[++
i
];
compact
(
fileName
,
true
);
}
}
}
}
}
}
...
@@ -301,9 +307,10 @@ public class MVStoreTool {
...
@@ -301,9 +307,10 @@ public class MVStoreTool {
* there.
* there.
*
*
* @param fileName the file name
* @param fileName the file name
* @param compress whether to compress the data
*/
*/
public
static
void
comp
ress
(
String
fileName
)
{
public
static
void
comp
act
(
String
fileName
,
boolean
compress
)
{
comp
ress
(
fileName
,
fileName
+
".new"
);
comp
act
(
fileName
,
fileName
+
".new"
,
compress
);
FileUtils
.
moveTo
(
fileName
,
fileName
+
".old"
);
FileUtils
.
moveTo
(
fileName
,
fileName
+
".old"
);
FileUtils
.
moveTo
(
fileName
,
fileName
);
FileUtils
.
moveTo
(
fileName
,
fileName
);
FileUtils
.
delete
(
fileName
+
".old"
);
FileUtils
.
delete
(
fileName
+
".old"
);
...
@@ -315,12 +322,18 @@ public class MVStoreTool {
...
@@ -315,12 +322,18 @@ public class MVStoreTool {
* @param sourceFileName the name of the source store
* @param sourceFileName the name of the source store
* @param targetFileName the name of the target store
* @param targetFileName the name of the target store
*/
*/
public
static
void
comp
ress
(
String
sourceFileName
,
String
targetFileName
)
{
public
static
void
comp
act
(
String
sourceFileName
,
String
targetFileName
,
boolean
compress
)
{
MVStore
source
=
new
MVStore
.
Builder
().
MVStore
source
=
new
MVStore
.
Builder
().
fileName
(
sourceFileName
).
readOnly
().
open
();
fileName
(
sourceFileName
).
readOnly
().
open
();
FileUtils
.
delete
(
targetFileName
);
FileUtils
.
delete
(
targetFileName
);
MVStore
target
=
new
MVStore
.
Builder
().
MVStore
.
Builder
b
=
new
MVStore
.
Builder
().
fileName
(
targetFileName
).
open
();
fileName
(
targetFileName
);
if
(
compress
)
{
b
.
compress
();
}
MVStore
target
=
b
.
open
();
MVMap
<
String
,
String
>
sourceMeta
=
source
.
getMetaMap
();
MVMap
<
String
,
String
>
sourceMeta
=
source
.
getMetaMap
();
MVMap
<
String
,
String
>
targetMeta
=
target
.
getMetaMap
();
MVMap
<
String
,
String
>
targetMeta
=
target
.
getMetaMap
();
for
(
Entry
<
String
,
String
>
m
:
sourceMeta
.
entrySet
())
{
for
(
Entry
<
String
,
String
>
m
:
sourceMeta
.
entrySet
())
{
...
@@ -345,7 +358,6 @@ public class MVStoreTool {
...
@@ -345,7 +358,6 @@ public class MVStoreTool {
MVMap
<
Object
,
Object
>
sourceMap
=
source
.
openMap
(
mapName
,
mp
);
MVMap
<
Object
,
Object
>
sourceMap
=
source
.
openMap
(
mapName
,
mp
);
MVMap
<
Object
,
Object
>
targetMap
=
target
.
openMap
(
mapName
,
mp
);
MVMap
<
Object
,
Object
>
targetMap
=
target
.
openMap
(
mapName
,
mp
);
targetMap
.
copyFrom
(
sourceMap
);
targetMap
.
copyFrom
(
sourceMap
);
target
.
commit
();
}
}
target
.
close
();
target
.
close
();
source
.
close
();
source
.
close
();
...
@@ -364,7 +376,7 @@ public class MVStoreTool {
...
@@ -364,7 +376,7 @@ public class MVStoreTool {
@Override
@Override
public
int
getMemory
(
Object
obj
)
{
public
int
getMemory
(
Object
obj
)
{
return
obj
==
null
?
0
:
((
byte
[])
obj
).
length
;
return
obj
==
null
?
0
:
((
byte
[])
obj
).
length
*
8
;
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/WriteBuffer.java
浏览文件 @
cbab3234
...
@@ -304,7 +304,11 @@ public class WriteBuffer {
...
@@ -304,7 +304,11 @@ public class WriteBuffer {
// grow at least 50% of the current size
// grow at least 50% of the current size
grow
=
Math
.
max
(
temp
.
capacity
()
/
2
,
grow
);
grow
=
Math
.
max
(
temp
.
capacity
()
/
2
,
grow
);
int
newCapacity
=
temp
.
capacity
()
+
grow
;
int
newCapacity
=
temp
.
capacity
()
+
grow
;
try
{
buff
=
ByteBuffer
.
allocate
(
newCapacity
);
buff
=
ByteBuffer
.
allocate
(
newCapacity
);
}
catch
(
OutOfMemoryError
e
)
{
throw
new
OutOfMemoryError
(
"Capacity: "
+
newCapacity
);
}
temp
.
flip
();
temp
.
flip
();
buff
.
put
(
temp
);
buff
.
put
(
temp
);
if
(
newCapacity
<=
MAX_REUSE_CAPACITY
)
{
if
(
newCapacity
<=
MAX_REUSE_CAPACITY
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
浏览文件 @
cbab3234
...
@@ -317,9 +317,9 @@ public class MVTableEngine implements TableEngine {
...
@@ -317,9 +317,9 @@ public class MVTableEngine implements TableEngine {
store
.
compactMoveChunks
();
store
.
compactMoveChunks
();
}
else
{
}
else
{
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
while
(
store
.
compact
(
9
9
,
16
*
1024
*
1024
))
{
while
(
store
.
compact
(
9
5
,
16
*
1024
*
1024
))
{
store
.
sync
();
store
.
sync
();
store
.
compactMoveChunks
(
16
*
1024
*
1024
);
store
.
compactMoveChunks
(
95
,
16
*
1024
*
1024
);
long
time
=
System
.
currentTimeMillis
()
-
start
;
long
time
=
System
.
currentTimeMillis
()
-
start
;
if
(
time
>
maxCompactTime
)
{
if
(
time
>
maxCompactTime
)
{
break
;
break
;
...
@@ -341,8 +341,8 @@ public class MVTableEngine implements TableEngine {
...
@@ -341,8 +341,8 @@ public class MVTableEngine implements TableEngine {
if
(!
store
.
getFileStore
().
isReadOnly
())
{
if
(!
store
.
getFileStore
().
isReadOnly
())
{
transactionStore
.
close
();
transactionStore
.
close
();
if
(
maxCompactTime
>
0
)
{
if
(
maxCompactTime
>
0
)
{
store
.
compact
(
9
9
,
1
*
1024
*
1024
);
store
.
compact
(
9
5
,
1024
*
1024
);
store
.
compactMoveChunks
(
1
*
1024
*
1024
);
store
.
compactMoveChunks
(
95
,
1024
*
1024
);
}
}
}
}
store
.
close
();
store
.
close
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestMVStoreTool.java
浏览文件 @
cbab3234
...
@@ -32,12 +32,12 @@ public class TestMVStoreTool extends TestBase {
...
@@ -32,12 +32,12 @@ public class TestMVStoreTool extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
;
// TODO work in progress
testCompress
();
// testCompress();
}
}
private
void
testCompress
()
{
private
void
testCompress
()
{
String
fileName
=
getBaseDir
()
+
"/testCompress.h3"
;
String
fileName
=
getBaseDir
()
+
"/testCompress.h3"
;
FileUtils
.
createDirectory
(
getBaseDir
());
FileUtils
.
delete
(
fileName
);
FileUtils
.
delete
(
fileName
);
// store with a very small page size, to make sure
// store with a very small page size, to make sure
// there are many leaf pages
// there are many leaf pages
...
@@ -51,15 +51,26 @@ public class TestMVStoreTool extends TestBase {
...
@@ -51,15 +51,26 @@ public class TestMVStoreTool extends TestBase {
s
.
commit
();
s
.
commit
();
}
}
}
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
map
=
s
.
openMap
(
"data"
+
i
);
for
(
int
j
=
0
;
j
<
i
*
i
;
j
++)
{
map
.
put
(
j
,
j
*
10
);
}
s
.
commit
();
}
s
.
close
();
s
.
close
();
// MVStoreTool.dump(fileName);
MVStoreTool
.
compact
(
fileName
,
fileName
+
".new"
,
false
);
// MVStoreTool.dump(fileName + ".new");
MVStoreTool
.
compact
(
fileName
,
fileName
+
".new.compress"
,
true
);
MVStoreTool
.
compress
(
fileName
,
fileName
+
".new"
);
MVStore
s1
=
new
MVStore
.
Builder
().
MVStore
s1
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
readOnly
().
open
();
fileName
(
fileName
).
readOnly
().
open
();
MVStore
s2
=
new
MVStore
.
Builder
().
MVStore
s2
=
new
MVStore
.
Builder
().
fileName
(
fileName
+
".new"
).
readOnly
().
open
();
fileName
(
fileName
+
".new"
).
readOnly
().
open
();
MVStore
s3
=
new
MVStore
.
Builder
().
fileName
(
fileName
+
".new.compress"
).
readOnly
().
open
();
assertEquals
(
s1
,
s2
);
assertEquals
(
s1
,
s2
);
assertEquals
(
s1
,
s3
);
assertTrue
(
FileUtils
.
size
(
fileName
+
".new"
)
<
FileUtils
.
size
(
fileName
));
assertTrue
(
FileUtils
.
size
(
fileName
+
".new.compress"
)
<
FileUtils
.
size
(
fileName
+
".new"
));
}
}
private
void
assertEquals
(
MVStore
a
,
MVStore
b
)
{
private
void
assertEquals
(
MVStore
a
,
MVStore
b
)
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论