Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
26984fbb
提交
26984fbb
authored
4月 04, 2018
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
now some efficiencies in free space accounting
上级
8e520ee6
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
36 行增加
和
19 行删除
+36
-19
FileStore.java
h2/src/main/org/h2/mvstore/FileStore.java
+15
-5
FreeSpaceBitSet.java
h2/src/main/org/h2/mvstore/FreeSpaceBitSet.java
+20
-9
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+1
-5
没有找到文件。
h2/src/main/org/h2/mvstore/FileStore.java
浏览文件 @
26984fbb
...
@@ -54,12 +54,12 @@ public class FileStore {
...
@@ -54,12 +54,12 @@ public class FileStore {
/**
/**
* The file name.
* The file name.
*/
*/
pr
otected
String
fileName
;
pr
ivate
String
fileName
;
/**
/**
* Whether this store is read-only.
* Whether this store is read-only.
*/
*/
pr
otected
boolean
readOnly
;
pr
ivate
boolean
readOnly
;
/**
/**
* The file size (cached).
* The file size (cached).
...
@@ -69,17 +69,17 @@ public class FileStore {
...
@@ -69,17 +69,17 @@ public class FileStore {
/**
/**
* The file.
* The file.
*/
*/
pr
otected
FileChannel
file
;
pr
ivate
FileChannel
file
;
/**
/**
* The encrypted file (if encryption is used).
* The encrypted file (if encryption is used).
*/
*/
pr
otected
FileChannel
encryptedFile
;
pr
ivate
FileChannel
encryptedFile
;
/**
/**
* The file lock.
* The file lock.
*/
*/
pr
otected
FileLock
fileLock
;
pr
ivate
FileLock
fileLock
;
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
...
@@ -337,6 +337,16 @@ public class FileStore {
...
@@ -337,6 +337,16 @@ public class FileStore {
return
freeSpace
.
allocate
(
length
);
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.
* Mark the space as free.
*
*
...
...
h2/src/main/org/h2/mvstore/FreeSpaceBitSet.java
浏览文件 @
26984fbb
...
@@ -94,6 +94,20 @@ public class FreeSpaceBitSet {
...
@@ -94,6 +94,20 @@ public class FreeSpaceBitSet {
* @return the start position in bytes
* @return the start position in bytes
*/
*/
public
long
allocate
(
int
length
)
{
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
);
int
blocks
=
getBlockCount
(
length
);
for
(
int
i
=
0
;;)
{
for
(
int
i
=
0
;;)
{
int
start
=
set
.
nextClearBit
(
i
);
int
start
=
set
.
nextClearBit
(
i
);
...
@@ -101,7 +115,9 @@ public class FreeSpaceBitSet {
...
@@ -101,7 +115,9 @@ public class FreeSpaceBitSet {
if
(
end
<
0
||
end
-
start
>=
blocks
)
{
if
(
end
<
0
||
end
-
start
>=
blocks
)
{
assert
set
.
nextSetBit
(
start
)
==
-
1
||
set
.
nextSetBit
(
start
)
>=
start
+
blocks
:
assert
set
.
nextSetBit
(
start
)
==
-
1
||
set
.
nextSetBit
(
start
)
>=
start
+
blocks
:
"Double alloc: "
+
Integer
.
toHexString
(
start
)
+
"/"
+
Integer
.
toHexString
(
blocks
)
+
" "
+
this
;
"Double alloc: "
+
Integer
.
toHexString
(
start
)
+
"/"
+
Integer
.
toHexString
(
blocks
)
+
" "
+
this
;
if
(
allocate
)
{
set
.
set
(
start
,
start
+
blocks
);
set
.
set
(
start
,
start
+
blocks
);
}
return
getPos
(
start
);
return
getPos
(
start
);
}
}
i
=
end
;
i
=
end
;
...
@@ -155,16 +171,11 @@ public class FreeSpaceBitSet {
...
@@ -155,16 +171,11 @@ public class FreeSpaceBitSet {
* @return the fill rate (0 - 100)
* @return the fill rate (0 - 100)
*/
*/
public
int
getFillRate
()
{
public
int
getFillRate
()
{
int
total
=
set
.
length
(),
count
=
0
;
int
cardinality
=
set
.
cardinality
();
for
(
int
i
=
0
;
i
<
total
;
i
++)
{
if
(
cardinality
==
0
)
{
if
(
set
.
get
(
i
))
{
count
++;
}
}
if
(
count
==
0
)
{
return
0
;
return
0
;
}
}
return
Math
.
max
(
1
,
(
int
)
(
100L
*
count
/
total
));
return
Math
.
max
(
1
,
(
int
)
(
100L
*
cardinality
/
set
.
length
()
));
}
}
/**
/**
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
26984fbb
...
@@ -1151,11 +1151,7 @@ public final class MVStore {
...
@@ -1151,11 +1151,7 @@ public final class MVStore {
c
.
metaRootPos
=
metaRoot
.
getPos
();
c
.
metaRootPos
=
metaRoot
.
getPos
();
// calculate and set the likely next position
// calculate and set the likely next position
if
(
reuseSpace
)
{
if
(
reuseSpace
)
{
int
predictBlocks
=
c
.
len
;
c
.
next
=
fileStore
.
predictAllocation
(
c
.
len
*
BLOCK_SIZE
)
/
BLOCK_SIZE
;
long
predictedNextStart
=
fileStore
.
allocate
(
predictBlocks
*
BLOCK_SIZE
);
fileStore
.
free
(
predictedNextStart
,
predictBlocks
*
BLOCK_SIZE
);
c
.
next
=
predictedNextStart
/
BLOCK_SIZE
;
}
else
{
}
else
{
// just after this chunk
// just after this chunk
c
.
next
=
0
;
c
.
next
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论