Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
726c1440
提交
726c1440
authored
2月 22, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: Fix "version to keep"; documentation
上级
aa600f94
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
56 行增加
和
15 行删除
+56
-15
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+14
-10
StreamStore.java
h2/src/main/org/h2/mvstore/StreamStore.java
+9
-0
LobStorageMap.java
h2/src/main/org/h2/store/LobStorageMap.java
+1
-2
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+32
-3
没有找到文件。
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
726c1440
...
...
@@ -49,6 +49,7 @@ TransactionStore:
MVStore:
- maybe change the length code to have lower gaps
- data kept in stream store if transaction is not committed?
- automated 'kill process' and 'power failure' test
- test and possibly improve compact operation (for large dbs)
...
...
@@ -1722,9 +1723,9 @@ public class MVStore {
}
/**
* How many versions to retain for in-memory stores. If not set, 5
versions
* are retained.
*
* How many versions to retain for in-memory stores. If not set, 5
old
*
versions
are retained.
*
* @param count the number of versions to keep
*/
public
void
setVersionsToKeep
(
int
count
)
{
...
...
@@ -1732,7 +1733,7 @@ public class MVStore {
}
/**
* Get the oldest version to retain in memory.
* Get the oldest version to retain in memory
(for in-memory stores)
.
*
* @return the version
*/
...
...
@@ -1749,7 +1750,7 @@ public class MVStore {
long
getOldestVersionToKeep
()
{
long
v
=
currentVersion
;
if
(
fileStore
==
null
)
{
return
v
-
versionsToKeep
;
return
v
-
versionsToKeep
+
1
;
}
long
storeVersion
=
currentStoreVersion
;
if
(
storeVersion
>
-
1
)
{
...
...
@@ -2321,12 +2322,12 @@ public class MVStore {
/**
* Encrypt / decrypt the file using the given password. This method has
* no effect for in-memory stores. The password is passed as a
char
* array so that it can be cleared as soon as possible. Please note
* no effect for in-memory stores. The password is passed as a
*
char
array so that it can be cleared as soon as possible. Please note
* there is still a small risk that password stays in memory (due to
* Java garbage collection). Also, the hashed encryption key is kept in
* memory as long as the file is open.
*
*
* @param password the password
* @return this
*/
...
...
@@ -2402,8 +2403,11 @@ public class MVStore {
}
/**
* Use the provided file store instead of the default one.
*
* Use the provided file store instead of the default one. Please note
* that any kind of store (including an off-heap store) is considered a
* "persistence", while an "in-memory store" means objects are not
* persisted and fully kept in the JVM heap.
*
* @param store the file store
* @return this
*/
...
...
h2/src/main/org/h2/mvstore/StreamStore.java
浏览文件 @
726c1440
...
...
@@ -149,10 +149,12 @@ public class StreamStore {
}
boolean
eof
=
len
<
maxBlockSize
;
if
(
len
<
minBlockSize
)
{
// in-place: 0, len (int), data
id
.
write
(
0
);
DataUtils
.
writeVarInt
(
id
,
len
);
id
.
write
(
buff
);
}
else
{
// block: 1, len (int), blockId (long)
id
.
write
(
1
);
DataUtils
.
writeVarInt
(
id
,
len
);
DataUtils
.
writeVarLong
(
id
,
writeBlock
(
buff
));
...
...
@@ -181,6 +183,7 @@ public class StreamStore {
private
ByteArrayOutputStream
putIndirectId
(
ByteArrayOutputStream
id
)
throws
IOException
{
byte
[]
data
=
id
.
toByteArray
();
id
=
new
ByteArrayOutputStream
();
// indirect: 2, total len (long), blockId (long)
id
.
write
(
2
);
DataUtils
.
writeVarLong
(
id
,
length
(
data
));
DataUtils
.
writeVarLong
(
id
,
writeBlock
(
data
));
...
...
@@ -241,15 +244,18 @@ public class StreamStore {
while
(
idBuffer
.
hasRemaining
())
{
switch
(
idBuffer
.
get
())
{
case
0
:
// in-place: 0, len (int), data
int
len
=
DataUtils
.
readVarInt
(
idBuffer
);
idBuffer
.
position
(
idBuffer
.
position
()
+
len
);
break
;
case
1
:
// block: 1, len (int), blockId (long)
DataUtils
.
readVarInt
(
idBuffer
);
long
k
=
DataUtils
.
readVarLong
(
idBuffer
);
map
.
remove
(
k
);
break
;
case
2
:
// indirect: 2, total len (long), blockId (long)
DataUtils
.
readVarLong
(
idBuffer
);
long
k2
=
DataUtils
.
readVarLong
(
idBuffer
);
// recurse
...
...
@@ -276,15 +282,18 @@ public class StreamStore {
while
(
idBuffer
.
hasRemaining
())
{
switch
(
idBuffer
.
get
())
{
case
0
:
// in-place: 0, len (int), data
int
len
=
DataUtils
.
readVarInt
(
idBuffer
);
idBuffer
.
position
(
idBuffer
.
position
()
+
len
);
length
+=
len
;
break
;
case
1
:
// block: 1, len (int), blockId (long)
length
+=
DataUtils
.
readVarInt
(
idBuffer
);
DataUtils
.
readVarLong
(
idBuffer
);
break
;
case
2
:
// indirect: 2, total len (long), blockId (long)
length
+=
DataUtils
.
readVarLong
(
idBuffer
);
DataUtils
.
readVarLong
(
idBuffer
);
break
;
...
...
h2/src/main/org/h2/store/LobStorageMap.java
浏览文件 @
726c1440
...
...
@@ -46,8 +46,7 @@ public class LobStorageMap implements LobStorageInterface {
* (which is a long) to the stream store id (which is a byte array).
*
* Key: lobId (long)
* Value: { streamStoreId (byte[]), tableId (int),
* byteCount (long), hashCode (long) }.
* Value: { streamStoreId (byte[]), tableId (int), byteCount (long), hash (long) }.
*/
private
MVMap
<
Long
,
Object
[]>
lobMap
;
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
726c1440
...
...
@@ -27,6 +27,7 @@ import org.h2.mvstore.type.StringDataType;
import
org.h2.store.fs.FilePath
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.test.utils.AssertThrows
;
/**
* Tests the MVStore.
...
...
@@ -55,6 +56,7 @@ public class TestMVStore extends TestBase {
testCacheInfo
();
testRollback
();
testVersionsToKeep
();
testVersionsToKeep2
();
testRemoveMap
();
testIsEmpty
();
testOffHeapStorage
();
...
...
@@ -184,9 +186,9 @@ public class TestMVStore extends TestBase {
map
.
put
(
i
,
i
);
s
.
commit
();
if
(
version
>=
6
)
{
map
.
openVersion
(
version
-
6
);
map
.
openVersion
(
version
-
5
);
try
{
map
.
openVersion
(
version
-
7
);
map
.
openVersion
(
version
-
6
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
// expected
...
...
@@ -194,6 +196,33 @@ public class TestMVStore extends TestBase {
}
}
}
private
void
testVersionsToKeep2
()
{
MVStore
s
=
new
MVStore
.
Builder
().
autoCommitDisabled
().
open
();
s
.
setVersionsToKeep
(
2
);
final
MVMap
<
Integer
,
String
>
m
=
s
.
openMap
(
"data"
);
s
.
commit
();
assertEquals
(
1
,
s
.
getCurrentVersion
());
m
.
put
(
1
,
"version 1"
);
s
.
commit
();
assertEquals
(
2
,
s
.
getCurrentVersion
());
m
.
put
(
1
,
"version 2"
);
s
.
commit
();
assertEquals
(
3
,
s
.
getCurrentVersion
());
m
.
put
(
1
,
"version 3"
);
s
.
commit
();
m
.
put
(
1
,
"version 4"
);
assertEquals
(
"version 4"
,
m
.
openVersion
(
4
).
get
(
1
));
assertEquals
(
"version 3"
,
m
.
openVersion
(
3
).
get
(
1
));
assertEquals
(
"version 2"
,
m
.
openVersion
(
2
).
get
(
1
));
new
AssertThrows
(
IllegalArgumentException
.
class
)
{
@Override
public
void
test
()
throws
Exception
{
m
.
openVersion
(
1
);
}
};
s
.
close
();
}
private
void
testRemoveMap
()
throws
Exception
{
String
fileName
=
getBaseDir
()
+
"/testCloseMap.h3"
;
...
...
@@ -1083,7 +1112,7 @@ public class TestMVStore extends TestBase {
// System.out.println("size: " + FileUtils.size(fileName));
}
}
private
void
testOldVersion
()
{
MVStore
s
;
for
(
int
op
=
0
;
op
<=
1
;
op
++)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论