Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
900b5667
提交
900b5667
authored
11月 06, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: simpler API
上级
e845504a
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
179 行增加
和
196 行删除
+179
-196
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+110
-140
OffHeapStore.java
h2/src/main/org/h2/mvstore/OffHeapStore.java
+1
-2
MVTableEngine.java
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
+2
-2
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+7
-6
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+3
-3
TestConcurrent.java
h2/src/test/org/h2/test/store/TestConcurrent.java
+9
-8
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+28
-28
TestMVStoreBenchmark.java
h2/src/test/org/h2/test/store/TestMVStoreBenchmark.java
+6
-2
TestMVTableEngine.java
h2/src/test/org/h2/test/store/TestMVTableEngine.java
+1
-1
TestTransactionStore.java
h2/src/test/org/h2/test/store/TestTransactionStore.java
+11
-4
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
900b5667
...
...
@@ -23,6 +23,7 @@ Change Log
</li><li>
Issue 73: MySQL compatibility: support REPLACE, patch by Cemo Koc.
</li><li>
The spatial index now works in MVCC mode when using the MVStore storage.
</li><li>
MVStore: concurrency problems have been fixed.
The API has been simplified.
</li><li>
Improve error message when dropping an index that belongs to a constraint,
specify constraint in error message.
</li><li>
Issue 518: java.sql.Connection.commit() freezes after LOB modification with EXCLUSIVE connection
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
900b5667
差异被折叠。
点击展开。
h2/src/main/org/h2/mvstore/OffHeapStore.java
浏览文件 @
900b5667
...
...
@@ -121,8 +121,7 @@ public class OffHeapStore extends FileStore {
@Override
public
void
close
()
{
truncate
(
0
);
freeSpace
.
clear
();
// do nothing (keep the data until it is garbage collected)
}
@Override
...
...
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
浏览文件 @
900b5667
...
...
@@ -260,7 +260,7 @@ public class MVTableEngine implements TableEngine {
public
void
compactFile
(
long
maxCompactTime
)
{
store
.
setRetentionTime
(
0
);
long
start
=
System
.
currentTimeMillis
();
while
(
store
.
compact
(
9
0
))
{
while
(
store
.
compact
(
9
9
))
{
store
.
sync
();
long
time
=
System
.
currentTimeMillis
()
-
start
;
if
(
time
>
maxCompactTime
)
{
...
...
@@ -280,7 +280,7 @@ public class MVTableEngine implements TableEngine {
public
void
close
(
long
maxCompactTime
)
{
if
(!
store
.
isClosed
()
&&
store
.
getFileStore
()
!=
null
)
{
if
(!
store
.
getFileStore
().
isReadOnly
())
{
store
.
stor
e
();
transactionStore
.
clos
e
();
long
start
=
System
.
currentTimeMillis
();
while
(
store
.
compact
(
90
))
{
long
time
=
System
.
currentTimeMillis
()
-
start
;
...
...
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
900b5667
...
...
@@ -170,7 +170,9 @@ public class TransactionStore {
public
synchronized
void
close
()
{
// to avoid losing transaction ids
settings
.
put
(
LAST_TRANSACTION_ID
,
""
+
lastTransactionId
);
store
.
store
();
if
(
store
.
getFileStore
()
!=
null
)
{
store
.
store
();
}
}
/**
...
...
@@ -191,7 +193,6 @@ public class TransactionStore {
private
void
commitIfNeeded
()
{
if
(
store
.
getUnsavedPageCount
()
>
MAX_UNSAVED_PAGES
)
{
if
(
store
.
getFileStore
()
!=
null
)
{
store
.
commit
();
store
.
store
();
}
}
...
...
@@ -354,10 +355,10 @@ public class TransactionStore {
firstOpenTransaction
=
-
1
;
}
if
(
store
.
getWriteDelay
()
==
0
)
{
if
(
store
.
getFileStore
()
=
=
null
)
{
return
;
if
(
store
.
getFileStore
()
!
=
null
)
{
store
.
store
()
;
}
store
.
commit
()
;
return
;
}
// to avoid having to store the transaction log,
// if there is no open transaction,
...
...
@@ -1207,7 +1208,7 @@ public class TransactionStore {
*/
public
Iterator
<
K
>
keyIterator
(
K
from
,
boolean
includeUncommitted
)
{
Cursor
<
K
>
it
=
map
.
keyIterator
(
from
);
return
wrapIterator
(
it
,
false
);
return
wrapIterator
(
it
,
includeUncommitted
);
}
/**
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
900b5667
...
...
@@ -470,18 +470,18 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
prof
.
interval
=
1
;
prof
.
startCollecting
();
if
(
test
.
mvStore
)
{
TestPerformance
.
main
(
"-init"
,
"-db"
,
"9"
,
"-size"
,
"1000
0
"
);
TestPerformance
.
main
(
"-init"
,
"-db"
,
"9"
,
"-size"
,
"1000"
);
}
else
{
TestPerformance
.
main
(
"-init"
,
"-db"
,
"1"
);
}
prof
.
stopCollecting
();
System
.
out
.
println
(
prof
.
getTop
(
3
));
System
.
out
.
println
(
prof
.
getTop
(
3
0
));
if
(
test
.
mvStore
)
{
prof
=
new
Profiler
();
prof
.
depth
=
16
;
prof
.
interval
=
1
;
prof
.
startCollecting
();
TestPerformance
.
main
(
"-init"
,
"-db"
,
"1"
,
"-size"
,
"1000
0
"
);
TestPerformance
.
main
(
"-init"
,
"-db"
,
"1"
,
"-size"
,
"1000"
);
prof
.
stopCollecting
();
System
.
out
.
println
(
prof
.
getTop
(
3
));
}
...
...
h2/src/test/org/h2/test/store/TestConcurrent.java
浏览文件 @
900b5667
...
...
@@ -43,7 +43,6 @@ public class TestConcurrent extends TestMVStore {
@Override
public
void
test
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
FileUtils
.
createDirectories
(
getBaseDir
());
FileUtils
.
deleteRecursive
(
"memFS:"
,
false
);
...
...
@@ -110,7 +109,7 @@ public class TestConcurrent extends TestMVStore {
m
.
clear
();
s
.
removeMap
(
m
);
if
(
x
%
5
==
0
)
{
s
.
incrementVersion
();
s
.
commit
();
}
}
task
.
get
();
...
...
@@ -124,9 +123,9 @@ public class TestConcurrent extends TestMVStore {
}
}
assertEquals
(
1
,
chunkCount
);
s
.
close
();
}
FileUtils
.
deleteRecursive
(
"memFS:"
,
false
);
}
private
void
testConcurrentStoreAndRemoveMap
()
throws
InterruptedException
{
...
...
@@ -159,6 +158,7 @@ public class TestConcurrent extends TestMVStore {
}
task
.
get
();
s
.
close
();
FileUtils
.
deleteRecursive
(
"memFS:"
,
false
);
}
private
void
testConcurrentStoreAndClose
()
throws
InterruptedException
{
...
...
@@ -200,6 +200,7 @@ public class TestConcurrent extends TestMVStore {
}
s
.
close
();
}
FileUtils
.
deleteRecursive
(
"memFS:"
,
false
);
}
/**
...
...
@@ -249,7 +250,7 @@ public class TestConcurrent extends TestMVStore {
}
m
.
get
(
rand
.
nextInt
(
size
));
}
s
.
incrementVersion
();
s
.
commit
();
Thread
.
sleep
(
1
);
}
task
.
get
();
...
...
@@ -341,7 +342,7 @@ public class TestConcurrent extends TestMVStore {
for
(
int
k
=
0
;
k
<
10000
;
k
++)
{
Iterator
<
Integer
>
it
=
map
.
keyIterator
(
r
.
nextInt
(
len
));
long
old
=
s
.
getCurrentVersion
();
s
.
incrementVersion
();
s
.
commit
();
s
.
setRetainVersion
(
old
-
100
);
while
(
map
.
getVersion
()
==
old
)
{
Thread
.
yield
();
...
...
@@ -423,7 +424,7 @@ public class TestConcurrent extends TestMVStore {
notDetected
.
incrementAndGet
();
}
}
s
.
incrementVersion
();
s
.
commit
();
Thread
.
sleep
(
1
);
}
task
.
get
();
...
...
@@ -438,7 +439,7 @@ public class TestConcurrent extends TestMVStore {
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
m
.
put
(
i
,
x
);
}
s
.
incrementVersion
();
s
.
commit
();
Task
task
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
...
...
@@ -462,7 +463,7 @@ public class TestConcurrent extends TestMVStore {
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
m
.
put
(
i
,
x
);
}
s
.
incrementVersion
();
s
.
commit
();
Thread
.
sleep
(
1
);
}
task
.
get
();
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
900b5667
...
...
@@ -148,7 +148,7 @@ public class TestMVStore extends TestBase {
s
.
store
();
}
assertTrue
(
1000
<
offHeap
.
getWriteCount
());
//
s.close();
s
.
close
();
s
=
new
MVStore
.
Builder
().
fileStore
(
offHeap
).
...
...
@@ -253,7 +253,6 @@ public class TestMVStore extends TestBase {
m
=
s
.
openMap
(
"data"
);
s
.
getFileStore
().
getFile
().
close
();
m
.
put
(
1
,
"Hello"
);
s
.
commit
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
if
(
exRef
.
get
()
!=
null
)
{
break
;
...
...
@@ -330,19 +329,19 @@ public class TestMVStore extends TestBase {
fileName
(
fileName
).
open
();
m
=
s
.
openMap
(
"data"
);
assert
Fals
e
(
m
.
containsKey
(
1
));
assert
Tru
e
(
m
.
containsKey
(
1
));
m
.
put
(
1
,
data
);
s
.
commit
();
m
.
put
(
2
,
data
);
m
.
put
(
-
1
,
data
);
s
.
store
();
m
.
put
(
-
2
,
data
);
s
.
close
();
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
open
();
m
=
s
.
openMap
(
"data"
);
assertTrue
(
m
.
containsKey
(
1
));
assert
False
(
m
.
containsKey
(
2
));
assertTrue
(
m
.
containsKey
(
-
1
));
assert
True
(
m
.
containsKey
(-
2
));
s
.
close
();
FileUtils
.
delete
(
fileName
);
...
...
@@ -377,7 +376,7 @@ public class TestMVStore extends TestBase {
m
.
put
(
1
,
"Hello"
);
s
.
store
();
long
v
=
s
.
getCurrentVersion
();
m
.
put
(
2
,
"World"
);
m
.
put
(
2
,
"World
.
"
);
Thread
.
sleep
(
5
);
// must not store, as nothing has been committed yet
s
.
closeImmediately
();
...
...
@@ -386,9 +385,11 @@ public class TestMVStore extends TestBase {
open
();
s
.
setWriteDelay
(
1
);
m
=
s
.
openMap
(
"data"
);
assertEquals
(
null
,
m
.
get
(
2
));
assertEquals
(
"World."
,
m
.
get
(
2
));
m
.
put
(
2
,
"World"
);
s
.
commit
();
s
.
store
();
v
=
s
.
getCurrentVersion
();
m
.
put
(
3
,
"!"
);
for
(
int
i
=
100
;
i
>
0
;
i
--)
{
...
...
@@ -400,7 +401,7 @@ public class TestMVStore extends TestBase {
}
Thread
.
sleep
(
1
);
}
s
.
close
();
s
.
close
Immediately
();
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
...
...
@@ -408,7 +409,7 @@ public class TestMVStore extends TestBase {
m
=
s
.
openMap
(
"data"
);
assertEquals
(
"Hello"
,
m
.
get
(
1
));
assertEquals
(
"World"
,
m
.
get
(
2
));
assert
False
(
m
.
containsKey
(
3
));
assert
Equals
(
"!"
,
m
.
get
(
3
));
s
.
close
();
FileUtils
.
delete
(
fileName
);
...
...
@@ -517,7 +518,7 @@ public class TestMVStore extends TestBase {
MVMap
<
Integer
,
Integer
>
map
;
map
=
s
.
openMap
(
"hello"
);
map
.
put
(
1
,
10
);
long
old
=
s
.
incrementVersion
();
long
old
=
s
.
commit
();
s
.
renameMap
(
map
,
"world"
);
map
.
put
(
2
,
20
);
assertEquals
(
"world"
,
map
.
getName
());
...
...
@@ -557,7 +558,7 @@ public class TestMVStore extends TestBase {
s
.
store
();
s
.
close
();
int
[]
expectedReadsForCacheSize
=
{
3405
,
2590
,
1924
,
1440
,
110
3
,
956
,
918
3405
,
2590
,
1924
,
1440
,
110
8
,
956
,
918
};
for
(
int
cacheSize
=
0
;
cacheSize
<=
6
;
cacheSize
+=
4
)
{
s
=
new
MVStore
.
Builder
().
...
...
@@ -816,8 +817,10 @@ public class TestMVStore extends TestBase {
MVStore
s
=
MVStore
.
open
(
fileName
);
assertEquals
(
0
,
s
.
getCurrentVersion
());
assertEquals
(
0
,
s
.
getStoreVersion
());
s
.
setStoreVersion
(
0
);
s
.
store
();
s
.
setStoreVersion
(
1
);
s
.
close
();
s
.
close
Immediately
();
s
=
MVStore
.
open
(
fileName
);
assertEquals
(
1
,
s
.
getCurrentVersion
());
assertEquals
(
0
,
s
.
getStoreVersion
());
...
...
@@ -840,7 +843,7 @@ public class TestMVStore extends TestBase {
map
.
put
(
i
,
10
*
i
);
}
Iterator
<
Integer
>
it
=
map
.
keySet
().
iterator
();
s
.
incrementVersion
();
s
.
commit
();
for
(
int
i
=
0
;
i
<
len
;
i
+=
2
)
{
map
.
remove
(
i
);
}
...
...
@@ -916,7 +919,7 @@ public class TestMVStore extends TestBase {
long
oldVersion
=
s
.
getCurrentVersion
();
// from now on, the old version is read-only
s
.
incrementVersion
();
s
.
commit
();
// more changes, in the new version
// changes can be rolled back if required
...
...
@@ -976,7 +979,7 @@ public class TestMVStore extends TestBase {
if
(
op
==
1
)
{
m
.
put
(
"1"
,
""
+
s
.
getCurrentVersion
());
}
s
.
incrementVersion
();
s
.
commit
();
}
for
(
int
j
=
0
;
j
<
s
.
getCurrentVersion
();
j
++)
{
MVMap
<
String
,
String
>
old
=
m
.
openVersion
(
j
);
...
...
@@ -997,14 +1000,14 @@ public class TestMVStore extends TestBase {
MVMap
<
String
,
String
>
m
;
m
=
s
.
openMap
(
"data"
);
long
first
=
s
.
getCurrentVersion
();
s
.
incrementVersion
();
s
.
commit
();
m
.
put
(
"1"
,
"Hello"
);
m
.
put
(
"2"
,
"World"
);
for
(
int
i
=
10
;
i
<
20
;
i
++)
{
m
.
put
(
""
+
i
,
"data"
);
}
long
old
=
s
.
getCurrentVersion
();
s
.
incrementVersion
();
s
.
commit
();
m
.
put
(
"1"
,
"Hallo"
);
m
.
put
(
"2"
,
"Welt"
);
MVMap
<
String
,
String
>
mFirst
;
...
...
@@ -1119,7 +1122,7 @@ public class TestMVStore extends TestBase {
assertTrue
(
s
.
hasUnsavedChanges
());
MVMap
<
String
,
String
>
m0
=
s
.
openMap
(
"data0"
);
m
.
put
(
"1"
,
"Hello"
);
assertEquals
(
1
,
s
.
incrementVersion
());
assertEquals
(
1
,
s
.
commit
());
s
.
rollbackTo
(
1
);
assertEquals
(
1
,
s
.
getCurrentVersion
());
assertEquals
(
"Hello"
,
m
.
get
(
"1"
));
...
...
@@ -1167,16 +1170,13 @@ public class TestMVStore extends TestBase {
assertEquals
(
"Hello"
,
m
.
get
(
"1"
));
assertFalse
(
m0
.
isReadOnly
());
m
.
put
(
"1"
,
"Hallo"
);
s
.
incrementVersion
();
s
.
commit
();
long
v3
=
s
.
getCurrentVersion
();
assertEquals
(
3
,
v3
);
long
v4
=
s
.
store
();
assertEquals
(
4
,
v4
);
assertEquals
(
4
,
s
.
getCurrentVersion
());
s
.
close
();
s
=
openStore
(
fileName
);
assertEquals
(
4
,
s
.
getCurrentVersion
());
assertEquals
(
3
,
s
.
getCurrentVersion
());
m
=
s
.
openMap
(
"data"
);
m
.
put
(
"1"
,
"Hi"
);
s
.
store
();
...
...
@@ -1185,7 +1185,7 @@ public class TestMVStore extends TestBase {
s
=
openStore
(
fileName
);
m
=
s
.
openMap
(
"data"
);
assertEquals
(
"Hi"
,
m
.
get
(
"1"
));
s
.
rollbackTo
(
v
4
);
s
.
rollbackTo
(
v
3
);
assertEquals
(
"Hallo"
,
m
.
get
(
"1"
));
s
.
close
();
...
...
@@ -1212,7 +1212,7 @@ public class TestMVStore extends TestBase {
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
m2
.
put
(
""
+
i
,
"Test"
);
}
long
v1
=
s
.
incrementVersion
();
long
v1
=
s
.
commit
();
assertEquals
(
1
,
v1
);
assertEquals
(
1
,
s
.
getCurrentVersion
());
MVMap
<
String
,
String
>
m1
=
s
.
openMap
(
"data1"
);
...
...
h2/src/test/org/h2/test/store/TestMVStoreBenchmark.java
浏览文件 @
900b5667
...
...
@@ -73,7 +73,7 @@ public class TestMVStoreBenchmark extends TestBase {
}
private
static
long
[]
getMemoryUsed
(
int
count
,
int
size
)
{
private
long
[]
getMemoryUsed
(
int
count
,
int
size
)
{
long
hash
,
tree
,
mv
;
ArrayList
<
Map
<
Integer
,
String
>>
mapList
;
long
mem
;
...
...
@@ -107,6 +107,10 @@ public class TestMVStoreBenchmark extends TestBase {
mv
=
getMemory
()
-
mem
;
mapList
.
size
();
trace
(
"hash: "
+
hash
/
1024
/
1024
+
" mb"
);
trace
(
"tree: "
+
tree
/
1024
/
1024
+
" mb"
);
trace
(
"mv: "
+
mv
/
1024
/
1024
+
" mb"
);
return
new
long
[]{
hash
,
tree
,
mv
};
}
...
...
@@ -179,7 +183,7 @@ public class TestMVStoreBenchmark extends TestBase {
}
time
=
System
.
currentTimeMillis
()
-
time
;
}
// System.out.println
(map.getClass().getName() + ": " + time);
trace
(
map
.
getClass
().
getName
()
+
": "
+
time
);
return
time
;
}
...
...
h2/src/test/org/h2/test/store/TestMVTableEngine.java
浏览文件 @
900b5667
...
...
@@ -141,7 +141,7 @@ public class TestMVTableEngine extends TestBase {
conn
.
close
();
long
sizeNew
=
FileUtils
.
size
(
getBaseDir
()
+
"/mvstore"
+
Constants
.
SUFFIX_MV_FILE
);
assertTrue
(
sizeNew
<
sizeOld
);
assertTrue
(
"new: "
+
sizeNew
+
" old: "
+
sizeOld
,
sizeNew
<
sizeOld
);
}
private
void
testTwoPhaseCommit
()
throws
Exception
{
...
...
h2/src/test/org/h2/test/store/TestTransactionStore.java
浏览文件 @
900b5667
...
...
@@ -59,6 +59,7 @@ public class TestTransactionStore extends TestBase {
private
void
testStopWhileCommitting
()
throws
Exception
{
String
fileName
=
getBaseDir
()
+
"/testStopWhileCommitting.h3"
;
FileUtils
.
delete
(
fileName
);
Random
r
=
new
Random
(
0
);
for
(
int
i
=
0
;
i
<
10
;)
{
MVStore
s
;
...
...
@@ -100,6 +101,16 @@ public class TestTransactionStore extends TestBase {
task
.
get
();
store
.
close
();
s
=
MVStore
.
open
(
fileName
);
// roll back a bit, until we have some undo log entries
assertTrue
(
s
.
hasMap
(
"undoLog"
));
for
(
int
back
=
0
;
back
<
100
;
back
++)
{
int
minus
=
r
.
nextInt
(
10
);
s
.
rollbackTo
(
Math
.
max
(
0
,
s
.
getCurrentVersion
()
-
minus
));
MVMap
<?,
?>
undo
=
s
.
openMap
(
"undoLog"
);
if
(
undo
.
size
()
>
0
)
{
break
;
}
}
ts
=
new
TransactionStore
(
s
);
List
<
Transaction
>
list
=
ts
.
getOpenTransactions
();
if
(
list
.
size
()
!=
0
)
{
...
...
@@ -111,10 +122,6 @@ public class TestTransactionStore extends TestBase {
s
.
close
();
FileUtils
.
delete
(
fileName
);
assertFalse
(
FileUtils
.
exists
(
fileName
));
FileUtils
.
delete
(
fileName
);
assertFalse
(
FileUtils
.
exists
(
fileName
));
s
.
close
();
FileUtils
.
delete
(
fileName
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论