Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f4d43c7f
提交
f4d43c7f
authored
4月 03, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: statement processing (currently relatively slow)
上级
bbb23ae3
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
84 行增加
和
33 行删除
+84
-33
Session.java
h2/src/main/org/h2/engine/Session.java
+2
-2
DataUtils.java
h2/src/main/org/h2/mvstore/DataUtils.java
+1
-1
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+15
-11
Page.java
h2/src/main/org/h2/mvstore/Page.java
+5
-0
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+2
-2
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+2
-3
MVTableEngine.java
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
+1
-3
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+7
-2
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+0
-3
TestMVTableEngine.java
h2/src/test/org/h2/test/store/TestMVTableEngine.java
+38
-0
TestTransactionStore.java
h2/src/test/org/h2/test/store/TestTransactionStore.java
+11
-6
没有找到文件。
h2/src/main/org/h2/engine/Session.java
浏览文件 @
f4d43c7f
...
...
@@ -23,8 +23,8 @@ import org.h2.jdbc.JdbcConnection;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.message.TraceSystem
;
import
org.h2.mvstore.TransactionStore
;
import
org.h2.mvstore.TransactionStore.Transaction
;
import
org.h2.mvstore.
db.
TransactionStore
;
import
org.h2.mvstore.
db.
TransactionStore.Transaction
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
...
...
h2/src/main/org/h2/mvstore/DataUtils.java
浏览文件 @
f4d43c7f
...
...
@@ -352,7 +352,7 @@ public class DataUtils {
file
,
src
.
remaining
(),
pos
,
e
);
}
}
/**
* Convert the length to a length code 0..31. 31 means more than 1 MB.
*
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
f4d43c7f
...
...
@@ -215,7 +215,7 @@ public class MVStore {
/**
* The version of the current store operation (if any).
*/
private
long
currentStoreVersion
=
-
1
;
private
volatile
long
currentStoreVersion
=
-
1
;
private
volatile
boolean
metaChanged
;
...
...
@@ -910,9 +910,9 @@ public class MVStore {
}
buff
.
limit
(
length
);
long
file
Length
=
getFileLength
Used
();
long
filePos
=
reuseSpace
?
allocateChunk
(
length
)
:
file
Length
;
boolean
storeAtEndOfFile
=
filePos
+
length
>=
file
Length
;
long
file
SizeUsed
=
getFileSize
Used
();
long
filePos
=
reuseSpace
?
allocateChunk
(
length
)
:
file
SizeUsed
;
boolean
storeAtEndOfFile
=
filePos
+
length
>=
file
SizeUsed
;
// free up the space of unused chunks now
for
(
Chunk
x
:
removedChunks
)
{
...
...
@@ -1046,7 +1046,7 @@ public class MVStore {
* @param minPercent the minimum percentage to save
*/
private
void
shrinkFileIfPossible
(
int
minPercent
)
{
long
used
=
getFile
Length
Used
();
long
used
=
getFile
Size
Used
();
if
(
used
>=
fileSize
)
{
return
;
}
...
...
@@ -1067,7 +1067,7 @@ public class MVStore {
fileSize
=
used
;
}
private
long
getFile
Length
Used
()
{
private
long
getFile
Size
Used
()
{
long
size
=
2
*
BLOCK_SIZE
;
for
(
Chunk
c
:
chunks
.
values
())
{
if
(
c
.
start
==
Long
.
MAX_VALUE
)
{
...
...
@@ -1409,7 +1409,11 @@ public class MVStore {
}
public
long
getRetainVersion
()
{
return
retainVersion
;
long
v
=
retainVersion
;
if
(
currentStoreVersion
>=
-
1
)
{
v
=
Math
.
min
(
v
,
currentStoreVersion
);
}
return
v
;
}
/**
...
...
@@ -1732,6 +1736,10 @@ public class MVStore {
}
store
(
true
);
}
public
boolean
isReadOnly
()
{
return
readOnly
;
}
/**
* A background writer to automatically store changes from time to time.
...
...
@@ -1909,8 +1917,4 @@ public class MVStore {
}
public
boolean
isReadOnly
()
{
return
readOnly
;
}
}
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
f4d43c7f
...
...
@@ -241,6 +241,7 @@ public class Page {
public
String
toString
()
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"id: "
).
append
(
System
.
identityHashCode
(
this
)).
append
(
'\n'
);
buff
.
append
(
"pos: "
).
append
(
pos
).
append
(
"\n"
);
for
(
int
i
=
0
;
i
<=
keyCount
;
i
++)
{
if
(
i
>
0
)
{
...
...
@@ -835,6 +836,10 @@ public class Page {
* @return the target buffer
*/
ByteBuffer
writeUnsavedRecursive
(
Chunk
chunk
,
ByteBuffer
buff
)
{
if
(
pos
!=
0
)
{
// already stored before
return
buff
;
}
if
(!
isLeaf
())
{
int
len
=
children
.
length
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
f4d43c7f
...
...
@@ -18,8 +18,8 @@ import org.h2.index.Cursor;
import
org.h2.index.IndexType
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.TransactionStore.Transaction
;
import
org.h2.mvstore.TransactionStore.TransactionMap
;
import
org.h2.mvstore.
db.
TransactionStore.Transaction
;
import
org.h2.mvstore.
db.
TransactionStore.TransactionMap
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
f4d43c7f
...
...
@@ -28,8 +28,7 @@ import org.h2.index.IndexType;
import
org.h2.index.MultiVersionIndex
;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.mvstore.TransactionStore
;
import
org.h2.mvstore.TransactionStore.Transaction
;
import
org.h2.mvstore.db.TransactionStore.Transaction
;
import
org.h2.result.Row
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.SchemaObject
;
...
...
@@ -521,7 +520,7 @@ public class MVTable extends TableBase {
rowCount
=
0
;
changesSinceAnalyze
=
0
;
}
@Override
public
void
addRow
(
Session
session
,
Row
row
)
{
lastModificationId
=
database
.
getNextModificationDataId
();
...
...
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
浏览文件 @
f4d43c7f
...
...
@@ -17,7 +17,6 @@ import org.h2.engine.Constants;
import
org.h2.engine.Database
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.TransactionStore
;
import
org.h2.table.TableBase
;
import
org.h2.util.New
;
...
...
@@ -116,8 +115,7 @@ public class MVTableEngine implements TableEngine {
* @param store the store
*/
static
void
store
(
MVStore
store
)
{
int
test
;
// store.compact(50);
store
.
compact
(
50
);
store
.
store
();
}
...
...
h2/src/main/org/h2/mvstore/TransactionStore.java
→
h2/src/main/org/h2/mvstore/
db/
TransactionStore.java
浏览文件 @
f4d43c7f
...
...
@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
;
package
org
.
h2
.
mvstore
.
db
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
...
...
@@ -13,6 +13,11 @@ import java.util.Iterator;
import
java.util.List
;
import
java.util.Map
;
import
org.h2.mvstore.Cursor
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMapConcurrent
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVMap.Builder
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.mvstore.type.ObjectDataType
;
...
...
@@ -111,7 +116,7 @@ public class TransactionStore {
Object
[]
data
=
openTransactions
.
get
(
id
);
int
status
=
(
Integer
)
data
[
0
];
String
name
=
(
String
)
data
[
1
];
long
[]
next
=
{
id
+
1
,
0
};
long
[]
next
=
{
id
+
1
,
-
1
};
long
[]
last
=
undoLog
.
floorKey
(
next
);
if
(
last
==
null
)
{
// no entry
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
f4d43c7f
...
...
@@ -998,9 +998,6 @@ public class TestMVStore extends TestBase {
assertEquals
(
"name:data"
,
m
.
get
(
"map."
+
id
));
assertTrue
(
m
.
get
(
"root.1"
).
length
()
>
0
);
assertTrue
(
m
.
containsKey
(
"chunk.1"
));
assertEquals
(
"id:1,length:263,maxLength:288,maxLengthLive:288,"
+
"metaRoot:274877910924,pageCount:2,pageCountLive:2,"
+
"start:8192,time:0,version:1"
,
m
.
get
(
"chunk.1"
));
assertTrue
(
m
.
containsKey
(
"chunk.2"
));
assertEquals
(
2
,
s
.
getCurrentVersion
());
...
...
h2/src/test/org/h2/test/store/TestMVTableEngine.java
浏览文件 @
f4d43c7f
...
...
@@ -34,6 +34,7 @@ public class TestMVTableEngine extends TestBase {
}
public
void
test
()
throws
Exception
{
// testSpeed();
testEncryption
();
testReadOnly
();
testReuseDiskSpace
();
...
...
@@ -41,6 +42,43 @@ public class TestMVTableEngine extends TestBase {
testLocking
();
testSimple
();
}
private
void
testSpeed
()
throws
Exception
{
String
dbName
;
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
dbName
=
"mvstore"
;
dbName
+=
";LOCK_MODE=0"
;
testSpeed
(
dbName
);
// Profiler prof = new Profiler().startCollecting();
dbName
=
"mvstore"
+
";DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine"
;
testSpeed
(
dbName
);
// System.out.println(prof.getTop(10));
}
}
private
void
testSpeed
(
String
dbName
)
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
Connection
conn
;
Statement
stat
;
String
url
=
getURL
(
dbName
,
true
);
String
user
=
getUser
();
String
password
=
getPassword
();
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar(255))"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
prep
.
setString
(
2
,
"Hello World"
);
long
time
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
100000
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
}
System
.
out
.
println
((
System
.
currentTimeMillis
()
-
time
)
+
" "
+
dbName
);
conn
.
close
();
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
}
private
void
testEncryption
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
...
...
h2/src/test/org/h2/test/store/TestTransactionStore.java
浏览文件 @
f4d43c7f
...
...
@@ -16,9 +16,9 @@ import java.util.List;
import
java.util.Random
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.TransactionStore
;
import
org.h2.mvstore.TransactionStore.Transaction
;
import
org.h2.mvstore.TransactionStore.TransactionMap
;
import
org.h2.mvstore.
db.
TransactionStore
;
import
org.h2.mvstore.
db.
TransactionStore.Transaction
;
import
org.h2.mvstore.
db.
TransactionStore.TransactionMap
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.util.New
;
...
...
@@ -176,9 +176,9 @@ public class TestTransactionStore extends TestBase {
assertEquals
(
1
,
tx
.
getId
());
m
=
tx
.
openMap
(
"test"
);
assertEquals
(
null
,
m
.
get
(
"1"
));
m
.
put
(
"2"
,
"Hello"
);
list
=
ts
.
getOpenTransactions
();
// only one was writing
assertEquals
(
1
,
list
.
size
());
assertEquals
(
2
,
list
.
size
());
txOld
=
list
.
get
(
0
);
assertEquals
(
0
,
txOld
.
getId
());
assertEquals
(
Transaction
.
STATUS_OPEN
,
txOld
.
getStatus
());
...
...
@@ -195,7 +195,12 @@ public class TestTransactionStore extends TestBase {
// TransactionStore was not closed, so we lost some ids
assertEquals
(
33
,
tx
.
getId
());
list
=
ts
.
getOpenTransactions
();
assertEquals
(
1
,
list
.
size
());
assertEquals
(
2
,
list
.
size
());
txOld
=
list
.
get
(
1
);
assertEquals
(
1
,
txOld
.
getId
());
assertEquals
(
Transaction
.
STATUS_OPEN
,
txOld
.
getStatus
());
assertEquals
(
null
,
txOld
.
getName
());
txOld
.
rollback
();
txOld
=
list
.
get
(
0
);
assertEquals
(
0
,
txOld
.
getId
());
assertEquals
(
Transaction
.
STATUS_PREPARED
,
txOld
.
getStatus
());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论