Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cefce952
提交
cefce952
authored
8月 03, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A persistent tree map (work in progress).
上级
4a0120b8
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
331 行增加
和
168 行删除
+331
-168
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+4
-1
TestCacheLIRS.java
h2/src/test/org/h2/test/store/TestCacheLIRS.java
+1
-5
TestDataUtils.java
h2/src/test/org/h2/test/store/TestDataUtils.java
+54
-0
BtreeMap.java
h2/src/tools/org/h2/dev/store/btree/BtreeMap.java
+25
-17
BtreeMapStore.java
h2/src/tools/org/h2/dev/store/btree/BtreeMapStore.java
+96
-93
Chunk.java
h2/src/tools/org/h2/dev/store/btree/Chunk.java
+4
-4
DataUtils.java
h2/src/tools/org/h2/dev/store/btree/DataUtils.java
+12
-0
Page.java
h2/src/tools/org/h2/dev/store/btree/Page.java
+135
-48
没有找到文件。
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
cefce952
...
...
@@ -103,6 +103,8 @@ import org.h2.test.server.TestAutoServer;
import
org.h2.test.server.TestNestedLoop
;
import
org.h2.test.server.TestWeb
;
import
org.h2.test.server.TestInit
;
import
org.h2.test.store.TestCacheLIRS
;
import
org.h2.test.store.TestDataUtils
;
import
org.h2.test.store.TestTreeMapStore
;
import
org.h2.test.synth.TestBtreeIndex
;
import
org.h2.test.synth.TestCrashAPI
;
...
...
@@ -662,8 +664,9 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
private
void
testUnit
()
{
// store
new
TestCacheLIRS
().
runTest
(
this
);
new
TestTreeMapStore
().
runTest
(
this
);
new
Test
Cache
().
runTest
(
this
);
new
Test
DataUtils
().
runTest
(
this
);
// unit
new
TestAutoReconnect
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/store/TestCache.java
→
h2/src/test/org/h2/test/store/TestCache
LIRS
.java
浏览文件 @
cefce952
...
...
@@ -12,13 +12,12 @@ import java.util.Map.Entry;
import
java.util.Random
;
import
org.h2.dev.store.btree.CacheLIRS
;
import
org.h2.test.TestBase
;
import
org.h2.upgrade.v1_1.util.Profiler
;
import
org.h2.util.New
;
/**
* Tests the cache algorithm.
*/
public
class
TestCache
extends
TestBase
{
public
class
TestCache
LIRS
extends
TestBase
{
/**
* Run just this test.
...
...
@@ -30,8 +29,6 @@ public class TestCache extends TestBase {
}
public
void
test
()
throws
Exception
{
Profiler
p
=
new
Profiler
();
p
.
startCollecting
();
testEdgeCases
();
testSize
();
testClear
();
...
...
@@ -42,7 +39,6 @@ public class TestCache extends TestBase {
testBadHashMethod
();
testScanResistance
();
testRandomOperations
();
System
.
out
.
println
(
p
.
getTop
(
5
));
}
private
void
testEdgeCases
()
{
...
...
h2/src/test/org/h2/test/store/TestDataUtils.java
0 → 100644
浏览文件 @
cefce952
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, Version
* 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
store
;
import
org.h2.dev.store.btree.Page
;
import
org.h2.test.TestBase
;
/**
* Test utility classes.
*/
public
class
TestDataUtils
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
testPagePos
();
}
private
void
testPagePos
()
{
int
lastCode
=
0
;
assertEquals
(
0
,
Page
.
encodeLength
(
32
));
assertEquals
(
1
,
Page
.
encodeLength
(
33
));
assertEquals
(
1
,
Page
.
encodeLength
(
48
));
assertEquals
(
2
,
Page
.
encodeLength
(
49
));
assertEquals
(
30
,
Page
.
encodeLength
(
1024
*
1024
));
assertEquals
(
31
,
Page
.
encodeLength
(
1024
*
1024
+
1
));
for
(
int
i
=
1024
*
1024
+
1
;
i
<
100
*
1024
*
1024
;
i
+=
1024
)
{
int
code
=
Page
.
encodeLength
(
i
);
assertEquals
(
31
,
code
);
}
for
(
int
i
=
0
;
i
<
1024
*
1024
;
i
++)
{
int
code
=
Page
.
encodeLength
(
i
);
assertTrue
(
code
<=
31
&&
code
>=
0
);
assertTrue
(
code
>=
lastCode
);
if
(
code
>
lastCode
)
{
lastCode
=
code
;
}
int
max
=
Page
.
getMaxLength
(
code
);
assertTrue
(
max
>=
i
&&
max
>=
32
);
}
}
}
h2/src/tools/org/h2/dev/store/btree/BtreeMap.java
浏览文件 @
cefce952
...
...
@@ -17,13 +17,13 @@ import java.util.Iterator;
public
class
BtreeMap
<
K
,
V
>
{
private
final
BtreeMapStore
store
;
private
final
long
id
;
private
final
int
id
;
private
final
String
name
;
private
final
DataType
keyType
;
private
final
DataType
valueType
;
private
Page
root
;
private
BtreeMap
(
BtreeMapStore
store
,
long
id
,
String
name
,
DataType
keyType
,
DataType
valueType
)
{
private
BtreeMap
(
BtreeMapStore
store
,
int
id
,
String
name
,
DataType
keyType
,
DataType
valueType
)
{
this
.
store
=
store
;
this
.
id
=
id
;
this
.
name
=
name
;
...
...
@@ -43,7 +43,7 @@ public class BtreeMap<K, V> {
* @param valueClass the value class
* @return the map
*/
static
<
K
,
V
>
BtreeMap
<
K
,
V
>
open
(
BtreeMapStore
store
,
long
id
,
String
name
,
DataType
keyType
,
DataType
valueType
)
{
static
<
K
,
V
>
BtreeMap
<
K
,
V
>
open
(
BtreeMapStore
store
,
int
id
,
String
name
,
DataType
keyType
,
DataType
valueType
)
{
return
new
BtreeMap
<
K
,
V
>(
store
,
id
,
name
,
keyType
,
valueType
);
}
...
...
@@ -96,6 +96,14 @@ public class BtreeMap<K, V> {
}
}
/**
* Remove all entries, and remove the map.
*/
public
void
remove
()
{
clear
();
store
.
removeMap
(
id
);
}
/**
* Remove a key-value pair.
*
...
...
@@ -114,7 +122,7 @@ public class BtreeMap<K, V> {
* @return true if yes
*/
boolean
isChanged
()
{
return
root
!=
null
&&
root
.
get
Id
()
<
0
;
return
root
!=
null
&&
root
.
get
Pos
()
<
0
;
}
private
void
markChanged
()
{
...
...
@@ -167,22 +175,22 @@ public class BtreeMap<K, V> {
}
/**
* Read a
nod
e.
* Read a
pag
e.
*
* @param
id the node id
* @return the
nod
e
* @param
pos the position of the page
* @return the
pag
e
*/
Page
readPage
(
long
id
)
{
return
store
.
readPage
(
this
,
id
);
Page
readPage
(
long
pos
)
{
return
store
.
readPage
(
this
,
pos
);
}
/**
* Remove a
nod
e.
* Remove a
pag
e.
*
* @param
id the node id
* @param
pos the position of the page
*/
void
removePage
(
long
id
)
{
store
.
removePage
(
id
);
void
removePage
(
long
pos
)
{
store
.
removePage
(
pos
);
}
/**
...
...
@@ -190,7 +198,7 @@ public class BtreeMap<K, V> {
*
* @param rootPos the position
*/
void
setRoot
(
long
rootPos
)
{
void
setRoot
Pos
(
long
rootPos
)
{
root
=
readPage
(
rootPos
);
}
...
...
@@ -205,9 +213,9 @@ public class BtreeMap<K, V> {
}
/**
* Get the root
nod
e.
* Get the root
pag
e.
*
* @return the root
nod
e
* @return the root
pag
e
*/
Page
getRoot
()
{
return
root
;
...
...
@@ -226,7 +234,7 @@ public class BtreeMap<K, V> {
return
store
.
getMaxPageSize
();
}
long
getId
()
{
int
getId
()
{
return
id
;
}
...
...
h2/src/tools/org/h2/dev/store/btree/BtreeMapStore.java
浏览文件 @
cefce952
差异被折叠。
点击展开。
h2/src/tools/org/h2/dev/store/btree/Chunk.java
浏览文件 @
cefce952
...
...
@@ -46,9 +46,9 @@ class Chunk {
int
collectPriority
;
/**
* The
offset
of the meta root.
* The
position
of the meta root.
*/
int
metaRootOffset
;
long
metaRootPos
;
Chunk
(
int
id
)
{
this
.
id
=
id
;
...
...
@@ -70,7 +70,7 @@ class Chunk {
c
.
length
=
Long
.
parseLong
(
prop
.
get
(
"length"
).
toString
());
c
.
entryCount
=
Integer
.
parseInt
(
prop
.
get
(
"entryCount"
).
toString
());
c
.
liveCount
=
Integer
.
parseInt
(
prop
.
get
(
"liveCount"
).
toString
());
c
.
metaRoot
Offset
=
Integer
.
parseInt
(
prop
.
get
(
"metaRoot"
).
toString
());
c
.
metaRoot
Pos
=
Long
.
parseLong
(
prop
.
get
(
"metaRoot"
).
toString
());
return
c
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
...
...
@@ -96,7 +96,7 @@ class Chunk {
"length:"
+
length
+
"\n"
+
"entryCount:"
+
entryCount
+
"\n"
+
"liveCount:"
+
liveCount
+
"\n"
+
"metaRoot:"
+
metaRoot
Offset
+
"\n"
;
"metaRoot:"
+
metaRoot
Pos
+
"\n"
;
}
}
...
...
h2/src/tools/org/h2/dev/store/btree/DataUtils.java
浏览文件 @
cefce952
...
...
@@ -6,7 +6,9 @@
*/
package
org
.
h2
.
dev
.
store
.
btree
;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
/**
* Utility methods
...
...
@@ -172,4 +174,14 @@ public class DataUtils {
}
}
static
void
readFully
(
FileChannel
file
,
ByteBuffer
buff
)
throws
IOException
{
do
{
int
len
=
file
.
read
(
buff
);
if
(
len
<
0
)
{
break
;
}
}
while
(
buff
.
remaining
()
>
0
);
buff
.
rewind
();
}
}
h2/src/tools/org/h2/dev/store/btree/Page.java
浏览文件 @
cefce952
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论