Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
320543a6
提交
320543a6
authored
1月 08, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't create a *.h2.db file when using the MVStore
上级
6e74c6eb
隐藏空白字符变更
内嵌
并排
正在显示
24 个修改的文件
包含
247 行增加
和
64 行删除
+247
-64
mvstore.html
h2/src/docsrc/html/mvstore.html
+2
-3
BackupCommand.java
h2/src/main/org/h2/command/dml/BackupCommand.java
+4
-1
Explain.java
h2/src/main/org/h2/command/dml/Explain.java
+2
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+25
-6
DatabaseInfo.java
h2/src/main/org/h2/jmx/DatabaseInfo.java
+52
-8
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+38
-3
Page.java
h2/src/main/org/h2/mvstore/Page.java
+3
-1
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+1
-1
Schema.java
h2/src/main/org/h2/schema/Schema.java
+1
-1
TcpServerThread.java
h2/src/main/org/h2/server/TcpServerThread.java
+2
-2
RecoverTester.java
h2/src/main/org/h2/store/RecoverTester.java
+2
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+19
-7
Backup.java
h2/src/main/org/h2/tools/Backup.java
+3
-1
Recover.java
h2/src/main/org/h2/tools/Recover.java
+11
-10
Restore.java
h2/src/main/org/h2/tools/Restore.java
+3
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+0
-1
TestOpenClose.java
h2/src/test/org/h2/test/db/TestOpenClose.java
+18
-5
TestTempTables.java
h2/src/test/org/h2/test/db/TestTempTables.java
+3
-0
TestWeb.java
h2/src/test/org/h2/test/server/TestWeb.java
+10
-3
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+27
-1
TestMVTableEngine.java
h2/src/test/org/h2/test/store/TestMVTableEngine.java
+1
-1
TestClearReferences.java
h2/src/test/org/h2/test/unit/TestClearReferences.java
+3
-0
TestJmx.java
h2/src/test/org/h2/test/unit/TestJmx.java
+16
-6
H2Database.java
h2/src/tools/org/h2/android/H2Database.java
+1
-2
没有找到文件。
h2/src/docsrc/html/mvstore.html
浏览文件 @
320543a6
...
...
@@ -469,9 +469,8 @@ This is work in progress. To try it out, append
to the database URL. In general, functionality and performance should be
similar than the current default storage engine (the page store).
There are a few features that have not been implemented yet or are not complete,
for example there is still a file named
<code>
.h2.db
</code>
,
and the
<code>
.lock.db
</code>
file is still used to lock a database
(long term, the plan is to no longer use those files).
for example the
<code>
.lock.db
</code>
file is still used to lock a database
(the plan is to no longer use this file by default).
</p>
<h2
id=
"differences"
>
Similar Projects and Differences to Other Storage Engines
</h2>
...
...
h2/src/main/org/h2/command/dml/BackupCommand.java
浏览文件 @
320543a6
...
...
@@ -72,7 +72,7 @@ public class BackupCommand extends Prepared {
backupPageStore
(
out
,
fn
,
db
.
getPageStore
());
// synchronize on the database, to avoid concurrent temp file
// creation / deletion / backup
String
base
=
FileUtils
.
getParent
(
fn
);
String
base
=
FileUtils
.
getParent
(
db
.
getName
()
);
synchronized
(
db
.
getLobSyncObject
())
{
String
prefix
=
db
.
getDatabasePath
();
String
dir
=
FileUtils
.
getParent
(
prefix
);
...
...
@@ -103,6 +103,9 @@ public class BackupCommand extends Prepared {
}
private
void
backupPageStore
(
ZipOutputStream
out
,
String
fileName
,
PageStore
store
)
throws
IOException
{
if
(
store
==
null
)
{
return
;
}
Database
db
=
session
.
getDatabase
();
fileName
=
FileUtils
.
getName
(
fileName
);
out
.
putNextEntry
(
new
ZipEntry
(
fileName
));
...
...
h2/src/main/org/h2/command/dml/Explain.java
浏览文件 @
320543a6
...
...
@@ -64,6 +64,8 @@ public class Explain extends Prepared {
if
(
maxrows
>=
0
)
{
String
plan
;
if
(
executeCommand
)
{
;
// TODO to the same for the MVStore
PageStore
store
=
db
.
isPersistent
()
?
db
.
getPageStore
()
:
null
;
if
(
store
!=
null
)
{
store
.
statisticsStart
();
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
320543a6
...
...
@@ -467,7 +467,10 @@ public class Database implements DataHandler {
* @return true if one exists
*/
static
boolean
exists
(
String
name
)
{
return
FileUtils
.
exists
(
name
+
Constants
.
SUFFIX_PAGE_FILE
);
if
(
FileUtils
.
exists
(
name
+
Constants
.
SUFFIX_PAGE_FILE
))
{
return
true
;
}
return
FileUtils
.
exists
(
name
+
Constants
.
SUFFIX_MV_FILE
);
}
/**
...
...
@@ -531,14 +534,19 @@ public class Database implements DataHandler {
String
dataFileName
=
databaseName
+
".data.db"
;
boolean
existsData
=
FileUtils
.
exists
(
dataFileName
);
String
pageFileName
=
databaseName
+
Constants
.
SUFFIX_PAGE_FILE
;
String
mvFileName
=
databaseName
+
Constants
.
SUFFIX_MV_FILE
;
boolean
existsPage
=
FileUtils
.
exists
(
pageFileName
);
if
(
existsData
&&
!
existsPage
)
{
boolean
existsMv
=
FileUtils
.
exists
(
mvFileName
);
if
(
existsData
&&
(!
existsPage
&&
!
existsMv
))
{
throw
DbException
.
get
(
ErrorCode
.
FILE_VERSION_ERROR_1
,
"Old database: "
+
dataFileName
+
" - please convert the database to a SQL script and re-create it."
);
}
if
(
existsPage
&&
!
FileUtils
.
canWrite
(
pageFileName
))
{
readOnly
=
true
;
}
if
(
existsMv
&&
!
FileUtils
.
canWrite
(
mvFileName
))
{
readOnly
=
true
;
}
if
(
readOnly
)
{
if
(
traceLevelFile
>=
TraceSystem
.
DEBUG
)
{
String
traceFile
=
Utils
.
getProperty
(
"java.io.tmpdir"
,
"."
)
+
"/"
+
"h2_"
+
System
.
currentTimeMillis
();
...
...
@@ -1837,8 +1845,10 @@ public class Database implements DataHandler {
mvStore
.
prepareCommit
(
session
,
transaction
);
return
;
}
pageStore
.
flushLog
();
pageStore
.
prepareCommit
(
session
,
transaction
);
if
(
pageStore
!=
null
)
{
pageStore
.
flushLog
();
pageStore
.
prepareCommit
(
session
,
transaction
);
}
}
/**
...
...
@@ -2262,8 +2272,11 @@ public class Database implements DataHandler {
}
public
PageStore
getPageStore
()
{
if
(
dbSettings
.
mvStore
&&
mvStore
==
null
)
{
mvStore
=
MVTableEngine
.
init
(
this
);
if
(
dbSettings
.
mvStore
)
{
if
(
mvStore
==
null
)
{
mvStore
=
MVTableEngine
.
init
(
this
);
}
return
null
;
}
if
(
pageStore
==
null
)
{
pageStore
=
new
PageStore
(
this
,
databaseName
+
Constants
.
SUFFIX_PAGE_FILE
,
accessModeData
,
cacheSize
);
...
...
@@ -2520,12 +2533,18 @@ public class Database implements DataHandler {
this
.
logMode
=
log
;
pageStore
.
setLogMode
(
log
);
}
if
(
mvStore
!=
null
)
{
this
.
logMode
=
log
;
}
}
public
int
getLogMode
()
{
if
(
pageStore
!=
null
)
{
return
pageStore
.
getLogMode
();
}
if
(
mvStore
!=
null
)
{
return
logMode
;
}
return
PageStore
.
LOG_MODE_OFF
;
}
...
...
h2/src/main/org/h2/jmx/DatabaseInfo.java
浏览文件 @
320543a6
...
...
@@ -20,6 +20,7 @@ import org.h2.engine.ConnectionInfo;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.store.PageStore
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
...
...
@@ -139,40 +140,83 @@ public class DatabaseInfo implements DatabaseInfoMBean {
@Override
public
long
getFileWriteCountTotal
()
{
return
database
.
isPersistent
()
?
database
.
getPageStore
().
getWriteCountTotal
()
:
0L
;
if
(!
database
.
isPersistent
())
{
return
0
;
}
PageStore
p
=
database
.
getPageStore
();
if
(
p
!=
null
)
{
return
p
.
getWriteCountTotal
();
}
// TODO remove this method when removing the page store
// (the MVStore doesn't support it)
return
0
;
}
@Override
public
long
getFileWriteCount
()
{
return
database
.
isPersistent
()
?
database
.
getPageStore
().
getWriteCount
()
:
0L
;
if
(!
database
.
isPersistent
())
{
return
0
;
}
PageStore
p
=
database
.
getPageStore
();
if
(
p
!=
null
)
{
return
p
.
getWriteCount
();
}
return
database
.
getMvStore
().
getStore
().
getFileStore
().
getReadCount
();
}
@Override
public
long
getFileReadCount
()
{
return
database
.
isPersistent
()
?
database
.
getPageStore
().
getReadCount
()
:
0L
;
if
(!
database
.
isPersistent
())
{
return
0
;
}
PageStore
p
=
database
.
getPageStore
();
if
(
p
!=
null
)
{
return
p
.
getReadCount
();
}
return
database
.
getMvStore
().
getStore
().
getFileStore
().
getReadCount
();
}
@Override
public
long
getFileSize
()
{
return
database
.
isPersistent
()
?
(
database
.
getPageStore
().
getPageCount
()
*
database
.
getPageStore
().
getPageSize
()
/
1024
)
:
0
;
if
(!
database
.
isPersistent
())
{
return
0
;
}
PageStore
p
=
database
.
getPageStore
();
if
(
p
!=
null
)
{
return
p
.
getPageCount
()
*
p
.
getPageSize
()
/
1024
;
}
return
database
.
getMvStore
().
getStore
().
getFileStore
().
size
();
}
@Override
public
int
getCacheSizeMax
()
{
return
database
.
isPersistent
()
?
database
.
getPageStore
().
getCache
().
getMaxMemory
()
:
0
;
if
(!
database
.
isPersistent
())
{
return
0
;
}
PageStore
p
=
database
.
getPageStore
();
if
(
p
!=
null
)
{
return
p
.
getCache
().
getMaxMemory
();
}
return
database
.
getMvStore
().
getStore
().
getCacheSize
()
*
1024
;
}
@Override
public
void
setCacheSizeMax
(
int
kb
)
{
if
(
database
.
isPersistent
())
{
database
.
getPageStore
().
getCache
().
setMaxMemory
(
kb
);
database
.
setCacheSize
(
kb
);
}
}
@Override
public
int
getCacheSize
()
{
return
database
.
isPersistent
()
?
database
.
getPageStore
().
getCache
().
getMemory
()
:
0
;
if
(!
database
.
isPersistent
())
{
return
0
;
}
PageStore
p
=
database
.
getPageStore
();
if
(
p
!=
null
)
{
return
p
.
getCache
().
getMemory
();
}
return
database
.
getMvStore
().
getStore
().
getCacheSizeUsed
()
*
1024
;
}
@Override
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
320543a6
...
...
@@ -1432,9 +1432,7 @@ public class MVStore {
"Negative position {0}"
,
filePos
);
}
p
=
Page
.
read
(
fileStore
,
map
,
pos
,
filePos
,
fileStore
.
size
());
if
(
cache
!=
null
)
{
cache
.
put
(
pos
,
p
,
p
.
getMemory
());
}
cachePage
(
pos
,
p
,
p
.
getMemory
());
}
return
p
;
}
...
...
@@ -2012,6 +2010,43 @@ public class MVStore {
public
int
getUnsavedPageCount
()
{
return
unsavedPageCount
;
}
/**
* Put the page in the cache.
*
* @param pos the page position
* @param page the page
* @param memory the memory used
*/
void
cachePage
(
long
pos
,
Page
page
,
int
memory
)
{
if
(
cache
!=
null
)
{
cache
.
put
(
pos
,
page
,
memory
);
}
}
/**
* Get the amount of memory used for caching, in MB.
*
* @return the amount of memory used for caching
*/
public
int
getCacheSizeUsed
()
{
if
(
cache
==
null
)
{
return
0
;
}
return
(
int
)
(
cache
.
getUsedMemory
()
/
1024
/
1024
);
}
/**
* Get the maximum cache size, in MB.
*
* @return the cache size
*/
public
int
getCacheSize
()
{
if
(
cache
==
null
)
{
return
0
;
}
return
(
int
)
(
cache
.
getMaxMemory
()
/
1024
/
1024
);
}
/**
* A background writer thread to automatically store changes from time to time.
...
...
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
320543a6
...
...
@@ -819,7 +819,8 @@ public class Page {
valueType
.
write
(
buff
,
values
[
i
]);
}
}
if
(
map
.
getStore
().
getCompress
())
{
MVStore
store
=
map
.
getStore
();
if
(
store
.
getCompress
())
{
Compressor
compressor
=
map
.
getStore
().
getCompressor
();
int
expLen
=
buff
.
position
()
-
compressStart
;
byte
[]
exp
=
new
byte
[
expLen
];
...
...
@@ -846,6 +847,7 @@ public class Page {
DataUtils
.
ERROR_INTERNAL
,
"Page already stored"
);
}
pos
=
DataUtils
.
getPagePos
(
chunkId
,
start
,
pageLength
,
type
);
store
.
cachePage
(
pos
,
this
,
getMemory
());
long
max
=
DataUtils
.
getPageMaxLength
(
pos
);
chunk
.
maxLength
+=
max
;
chunk
.
maxLengthLive
+=
max
;
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
320543a6
...
...
@@ -625,6 +625,7 @@ public class MVTable extends TableBase {
database
.
getLobStorage
().
removeAllForTable
(
getId
());
database
.
lockMeta
(
session
);
}
database
.
getMvStore
().
removeTable
(
this
);
super
.
removeChildrenAndResources
(
session
);
// go backwards because database.removeIndex will call table.removeIndex
while
(
indexes
.
size
()
>
1
)
{
...
...
@@ -643,7 +644,6 @@ public class MVTable extends TableBase {
}
primaryIndex
.
remove
(
session
);
database
.
removeMeta
(
session
,
getId
());
database
.
getMvStore
().
removeTable
(
this
);
primaryIndex
=
null
;
close
(
session
);
invalidate
();
...
...
h2/src/main/org/h2/schema/Schema.java
浏览文件 @
320543a6
...
...
@@ -570,7 +570,7 @@ public class Schema extends DbObjectBase {
}
data
.
schema
=
this
;
if
(
data
.
tableEngine
==
null
)
{
if
(
database
.
getSettings
().
mvStore
)
{
if
(
database
.
getSettings
().
mvStore
&&
database
.
isPersistent
()
)
{
data
.
tableEngine
=
MVTableEngine
.
class
.
getName
();
}
}
...
...
h2/src/main/org/h2/server/TcpServerThread.java
浏览文件 @
320543a6
...
...
@@ -135,8 +135,6 @@ public class TcpServerThread implements Runnable {
if
(
server
.
getIfExists
())
{
ci
.
setProperty
(
"IFEXISTS"
,
"TRUE"
);
}
session
=
Engine
.
getInstance
().
createSession
(
ci
);
transfer
.
setSession
(
session
);
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
);
transfer
.
writeInt
(
clientVersion
);
transfer
.
flush
();
...
...
@@ -145,6 +143,8 @@ public class TcpServerThread implements Runnable {
ci
.
setFileEncryptionKey
(
transfer
.
readBytes
());
}
}
session
=
Engine
.
getInstance
().
createSession
(
ci
);
transfer
.
setSession
(
session
);
server
.
addConnection
(
threadId
,
originalURL
,
ci
.
getUserName
());
trace
(
"Connected"
);
}
catch
(
Throwable
e
)
{
...
...
h2/src/main/org/h2/store/RecoverTester.java
浏览文件 @
320543a6
...
...
@@ -68,7 +68,8 @@ public class RecoverTester implements Recorder {
if
(
op
!=
Recorder
.
WRITE
&&
op
!=
Recorder
.
TRUNCATE
)
{
return
;
}
if
(!
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
))
{
if
(!
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
)
&&
!
fileName
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
))
{
return
;
}
writeCount
++;
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
320543a6
...
...
@@ -40,6 +40,8 @@ import org.h2.index.IndexType;
import
org.h2.index.MetaIndex
;
import
org.h2.index.MultiVersionIndex
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.FileStore
;
import
org.h2.mvstore.db.MVTableEngine.Store
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
...
...
@@ -919,13 +921,23 @@ public class MetaTable extends Table {
}
if
(
database
.
isPersistent
())
{
PageStore
store
=
database
.
getPageStore
();
add
(
rows
,
"info.FILE_WRITE_TOTAL"
,
""
+
store
.
getWriteCountTotal
());
add
(
rows
,
"info.FILE_WRITE"
,
""
+
store
.
getWriteCount
());
add
(
rows
,
"info.FILE_READ"
,
""
+
store
.
getReadCount
());
add
(
rows
,
"info.PAGE_COUNT"
,
""
+
store
.
getPageCount
());
add
(
rows
,
"info.PAGE_SIZE"
,
""
+
store
.
getPageSize
());
add
(
rows
,
"info.CACHE_MAX_SIZE"
,
""
+
store
.
getCache
().
getMaxMemory
());
add
(
rows
,
"info.CACHE_SIZE"
,
""
+
store
.
getCache
().
getMemory
());
if
(
store
!=
null
)
{
add
(
rows
,
"info.FILE_WRITE_TOTAL"
,
""
+
store
.
getWriteCountTotal
());
add
(
rows
,
"info.FILE_WRITE"
,
""
+
store
.
getWriteCount
());
add
(
rows
,
"info.FILE_READ"
,
""
+
store
.
getReadCount
());
add
(
rows
,
"info.PAGE_COUNT"
,
""
+
store
.
getPageCount
());
add
(
rows
,
"info.PAGE_SIZE"
,
""
+
store
.
getPageSize
());
add
(
rows
,
"info.CACHE_MAX_SIZE"
,
""
+
store
.
getCache
().
getMaxMemory
());
add
(
rows
,
"info.CACHE_SIZE"
,
""
+
store
.
getCache
().
getMemory
());
}
Store
mvStore
=
database
.
getMvStore
();
if
(
mvStore
!=
null
)
{
FileStore
fs
=
mvStore
.
getStore
().
getFileStore
();
add
(
rows
,
"info.FILE_WRITE"
,
""
+
fs
.
getWriteCount
());
add
(
rows
,
"info.FILE_READ"
,
""
+
fs
.
getReadCount
());
add
(
rows
,
"info.CACHE_MAX_SIZE"
,
""
+
mvStore
.
getStore
().
getCacheSize
());
add
(
rows
,
"info.CACHE_SIZE"
,
""
+
mvStore
.
getStore
().
getCacheSizeUsed
());
}
}
break
;
}
...
...
h2/src/main/org/h2/tools/Backup.java
浏览文件 @
320543a6
...
...
@@ -130,7 +130,9 @@ public class Backup extends Tool {
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
fileOut
);
String
base
=
""
;
for
(
String
fileName
:
list
)
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
)
||
allFiles
)
{
if
(
allFiles
||
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
)
||
fileName
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
))
{
base
=
FileUtils
.
getParent
(
fileName
);
break
;
}
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
320543a6
...
...
@@ -91,7 +91,6 @@ public class Recover extends Tool implements DataHandler {
private
int
pageSize
;
private
FileStore
store
;
private
int
[]
parents
;
private
String
mvFile
;
private
Stats
stat
;
...
...
@@ -250,16 +249,15 @@ public class Recover extends Tool implements DataHandler {
}
for
(
String
fileName
:
list
)
{
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
))
{
String
mvFile
=
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_PAGE_FILE
.
length
())
+
Constants
.
SUFFIX_MV_FILE
;
if
(
list
.
contains
(
mvFile
))
{
this
.
mvFile
=
mvFile
;
}
dumpPageStore
(
fileName
);
}
else
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_LOB_FILE
))
{
dumpLob
(
fileName
,
false
);
}
else
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
))
{
PrintWriter
writer
=
getWriter
(
fileName
,
".txt"
);
String
f
=
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_PAGE_FILE
.
length
());
PrintWriter
writer
=
getWriter
(
f
+
".h2.db"
,
".sql"
);
dumpMVStoreFile
(
writer
,
fileName
);
writer
.
close
();
writer
=
getWriter
(
fileName
,
".txt"
);
MVStoreTool
.
dump
(
fileName
,
writer
);
writer
.
close
();
}
...
...
@@ -455,9 +453,6 @@ public class Recover extends Tool implements DataHandler {
schema
.
clear
();
objectIdSet
=
New
.
hashSet
();
dumpPageStore
(
writer
,
pageCount
);
if
(
mvFile
!=
null
)
{
dumpMVStoreFile
(
writer
,
mvFile
);
}
writeSchema
(
writer
);
try
{
dumpPageLogStream
(
writer
,
logKey
,
logFirstTrunkPage
,
logFirstDataPage
,
pageCount
);
...
...
@@ -488,6 +483,11 @@ public class Recover extends Tool implements DataHandler {
private
void
dumpMVStoreFile
(
PrintWriter
writer
,
String
fileName
)
{
writer
.
println
(
"-- mvstore"
);
writer
.
println
(
"CREATE ALIAS IF NOT EXISTS READ_BLOB FOR \""
+
this
.
getClass
().
getName
()
+
".readBlob\";"
);
writer
.
println
(
"CREATE ALIAS IF NOT EXISTS READ_CLOB FOR \""
+
this
.
getClass
().
getName
()
+
".readClob\";"
);
writer
.
println
(
"CREATE ALIAS IF NOT EXISTS READ_BLOB_DB FOR \""
+
this
.
getClass
().
getName
()
+
".readBlobDb\";"
);
writer
.
println
(
"CREATE ALIAS IF NOT EXISTS READ_CLOB_DB FOR \""
+
this
.
getClass
().
getName
()
+
".readClobDb\";"
);
resetSchema
();
setDatabaseName
(
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_MV_FILE
.
length
()));
MVStore
mv
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
readOnly
().
open
();
TransactionStore
store
=
new
TransactionStore
(
mv
);
...
...
@@ -551,6 +551,7 @@ public class Recover extends Tool implements DataHandler {
}
}
}
writeSchema
(
writer
);
}
catch
(
Throwable
e
)
{
writeError
(
writer
,
e
);
}
finally
{
...
...
h2/src/main/org/h2/tools/Restore.java
浏览文件 @
320543a6
...
...
@@ -124,6 +124,9 @@ public class Restore extends Tool {
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_PAGE_FILE
))
{
return
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_PAGE_FILE
.
length
());
}
if
(
fileName
.
endsWith
(
Constants
.
SUFFIX_MV_FILE
))
{
return
fileName
.
substring
(
0
,
fileName
.
length
()
-
Constants
.
SUFFIX_MV_FILE
.
length
());
}
return
null
;
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
320543a6
...
...
@@ -730,7 +730,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
// synth
new
TestBtreeIndex
().
runTest
(
this
);
new
TestDiskFull
().
runTest
(
this
);
new
TestCrashAPI
().
runTest
(
this
);
new
TestFuzzOptimizations
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/db/TestOpenClose.java
浏览文件 @
320543a6
...
...
@@ -15,6 +15,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Restore
;
...
...
@@ -63,17 +64,29 @@ public class TestOpenClose extends TestBase {
if
(
config
.
memory
||
config
.
reopen
)
{
return
;
}
FileUtils
.
delete
(
"split:"
+
getBaseDir
()
+
"/openClose2.h2.db"
);
String
fn
=
getBaseDir
()
+
"/openClose2"
;
if
(
config
.
mvStore
)
{
fn
+=
Constants
.
SUFFIX_MV_FILE
;
}
else
{
fn
+=
Constants
.
SUFFIX_PAGE_FILE
;
}
FileUtils
.
delete
(
"split:"
+
fn
);
Connection
conn
;
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:split:18:"
+
getBaseDir
()
+
"/openClose2"
);
String
url
=
"jdbc:h2:split:18:"
+
getBaseDir
()
+
"/openClose2"
;
url
=
getURL
(
url
,
true
);
conn
=
DriverManager
.
getConnection
(
url
);
conn
.
createStatement
().
execute
(
"create table test(id int, name varchar) as select 1, space(1000000)"
);
conn
.
close
();
FileChannel
c
=
FileUtils
.
open
(
getBaseDir
()
+
"/openClose2.h2.db
.1.part"
,
"rw"
);
FileChannel
c
=
FileUtils
.
open
(
fn
+
"
.1.part"
,
"rw"
);
c
.
position
(
c
.
size
()
*
2
-
1
);
c
.
write
(
ByteBuffer
.
wrap
(
new
byte
[
1
]));
c
.
close
();
assertThrows
(
ErrorCode
.
IO_EXCEPTION_2
,
this
).
getConnection
(
"jdbc:h2:split:18:"
+
getBaseDir
()
+
"/openClose2"
);
FileUtils
.
delete
(
"split:"
+
getBaseDir
()
+
"/openClose2.h2.db"
);
if
(
config
.
mvStore
)
{
assertThrows
(
ErrorCode
.
FILE_CORRUPTED_1
,
this
).
getConnection
(
url
);
}
else
{
assertThrows
(
ErrorCode
.
IO_EXCEPTION_2
,
this
).
getConnection
(
url
);
}
FileUtils
.
delete
(
"split:"
+
fn
);
}
private
void
testCloseDelay
()
throws
Exception
{
...
...
h2/src/test/org/h2/test/db/TestTempTables.java
浏览文件 @
320543a6
...
...
@@ -160,6 +160,9 @@ public class TestTempTables extends TestBase {
if
(
config
.
memory
)
{
return
;
}
if
(
config
.
mvStore
)
{
return
;
}
deleteDb
(
"tempTables"
);
Connection
conn
=
getConnection
(
"tempTables"
);
Statement
stat
=
conn
.
createStatement
();
...
...
h2/src/test/org/h2/test/server/TestWeb.java
浏览文件 @
320543a6
...
...
@@ -37,6 +37,7 @@ import javax.servlet.ServletContext;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.server.web.WebServlet
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
...
...
@@ -178,10 +179,16 @@ public class TestWeb extends TestBase {
assertTrue
(
FileUtils
.
exists
(
getBaseDir
()
+
"/backup.zip"
));
result
=
client
.
get
(
url
,
"tools.do?tool=DeleteDbFiles&args=-dir,"
+
getBaseDir
()
+
",-db,web"
);
assertFalse
(
FileUtils
.
exists
(
getBaseDir
()
+
"/web.h2.db"
));
String
fn
=
getBaseDir
()
+
"/web"
;
if
(
config
.
mvStore
)
{
fn
+=
Constants
.
SUFFIX_MV_FILE
;
}
else
{
fn
+=
Constants
.
SUFFIX_PAGE_FILE
;
}
assertFalse
(
FileUtils
.
exists
(
fn
));
result
=
client
.
get
(
url
,
"tools.do?tool=Restore&args=-dir,"
+
getBaseDir
()
+
",-db,web,-file,"
+
getBaseDir
()
+
"/backup.zip"
);
assertTrue
(
FileUtils
.
exists
(
getBaseDir
()
+
"/web.h2.db"
));
assertTrue
(
FileUtils
.
exists
(
fn
));
FileUtils
.
delete
(
getBaseDir
()
+
"/web.h2.sql"
);
FileUtils
.
delete
(
getBaseDir
()
+
"/backup.zip"
);
result
=
client
.
get
(
url
,
"tools.do?tool=Recover&args=-dir,"
+
...
...
@@ -192,7 +199,7 @@ public class TestWeb extends TestBase {
getBaseDir
()
+
"/web.h2.sql,-url,"
+
getURL
(
"web"
,
true
)
+
",-user,"
+
getUser
()
+
",-password,"
+
getPassword
());
FileUtils
.
delete
(
getBaseDir
()
+
"/web.h2.sql"
);
assertTrue
(
FileUtils
.
exists
(
getBaseDir
()
+
"/web.h2.db"
));
assertTrue
(
FileUtils
.
exists
(
fn
));
deleteDb
(
"web"
);
}
finally
{
server
.
shutdown
();
...
...
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
320543a6
...
...
@@ -48,6 +48,7 @@ public class TestMVStore extends TestBase {
public
void
test
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
FileUtils
.
createDirectories
(
getBaseDir
());
testCacheInfo
();
testRollback
();
testVersionsToKeep
();
testRemoveMap
();
...
...
@@ -98,6 +99,29 @@ public class TestMVStore extends TestBase {
// longer running tests
testLargerThan2G
();
}
private
void
testCacheInfo
()
{
String
fileName
=
getBaseDir
()
+
"/testCloseMap.h3"
;
MVStore
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
cacheSize
(
2
).
open
();
assertEquals
(
2
,
s
.
getCacheSize
());
MVMap
<
Integer
,
byte
[]>
map
;
map
=
s
.
openMap
(
"data"
);
byte
[]
data
=
new
byte
[
100
*
1024
];
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
map
.
put
(
i
,
data
);
s
.
commit
();
if
(
i
<
10
)
{
assertEquals
(
0
,
s
.
getCacheSizeUsed
());
}
else
if
(
i
>
20
)
{
assertEquals
(
1
,
s
.
getCacheSizeUsed
());
}
}
s
.
close
();
s
=
new
MVStore
.
Builder
().
open
();
assertEquals
(
0
,
s
.
getCacheSize
());
assertEquals
(
0
,
s
.
getCacheSizeUsed
());
s
.
close
();
}
private
void
testVersionsToKeep
()
throws
Exception
{
MVStore
s
=
new
MVStore
.
Builder
().
open
();
...
...
@@ -576,9 +600,11 @@ public class TestMVStore extends TestBase {
3406
,
2590
,
1924
,
1440
,
1102
,
956
,
918
};
for
(
int
cacheSize
=
0
;
cacheSize
<=
6
;
cacheSize
+=
4
)
{
int
cacheMB
=
1
+
3
*
cacheSize
;
s
=
new
MVStore
.
Builder
().
fileName
(
fileName
).
cacheSize
(
1
+
3
*
cacheSize
).
open
();
cacheSize
(
cacheMB
).
open
();
assertEquals
(
cacheMB
,
s
.
getCacheSize
());
map
=
s
.
openMap
(
"test"
);
for
(
int
i
=
0
;
i
<
1024
;
i
+=
128
)
{
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
...
...
h2/src/test/org/h2/test/store/TestMVTableEngine.java
浏览文件 @
320543a6
...
...
@@ -534,7 +534,7 @@ public class TestMVTableEngine extends TestBase {
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int)"
);
conn
.
close
();
FileUtils
.
setReadOnly
(
getBaseDir
()
+
"/mvstore
.h2.db"
);
FileUtils
.
setReadOnly
(
getBaseDir
()
+
"/mvstore
"
+
Constants
.
SUFFIX_MV_FILE
);
conn
=
getConnection
(
dbName
);
Database
db
=
(
Database
)
((
JdbcConnection
)
conn
).
getSession
().
getDataHandler
();
assertTrue
(
db
.
getMvStore
().
getStore
().
getFileStore
().
isReadOnly
());
...
...
h2/src/test/org/h2/test/unit/TestClearReferences.java
浏览文件 @
320543a6
...
...
@@ -105,6 +105,9 @@ public class TestClearReferences extends TestBase {
if
(!
name
.
endsWith
(
".class"
))
{
return
;
}
if
(
name
.
indexOf
(
'$'
)
>=
0
)
{
return
;
}
String
className
=
file
.
getAbsolutePath
().
replace
(
'\\'
,
'/'
);
className
=
className
.
substring
(
className
.
lastIndexOf
(
"org/h2"
));
String
packageName
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
'/'
));
...
...
h2/src/test/org/h2/test/unit/TestJmx.java
浏览文件 @
320543a6
...
...
@@ -101,6 +101,8 @@ public class TestJmx extends TestBase {
conn
.
close
();
conn
=
getConnection
(
"jmx;jmx=true"
);
conn
.
close
();
conn
=
getConnection
(
"jmx;jmx=true"
);
name
=
new
ObjectName
(
"org.h2:name=JMX,*"
);
...
...
@@ -110,12 +112,20 @@ public class TestJmx extends TestBase {
assertEquals
(
"16384"
,
mbeanServer
.
getAttribute
(
name
,
"CacheSizeMax"
).
toString
());
mbeanServer
.
setAttribute
(
name
,
new
Attribute
(
"CacheSizeMax"
,
1
));
assertEquals
(
"1"
,
mbeanServer
.
getAttribute
(
name
,
"CacheSizeMax"
).
toString
());
assertTrue
(
0
<
(
Integer
)
mbeanServer
.
getAttribute
(
name
,
"CacheSize"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileSize"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileReadCount"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileWriteCount"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileWriteCountTotal"
));
if
(
config
.
mvStore
)
{
assertEquals
(
"1024"
,
mbeanServer
.
getAttribute
(
name
,
"CacheSizeMax"
).
toString
());
assertEquals
(
"0"
,
mbeanServer
.
getAttribute
(
name
,
"CacheSize"
).
toString
());
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileReadCount"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileWriteCount"
));
assertEquals
(
"0"
,
mbeanServer
.
getAttribute
(
name
,
"FileWriteCountTotal"
).
toString
());
}
else
{
assertEquals
(
"1"
,
mbeanServer
.
getAttribute
(
name
,
"CacheSizeMax"
).
toString
());
assertTrue
(
0
<
(
Integer
)
mbeanServer
.
getAttribute
(
name
,
"CacheSize"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileSize"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileReadCount"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileWriteCount"
));
assertTrue
(
0
<
(
Long
)
mbeanServer
.
getAttribute
(
name
,
"FileWriteCountTotal"
));
}
mbeanServer
.
setAttribute
(
name
,
new
Attribute
(
"LogMode"
,
0
));
assertEquals
(
"0"
,
mbeanServer
.
getAttribute
(
name
,
"LogMode"
).
toString
());
...
...
h2/src/tools/org/h2/android/H2Database.java
浏览文件 @
320543a6
...
...
@@ -247,8 +247,7 @@ public class H2Database {
* @return the page size
*/
public
long
getPageSize
()
{
PageStore
store
=
session
.
getDatabase
().
getPageStore
();
return
store
==
null
?
0
:
store
.
getPageSize
();
return
0
;
}
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论