Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c4ce9e65
提交
c4ce9e65
authored
4月 19, 2017
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eliminate memory estimations for "mem:" case
上级
51847fec
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
101 行增加
和
77 行删除
+101
-77
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+1
-1
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+11
-15
Page.java
h2/src/main/org/h2/mvstore/Page.java
+86
-60
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+3
-1
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
c4ce9e65
...
@@ -72,7 +72,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -72,7 +72,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
protected
MVMap
(
DataType
keyType
,
DataType
valueType
)
{
protected
MVMap
(
DataType
keyType
,
DataType
valueType
)
{
this
.
keyType
=
keyType
;
this
.
keyType
=
keyType
;
this
.
valueType
=
valueType
;
this
.
valueType
=
valueType
;
this
.
root
=
Page
.
createEmpty
(
this
,
-
1
);
}
}
/**
/**
...
@@ -106,6 +105,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -106,6 +105,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
this
.
id
=
DataUtils
.
readHexInt
(
config
,
"id"
,
0
);
this
.
id
=
DataUtils
.
readHexInt
(
config
,
"id"
,
0
);
this
.
createVersion
=
DataUtils
.
readHexLong
(
config
,
"createVersion"
,
0
);
this
.
createVersion
=
DataUtils
.
readHexLong
(
config
,
"createVersion"
,
0
);
this
.
writeVersion
=
store
.
getCurrentVersion
();
this
.
writeVersion
=
store
.
getCurrentVersion
();
this
.
root
=
Page
.
createEmpty
(
this
,
-
1
);
}
}
/**
/**
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
c4ce9e65
...
@@ -120,7 +120,7 @@ MVStore:
...
@@ -120,7 +120,7 @@ MVStore:
/**
/**
* A persistent storage for maps.
* A persistent storage for maps.
*/
*/
public
class
MVStore
{
public
final
class
MVStore
{
/**
/**
* Whether assertions are enabled.
* Whether assertions are enabled.
...
@@ -292,12 +292,15 @@ public class MVStore {
...
@@ -292,12 +292,15 @@ public class MVStore {
Object
o
=
config
.
get
(
"compress"
);
Object
o
=
config
.
get
(
"compress"
);
this
.
compressionLevel
=
o
==
null
?
0
:
(
Integer
)
o
;
this
.
compressionLevel
=
o
==
null
?
0
:
(
Integer
)
o
;
String
fileName
=
(
String
)
config
.
get
(
"fileName"
);
String
fileName
=
(
String
)
config
.
get
(
"fileName"
);
o
=
config
.
get
(
"pageSplitSize"
);
fileStore
=
(
FileStore
)
config
.
get
(
"fileStore"
);
if
(
o
==
null
)
{
fileStoreIsProvided
=
fileStore
!=
null
;
pageSplitSize
=
fileName
==
null
?
4
*
1024
:
16
*
1024
;
if
(
fileStore
==
null
&&
fileName
!=
null
)
{
}
else
{
fileStore
=
new
FileStore
();
pageSplitSize
=
(
Integer
)
o
;
}
}
o
=
config
.
get
(
"pageSplitSize"
);
pageSplitSize
=
o
!=
null
?
(
Integer
)
o
:
fileStore
==
null
?
48
:
16
*
1024
;
o
=
config
.
get
(
"backgroundExceptionHandler"
);
o
=
config
.
get
(
"backgroundExceptionHandler"
);
this
.
backgroundExceptionHandler
=
(
UncaughtExceptionHandler
)
o
;
this
.
backgroundExceptionHandler
=
(
UncaughtExceptionHandler
)
o
;
meta
=
new
MVMap
<
String
,
String
>(
StringDataType
.
INSTANCE
,
meta
=
new
MVMap
<
String
,
String
>(
StringDataType
.
INSTANCE
,
...
@@ -306,18 +309,11 @@ public class MVStore {
...
@@ -306,18 +309,11 @@ public class MVStore {
c
.
put
(
"id"
,
0
);
c
.
put
(
"id"
,
0
);
c
.
put
(
"createVersion"
,
currentVersion
);
c
.
put
(
"createVersion"
,
currentVersion
);
meta
.
init
(
this
,
c
);
meta
.
init
(
this
,
c
);
fileStore
=
(
FileStore
)
config
.
get
(
"fileStore"
);
if
(
fileStore
==
null
)
{
if
(
fileName
==
null
&&
fileStore
==
null
)
{
cache
=
null
;
cache
=
null
;
cacheChunkRef
=
null
;
cacheChunkRef
=
null
;
return
;
return
;
}
}
if
(
fileStore
==
null
)
{
fileStoreIsProvided
=
false
;
fileStore
=
new
FileStore
();
}
else
{
fileStoreIsProvided
=
true
;
}
retentionTime
=
fileStore
.
getDefaultRetentionTime
();
retentionTime
=
fileStore
.
getDefaultRetentionTime
();
boolean
readOnly
=
config
.
containsKey
(
"readOnly"
);
boolean
readOnly
=
config
.
containsKey
(
"readOnly"
);
o
=
config
.
get
(
"cacheSize"
);
o
=
config
.
get
(
"cacheSize"
);
...
@@ -995,7 +991,7 @@ public class MVStore {
...
@@ -995,7 +991,7 @@ public class MVStore {
*
*
* @return the new version
* @return the new version
*/
*/
public
long
commit
()
{
public
synchronized
long
commit
()
{
if
(
fileStore
!=
null
)
{
if
(
fileStore
!=
null
)
{
return
commitAndSave
();
return
commitAndSave
();
}
}
...
...
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
c4ce9e65
...
@@ -36,6 +36,7 @@ public class Page {
...
@@ -36,6 +36,7 @@ public class Page {
* An empty object array.
* An empty object array.
*/
*/
public
static
final
Object
[]
EMPTY_OBJECT_ARRAY
=
new
Object
[
0
];
public
static
final
Object
[]
EMPTY_OBJECT_ARRAY
=
new
Object
[
0
];
private
static
final
int
IN_MEMORY
=
Integer
.
MIN_VALUE
;
private
final
MVMap
<?,
?>
map
;
private
final
MVMap
<?,
?>
map
;
private
long
version
;
private
long
version
;
...
@@ -125,13 +126,15 @@ public class Page {
...
@@ -125,13 +126,15 @@ public class Page {
p
.
values
=
values
;
p
.
values
=
values
;
p
.
children
=
children
;
p
.
children
=
children
;
p
.
totalCount
=
totalCount
;
p
.
totalCount
=
totalCount
;
if
(
memory
==
0
)
{
MVStore
store
=
map
.
store
;
if
(
store
.
getFileStore
()
==
null
)
{
p
.
memory
=
IN_MEMORY
;
}
else
if
(
memory
==
0
)
{
p
.
recalculateMemory
();
p
.
recalculateMemory
();
}
else
{
}
else
{
p
.
addMemory
(
memory
);
p
.
addMemory
(
memory
);
}
}
MVStore
store
=
map
.
store
;
if
(
store
.
getFileStore
()
!=
null
)
{
if
(
store
!=
null
)
{
store
.
registerUnsavedPage
(
p
.
memory
);
store
.
registerUnsavedPage
(
p
.
memory
);
}
}
return
p
;
return
p
;
...
@@ -146,18 +149,8 @@ public class Page {
...
@@ -146,18 +149,8 @@ public class Page {
* @return the page
* @return the page
*/
*/
public
static
Page
create
(
MVMap
<?,
?>
map
,
long
version
,
Page
source
)
{
public
static
Page
create
(
MVMap
<?,
?>
map
,
long
version
,
Page
source
)
{
Page
p
=
new
Page
(
map
,
version
);
return
create
(
map
,
version
,
source
.
keys
,
source
.
values
,
source
.
children
,
// the position is 0
source
.
totalCount
,
source
.
memory
);
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
;
}
}
/**
/**
...
@@ -302,7 +295,7 @@ public class Page {
...
@@ -302,7 +295,7 @@ public class Page {
Page
newPage
=
create
(
map
,
version
,
Page
newPage
=
create
(
map
,
version
,
keys
,
values
,
keys
,
values
,
children
,
totalCount
,
children
,
totalCount
,
getMemory
()
);
memory
);
// mark the old as deleted
// mark the old as deleted
removePage
();
removePage
();
newPage
.
cachedCompare
=
cachedCompare
;
newPage
.
cachedCompare
=
cachedCompare
;
...
@@ -388,9 +381,11 @@ public class Page {
...
@@ -388,9 +381,11 @@ public class Page {
Page
newPage
=
create
(
map
,
version
,
Page
newPage
=
create
(
map
,
version
,
bKeys
,
bValues
,
bKeys
,
bValues
,
null
,
null
,
bKeys
.
length
,
0
);
b
,
0
);
recalculateMemory
();
if
(
isPersistent
())
{
newPage
.
recalculateMemory
();
recalculateMemory
();
newPage
.
recalculateMemory
();
}
return
newPage
;
return
newPage
;
}
}
...
@@ -422,8 +417,10 @@ public class Page {
...
@@ -422,8 +417,10 @@ public class Page {
bKeys
,
null
,
bKeys
,
null
,
bChildren
,
bChildren
,
t
,
0
);
t
,
0
);
recalculateMemory
();
if
(
isPersistent
())
{
newPage
.
recalculateMemory
();
recalculateMemory
();
newPage
.
recalculateMemory
();
}
return
newPage
;
return
newPage
;
}
}
...
@@ -498,13 +495,15 @@ public class Page {
...
@@ -498,13 +495,15 @@ public class Page {
// this is slightly slower:
// this is slightly slower:
// keys = Arrays.copyOf(keys, keys.length);
// keys = Arrays.copyOf(keys, keys.length);
keys
=
keys
.
clone
();
keys
=
keys
.
clone
();
Object
old
=
keys
[
index
];
if
(
isPersistent
())
{
DataType
keyType
=
map
.
getKeyType
();
Object
old
=
keys
[
index
];
int
mem
=
keyType
.
getMemory
(
key
);
DataType
keyType
=
map
.
getKeyType
();
if
(
old
!=
null
)
{
int
mem
=
keyType
.
getMemory
(
key
);
mem
-=
keyType
.
getMemory
(
old
);
if
(
old
!=
null
)
{
mem
-=
keyType
.
getMemory
(
old
);
}
addMemory
(
mem
);
}
}
addMemory
(
mem
);
keys
[
index
]
=
key
;
keys
[
index
]
=
key
;
}
}
...
@@ -521,8 +520,10 @@ public class Page {
...
@@ -521,8 +520,10 @@ public class Page {
// values = Arrays.copyOf(values, values.length);
// values = Arrays.copyOf(values, values.length);
values
=
values
.
clone
();
values
=
values
.
clone
();
DataType
valueType
=
map
.
getValueType
();
DataType
valueType
=
map
.
getValueType
();
addMemory
(
valueType
.
getMemory
(
value
)
-
if
(
isPersistent
())
{
valueType
.
getMemory
(
old
));
addMemory
(
valueType
.
getMemory
(
value
)
-
valueType
.
getMemory
(
old
));
}
values
[
index
]
=
value
;
values
[
index
]
=
value
;
return
old
;
return
old
;
}
}
...
@@ -569,8 +570,10 @@ public class Page {
...
@@ -569,8 +570,10 @@ public class Page {
keys
[
index
]
=
key
;
keys
[
index
]
=
key
;
values
[
index
]
=
value
;
values
[
index
]
=
value
;
totalCount
++;
totalCount
++;
addMemory
(
map
.
getKeyType
().
getMemory
(
key
)
+
if
(
isPersistent
())
{
map
.
getValueType
().
getMemory
(
value
));
addMemory
(
map
.
getKeyType
().
getMemory
(
key
)
+
map
.
getValueType
().
getMemory
(
value
));
}
}
}
/**
/**
...
@@ -595,8 +598,10 @@ public class Page {
...
@@ -595,8 +598,10 @@ public class Page {
children
=
newChildren
;
children
=
newChildren
;
totalCount
+=
childPage
.
totalCount
;
totalCount
+=
childPage
.
totalCount
;
addMemory
(
map
.
getKeyType
().
getMemory
(
key
)
+
if
(
isPersistent
())
{
DataUtils
.
PAGE_MEMORY_CHILD
);
addMemory
(
map
.
getKeyType
().
getMemory
(
key
)
+
DataUtils
.
PAGE_MEMORY_CHILD
);
}
}
}
/**
/**
...
@@ -607,22 +612,28 @@ public class Page {
...
@@ -607,22 +612,28 @@ public class Page {
public
void
remove
(
int
index
)
{
public
void
remove
(
int
index
)
{
int
keyLength
=
keys
.
length
;
int
keyLength
=
keys
.
length
;
int
keyIndex
=
index
>=
keyLength
?
index
-
1
:
index
;
int
keyIndex
=
index
>=
keyLength
?
index
-
1
:
index
;
Object
old
=
keys
[
keyIndex
];
if
(
isPersistent
())
{
addMemory
(-
map
.
getKeyType
().
getMemory
(
old
));
Object
old
=
keys
[
keyIndex
];
addMemory
(-
map
.
getKeyType
().
getMemory
(
old
));
}
Object
[]
newKeys
=
new
Object
[
keyLength
-
1
];
Object
[]
newKeys
=
new
Object
[
keyLength
-
1
];
DataUtils
.
copyExcept
(
keys
,
newKeys
,
keyLength
,
keyIndex
);
DataUtils
.
copyExcept
(
keys
,
newKeys
,
keyLength
,
keyIndex
);
keys
=
newKeys
;
keys
=
newKeys
;
if
(
values
!=
null
)
{
if
(
values
!=
null
)
{
old
=
values
[
index
];
if
(
isPersistent
())
{
addMemory
(-
map
.
getValueType
().
getMemory
(
old
));
Object
old
=
values
[
index
];
addMemory
(-
map
.
getValueType
().
getMemory
(
old
));
}
Object
[]
newValues
=
new
Object
[
keyLength
-
1
];
Object
[]
newValues
=
new
Object
[
keyLength
-
1
];
DataUtils
.
copyExcept
(
values
,
newValues
,
keyLength
,
index
);
DataUtils
.
copyExcept
(
values
,
newValues
,
keyLength
,
index
);
values
=
newValues
;
values
=
newValues
;
totalCount
--;
totalCount
--;
}
}
if
(
children
!=
null
)
{
if
(
children
!=
null
)
{
addMemory
(-
DataUtils
.
PAGE_MEMORY_CHILD
);
if
(
isPersistent
())
{
addMemory
(-
DataUtils
.
PAGE_MEMORY_CHILD
);
}
long
countOffset
=
children
[
index
].
count
;
long
countOffset
=
children
[
index
].
count
;
int
childCount
=
children
.
length
;
int
childCount
=
children
.
length
;
...
@@ -887,37 +898,50 @@ public class Page {
...
@@ -887,37 +898,50 @@ public class Page {
return
pos
!=
0
?
(
int
)
(
pos
|
(
pos
>>>
32
))
:
super
.
hashCode
();
return
pos
!=
0
?
(
int
)
(
pos
|
(
pos
>>>
32
))
:
super
.
hashCode
();
}
}
private
boolean
isPersistent
()
{
return
memory
!=
IN_MEMORY
;
}
public
int
getMemory
()
{
public
int
getMemory
()
{
if
(
MVStore
.
ASSERT
)
{
if
(
isPersistent
())
{
int
mem
=
memory
;
if
(
MVStore
.
ASSERT
)
{
recalculateMemory
();
int
mem
=
memory
;
if
(
mem
!=
memory
)
{
recalculateMemory
();
throw
DataUtils
.
newIllegalStateException
(
if
(
mem
!=
memory
)
{
DataUtils
.
ERROR_INTERNAL
,
"Memory calculation error"
);
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_INTERNAL
,
"Memory calculation error"
);
}
}
}
return
memory
;
}
}
return
memory
;
return
getKeyCount
()
;
}
}
private
void
addMemory
(
int
mem
)
{
private
void
addMemory
(
int
mem
)
{
if
(!
isPersistent
())
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_INTERNAL
,
"Memory calculation error2"
);
}
memory
+=
mem
;
memory
+=
mem
;
}
}
private
void
recalculateMemory
()
{
private
void
recalculateMemory
()
{
int
mem
=
DataUtils
.
PAGE_MEMORY
;
if
(
isPersistent
())
{
DataType
keyType
=
map
.
getKeyType
();
int
mem
=
DataUtils
.
PAGE_MEMORY
;
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
DataType
keyType
=
map
.
getKeyType
();
mem
+=
keyType
.
getMemory
(
keys
[
i
]);
}
if
(
this
.
isLeaf
())
{
DataType
valueType
=
map
.
getValueType
();
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
mem
+=
valueType
.
getMemory
(
value
s
[
i
]);
mem
+=
keyType
.
getMemory
(
key
s
[
i
]);
}
}
}
else
{
if
(
this
.
isLeaf
())
{
mem
+=
this
.
getRawChildPageCount
()
*
DataUtils
.
PAGE_MEMORY_CHILD
;
DataType
valueType
=
map
.
getValueType
();
for
(
int
i
=
0
;
i
<
keys
.
length
;
i
++)
{
mem
+=
valueType
.
getMemory
(
values
[
i
]);
}
}
else
{
mem
+=
this
.
getRawChildPageCount
()
*
DataUtils
.
PAGE_MEMORY_CHILD
;
}
addMemory
(
mem
-
memory
);
}
}
addMemory
(
mem
-
memory
);
}
}
void
setVersion
(
long
version
)
{
void
setVersion
(
long
version
)
{
...
@@ -928,11 +952,13 @@ public class Page {
...
@@ -928,11 +952,13 @@ public class Page {
* Remove the page.
* Remove the page.
*/
*/
public
void
removePage
()
{
public
void
removePage
()
{
long
p
=
pos
;
if
(
isPersistent
())
{
if
(
p
==
0
)
{
long
p
=
pos
;
removedInMemory
=
true
;
if
(
p
==
0
)
{
removedInMemory
=
true
;
}
map
.
removePage
(
p
,
memory
);
}
}
map
.
removePage
(
p
,
memory
);
}
}
/**
/**
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
c4ce9e65
...
@@ -1416,7 +1416,9 @@ public class TestMVStore extends TestBase {
...
@@ -1416,7 +1416,9 @@ public class TestMVStore extends TestBase {
assertEquals
(
i
+
1
,
m
.
size
());
assertEquals
(
i
+
1
,
m
.
size
());
}
}
assertEquals
(
1000
,
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
();
s
.
commit
();
assertEquals
(
2
,
s
.
getFileStore
().
getWriteCount
());
assertEquals
(
2
,
s
.
getFileStore
().
getWriteCount
());
s
.
close
();
s
.
close
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论