Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0b2f0e40
提交
0b2f0e40
authored
8月 03, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: deal with the case that data was moved to a new chunk (work in progress)
上级
14111f79
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
60 行增加
和
40 行删除
+60
-40
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+44
-35
MVMapConcurrent.java
h2/src/main/org/h2/mvstore/MVMapConcurrent.java
+1
-1
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+6
-2
TestConcurrent.java
h2/src/test/org/h2/test/store/TestConcurrent.java
+9
-2
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
0b2f0e40
...
@@ -792,45 +792,56 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -792,45 +792,56 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* Re-write any pages that belong to one of the chunks in the given set.
* Re-write any pages that belong to one of the chunks in the given set.
*
*
* @param set the set of chunk ids
* @param set the set of chunk ids
* @return whether rewriting was successful
*/
*/
void
rewrite
(
Set
<
Integer
>
set
)
{
boolean
rewrite
(
Set
<
Integer
>
set
)
{
if
(
root
.
getVersion
()
<
createVersion
)
{
// a new map
return
true
;
}
// read from old version, to avoid concurrent reads
MVMap
<
K
,
V
>
readMap
=
openVersion
(
root
.
getVersion
()
-
1
);
try
{
try
{
rewrite
(
root
,
set
);
rewrite
(
readMap
.
root
,
set
);
return
true
;
}
catch
(
IllegalStateException
e
)
{
}
catch
(
IllegalStateException
e
)
{
if
(
DataUtils
.
getErrorCode
(
e
.
getMessage
())
==
DataUtils
.
ERROR_CHUNK_NOT_FOUND
)
{
if
(
DataUtils
.
getErrorCode
(
e
.
getMessage
())
==
DataUtils
.
ERROR_CHUNK_NOT_FOUND
)
{
// ignore
// ignore
}
else
{
return
false
;
throw
e
;
}
}
throw
e
;
}
}
}
}
private
int
rewrite
(
Page
p
,
Set
<
Integer
>
set
)
{
private
int
rewrite
(
Page
p
,
Set
<
Integer
>
set
)
{
if
(
p
.
isLeaf
())
{
if
(
p
.
isLeaf
())
{
long
pos
=
p
.
getPos
();
long
pos
=
p
.
getPos
();
if
(
pos
==
0
)
{
return
0
;
}
int
chunkId
=
DataUtils
.
getPageChunkId
(
pos
);
int
chunkId
=
DataUtils
.
getPageChunkId
(
pos
);
if
(!
set
.
contains
(
chunkId
))
{
if
(!
set
.
contains
(
chunkId
))
{
return
0
;
return
0
;
}
}
if
(
p
.
getKeyCount
()
>
0
)
{
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
K
key
=
(
K
)
p
.
getKey
(
0
);
K
key
=
(
K
)
p
.
getKey
(
0
);
V
value
=
get
(
key
);
V
value
=
get
(
key
);
if
(
value
!=
null
)
{
if
(
value
!=
null
)
{
// this is to avoid storing while replacing, to avoid a
// deadlock when rewriting the meta map
// TODO there should be no deadlocks possible
store
.
beforeWrite
();
replace
(
key
,
value
,
value
);
replace
(
key
,
value
,
value
);
}
}
}
return
1
;
return
1
;
}
}
int
writtenPageCount
=
0
;
int
writtenPageCount
=
0
;
for
(
int
i
=
0
;
i
<
p
.
getChildPageCount
();
i
++)
{
for
(
int
i
=
0
;
i
<
p
.
getChildPageCount
();
i
++)
{
long
p
os
=
p
.
getChildPagePos
(
i
);
long
childP
os
=
p
.
getChildPagePos
(
i
);
if
(
pos
!=
0
&&
DataUtils
.
getPageType
(
p
os
)
==
DataUtils
.
PAGE_TYPE_LEAF
)
{
if
(
childPos
!=
0
&&
DataUtils
.
getPageType
(
childP
os
)
==
DataUtils
.
PAGE_TYPE_LEAF
)
{
// we would need to load the page, and it's a leaf:
// we would need to load the page, and it's a leaf:
// only do that if it's within the set of chunks we are
// only do that if it's within the set of chunks we are
// interested in
// interested in
int
chunkId
=
DataUtils
.
getPageChunkId
(
p
os
);
int
chunkId
=
DataUtils
.
getPageChunkId
(
childP
os
);
if
(!
set
.
contains
(
chunkId
))
{
if
(!
set
.
contains
(
chunkId
))
{
continue
;
continue
;
}
}
...
@@ -839,7 +850,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -839,7 +850,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
}
}
if
(
writtenPageCount
==
0
)
{
if
(
writtenPageCount
==
0
)
{
long
pos
=
p
.
getPos
();
long
pos
=
p
.
getPos
();
if
(
pos
!=
0
)
{
int
chunkId
=
DataUtils
.
getPageChunkId
(
pos
);
int
chunkId
=
DataUtils
.
getPageChunkId
(
pos
);
if
(
set
.
contains
(
chunkId
))
{
if
(
set
.
contains
(
chunkId
))
{
// an inner node page that is in one of the chunks,
// an inner node page that is in one of the chunks,
...
@@ -861,7 +871,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -861,7 +871,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
writtenPageCount
++;
writtenPageCount
++;
}
}
}
}
}
return
writtenPageCount
;
return
writtenPageCount
;
}
}
...
...
h2/src/main/org/h2/mvstore/MVMapConcurrent.java
浏览文件 @
0b2f0e40
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
0b2f0e40
...
@@ -1683,9 +1683,13 @@ public class MVStore {
...
@@ -1683,9 +1683,13 @@ public class MVStore {
for
(
MVMap
<?,
?>
m
:
maps
.
values
())
{
for
(
MVMap
<?,
?>
m
:
maps
.
values
())
{
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
MVMap
<
Object
,
Object
>
map
=
(
MVMap
<
Object
,
Object
>)
m
;
MVMap
<
Object
,
Object
>
map
=
(
MVMap
<
Object
,
Object
>)
m
;
map
.
rewrite
(
set
);
if
(!
map
.
rewrite
(
set
))
{
return
;
}
}
if
(!
meta
.
rewrite
(
set
))
{
return
;
}
}
meta
.
rewrite
(
set
);
commitAndSave
();
commitAndSave
();
boolean
commitAgain
=
false
;
boolean
commitAgain
=
false
;
for
(
Chunk
c
:
old
)
{
for
(
Chunk
c
:
old
)
{
...
...
h2/src/test/org/h2/test/store/TestConcurrent.java
浏览文件 @
0b2f0e40
...
@@ -64,8 +64,9 @@ public class TestConcurrent extends TestMVStore {
...
@@ -64,8 +64,9 @@ public class TestConcurrent extends TestMVStore {
private
void
testConcurrentAutoCommitAndChange
()
throws
InterruptedException
{
private
void
testConcurrentAutoCommitAndChange
()
throws
InterruptedException
{
String
fileName
=
"memFS:testConcurrentChangeAndBackgroundCompact"
;
String
fileName
=
"memFS:testConcurrentChangeAndBackgroundCompact"
;
FileUtils
.
delete
(
fileName
);
FileUtils
.
delete
(
fileName
);
final
MVStore
s
=
new
MVStore
.
Builder
().
fileName
(
final
MVStore
s
=
new
MVStore
.
Builder
().
fileName
).
open
();
fileName
(
fileName
).
pageSplitSize
(
100
).
open
();
try
{
try
{
s
.
setRetentionTime
(
1000
);
s
.
setRetentionTime
(
1000
);
s
.
setAutoCommitDelay
(
1
);
s
.
setAutoCommitDelay
(
1
);
...
@@ -78,6 +79,8 @@ public class TestConcurrent extends TestMVStore {
...
@@ -78,6 +79,8 @@ public class TestConcurrent extends TestMVStore {
}
}
};
};
final
MVMap
<
Integer
,
Integer
>
dataMap
=
s
.
openMap
(
"data"
);
final
MVMap
<
Integer
,
Integer
>
dataMap
=
s
.
openMap
(
"data"
);
final
MVMap
<
Integer
,
Integer
>
dataSmallMap
=
s
.
openMap
(
"dataSmall"
);
s
.
openMap
(
"emptyMap"
);
final
AtomicInteger
counter
=
new
AtomicInteger
();
final
AtomicInteger
counter
=
new
AtomicInteger
();
Task
task2
=
new
Task
()
{
Task
task2
=
new
Task
()
{
@Override
@Override
...
@@ -85,6 +88,10 @@ public class TestConcurrent extends TestMVStore {
...
@@ -85,6 +88,10 @@ public class TestConcurrent extends TestMVStore {
while
(!
stop
)
{
while
(!
stop
)
{
int
i
=
counter
.
getAndIncrement
();
int
i
=
counter
.
getAndIncrement
();
dataMap
.
put
(
i
,
i
*
10
);
dataMap
.
put
(
i
,
i
*
10
);
dataSmallMap
.
put
(
i
%
100
,
i
*
10
);
if
(
i
%
100
==
0
)
{
dataSmallMap
.
clear
();
}
}
}
}
}
};
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论