Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
fb4be198
提交
fb4be198
authored
10 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Synchronize write access (needed for background compact operations)
上级
bd147171
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
79 行增加
和
19 行删除
+79
-19
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+11
-9
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+9
-8
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-2
TestConcurrent.java
h2/src/test/org/h2/test/store/TestConcurrent.java
+57
-0
没有找到文件。
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
fb4be198
...
...
@@ -123,7 +123,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/
@Override
@SuppressWarnings
(
"unchecked"
)
public
V
put
(
K
key
,
V
value
)
{
public
synchronized
V
put
(
K
key
,
V
value
)
{
DataUtils
.
checkArgument
(
value
!=
null
,
"The value may not be null"
);
beforeWrite
();
try
{
...
...
@@ -534,7 +534,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* Remove all entries.
*/
@Override
public
void
clear
()
{
public
synchronized
void
clear
()
{
beforeWrite
();
try
{
root
.
removeAllRecursive
();
...
...
@@ -563,7 +563,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* @return the old value if the key existed, or null otherwise
*/
@Override
public
V
remove
(
Object
key
)
{
public
synchronized
V
remove
(
Object
key
)
{
beforeWrite
();
try
{
long
v
=
writeVersion
;
...
...
@@ -809,9 +809,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
}
@SuppressWarnings
(
"unchecked"
)
K
key
=
(
K
)
p
.
getKey
(
0
);
@SuppressWarnings
(
"unchecked"
)
V
value
=
(
V
)
p
.
getValue
(
0
);
put
(
key
,
value
);
V
value
=
get
(
key
);
if
(
value
!=
null
)
{
replace
(
key
,
value
,
value
);
}
return
1
;
}
int
writtenPageCount
=
0
;
...
...
@@ -842,9 +843,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
}
@SuppressWarnings
(
"unchecked"
)
K
key
=
(
K
)
p2
.
getKey
(
0
);
@SuppressWarnings
(
"unchecked"
)
V
value
=
(
V
)
p2
.
getValue
(
0
);
put
(
key
,
value
);
V
value
=
get
(
key
);
if
(
value
!=
null
)
{
replace
(
key
,
value
,
value
);
}
writtenPageCount
++;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
fb4be198
...
...
@@ -1707,9 +1707,9 @@ public class MVStore {
page
.
setPos
(
pos
);
Object
k
=
map
.
getLiveKey
(
page
);
if
(
k
!=
null
)
{
Object
value
=
map
.
remove
(
k
);
Object
value
=
map
.
get
(
k
);
if
(
value
!=
null
)
{
map
.
put
(
k
,
value
);
map
.
replace
(
k
,
value
,
value
);
changeCount
++;
}
}
...
...
@@ -2293,13 +2293,14 @@ public class MVStore {
fileOps
=
false
;
}
// use a lower fill rate if there were any file operations
int
fillRate
=
fileOps
?
autoCompactFillRate
/
4
:
autoCompactFillRate
;
int
fillRate
=
fileOps
?
autoCompactFillRate
/
3
:
autoCompactFillRate
;
compact
(
fillRate
,
autoCommitMemory
);
if
(!
fileOps
)
{
// if there were no file operations at all,
// compact the file by moving chunks
compactMoveChunks
(
autoCompactFillRate
,
autoCommitMemory
);
}
;
// TODO find out why this doesn't work
// if (!fileOps) {
// // if there were no file operations at all,
// // compact the file by moving chunks
// compactMoveChunks(autoCompactFillRate, autoCommitMemory);
// }
autoCompactLastFileOpCount
=
fileStore
.
getWriteCount
()
+
fileStore
.
getReadCount
();
}
catch
(
Exception
e
)
{
if
(
backgroundExceptionHandler
!=
null
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
fb4be198
...
...
@@ -625,7 +625,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new
TestCompatibility
().
runTest
(
this
);
new
TestCompatibilityOracle
().
runTest
(
this
);
new
TestCsv
().
runTest
(
this
);
new
TestDateStorage
().
runTest
(
this
);
new
TestDateStorage
().
runTest
(
this
);
// TODO test
new
TestDeadlock
().
runTest
(
this
);
new
TestDrop
().
runTest
(
this
);
new
TestDuplicateKeyUpdate
().
runTest
(
this
);
...
...
@@ -721,7 +721,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
// synth
new
TestBtreeIndex
().
runTest
(
this
);
new
TestConcurrentUpdate
().
runTest
(
this
);
new
TestDiskFull
().
runTest
(
this
);
new
TestDiskFull
().
runTest
(
this
);
// TODO test
new
TestCrashAPI
().
runTest
(
this
);
new
TestFuzzOptimizations
().
runTest
(
this
);
new
TestLimit
().
runTest
(
this
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestConcurrent.java
浏览文件 @
fb4be198
...
...
@@ -47,6 +47,8 @@ public class TestConcurrent extends TestMVStore {
FileUtils
.
createDirectories
(
getBaseDir
());
FileUtils
.
deleteRecursive
(
"memFS:"
,
false
);
testConcurrentReplaceAndRead
();
testConcurrentChangeAndCompact
();
testConcurrentChangeAndGetVersion
();
testConcurrentFree
();
testConcurrentStoreAndRemoveMap
();
...
...
@@ -57,6 +59,61 @@ public class TestConcurrent extends TestMVStore {
testConcurrentWrite
();
testConcurrentRead
();
}
private
void
testConcurrentReplaceAndRead
()
throws
InterruptedException
{
final
MVStore
s
=
new
MVStore
.
Builder
().
open
();
final
MVMap
<
Integer
,
Integer
>
map
=
s
.
openMap
(
"data"
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
map
.
put
(
i
,
i
%
100
);
}
Task
task
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
int
i
=
0
;
while
(!
stop
)
{
map
.
put
(
i
%
100
,
i
%
100
);
i
++;
if
(
i
%
1000
==
0
)
{
s
.
commit
();
}
}
}
};
task
.
execute
();
Thread
.
sleep
(
1
);
for
(
int
i
=
0
;
!
task
.
isFinished
()
&&
i
<
1000000
;
i
++)
{
assertEquals
(
i
%
100
,
map
.
get
(
i
%
100
).
intValue
());
}
task
.
get
();
s
.
close
();
}
private
void
testConcurrentChangeAndCompact
()
throws
InterruptedException
{
final
MVStore
s
=
new
MVStore
.
Builder
().
fileName
(
"memFS:testConcurrentChangeAndBackgroundCompact"
).
autoCommitDisabled
().
open
();
s
.
setRetentionTime
(
0
);
Task
task
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
while
(!
stop
)
{
s
.
compact
(
100
,
1024
*
1024
);
// s.compactMoveChunks(100, 1024 * 1024);
// s.compact(100, 1024 * 1024);
}
}
};
task
.
execute
();
Thread
.
sleep
(
1
);
for
(
int
i
=
0
;
!
task
.
isFinished
()
&&
i
<
1000
;
i
++)
{
MVMap
<
Integer
,
Integer
>
map
=
s
.
openMap
(
"d"
+
(
i
%
3
));
// MVMap<Integer, Integer> map = s.openMap("d" + (i % 3),
// new MVMapConcurrent.Builder<Integer, Integer>());
map
.
put
(
0
,
i
);
s
.
commit
();
}
task
.
get
();
s
.
close
();
}
private
void
testConcurrentChangeAndGetVersion
()
throws
InterruptedException
{
for
(
int
test
=
0
;
test
<
10
;
test
++)
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论