Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
67bed1a9
提交
67bed1a9
authored
8月 29, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Opening an closing a database is now faster.
上级
7b65f2a3
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
61 行增加
和
46 行删除
+61
-46
ConnectionInfo.java
h2/src/main/org/h2/engine/ConnectionInfo.java
+10
-7
Database.java
h2/src/main/org/h2/engine/Database.java
+1
-21
FileStore.java
h2/src/main/org/h2/store/FileStore.java
+7
-3
PageLog.java
h2/src/main/org/h2/store/PageLog.java
+6
-1
PageOutputStream.java
h2/src/main/org/h2/store/PageOutputStream.java
+1
-1
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+22
-10
PageStreamTrunk.java
h2/src/main/org/h2/store/PageStreamTrunk.java
+14
-3
没有找到文件。
h2/src/main/org/h2/engine/ConnectionInfo.java
浏览文件 @
67bed1a9
...
...
@@ -37,6 +37,7 @@ public class ConnectionInfo implements Cloneable {
* The database name
*/
private
String
name
;
private
String
nameNormalized
;
private
boolean
remote
;
private
boolean
ssl
;
private
boolean
persistent
;
...
...
@@ -331,14 +332,16 @@ public class ConnectionInfo implements Cloneable {
*/
String
getName
()
{
if
(
persistent
)
{
String
suffix
=
Constants
.
SUFFIX_PAGE_FILE
;
String
n
=
IOUtils
.
normalize
(
name
+
suffix
);
String
fileName
=
IOUtils
.
getFileName
(
n
);
if
(
fileName
.
length
()
<
suffix
.
length
()
+
1
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_DATABASE_NAME_1
,
name
);
if
(
nameNormalized
==
null
)
{
String
suffix
=
Constants
.
SUFFIX_PAGE_FILE
;
String
n
=
IOUtils
.
normalize
(
name
+
suffix
);
String
fileName
=
IOUtils
.
getFileName
(
n
);
if
(
fileName
.
length
()
<
suffix
.
length
()
+
1
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_DATABASE_NAME_1
,
name
);
}
nameNormalized
=
n
.
substring
(
0
,
n
.
length
()
-
suffix
.
length
());
}
n
=
n
.
substring
(
0
,
n
.
length
()
-
suffix
.
length
());
return
IOUtils
.
normalize
(
n
);
return
nameNormalized
;
}
return
name
;
}
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
67bed1a9
...
...
@@ -535,7 +535,6 @@ public class Database implements DataHandler {
starting
=
true
;
getPageStore
();
starting
=
false
;
reserveLobFileObjectIds
();
writer
=
WriterThread
.
create
(
this
,
writeDelay
);
}
else
{
traceSystem
=
new
TraceSystem
(
null
);
...
...
@@ -1431,30 +1430,11 @@ public class Database implements DataHandler {
}
}
private
void
reserveLobFileObjectIds
()
{
String
prefix
=
IOUtils
.
normalize
(
databaseName
)
+
"."
;
String
path
=
IOUtils
.
getParent
(
databaseName
);
String
[]
list
=
IOUtils
.
listFiles
(
path
);
for
(
String
name
:
list
)
{
if
(
name
.
endsWith
(
Constants
.
SUFFIX_LOB_FILE
)
&&
IOUtils
.
fileStartsWith
(
name
,
prefix
))
{
name
=
name
.
substring
(
prefix
.
length
());
name
=
name
.
substring
(
0
,
name
.
length
()
-
Constants
.
SUFFIX_LOB_FILE
.
length
());
int
dot
=
name
.
indexOf
(
'.'
);
if
(
dot
>=
0
)
{
String
id
=
name
.
substring
(
dot
+
1
);
int
objectId
=
Integer
.
parseInt
(
id
);
objectIds
.
set
(
objectId
);
}
}
}
}
private
void
deleteOldTempFiles
()
{
String
path
=
IOUtils
.
getParent
(
databaseName
);
String
prefix
=
IOUtils
.
normalize
(
databaseName
);
String
[]
list
=
IOUtils
.
listFiles
(
path
);
for
(
String
name
:
list
)
{
if
(
name
.
endsWith
(
Constants
.
SUFFIX_TEMP_FILE
)
&&
IOUtils
.
fileStartsWith
(
name
,
prefix
))
{
if
(
name
.
endsWith
(
Constants
.
SUFFIX_TEMP_FILE
)
&&
IOUtils
.
fileStartsWith
(
name
,
databaseName
))
{
// can't always delete the files, they may still be open
IOUtils
.
tryDelete
(
name
);
}
...
...
h2/src/main/org/h2/store/FileStore.java
浏览文件 @
67bed1a9
...
...
@@ -78,16 +78,20 @@ public class FileStore {
tempFileDeleter
=
handler
.
getTempFileDeleter
();
}
try
{
fs
.
createDir
s
(
name
);
if
(
fs
.
exists
(
name
)
&&
!
fs
.
canWrite
(
name
))
{
boolean
exists
=
fs
.
exist
s
(
name
);
if
(
exists
&&
!
fs
.
canWrite
(
name
))
{
mode
=
"r"
;
this
.
mode
=
mode
;
}
else
{
fs
.
createDirs
(
name
);
}
file
=
fs
.
openFileObject
(
name
,
mode
);
if
(
mode
.
length
()
>
2
)
{
synchronousMode
=
true
;
}
fileLength
=
file
.
length
();
if
(
exists
)
{
fileLength
=
file
.
length
();
}
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
"name: "
+
name
+
" mode: "
+
mode
);
}
...
...
h2/src/main/org/h2/store/PageLog.java
浏览文件 @
67bed1a9
...
...
@@ -188,7 +188,12 @@ public class PageLog {
* Free up all pages allocated by the log.
*/
void
free
()
{
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"log free"
);
}
int
currentDataPage
=
0
;
if
(
pageOut
!=
null
)
{
currentDataPage
=
pageOut
.
getCurrentDataPageId
();
pageOut
.
freeReserved
();
}
PageStreamTrunk
.
Iterator
it
=
new
PageStreamTrunk
.
Iterator
(
store
,
firstTrunkPage
);
...
...
@@ -200,7 +205,7 @@ public class PageLog {
}
break
;
}
t
.
free
();
t
.
free
(
currentDataPage
);
firstTrunkPage
=
t
.
getNextTrunk
();
}
}
...
...
h2/src/main/org/h2/store/PageOutputStream.java
浏览文件 @
67bed1a9
...
...
@@ -191,7 +191,7 @@ public class PageOutputStream {
* @param t the trunk page
*/
void
free
(
PageStreamTrunk
t
)
{
pageCount
-=
t
.
free
();
pageCount
-=
t
.
free
(
0
);
}
/**
...
...
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
67bed1a9
...
...
@@ -402,6 +402,9 @@ public class PageStore implements CacheWriter {
// ensure the free list is backed up again
log
.
checkpoint
();
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"writeFree"
);
}
byte
[]
test
=
new
byte
[
16
];
byte
[]
empty
=
new
byte
[
pageSize
];
for
(
int
i
=
PAGE_ID_FREE_LIST_ROOT
;
i
<
pageCount
;
i
++)
{
...
...
@@ -444,13 +447,12 @@ public class PageStore implements CacheWriter {
// open a new log at the very end
// (to be truncated later)
writeBack
();
log
.
free
();
recoveryRunning
=
true
;
try
{
log
.
free
();
logFirstTrunkPage
=
lastUsed
+
1
;
allocatePage
(
logFirstTrunkPage
);
log
.
openForWriting
(
logFirstTrunkPage
,
true
);
// ensure the free list is backed up again
log
.
checkpoint
();
}
finally
{
...
...
@@ -465,12 +467,6 @@ public class PageStore implements CacheWriter {
}
int
blockSize
=
fully
?
COMPACT_BLOCK_SIZE
:
1
;
for
(
int
x
=
lastUsed
,
j
=
0
;
x
>
MIN_PAGE_COUNT
&&
j
<
maxMove
;
x
-=
blockSize
)
{
for
(
int
full
=
x
-
blockSize
+
1
;
full
<=
x
;
full
++)
{
if
(
full
>
MIN_PAGE_COUNT
)
{
// ensure the page is in the disk buffer
readPage
(
full
);
}
}
for
(
int
full
=
x
-
blockSize
+
1
;
full
<=
x
;
full
++)
{
if
(
full
>
MIN_PAGE_COUNT
)
{
synchronized
(
database
)
{
...
...
@@ -501,10 +497,10 @@ public class PageStore implements CacheWriter {
writeBack
();
log
.
checkpoint
();
log
.
free
();
// truncate the log
recoveryRunning
=
true
;
try
{
log
.
free
();
setLogFirstPage
(
0
,
0
,
0
);
}
finally
{
recoveryRunning
=
false
;
...
...
@@ -1061,7 +1057,7 @@ public class PageStore implements CacheWriter {
*/
void
free
(
int
pageId
,
boolean
undo
)
{
if
(
trace
.
isDebugEnabled
())
{
// trace.debug("free
Page " + pageId
);
// trace.debug("free
" + pageId + " " + undo
);
}
synchronized
(
database
)
{
cache
.
remove
(
pageId
);
...
...
@@ -1085,6 +1081,22 @@ public class PageStore implements CacheWriter {
}
}
/**
* Add a page to the free list. The page is not used, therefore doesn't need to be overwritten.
*
* @param pageId the page id
*/
void
freeUnused
(
int
pageId
)
{
if
(
trace
.
isDebugEnabled
())
{
trace
.
debug
(
"freeUnused "
+
pageId
);
}
synchronized
(
database
)
{
cache
.
remove
(
pageId
);
freePage
(
pageId
);
freed
.
set
(
pageId
);
}
}
/**
* Create a data object.
*
...
...
h2/src/main/org/h2/store/PageStreamTrunk.java
浏览文件 @
67bed1a9
...
...
@@ -158,17 +158,28 @@ public class PageStreamTrunk extends Page {
}
/**
* Free this page and all data pages.
* Free this page and all data pages. Pages after the last used data page
* (if within this list) are empty and therefore not just freed, but marked
* as not used.
*
* @param lastUsedPage the last used data page
* @return the number of pages freed
*/
int
free
()
{
int
free
(
int
lastUsedPage
)
{
store
.
free
(
getPos
(),
false
);
int
freed
=
1
;
boolean
notUsed
=
false
;
for
(
int
i
=
0
;
i
<
pageCount
;
i
++)
{
int
page
=
pageIds
[
i
];
store
.
free
(
page
,
false
);
if
(
notUsed
)
{
store
.
freeUnused
(
page
);
}
else
{
store
.
free
(
page
,
false
);
}
freed
++;
if
(
page
==
lastUsedPage
)
{
notUsed
=
true
;
}
}
return
freed
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论