Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e833c48d
提交
e833c48d
authored
11月 12, 2018
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
speedup unused chunks collection
上级
b824b78d
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
67 行增加
和
45 行删除
+67
-45
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+67
-45
没有找到文件。
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
e833c48d
...
@@ -305,6 +305,8 @@ public class MVStore {
...
@@ -305,6 +305,8 @@ public class MVStore {
private
long
lastFreeUnusedChunks
;
private
long
lastFreeUnusedChunks
;
private
final
ThreadPoolExecutor
executorService
;
/**
/**
* Create and open the store.
* Create and open the store.
*
*
...
@@ -353,6 +355,8 @@ public class MVStore {
...
@@ -353,6 +355,8 @@ public class MVStore {
}
}
pageSplitSize
=
pgSplitSize
;
pageSplitSize
=
pgSplitSize
;
keysPerPage
=
DataUtils
.
getConfigParam
(
config
,
"keysPerPage"
,
48
);
keysPerPage
=
DataUtils
.
getConfigParam
(
config
,
"keysPerPage"
,
48
);
executorService
=
new
ThreadPoolExecutor
(
10
,
10
,
10L
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<
Runnable
>(
keysPerPage
+
1
));
backgroundExceptionHandler
=
backgroundExceptionHandler
=
(
UncaughtExceptionHandler
)
config
.
get
(
"backgroundExceptionHandler"
);
(
UncaughtExceptionHandler
)
config
.
get
(
"backgroundExceptionHandler"
);
meta
=
new
MVMap
<>(
this
);
meta
=
new
MVMap
<>(
this
);
...
@@ -941,6 +945,11 @@ public class MVStore {
...
@@ -941,6 +945,11 @@ public class MVStore {
return
;
return
;
}
}
stopBackgroundThread
();
stopBackgroundThread
();
if
(
shrinkIfPossible
)
{
executorService
.
shutdown
();
}
else
{
executorService
.
shutdownNow
();
}
closed
=
true
;
closed
=
true
;
storeLock
.
lock
();
storeLock
.
lock
();
try
{
try
{
...
@@ -1349,16 +1358,14 @@ public class MVStore {
...
@@ -1349,16 +1358,14 @@ public class MVStore {
if
(
time
>=
lastFreeUnusedChunks
+
freeDelay
)
{
if
(
time
>=
lastFreeUnusedChunks
+
freeDelay
)
{
// set early in case it fails (out of memory or so)
// set early in case it fails (out of memory or so)
lastFreeUnusedChunks
=
time
;
lastFreeUnusedChunks
=
time
;
freeUnusedChunks
();
freeUnusedChunks
(
true
);
// set it here as well, to avoid calling it often if it was slow
lastFreeUnusedChunks
=
getTimeSinceCreation
();
}
}
}
}
private
void
freeUnusedChunks
()
{
private
void
freeUnusedChunks
(
boolean
fast
)
{
assert
storeLock
.
isHeldByCurrentThread
();
assert
storeLock
.
isHeldByCurrentThread
();
if
(
lastChunk
!=
null
&&
reuseSpace
)
{
if
(
lastChunk
!=
null
&&
reuseSpace
)
{
Set
<
Integer
>
referenced
=
collectReferencedChunks
();
Set
<
Integer
>
referenced
=
collectReferencedChunks
(
fast
);
long
time
=
getTimeSinceCreation
();
long
time
=
getTimeSinceCreation
();
for
(
Iterator
<
Chunk
>
iterator
=
chunks
.
values
().
iterator
();
iterator
.
hasNext
();
)
{
for
(
Iterator
<
Chunk
>
iterator
=
chunks
.
values
().
iterator
();
iterator
.
hasNext
();
)
{
...
@@ -1383,52 +1390,67 @@ public class MVStore {
...
@@ -1383,52 +1390,67 @@ public class MVStore {
}
}
}
}
}
}
// set it here, to avoid calling it often if it was slow
lastFreeUnusedChunks
=
getTimeSinceCreation
();
}
}
}
}
private
Set
<
Integer
>
collectReferencedChunks
()
{
private
Set
<
Integer
>
collectReferencedChunks
(
boolean
fast
)
{
final
ThreadPoolExecutor
executorService
=
new
ThreadPoolExecutor
(
10
,
10
,
10L
,
TimeUnit
.
SECONDS
,
assert
lastChunk
!=
null
;
new
ArrayBlockingQueue
<
Runnable
>(
keysPerPage
+
1
));
final
AtomicInteger
executingThreadCounter
=
new
AtomicInteger
(
0
);
final
AtomicInteger
executingThreadCounter
=
new
AtomicInteger
(
0
);
try
{
ChunkIdsCollector
collector
=
new
ChunkIdsCollector
(
meta
.
getId
());
ChunkIdsCollector
collector
=
new
ChunkIdsCollector
(
meta
.
getId
());
Set
<
Long
>
inspectedRoots
=
new
HashSet
<>();
long
pos
=
lastChunk
.
metaRootPos
;
inspectedRoots
.
add
(
pos
);
collector
.
visit
(
pos
,
executorService
,
executingThreadCounter
);
long
oldestVersionToKeep
=
getOldestVersionToKeep
();
long
oldestVersionToKeep
=
getOldestVersionToKeep
();
MVMap
.
RootReference
rootReference
=
meta
.
getRoot
();
MVMap
.
RootReference
rootReference
=
meta
.
getRoot
();
if
(
fast
)
{
MVMap
.
RootReference
previous
;
while
(
rootReference
.
version
>=
oldestVersionToKeep
&&
(
previous
=
rootReference
.
previous
)
!=
null
)
{
rootReference
=
previous
;
}
inspectVersion
(
rootReference
,
collector
,
executingThreadCounter
,
null
);
Page
rootPage
=
rootReference
.
root
;
long
pos
=
rootPage
.
getPos
();
assert
rootPage
.
isSaved
();
int
chunkId
=
DataUtils
.
getPageChunkId
(
pos
);
while
(++
chunkId
<=
lastChunk
.
id
)
{
collector
.
registerChunk
(
chunkId
);
}
}
else
{
Set
<
Long
>
inspectedRoots
=
new
HashSet
<>();
do
{
do
{
inspectVersion
(
rootReference
,
collector
,
executingThreadCounter
,
inspectedRoots
);
}
while
(
rootReference
.
version
>=
oldestVersionToKeep
&&
(
rootReference
=
rootReference
.
previous
)
!=
null
);
}
return
collector
.
getReferenced
();
}
private
void
inspectVersion
(
MVMap
.
RootReference
rootReference
,
ChunkIdsCollector
collector
,
AtomicInteger
executingThreadCounter
,
Set
<
Long
>
inspectedRoots
)
{
Page
rootPage
=
rootReference
.
root
;
Page
rootPage
=
rootReference
.
root
;
pos
=
rootPage
.
getPos
();
long
pos
=
rootPage
.
getPos
();
if
(!
rootPage
.
isSaved
())
{
if
(
rootPage
.
isSaved
())
{
collector
.
setMapId
(
meta
.
getId
());
if
(
inspectedRoots
!=
null
&&
!
inspectedRoots
.
add
(
pos
))
{
collector
.
visit
(
rootPage
,
executorService
,
executingThreadCounter
)
;
return
;
}
else
if
(
inspectedRoots
.
add
(
pos
))
{
}
collector
.
setMapId
(
meta
.
getId
());
collector
.
setMapId
(
meta
.
getId
());
collector
.
visit
(
pos
,
executorService
,
executingThreadCounter
);
collector
.
visit
(
pos
,
executorService
,
executingThreadCounter
);
}
}
for
(
Cursor
<
String
,
String
>
c
=
new
Cursor
<>(
rootPage
,
"root."
);
c
.
hasNext
();
)
{
for
(
Cursor
<
String
,
String
>
c
=
new
Cursor
<>(
rootPage
,
"root."
);
c
.
hasNext
();)
{
String
key
=
c
.
next
();
String
key
=
c
.
next
();
assert
key
!=
null
;
assert
key
!=
null
;
if
(!
key
.
startsWith
(
"root."
))
{
if
(!
key
.
startsWith
(
"root."
))
{
break
;
break
;
}
}
pos
=
DataUtils
.
parseHexLong
(
c
.
getValue
());
pos
=
DataUtils
.
parseHexLong
(
c
.
getValue
());
if
(
DataUtils
.
isPageSaved
(
pos
)
&&
inspectedRoots
.
add
(
pos
))
{
assert
DataUtils
.
isPageSaved
(
pos
);
// to allow for something like "root.tmp.123" to be
if
(
inspectedRoots
==
null
||
inspectedRoots
.
add
(
pos
))
{
//
processed
// to allow for something like "root.tmp.123" to be
processed
int
mapId
=
DataUtils
.
parseHexInt
(
key
.
substring
(
key
.
lastIndexOf
(
'.'
)
+
1
));
int
mapId
=
DataUtils
.
parseHexInt
(
key
.
substring
(
key
.
lastIndexOf
(
'.'
)
+
1
));
collector
.
setMapId
(
mapId
);
collector
.
setMapId
(
mapId
);
collector
.
visit
(
pos
,
executorService
,
executingThreadCounter
);
collector
.
visit
(
pos
,
executorService
,
executingThreadCounter
);
}
}
}
}
}
while
(
rootReference
.
version
>=
oldestVersionToKeep
&&
(
rootReference
=
rootReference
.
previous
)
!=
null
);
return
collector
.
getReferenced
();
}
finally
{
executorService
.
shutdownNow
();
}
}
}
final
class
ChunkIdsCollector
{
final
class
ChunkIdsCollector
{
...
@@ -1769,7 +1791,7 @@ public class MVStore {
...
@@ -1769,7 +1791,7 @@ public class MVStore {
boolean
oldReuse
=
reuseSpace
;
boolean
oldReuse
=
reuseSpace
;
try
{
try
{
retentionTime
=
-
1
;
retentionTime
=
-
1
;
freeUnusedChunks
();
freeUnusedChunks
(
false
);
if
(
fileStore
.
getFillRate
()
<=
targetFillRate
)
{
if
(
fileStore
.
getFillRate
()
<=
targetFillRate
)
{
long
start
=
fileStore
.
getFirstFree
()
/
BLOCK_SIZE
;
long
start
=
fileStore
.
getFirstFree
()
/
BLOCK_SIZE
;
ArrayList
<
Chunk
>
move
=
findChunksToMove
(
start
,
moveSize
);
ArrayList
<
Chunk
>
move
=
findChunksToMove
(
start
,
moveSize
);
...
@@ -2064,7 +2086,7 @@ public class MVStore {
...
@@ -2064,7 +2086,7 @@ public class MVStore {
}
}
}
}
meta
.
rewrite
(
set
);
meta
.
rewrite
(
set
);
freeUnusedChunks
();
freeUnusedChunks
(
false
);
commit
();
commit
();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论