Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
781f90d6
Unverified
提交
781f90d6
authored
7 年前
作者:
Andrei Tokar
提交者:
GitHub
7 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1035 from h2database/free_space_bs
Minor free space accointing changes
上级
817b0944
5c164418
master
version-1.4.198
无相关合并请求
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
54 行增加
和
22 行删除
+54
-22
FileStore.java
h2/src/main/org/h2/mvstore/FileStore.java
+15
-5
FreeSpaceBitSet.java
h2/src/main/org/h2/mvstore/FreeSpaceBitSet.java
+26
-9
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+13
-8
没有找到文件。
h2/src/main/org/h2/mvstore/FileStore.java
浏览文件 @
781f90d6
...
...
@@ -54,12 +54,12 @@ public class FileStore {
/**
* The file name.
*/
pr
otected
String
fileName
;
pr
ivate
String
fileName
;
/**
* Whether this store is read-only.
*/
pr
otected
boolean
readOnly
;
pr
ivate
boolean
readOnly
;
/**
* The file size (cached).
...
...
@@ -69,17 +69,17 @@ public class FileStore {
/**
* The file.
*/
pr
otected
FileChannel
file
;
pr
ivate
FileChannel
file
;
/**
* The encrypted file (if encryption is used).
*/
pr
otected
FileChannel
encryptedFile
;
pr
ivate
FileChannel
encryptedFile
;
/**
* The file lock.
*/
pr
otected
FileLock
fileLock
;
pr
ivate
FileLock
fileLock
;
@Override
public
String
toString
()
{
...
...
@@ -337,6 +337,16 @@ public class FileStore {
return
freeSpace
.
allocate
(
length
);
}
/**
* Calculate starting position of the prospective allocation.
*
* @param length the number of bytes to allocate
* @return the start position in bytes
*/
public
long
predictAllocation
(
int
length
)
{
return
freeSpace
.
predictAllocation
(
length
);
}
/**
* Mark the space as free.
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/FreeSpaceBitSet.java
浏览文件 @
781f90d6
...
...
@@ -94,12 +94,30 @@ public class FreeSpaceBitSet {
* @return the start position in bytes
*/
public
long
allocate
(
int
length
)
{
return
allocate
(
length
,
true
);
}
/**
* Calculate starting position of the prospective allocation.
*
* @param length the number of bytes to allocate
* @return the start position in bytes
*/
public
long
predictAllocation
(
int
length
)
{
return
allocate
(
length
,
false
);
}
private
long
allocate
(
int
length
,
boolean
allocate
)
{
int
blocks
=
getBlockCount
(
length
);
for
(
int
i
=
0
;;)
{
int
start
=
set
.
nextClearBit
(
i
);
int
end
=
set
.
nextSetBit
(
start
+
1
);
if
(
end
<
0
||
end
-
start
>=
blocks
)
{
set
.
set
(
start
,
start
+
blocks
);
assert
set
.
nextSetBit
(
start
)
==
-
1
||
set
.
nextSetBit
(
start
)
>=
start
+
blocks
:
"Double alloc: "
+
Integer
.
toHexString
(
start
)
+
"/"
+
Integer
.
toHexString
(
blocks
)
+
" "
+
this
;
if
(
allocate
)
{
set
.
set
(
start
,
start
+
blocks
);
}
return
getPos
(
start
);
}
i
=
end
;
...
...
@@ -115,6 +133,8 @@ public class FreeSpaceBitSet {
public
void
markUsed
(
long
pos
,
int
length
)
{
int
start
=
getBlock
(
pos
);
int
blocks
=
getBlockCount
(
length
);
assert
set
.
nextSetBit
(
start
)
==
-
1
||
set
.
nextSetBit
(
start
)
>=
start
+
blocks
:
"Double mark: "
+
Integer
.
toHexString
(
start
)
+
"/"
+
Integer
.
toHexString
(
blocks
)
+
" "
+
this
;
set
.
set
(
start
,
start
+
blocks
);
}
...
...
@@ -127,6 +147,8 @@ public class FreeSpaceBitSet {
public
void
free
(
long
pos
,
int
length
)
{
int
start
=
getBlock
(
pos
);
int
blocks
=
getBlockCount
(
length
);
assert
set
.
nextClearBit
(
start
)
>=
start
+
blocks
:
"Double free: "
+
Integer
.
toHexString
(
start
)
+
"/"
+
Integer
.
toHexString
(
blocks
)
+
" "
+
this
;
set
.
clear
(
start
,
start
+
blocks
);
}
...
...
@@ -149,16 +171,11 @@ public class FreeSpaceBitSet {
* @return the fill rate (0 - 100)
*/
public
int
getFillRate
()
{
int
total
=
set
.
length
(),
count
=
0
;
for
(
int
i
=
0
;
i
<
total
;
i
++)
{
if
(
set
.
get
(
i
))
{
count
++;
}
}
if
(
count
==
0
)
{
int
cardinality
=
set
.
cardinality
();
if
(
cardinality
==
0
)
{
return
0
;
}
return
Math
.
max
(
1
,
(
int
)
(
100L
*
count
/
total
));
return
Math
.
max
(
1
,
(
int
)
(
100L
*
cardinality
/
set
.
length
()
));
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
781f90d6
...
...
@@ -662,10 +662,8 @@ public final class MVStore {
}
setLastChunk
(
newest
);
loadChunkMeta
();
// read all chunk headers and footers within the retention time,
// to detect unwritten data after a power failure
verifyLastChunks
();
// build the free space list
fileStore
.
clear
();
for
(
Chunk
c
:
chunks
.
values
())
{
if
(
c
.
pageCountLive
==
0
)
{
// remove this chunk in the next save operation
...
...
@@ -675,6 +673,11 @@ public final class MVStore {
int
length
=
c
.
len
*
BLOCK_SIZE
;
fileStore
.
markUsed
(
start
,
length
);
}
assert
fileStore
.
getFileLengthInUse
()
==
measureFileLengthInUse
()
:
fileStore
.
getFileLengthInUse
()
+
" != "
+
measureFileLengthInUse
();
// read all chunk headers and footers within the retention time,
// to detect unwritten data after a power failure
verifyLastChunks
();
}
private
void
loadChunkMeta
()
{
...
...
@@ -1143,14 +1146,12 @@ public final class MVStore {
c
.
block
=
filePos
/
BLOCK_SIZE
;
c
.
len
=
length
/
BLOCK_SIZE
;
assert
fileStore
.
getFileLengthInUse
()
==
measureFileLengthInUse
()
:
fileStore
.
getFileLengthInUse
()
+
" != "
+
measureFileLengthInUse
()
+
" "
+
c
;
c
.
metaRootPos
=
metaRoot
.
getPos
();
// calculate and set the likely next position
if
(
reuseSpace
)
{
int
predictBlocks
=
c
.
len
;
long
predictedNextStart
=
fileStore
.
allocate
(
predictBlocks
*
BLOCK_SIZE
);
fileStore
.
free
(
predictedNextStart
,
predictBlocks
*
BLOCK_SIZE
);
c
.
next
=
predictedNextStart
/
BLOCK_SIZE
;
c
.
next
=
fileStore
.
predictAllocation
(
c
.
len
*
BLOCK_SIZE
)
/
BLOCK_SIZE
;
}
else
{
// just after this chunk
c
.
next
=
0
;
...
...
@@ -1257,6 +1258,8 @@ public final class MVStore {
long
start
=
c
.
block
*
BLOCK_SIZE
;
int
length
=
c
.
len
*
BLOCK_SIZE
;
fileStore
.
free
(
start
,
length
);
assert
fileStore
.
getFileLengthInUse
()
==
measureFileLengthInUse
()
:
fileStore
.
getFileLengthInUse
()
+
" != "
+
measureFileLengthInUse
();
}
else
{
if
(
c
.
unused
==
0
)
{
c
.
unused
=
time
;
...
...
@@ -2304,6 +2307,8 @@ public final class MVStore {
long
start
=
c
.
block
*
BLOCK_SIZE
;
int
length
=
c
.
len
*
BLOCK_SIZE
;
fileStore
.
free
(
start
,
length
);
assert
fileStore
.
getFileLengthInUse
()
==
measureFileLengthInUse
()
:
fileStore
.
getFileLengthInUse
()
+
" != "
+
measureFileLengthInUse
();
// overwrite the chunk,
// so it is not be used later on
WriteBuffer
buff
=
getWriteBuffer
();
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论