Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3b16f12f
提交
3b16f12f
authored
6 年前
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cherry-pick from fork-join
上级
5c4719de
master
version-1.4.198
无相关合并请求
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
59 行增加
和
67 行删除
+59
-67
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+5
-5
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+7
-22
Page.java
h2/src/main/org/h2/mvstore/Page.java
+46
-39
MVRTreeMap.java
h2/src/main/org/h2/mvstore/rtree/MVRTreeMap.java
+1
-1
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
3b16f12f
...
...
@@ -993,7 +993,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* @param memory the number of bytes used for this page
*/
protected
final
void
removePage
(
long
pos
,
int
memory
)
{
store
.
removePage
(
this
,
pos
,
memory
);
store
.
removePage
(
pos
,
memory
);
}
/**
...
...
@@ -1190,10 +1190,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
int
attempt
=
0
;
int
keyCount
;
while
((
keyCount
=
rootReference
.
getAppendCounter
())
>
0
)
{
Page
page
=
Page
.
create
(
this
,
Page
page
=
Page
.
create
Leaf
(
this
,
Arrays
.
copyOf
(
keysBuffer
,
keyCount
),
Arrays
.
copyOf
(
valuesBuffer
,
keyCount
),
null
,
keyCount
,
0
);
0
);
CursorPos
pos
=
rootReference
.
root
.
getAppendCursorPos
(
null
);
assert
page
.
map
==
this
;
assert
pos
!=
null
;
...
...
@@ -1215,7 +1215,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
Page
.
PageReference
children
[]
=
new
Page
.
PageReference
[]
{
new
Page
.
PageReference
(
p
),
new
Page
.
PageReference
(
page
)};
p
=
Page
.
create
(
this
,
keys
,
null
,
children
,
p
.
getTotalCount
()
+
page
.
getTotalCount
(),
0
);
p
=
Page
.
create
Node
(
this
,
keys
,
children
,
p
.
getTotalCount
()
+
page
.
getTotalCount
(),
0
);
}
break
;
}
...
...
@@ -1784,7 +1784,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
new
Page
.
PageReference
(
p
),
new
Page
.
PageReference
(
split
)
};
p
=
Page
.
create
(
this
,
keys
,
null
,
children
,
totalCount
,
0
);
p
=
Page
.
create
Node
(
this
,
keys
,
children
,
totalCount
,
0
);
break
;
}
Page
c
=
p
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
3b16f12f
...
...
@@ -1412,9 +1412,7 @@ public class MVStore {
}
public
Set
<
Integer
>
getReferenced
()
{
Set
<
Integer
>
set
=
new
HashSet
<>();
set
.
addAll
(
referencedChunks
.
keySet
());
return
set
;
return
new
HashSet
<>(
referencedChunks
.
keySet
());
}
public
void
visit
(
Page
page
,
ThreadPoolExecutor
executorService
,
AtomicInteger
executingThreadCounter
)
{
...
...
@@ -1426,7 +1424,8 @@ public class MVStore {
if
(
count
==
0
)
{
return
;
}
final
ChunkIdsCollector
childCollector
=
new
ChunkIdsCollector
(
this
);
ChunkIdsCollector
childCollector
=
DataUtils
.
isPageSaved
(
pos
)
&&
cacheChunkRef
!=
null
?
new
ChunkIdsCollector
(
this
)
:
this
;
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Page
childPage
=
page
.
getChildPageIfLoaded
(
i
);
if
(
childPage
!=
null
)
{
...
...
@@ -1436,7 +1435,7 @@ public class MVStore {
}
}
// and cache resulting set of chunk ids
if
(
DataUtils
.
isPageSaved
(
pos
)
&&
cacheChunkRef
!=
null
)
{
if
(
childCollector
!=
this
)
{
int
[]
chunkIds
=
childCollector
.
getChunkIds
();
cacheChunkRef
.
put
(
pos
,
chunkIds
,
Constants
.
MEMORY_ARRAY
+
4
*
chunkIds
.
length
);
}
...
...
@@ -1450,7 +1449,7 @@ public class MVStore {
if
(
DataUtils
.
getPageType
(
pos
)
==
DataUtils
.
PAGE_TYPE_LEAF
)
{
return
;
}
int
chunkIds
[]
;
int
[]
chunkIds
;
if
(
cacheChunkRef
!=
null
&&
(
chunkIds
=
cacheChunkRef
.
get
(
pos
))
!=
null
)
{
// there is a cached set of chunk ids for this position
for
(
int
chunkId
:
chunkIds
)
{
...
...
@@ -1490,7 +1489,7 @@ public class MVStore {
}
private
int
[]
getChunkIds
()
{
int
chunkIds
[]
=
new
int
[
referencedChunks
.
size
()];
int
[]
chunkIds
=
new
int
[
referencedChunks
.
size
()];
int
index
=
0
;
for
(
Integer
chunkId
:
referencedChunks
.
keySet
())
{
chunkIds
[
index
++]
=
chunkId
;
...
...
@@ -2070,11 +2069,10 @@ public class MVStore {
/**
* Remove a page.
*
* @param map the map the page belongs to
* @param pos the position of the page
* @param memory the memory usage
*/
void
removePage
(
MVMap
<?,
?>
map
,
long
pos
,
int
memory
)
{
void
removePage
(
long
pos
,
int
memory
)
{
// we need to keep temporary pages,
// to support reading old versions and rollback
if
(!
DataUtils
.
isPageSaved
(
pos
))
{
...
...
@@ -2086,19 +2084,6 @@ public class MVStore {
return
;
}
// This could result in a cache miss if the operation is rolled back,
// but we don't optimize for rollback.
// We could also keep the page in the cache, as somebody
// could still read it (reading the old version).
/*
if (cache != null) {
if (DataUtils.getPageType(pos) == DataUtils.PAGE_TYPE_LEAF) {
// keep nodes in the cache, because they are still used for
// garbage collection
cache.remove(pos);
}
}
*/
int
chunkId
=
DataUtils
.
getPageChunkId
(
pos
);
// synchronize, because pages could be freed concurrently
synchronized
(
freedPageSpace
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
3b16f12f
...
...
@@ -131,7 +131,7 @@ public abstract class Page implements Cloneable
memory
=
source
.
memory
;
}
Page
(
MVMap
<?,
?>
map
,
Object
keys
[]
)
{
Page
(
MVMap
<?,
?>
map
,
Object
[]
keys
)
{
this
.
map
=
map
;
this
.
keys
=
keys
;
}
...
...
@@ -143,37 +143,46 @@ public abstract class Page implements Cloneable
* @return the new page
*/
static
Page
createEmptyLeaf
(
MVMap
<?,
?>
map
)
{
Page
page
=
new
Leaf
(
map
,
EMPTY_OBJECT_ARRAY
,
EMPTY_OBJECT_ARRAY
);
page
.
initMemoryAccount
(
PAGE_LEAF_MEMORY
);
return
page
;
return
createLeaf
(
map
,
EMPTY_OBJECT_ARRAY
,
EMPTY_OBJECT_ARRAY
,
PAGE_LEAF_MEMORY
);
}
public
static
Page
createEmptyNode
(
MVMap
<?,
?>
map
)
{
Page
page
=
new
NonLeaf
(
map
,
EMPTY_OBJECT_ARRAY
,
SINGLE_EMPTY
,
0
);
page
.
initMemoryAccount
(
PAGE_NODE_MEMORY
+
MEMORY_POINTER
+
PAGE_MEMORY_CHILD
);
// there is always one child
return
page
;
static
Page
createEmptyNode
(
MVMap
<?,
?>
map
)
{
return
createNode
(
map
,
EMPTY_OBJECT_ARRAY
,
SINGLE_EMPTY
,
0
,
PAGE_NODE_MEMORY
+
MEMORY_POINTER
+
PAGE_MEMORY_CHILD
);
// there is always one child
}
/**
* Create a new page. The arrays are not cloned.
* Create a new
non-leaf
page. The arrays are not cloned.
*
* @param map the map
* @param keys the keys
* @param values the values
* @param children the child page positions
* @param totalCount the total number of keys
* @param memory the memory used in bytes
* @return the page
*/
public
static
Page
create
(
MVMap
<?,
?>
map
,
Object
[]
keys
,
Object
[]
values
,
PageReference
[]
children
,
public
static
Page
createNode
(
MVMap
<?,
?>
map
,
Object
[]
keys
,
PageReference
[]
children
,
long
totalCount
,
int
memory
)
{
assert
keys
!=
null
;
Page
p
=
children
==
null
?
new
Leaf
(
map
,
keys
,
values
)
:
new
NonLeaf
(
map
,
keys
,
children
,
totalCount
);
p
.
initMemoryAccount
(
memory
);
return
p
;
Page
page
=
new
NonLeaf
(
map
,
keys
,
children
,
totalCount
);
page
.
initMemoryAccount
(
memory
);
return
page
;
}
/**
* Create a new leaf page. The arrays are not cloned.
*
* @param map the map
* @param keys the keys
* @param values the values
* @param memory the memory used in bytes
* @return the page
*/
public
static
Page
createLeaf
(
MVMap
<?,
?>
map
,
Object
[]
keys
,
Object
[]
values
,
int
memory
)
{
assert
keys
!=
null
;
Page
page
=
new
Leaf
(
map
,
keys
,
values
);
page
.
initMemoryAccount
(
memory
);
return
page
;
}
private
void
initMemoryAccount
(
int
memoryCount
)
{
...
...
@@ -532,8 +541,8 @@ public abstract class Page implements Cloneable
final
Object
[]
splitKeys
(
int
aCount
,
int
bCount
)
{
assert
aCount
+
bCount
<=
getKeyCount
();
Object
aKeys
[]
=
createKeyStorage
(
aCount
);
Object
bKeys
[]
=
createKeyStorage
(
bCount
);
Object
[]
aKeys
=
createKeyStorage
(
aCount
);
Object
[]
bKeys
=
createKeyStorage
(
bCount
);
System
.
arraycopy
(
keys
,
0
,
aKeys
,
0
,
aCount
);
System
.
arraycopy
(
keys
,
getKeyCount
()
-
bCount
,
bKeys
,
0
,
bCount
);
keys
=
aKeys
;
...
...
@@ -639,7 +648,7 @@ public abstract class Page implements Cloneable
Object
old
=
getKey
(
index
);
addMemory
(-
MEMORY_POINTER
-
keyType
.
getMemory
(
old
));
}
Object
newKeys
[]
=
new
Object
[
keyCount
-
1
];
Object
[]
newKeys
=
new
Object
[
keyCount
-
1
];
DataUtils
.
copyExcept
(
keys
,
newKeys
,
keyCount
,
index
);
keys
=
newKeys
;
}
...
...
@@ -873,7 +882,7 @@ public abstract class Page implements Cloneable
memory
+=
mem
;
}
protected
final
void
recalculateMemory
()
{
final
void
recalculateMemory
()
{
assert
isPersistent
();
memory
=
calculateMemory
();
}
...
...
@@ -1005,13 +1014,13 @@ public abstract class Page implements Cloneable
super
(
map
);
}
private
NonLeaf
(
MVMap
<?,
?>
map
,
NonLeaf
source
,
PageReference
children
[]
,
long
totalCount
)
{
private
NonLeaf
(
MVMap
<?,
?>
map
,
NonLeaf
source
,
PageReference
[]
children
,
long
totalCount
)
{
super
(
map
,
source
);
this
.
children
=
children
;
this
.
totalCount
=
totalCount
;
}
NonLeaf
(
MVMap
<?,
?>
map
,
Object
keys
[],
PageReference
children
[]
,
long
totalCount
)
{
NonLeaf
(
MVMap
<?,
?>
map
,
Object
[]
keys
,
PageReference
[]
children
,
long
totalCount
)
{
super
(
map
,
keys
);
this
.
children
=
children
;
this
.
totalCount
=
totalCount
;
...
...
@@ -1058,11 +1067,10 @@ public abstract class Page implements Cloneable
}
@Override
@SuppressWarnings
(
"SuspiciousSystemArraycopy"
)
public
Page
split
(
int
at
)
{
assert
!
isSaved
();
int
b
=
getKeyCount
()
-
at
;
Object
bKeys
[]
=
splitKeys
(
at
,
b
-
1
);
Object
[]
bKeys
=
splitKeys
(
at
,
b
-
1
);
PageReference
[]
aChildren
=
new
PageReference
[
at
+
1
];
PageReference
[]
bChildren
=
new
PageReference
[
b
];
System
.
arraycopy
(
children
,
0
,
aChildren
,
0
,
at
+
1
);
...
...
@@ -1078,7 +1086,7 @@ public abstract class Page implements Cloneable
for
(
PageReference
x
:
bChildren
)
{
t
+=
x
.
count
;
}
Page
newPage
=
create
(
map
,
bKeys
,
null
,
bChildren
,
t
,
0
);
Page
newPage
=
create
Node
(
map
,
bKeys
,
bChildren
,
t
,
0
);
if
(
isPersistent
())
{
recalculateMemory
();
}
...
...
@@ -1132,7 +1140,7 @@ public abstract class Page implements Cloneable
int
childCount
=
getRawChildPageCount
();
insertKey
(
index
,
key
);
PageReference
newChildren
[]
=
new
PageReference
[
childCount
+
1
];
PageReference
[]
newChildren
=
new
PageReference
[
childCount
+
1
];
DataUtils
.
copyWithGap
(
children
,
newChildren
,
childCount
,
index
);
children
=
newChildren
;
children
[
index
]
=
new
PageReference
(
childPage
);
...
...
@@ -1151,7 +1159,7 @@ public abstract class Page implements Cloneable
addMemory
(-
MEMORY_POINTER
-
PAGE_MEMORY_CHILD
);
}
totalCount
-=
children
[
index
].
count
;
PageReference
newChildren
[]
=
new
PageReference
[
childCount
-
1
];
PageReference
[]
newChildren
=
new
PageReference
[
childCount
-
1
];
DataUtils
.
copyExcept
(
children
,
newChildren
,
childCount
,
index
);
children
=
newChildren
;
}
...
...
@@ -1190,7 +1198,7 @@ public abstract class Page implements Cloneable
protected
void
readPayLoad
(
ByteBuffer
buff
)
{
int
keyCount
=
getKeyCount
();
children
=
new
PageReference
[
keyCount
+
1
];
long
p
[]
=
new
long
[
keyCount
+
1
];
long
[]
p
=
new
long
[
keyCount
+
1
];
for
(
int
i
=
0
;
i
<=
keyCount
;
i
++)
{
p
[
i
]
=
buff
.
getLong
();
}
...
...
@@ -1282,7 +1290,7 @@ public abstract class Page implements Cloneable
/**
* The storage for values.
*/
private
Object
values
[]
;
private
Object
[]
values
;
Leaf
(
MVMap
<?,
?>
map
)
{
super
(
map
);
...
...
@@ -1293,7 +1301,7 @@ public abstract class Page implements Cloneable
this
.
values
=
source
.
values
;
}
Leaf
(
MVMap
<?,
?>
map
,
Object
keys
[],
Object
values
[]
)
{
Leaf
(
MVMap
<?,
?>
map
,
Object
[]
keys
,
Object
[]
values
)
{
super
(
map
,
keys
);
this
.
values
=
values
;
}
...
...
@@ -1327,19 +1335,18 @@ public abstract class Page implements Cloneable
}
@Override
@SuppressWarnings
(
"SuspiciousSystemArraycopy"
)
public
Page
split
(
int
at
)
{
assert
!
isSaved
();
int
b
=
getKeyCount
()
-
at
;
Object
bKeys
[]
=
splitKeys
(
at
,
b
);
Object
bValues
[]
=
createValueStorage
(
b
);
Object
[]
bKeys
=
splitKeys
(
at
,
b
);
Object
[]
bValues
=
createValueStorage
(
b
);
if
(
values
!=
null
)
{
Object
aValues
[]
=
createValueStorage
(
at
);
Object
[]
aValues
=
createValueStorage
(
at
);
System
.
arraycopy
(
values
,
0
,
aValues
,
0
,
at
);
System
.
arraycopy
(
values
,
at
,
bValues
,
0
,
b
);
values
=
aValues
;
}
Page
newPage
=
create
(
map
,
bKeys
,
bValues
,
null
,
b
,
0
);
Page
newPage
=
create
Leaf
(
map
,
bKeys
,
bValues
,
0
);
if
(
isPersistent
())
{
recalculateMemory
();
}
...
...
@@ -1384,7 +1391,7 @@ public abstract class Page implements Cloneable
insertKey
(
index
,
key
);
if
(
values
!=
null
)
{
Object
newValues
[]
=
createValueStorage
(
keyCount
+
1
);
Object
[]
newValues
=
createValueStorage
(
keyCount
+
1
);
DataUtils
.
copyWithGap
(
values
,
newValues
,
keyCount
,
index
);
values
=
newValues
;
setValueInternal
(
index
,
value
);
...
...
@@ -1407,7 +1414,7 @@ public abstract class Page implements Cloneable
Object
old
=
getValue
(
index
);
addMemory
(-
MEMORY_POINTER
-
map
.
getValueType
().
getMemory
(
old
));
}
Object
newValues
[]
=
createValueStorage
(
keyCount
-
1
);
Object
[]
newValues
=
createValueStorage
(
keyCount
-
1
);
DataUtils
.
copyExcept
(
values
,
newValues
,
keyCount
,
index
);
values
=
newValues
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/rtree/MVRTreeMap.java
浏览文件 @
3b16f12f
...
...
@@ -154,7 +154,7 @@ public final class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
new
Page
.
PageReference
(
split
),
Page
.
PageReference
.
EMPTY
};
p
=
Page
.
create
(
this
,
keys
,
null
,
children
,
totalCount
,
0
);
p
=
Page
.
create
Node
(
this
,
keys
,
children
,
totalCount
,
0
);
if
(
store
.
getFileStore
()
!=
null
)
{
store
.
registerUnsavedPage
(
p
.
getMemory
());
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论