Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5831e75e
提交
5831e75e
authored
7月 11, 2017
作者:
Noel Grandin
提交者:
GitHub
7月 11, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #553 from andreitokar/mem_optimization
eliminate memory estimations for "mem:" case
上级
5fa31ee0
09fd1633
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
86 行增加
和
66 行删除
+86
-66
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+1
-1
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+15
-13
Page.java
h2/src/main/org/h2/mvstore/Page.java
+67
-51
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+3
-1
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
5831e75e
...
...
@@ -72,7 +72,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
protected
MVMap
(
DataType
keyType
,
DataType
valueType
)
{
this
.
keyType
=
keyType
;
this
.
valueType
=
valueType
;
this
.
root
=
Page
.
createEmpty
(
this
,
-
1
);
}
/**
...
...
@@ -106,6 +105,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
this
.
id
=
DataUtils
.
readHexInt
(
config
,
"id"
,
0
);
this
.
createVersion
=
DataUtils
.
readHexLong
(
config
,
"createVersion"
,
0
);
this
.
writeVersion
=
store
.
getCurrentVersion
();
this
.
root
=
Page
.
createEmpty
(
this
,
-
1
);
}
/**
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
5831e75e
...
...
@@ -120,7 +120,7 @@ MVStore:
/**
* A persistent storage for maps.
*/
public
class
MVStore
{
public
final
class
MVStore
{
/**
* Whether assertions are enabled.
...
...
@@ -292,12 +292,21 @@ public class MVStore {
Object
o
=
config
.
get
(
"compress"
);
this
.
compressionLevel
=
o
==
null
?
0
:
(
Integer
)
o
;
String
fileName
=
(
String
)
config
.
get
(
"fileName"
);
fileStore
=
(
FileStore
)
config
.
get
(
"fileStore"
);
fileStoreIsProvided
=
fileStore
!=
null
;
if
(
fileStore
==
null
&&
fileName
!=
null
)
{
fileStore
=
new
FileStore
();
}
o
=
config
.
get
(
"pageSplitSize"
);
if
(
o
==
null
)
{
pageSplitSize
=
fileName
==
null
?
4
*
1024
:
16
*
1024
;
int
pgSplitSize
;
if
(
o
!=
null
)
{
pgSplitSize
=
(
Integer
)
o
;
}
else
if
(
fileStore
!=
null
)
{
pgSplitSize
=
16
*
1024
;
}
else
{
p
ageSplitSize
=
(
Integer
)
o
;
p
gSplitSize
=
48
;
// number of keys per page in that case
}
pageSplitSize
=
pgSplitSize
;
o
=
config
.
get
(
"backgroundExceptionHandler"
);
this
.
backgroundExceptionHandler
=
(
UncaughtExceptionHandler
)
o
;
meta
=
new
MVMap
<
String
,
String
>(
StringDataType
.
INSTANCE
,
...
...
@@ -306,18 +315,11 @@ public class MVStore {
c
.
put
(
"id"
,
0
);
c
.
put
(
"createVersion"
,
currentVersion
);
meta
.
init
(
this
,
c
);
fileStore
=
(
FileStore
)
config
.
get
(
"fileStore"
);
if
(
fileName
==
null
&&
fileStore
==
null
)
{
if
(
fileStore
==
null
)
{
cache
=
null
;
cacheChunkRef
=
null
;
return
;
}
if
(
fileStore
==
null
)
{
fileStoreIsProvided
=
false
;
fileStore
=
new
FileStore
();
}
else
{
fileStoreIsProvided
=
true
;
}
retentionTime
=
fileStore
.
getDefaultRetentionTime
();
boolean
readOnly
=
config
.
containsKey
(
"readOnly"
);
o
=
config
.
get
(
"cacheSize"
);
...
...
@@ -995,7 +997,7 @@ public class MVStore {
*
* @return the new version
*/
public
long
commit
()
{
public
synchronized
long
commit
()
{
if
(
fileStore
!=
null
)
{
return
commitAndSave
();
}
...
...
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
5831e75e
...
...
@@ -36,6 +36,7 @@ public class Page {
* An empty object array.
*/
public
static
final
Object
[]
EMPTY_OBJECT_ARRAY
=
new
Object
[
0
];
private
static
final
int
IN_MEMORY
=
Integer
.
MIN_VALUE
;
private
final
MVMap
<?,
?>
map
;
private
long
version
;
...
...
@@ -52,7 +53,7 @@ public class Page {
private
int
cachedCompare
;
/**
* The estimated memory used.
* The estimated memory used
in persistent case, IN_MEMORY marker value otherwise
.
*/
private
int
memory
;
...
...
@@ -125,13 +126,15 @@ public class Page {
p
.
values
=
values
;
p
.
children
=
children
;
p
.
totalCount
=
totalCount
;
if
(
memory
==
0
)
{
MVStore
store
=
map
.
store
;
if
(
store
.
getFileStore
()
==
null
)
{
p
.
memory
=
IN_MEMORY
;
}
else
if
(
memory
==
0
)
{
p
.
recalculateMemory
();
}
else
{
p
.
addMemory
(
memory
);
}
MVStore
store
=
map
.
store
;
if
(
store
!=
null
)
{
if
(
store
.
getFileStore
()
!=
null
)
{
store
.
registerUnsavedPage
(
p
.
memory
);
}
return
p
;
...
...
@@ -146,18 +149,8 @@ public class Page {
* @return the page
*/
public
static
Page
create
(
MVMap
<?,
?>
map
,
long
version
,
Page
source
)
{
Page
p
=
new
Page
(
map
,
version
);
// the position is 0
p
.
keys
=
source
.
keys
;
p
.
values
=
source
.
values
;
p
.
children
=
source
.
children
;
p
.
totalCount
=
source
.
totalCount
;
p
.
memory
=
source
.
memory
;
MVStore
store
=
map
.
store
;
if
(
store
!=
null
)
{
store
.
registerUnsavedPage
(
p
.
memory
);
}
return
p
;
return
create
(
map
,
version
,
source
.
keys
,
source
.
values
,
source
.
children
,
source
.
totalCount
,
source
.
memory
);
}
/**
...
...
@@ -302,7 +295,7 @@ public class Page {
Page
newPage
=
create
(
map
,
version
,
keys
,
values
,
children
,
totalCount
,
getMemory
()
);
memory
);
// mark the old as deleted
removePage
();
newPage
.
cachedCompare
=
cachedCompare
;
...
...
@@ -368,7 +361,11 @@ public class Page {
* @return the page with the entries after the split index
*/
Page
split
(
int
at
)
{
return
isLeaf
()
?
splitLeaf
(
at
)
:
splitNode
(
at
);
Page
page
=
isLeaf
()
?
splitLeaf
(
at
)
:
splitNode
(
at
);
if
(
isPersistent
())
{
recalculateMemory
();
}
return
page
;
}
private
Page
splitLeaf
(
int
at
)
{
...
...
@@ -388,9 +385,7 @@ public class Page {
Page
newPage
=
create
(
map
,
version
,
bKeys
,
bValues
,
null
,
bKeys
.
length
,
0
);
recalculateMemory
();
newPage
.
recalculateMemory
();
b
,
0
);
return
newPage
;
}
...
...
@@ -422,8 +417,6 @@ public class Page {
bKeys
,
null
,
bChildren
,
t
,
0
);
recalculateMemory
();
newPage
.
recalculateMemory
();
return
newPage
;
}
...
...
@@ -498,6 +491,7 @@ public class Page {
// this is slightly slower:
// keys = Arrays.copyOf(keys, keys.length);
keys
=
keys
.
clone
();
if
(
isPersistent
())
{
Object
old
=
keys
[
index
];
DataType
keyType
=
map
.
getKeyType
();
int
mem
=
keyType
.
getMemory
(
key
);
...
...
@@ -505,6 +499,7 @@ public class Page {
mem
-=
keyType
.
getMemory
(
old
);
}
addMemory
(
mem
);
}
keys
[
index
]
=
key
;
}
...
...
@@ -521,8 +516,10 @@ public class Page {
// values = Arrays.copyOf(values, values.length);
values
=
values
.
clone
();
DataType
valueType
=
map
.
getValueType
();
if
(
isPersistent
())
{
addMemory
(
valueType
.
getMemory
(
value
)
-
valueType
.
getMemory
(
old
));
}
values
[
index
]
=
value
;
return
old
;
}
...
...
@@ -569,9 +566,11 @@ public class Page {
keys
[
index
]
=
key
;
values
[
index
]
=
value
;
totalCount
++;
if
(
isPersistent
())
{
addMemory
(
map
.
getKeyType
().
getMemory
(
key
)
+
map
.
getValueType
().
getMemory
(
value
));
}
}
/**
* Insert a child page into this node.
...
...
@@ -595,9 +594,11 @@ public class Page {
children
=
newChildren
;
totalCount
+=
childPage
.
totalCount
;
if
(
isPersistent
())
{
addMemory
(
map
.
getKeyType
().
getMemory
(
key
)
+
DataUtils
.
PAGE_MEMORY_CHILD
);
}
}
/**
* Remove the key and value (or child) at the given index.
...
...
@@ -607,22 +608,28 @@ public class Page {
public
void
remove
(
int
index
)
{
int
keyLength
=
keys
.
length
;
int
keyIndex
=
index
>=
keyLength
?
index
-
1
:
index
;
if
(
isPersistent
())
{
Object
old
=
keys
[
keyIndex
];
addMemory
(-
map
.
getKeyType
().
getMemory
(
old
));
}
Object
[]
newKeys
=
new
Object
[
keyLength
-
1
];
DataUtils
.
copyExcept
(
keys
,
newKeys
,
keyLength
,
keyIndex
);
keys
=
newKeys
;
if
(
values
!=
null
)
{
old
=
values
[
index
];
if
(
isPersistent
())
{
Object
old
=
values
[
index
];
addMemory
(-
map
.
getValueType
().
getMemory
(
old
));
}
Object
[]
newValues
=
new
Object
[
keyLength
-
1
];
DataUtils
.
copyExcept
(
values
,
newValues
,
keyLength
,
index
);
values
=
newValues
;
totalCount
--;
}
if
(
children
!=
null
)
{
if
(
isPersistent
())
{
addMemory
(-
DataUtils
.
PAGE_MEMORY_CHILD
);
}
long
countOffset
=
children
[
index
].
count
;
int
childCount
=
children
.
length
;
...
...
@@ -887,7 +894,12 @@ public class Page {
return
pos
!=
0
?
(
int
)
(
pos
|
(
pos
>>>
32
))
:
super
.
hashCode
();
}
private
boolean
isPersistent
()
{
return
memory
!=
IN_MEMORY
;
}
public
int
getMemory
()
{
if
(
isPersistent
())
{
if
(
MVStore
.
ASSERT
)
{
int
mem
=
memory
;
recalculateMemory
();
...
...
@@ -898,6 +910,8 @@ public class Page {
}
return
memory
;
}
return
getKeyCount
();
}
private
void
addMemory
(
int
mem
)
{
memory
+=
mem
;
...
...
@@ -928,12 +942,14 @@ public class Page {
* Remove the page.
*/
public
void
removePage
()
{
if
(
isPersistent
())
{
long
p
=
pos
;
if
(
p
==
0
)
{
removedInMemory
=
true
;
}
map
.
removePage
(
p
,
memory
);
}
}
/**
* A pointer to a page, either in-memory or using a page position.
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
5831e75e
...
...
@@ -1416,7 +1416,9 @@ public class TestMVStore extends TestBase {
assertEquals
(
i
+
1
,
m
.
size
());
}
assertEquals
(
1000
,
m
.
size
());
assertEquals
(
131896
,
s
.
getUnsavedMemory
());
// previously (131896) we fail to account for initial root page for every map
// there are two of them here (meta and "data"), hence lack of 256 bytes
assertEquals
(
132152
,
s
.
getUnsavedMemory
());
s
.
commit
();
assertEquals
(
2
,
s
.
getFileStore
().
getWriteCount
());
s
.
close
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论