Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cda72762
提交
cda72762
authored
5月 01, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore table engine
上级
674328ac
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
70 行增加
和
21 行删除
+70
-21
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+4
-1
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+31
-7
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+3
-4
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+4
-0
TestMVTableEngine.java
h2/src/test/org/h2/test/store/TestMVTableEngine.java
+28
-9
没有找到文件。
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
cda72762
...
...
@@ -828,7 +828,6 @@ public class MVStore {
meta
.
remove
(
"rollbackOnOpen"
);
retainChunk
=
null
;
}
// the last chunk was not completely correct in the last store()
// this needs to be updated now (it's better not to update right after
// storing, because that would modify the meta map again)
...
...
@@ -1746,6 +1745,10 @@ public class MVStore {
return
readOnly
;
}
public
boolean
isClosed
()
{
return
closed
;
}
/**
* A background writer to automatically store changes from time to time.
*/
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
cda72762
...
...
@@ -106,8 +106,24 @@ public class MVPrimaryIndex extends BaseIndex {
Long
c
=
row
.
getValue
(
mainIndexColumn
).
getLong
();
row
.
setKey
(
c
);
}
if
(
mvTable
.
getContainsLargeObject
())
{
for
(
int
i
=
0
,
len
=
row
.
getColumnCount
();
i
<
len
;
i
++)
{
Value
v
=
row
.
getValue
(
i
);
Value
v2
=
v
.
link
(
database
,
getId
());
if
(
v2
.
isLinked
())
{
session
.
unlinkAtCommitStop
(
v2
);
}
if
(
v
!=
v2
)
{
row
.
setValue
(
i
,
v2
);
}
}
}
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
if
(
map
.
containsKey
(
ValueLong
.
get
(
row
.
getKey
())))
{
Value
key
=
ValueLong
.
get
(
row
.
getKey
());
Value
old
=
map
.
getLatest
(
key
);
if
(
old
!=
null
)
{
String
sql
=
"PRIMARY KEY ON "
+
table
.
getSQL
();
if
(
mainIndexColumn
>=
0
&&
mainIndexColumn
<
indexColumns
.
length
)
{
sql
+=
"("
+
indexColumns
[
mainIndexColumn
].
getSQL
()
+
")"
;
...
...
@@ -116,12 +132,20 @@ public class MVPrimaryIndex extends BaseIndex {
e
.
setSource
(
this
);
throw
e
;
}
map
.
put
(
ValueLong
.
get
(
row
.
getKey
())
,
ValueArray
.
get
(
row
.
getValueList
()));
map
.
put
(
key
,
ValueArray
.
get
(
row
.
getValueList
()));
lastKey
=
Math
.
max
(
lastKey
,
row
.
getKey
());
}
@Override
public
void
remove
(
Session
session
,
Row
row
)
{
if
(
mvTable
.
getContainsLargeObject
())
{
for
(
int
i
=
0
,
len
=
row
.
getColumnCount
();
i
<
len
;
i
++)
{
Value
v
=
row
.
getValue
(
i
);
if
(
v
.
isLinked
())
{
session
.
unlinkAtCommit
(
v
);
}
}
}
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
Value
old
=
map
.
remove
(
ValueLong
.
get
(
row
.
getKey
()));
if
(
old
==
null
)
{
...
...
@@ -172,8 +196,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
long
cost
=
10
*
(
map
.
getSize
()
+
Constants
.
COST_ROW_OFFSET
);
long
cost
=
10
*
(
dataMap
.
map
.
getSize
()
+
Constants
.
COST_ROW_OFFSET
);
return
cost
;
}
...
...
@@ -208,10 +231,11 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public
Cursor
findFirstOrLast
(
Session
session
,
boolean
first
)
{
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
if
(
map
.
getSize
()
==
0
)
{
Value
v
=
first
?
map
.
firstKey
()
:
map
.
lastKey
();
if
(
v
==
null
)
{
return
new
MVStoreCursor
(
session
,
Collections
.<
Value
>
emptyList
().
iterator
(),
0
);
}
long
key
=
first
?
map
.
firstKey
().
getLong
()
:
map
.
lastKey
()
.
getLong
();
long
key
=
v
.
getLong
();
MVStoreCursor
cursor
=
new
MVStoreCursor
(
session
,
Arrays
.
asList
((
Value
)
ValueLong
.
get
(
key
)).
iterator
(),
key
);
cursor
.
next
();
...
...
@@ -231,7 +255,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public
long
getRowCountApproximation
()
{
return
getMap
(
null
)
.
getSize
();
return
dataMap
.
map
.
getSize
();
}
public
long
getDiskSpaceUsed
()
{
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
cda72762
...
...
@@ -172,8 +172,7 @@ public class MVSecondaryIndex extends BaseIndex {
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
SortOrder
sortOrder
)
{
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
return
10
*
getCostRangeIndex
(
masks
,
map
.
getSize
(),
sortOrder
);
return
10
*
getCostRangeIndex
(
masks
,
dataMap
.
map
.
getSize
(),
sortOrder
);
}
@Override
...
...
@@ -217,7 +216,7 @@ public class MVSecondaryIndex extends BaseIndex {
@Override
public
boolean
needRebuild
()
{
return
getMap
(
null
)
.
getSize
()
==
0
;
return
dataMap
.
map
.
getSize
()
==
0
;
}
@Override
...
...
@@ -228,7 +227,7 @@ public class MVSecondaryIndex extends BaseIndex {
@Override
public
long
getRowCountApproximation
()
{
return
getMap
(
null
)
.
getSize
();
return
dataMap
.
map
.
getSize
();
}
public
long
getDiskSpaceUsed
()
{
...
...
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
cda72762
...
...
@@ -234,6 +234,9 @@ public class TransactionStore {
* @param maxLogId the last log id
*/
void
commit
(
Transaction
t
,
long
maxLogId
)
{
if
(
store
.
isClosed
())
{
return
;
}
for
(
long
logId
=
0
;
logId
<
maxLogId
;
logId
++)
{
long
[]
undoKey
=
new
long
[]
{
t
.
getId
(),
logId
};
...
...
@@ -634,6 +637,7 @@ public class TransactionStore {
*
* @param key the key
* @param value the new value (not null)
* @return the old value
* @throws IllegalStateException if a lock timeout occurs
*/
public
V
put
(
K
key
,
V
value
)
{
...
...
h2/src/test/org/h2/test/store/TestMVTableEngine.java
浏览文件 @
cda72762
...
...
@@ -8,6 +8,7 @@ package org.h2.test.store;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.PrintWriter
;
import
java.math.BigDecimal
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
...
...
@@ -38,8 +39,9 @@ public class TestMVTableEngine extends TestBase {
}
public
void
test
()
throws
Exception
{
//testSpeed();
// testBlob();
// testSpeed();
testReopen
();
testBlob
();
testExclusiveLock
();
testEncryption
();
testReadOnly
();
...
...
@@ -61,7 +63,7 @@ int tes;
dbName
=
"mvstore"
+
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine"
;
dbName
+=
";LOCK_MODE=0"
;
//
dbName += ";LOG=0";
dbName
+=
";LOG=0"
;
testSpeed
(
dbName
);
//System.out.println(prof.getTop(10));
}
...
...
@@ -117,8 +119,8 @@ int tes;
// 1541 mvstore;DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine;LOCK_MODE=0 before
// 1551 mvstore;DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine;LOCK_MODE=0 after
prep
.
setString
(
2
,
new
String
(
new
char
[
10
]).
replace
((
char
)
0
,
'x'
));
for
(
int
i
=
0
;
i
<
8
0000
;
i
++)
{
prep
.
setString
(
2
,
new
String
(
new
char
[
10
0
]).
replace
((
char
)
0
,
'x'
));
for
(
int
i
=
0
;
i
<
20
0000
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
...
...
@@ -129,6 +131,21 @@ int tes;
System
.
out
.
println
((
System
.
currentTimeMillis
()
-
time
)
+
" "
+
dbName
+
" after"
);
}
private
void
testReopen
()
throws
SQLException
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
Connection
conn
;
Statement
stat
;
conn
=
getConnection
(
"mvstore"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar) "
+
"engine \"org.h2.mvstore.db.MVTableEngine\""
);
conn
.
close
();
conn
=
getConnection
(
"mvstore"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testBlob
()
throws
SQLException
,
IOException
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
String
dbName
=
"mvstore"
+
...
...
@@ -139,10 +156,9 @@ int tes;
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name blob)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(1, ?)"
);
prep
.
setBinaryStream
(
1
,
new
ByteArrayInputStream
(
new
byte
[
1
000
]));
prep
.
setBinaryStream
(
1
,
new
ByteArrayInputStream
(
new
byte
[
1
29
]));
prep
.
execute
();
conn
.
close
();
conn
=
getConnection
(
dbName
);
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
);
...
...
@@ -152,7 +168,7 @@ int tes;
while
(
in
.
read
()
>=
0
)
{
len
++;
}
assertEquals
(
1
0000
,
len
);
assertEquals
(
1
29
,
len
);
}
conn
.
close
();
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
...
...
@@ -169,11 +185,12 @@ int tes;
String
password
=
"123 123"
;
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
stat
.
execute
(
"create table test(id int
primary key
)"
);
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"select * from test"
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
}
...
...
@@ -451,6 +468,8 @@ int tes;
assertEquals
(
"Hello"
,
rs
.
getString
(
2
));
assertEquals
(
1
,
rs
.
getInt
(
3
));
stat
.
execute
(
"update test set name = 'Hello' where id = 1"
);
if
(!
config
.
memory
)
{
conn
.
close
();
conn
=
getConnection
(
dbName
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论