Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6acd8d14
提交
6acd8d14
authored
2月 09, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
7b88d790
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
253 行增加
和
180 行删除
+253
-180
SysProperties.java
h2/src/main/org/h2/constant/SysProperties.java
+3
-1
Database.java
h2/src/main/org/h2/engine/Database.java
+2
-5
JdbcConnection.java
h2/src/main/org/h2/jdbc/JdbcConnection.java
+0
-2
LogFile.java
h2/src/main/org/h2/log/LogFile.java
+2
-0
DiskFile.java
h2/src/main/org/h2/store/DiskFile.java
+4
-0
FileStore.java
h2/src/main/org/h2/store/FileStore.java
+4
-4
Storage.java
h2/src/main/org/h2/store/Storage.java
+3
-1
WriterThread.java
h2/src/main/org/h2/store/WriterThread.java
+0
-60
DelayedFileDeleter.java
h2/src/main/org/h2/util/DelayedFileDeleter.java
+181
-0
TempFileDeleter.java
h2/src/main/org/h2/util/TempFileDeleter.java
+0
-74
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+4
-0
TestIndex.java
h2/src/test/org/h2/test/db/TestIndex.java
+44
-30
TestLob.java
h2/src/test/org/h2/test/db/TestLob.java
+4
-3
没有找到文件。
h2/src/main/org/h2/constant/SysProperties.java
浏览文件 @
6acd8d14
...
...
@@ -395,6 +395,8 @@ private int test;
* INTERNAL
*/
public
static
int
getLogFileDeleteDelay
()
{
return
getIntSetting
(
H2_LOG_DELETE_DELAY
,
2000
);
int
test
;
return
getIntSetting
(
H2_LOG_DELETE_DELAY
,
0
);
// return getIntSetting(H2_LOG_DELETE_DELAY, 2000);
}
}
h2/src/main/org/h2/engine/Database.java
浏览文件 @
6acd8d14
...
...
@@ -51,6 +51,7 @@ import org.h2.util.BitField;
import
org.h2.util.ByteUtils
;
import
org.h2.util.CacheLRU
;
import
org.h2.util.ClassUtils
;
import
org.h2.util.DelayedFileDeleter
;
import
org.h2.util.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.IntHashMap
;
...
...
@@ -1344,11 +1345,7 @@ public class Database implements DataHandler {
}
public
void
deleteLogFileLater
(
String
fileName
)
throws
SQLException
{
if
(
writer
==
null
)
{
FileUtils
.
delete
(
fileName
);
}
else
{
writer
.
deleteLater
(
fileName
);
}
DelayedFileDeleter
.
getInstance
().
deleteLater
(
fileName
);
}
public
Class
loadUserClass
(
String
className
)
throws
SQLException
{
...
...
h2/src/main/org/h2/jdbc/JdbcConnection.java
浏览文件 @
6acd8d14
...
...
@@ -34,7 +34,6 @@ import org.h2.message.TraceObject;
import
org.h2.result.ResultInterface
;
import
org.h2.util.ClassUtils
;
import
org.h2.util.JdbcConnectionListener
;
import
org.h2.util.TempFileDeleter
;
import
org.h2.value.Value
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueLob
;
...
...
@@ -214,7 +213,6 @@ public class JdbcConnection extends TraceObject implements Connection {
* rolled back.
*/
public
void
close
()
throws
SQLException
{
TempFileDeleter
.
deleteUnused
();
synchronized
(
this
)
{
if
(
listener
==
null
)
{
closeConnection
();
...
...
h2/src/main/org/h2/log/LogFile.java
浏览文件 @
6acd8d14
...
...
@@ -312,6 +312,8 @@ public class LogFile {
}
public
void
redoAllGoEnd
()
throws
SQLException
{
int
test
;
//System.out.println("redo log " + fileName);
boolean
readOnly
=
logSystem
.
getDatabase
().
getReadOnly
();
long
length
=
file
.
length
();
if
(
length
<=
FileStore
.
HEADER_LENGTH
)
{
...
...
h2/src/main/org/h2/store/DiskFile.java
浏览文件 @
6acd8d14
...
...
@@ -213,6 +213,10 @@ public class DiskFile implements CacheWriter {
}
public
void
initFromSummary
(
byte
[]
summary
)
{
int
test
;
//System.out.println("init from summary: " + this);
synchronized
(
database
)
{
if
(
summary
==
null
||
summary
.
length
==
0
)
{
ObjectArray
list
=
database
.
getAllStorages
();
...
...
h2/src/main/org/h2/store/FileStore.java
浏览文件 @
6acd8d14
...
...
@@ -16,7 +16,7 @@ import org.h2.security.SecureFileStore;
import
org.h2.store.fs.FileObject
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.
Temp
FileDeleter
;
import
org.h2.util.
Delayed
FileDeleter
;
/**
* This class is an abstraction of a random access file.
...
...
@@ -163,7 +163,7 @@ public class FileStore {
public
void
closeAndDeleteSilently
()
{
if
(
file
!=
null
)
{
closeSilently
();
TempFileDeleter
.
d
eleteFile
(
autoDeleteReference
,
name
);
DelayedFileDeleter
.
getInstance
().
autoD
eleteFile
(
autoDeleteReference
,
name
);
name
=
null
;
}
}
...
...
@@ -324,11 +324,11 @@ public class FileStore {
}
public
void
autoDelete
()
{
autoDeleteReference
=
TempFileDeleter
.
add
File
(
name
,
this
);
autoDeleteReference
=
DelayedFileDeleter
.
getInstance
().
addTemp
File
(
name
,
this
);
}
public
void
stopAutoDelete
()
{
TempFileDeleter
.
stopAutoDelete
(
autoDeleteReference
,
name
);
DelayedFileDeleter
.
getInstance
()
.
stopAutoDelete
(
autoDeleteReference
,
name
);
autoDeleteReference
=
null
;
}
...
...
h2/src/main/org/h2/store/Storage.java
浏览文件 @
6acd8d14
...
...
@@ -201,7 +201,9 @@ public class Storage {
public
void
delete
(
Session
session
)
throws
SQLException
{
truncate
(
session
);
database
.
removeStorage
(
id
,
file
);
int
test
;
// database.removeStorage(id, file);
}
// private int allocateBest(int start, int blocks) {
...
...
h2/src/main/org/h2/store/WriterThread.java
浏览文件 @
6acd8d14
...
...
@@ -6,9 +6,6 @@ package org.h2.store;
import
java.lang.ref.WeakReference
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map.Entry
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
...
...
@@ -19,10 +16,7 @@ import org.h2.log.LogSystem;
import
org.h2.message.Trace
;
import
org.h2.message.TraceSystem
;
import
org.h2.table.Table
;
import
org.h2.util.FileUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ObjectUtils
;
import
org.h2.util.TempFileDeleter
;
/**
* The writer thread is responsible to flush the transaction log file from time to time.
...
...
@@ -44,55 +38,6 @@ public class WriterThread extends Thread {
private
int
writeDelay
;
private
long
lastIndexFlush
;
private
volatile
boolean
stop
;
private
HashMap
deleteLater
=
new
HashMap
();
private
volatile
long
deleteNext
;
public
void
deleteLater
(
String
fileName
)
{
long
at
=
System
.
currentTimeMillis
()
+
SysProperties
.
getLogFileDeleteDelay
();
if
(
at
<
deleteNext
||
deleteNext
==
0
)
{
deleteNext
=
at
;
}
synchronized
(
deleteLater
)
{
deleteLater
.
put
(
fileName
,
ObjectUtils
.
getLong
(
at
));
}
}
private
void
delete
(
boolean
now
)
{
if
(!
now
&&
(
deleteNext
==
0
||
System
.
currentTimeMillis
()
<
deleteNext
))
{
return
;
}
long
time
=
System
.
currentTimeMillis
();
ObjectArray
delete
=
new
ObjectArray
();
synchronized
(
deleteLater
)
{
deleteNext
=
0
;
for
(
Iterator
it
=
deleteLater
.
entrySet
().
iterator
();
it
.
hasNext
();)
{
Entry
entry
=
(
Entry
)
it
.
next
();
long
at
=
((
Long
)
entry
.
getValue
()).
longValue
();
if
(
now
||
time
>=
at
)
{
String
fileName
=
(
String
)
entry
.
getKey
();
delete
.
add
(
fileName
);
}
else
{
if
(
at
<
deleteNext
||
deleteNext
==
0
)
{
deleteNext
=
at
;
}
}
}
}
for
(
int
i
=
0
;
i
<
delete
.
size
();
i
++)
{
String
fileName
=
(
String
)
delete
.
get
(
i
);
try
{
FileUtils
.
delete
(
fileName
);
synchronized
(
deleteLater
)
{
deleteLater
.
remove
(
fileName
);
}
}
catch
(
SQLException
e
)
{
Database
database
=
(
Database
)
databaseRef
.
get
();
if
(
database
!=
null
)
{
database
.
getTrace
(
Trace
.
DATABASE
).
error
(
"delete "
+
fileName
,
e
);
}
}
}
}
private
WriterThread
(
Database
database
,
int
writeDelay
)
{
this
.
databaseRef
=
new
WeakReference
(
database
);
...
...
@@ -161,8 +106,6 @@ public class WriterThread extends Thread {
public
void
run
()
{
while
(!
stop
)
{
delete
(
false
);
TempFileDeleter
.
deleteUnused
();
Database
database
=
(
Database
)
databaseRef
.
get
();
if
(
database
==
null
)
{
break
;
...
...
@@ -196,9 +139,6 @@ public class WriterThread extends Thread {
}
public
void
stopThread
()
{
int
testing
;
delete
(
false
);
stop
=
true
;
}
...
...
h2/src/main/org/h2/util/DelayedFileDeleter.java
0 → 100644
浏览文件 @
6acd8d14
/*
* Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
util
;
import
java.lang.ref.PhantomReference
;
import
java.lang.ref.Reference
;
import
java.lang.ref.ReferenceQueue
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map.Entry
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
/**
* Deletes files later on or if they are not used.
* This class deletes temporary files when they are not used any longer.
*/
public
class
DelayedFileDeleter
extends
Thread
{
private
static
DelayedFileDeleter
instance
;
private
final
ReferenceQueue
queue
=
new
ReferenceQueue
();
private
final
HashMap
refMap
=
new
HashMap
();
private
final
HashMap
deleteLater
=
new
HashMap
();
private
long
deleteNext
;
public
synchronized
void
deleteLater
(
String
fileName
)
throws
SQLException
{
int
delay
=
SysProperties
.
getLogFileDeleteDelay
();
if
(
delay
==
0
&&
deleteLater
.
size
()
==
0
)
{
// shortcut if delay is 0
FileUtils
.
delete
(
fileName
);
return
;
}
long
at
=
System
.
currentTimeMillis
()
+
delay
;
if
(
deleteNext
!=
0
&&
at
<=
deleteNext
)
{
// make sure files are deleted in the correct order
at
=
deleteNext
+
1
;
}
deleteNext
=
at
;
deleteLater
.
put
(
fileName
,
ObjectUtils
.
getLong
(
at
));
}
/**
* Delete at most one old file (after the delay)
*/
private
void
deleteOld
()
{
long
now
=
System
.
currentTimeMillis
();
if
(
deleteNext
==
0
||
now
<
deleteNext
)
{
return
;
}
String
delete
=
null
;
long
oldest
=
0
;
for
(
Iterator
it
=
deleteLater
.
entrySet
().
iterator
();
it
.
hasNext
();)
{
Entry
entry
=
(
Entry
)
it
.
next
();
long
at
=
((
Long
)
entry
.
getValue
()).
longValue
();
if
(
at
<
now
&&
(
delete
==
null
||
at
<
oldest
))
{
delete
=
(
String
)
entry
.
getKey
();
oldest
=
at
;
}
}
if
(
delete
==
null
)
{
return
;
}
try
{
FileUtils
.
delete
(
delete
);
}
catch
(
SQLException
e
)
{
// ignore
}
deleteLater
.
remove
(
delete
);
}
public
static
synchronized
DelayedFileDeleter
getInstance
()
{
if
(
instance
==
null
)
{
int
test
;
//System.out.println("DelayerFileDeleter.getInstance()");
instance
=
new
DelayedFileDeleter
();
instance
.
setDaemon
(
true
);
instance
.
setPriority
(
Thread
.
MIN_PRIORITY
);
instance
.
start
();
}
return
instance
;
}
private
DelayedFileDeleter
()
{
setName
(
"H2 FileDeleter"
);
}
public
void
run
()
{
while
(
true
)
{
try
{
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
synchronized
(
this
)
{
if
(
refMap
.
size
()
!=
0
)
{
deleteUnused
();
}
else
if
(
deleteLater
.
size
()
!=
0
)
{
deleteOld
();
}
else
{
break
;
}
}
}
int
test
;
//System.out.println("DelayerFileDeleter.stop()");
}
/**
* Add a temp file to the queue and delete it if it is no longer referenced.
*
* @param fileName the file name
* @param file the object to track
* @return the reference
*/
public
synchronized
Reference
addTempFile
(
String
fileName
,
Object
file
)
{
FileUtils
.
trace
(
"FileDeleter.addFile"
,
fileName
,
file
);
PhantomReference
ref
=
new
PhantomReference
(
file
,
queue
);
refMap
.
put
(
ref
,
fileName
);
return
ref
;
}
/**
* Delete a file now and remove it from the queue.
*
* @param the reference in the queue
* @param fileName the file name
*/
public
synchronized
void
autoDeleteFile
(
Reference
ref
,
String
fileName
)
{
if
(
ref
!=
null
)
{
String
f2
=
(
String
)
refMap
.
remove
(
ref
);
if
(
SysProperties
.
CHECK
&&
f2
!=
null
&&
fileName
!=
null
&&
!
f2
.
equals
(
fileName
))
{
throw
Message
.
getInternalError
(
"f2:"
+
f2
+
" f:"
+
fileName
);
}
}
if
(
fileName
!=
null
&&
FileUtils
.
exists
(
fileName
))
{
try
{
FileUtils
.
trace
(
"FileDeleter.deleteFile"
,
fileName
,
null
);
FileUtils
.
delete
(
fileName
);
}
catch
(
Exception
e
)
{
// TODO log such errors?
}
deleteUnused
();
}
}
/**
* Delete all unreferenced files that have been garbage collected now.
* This method is called from time to time by the application.
*/
private
void
deleteUnused
()
{
while
(
true
)
{
Reference
ref
=
queue
.
poll
();
if
(
ref
==
null
)
{
break
;
}
autoDeleteFile
(
ref
,
null
);
}
}
/**
* Remove a file from the list of files to be deleted.
*
* @param ref the reference
* @param fileName the file name
*/
public
synchronized
void
stopAutoDelete
(
Reference
ref
,
String
fileName
)
{
FileUtils
.
trace
(
"FileDeleter.stopAutoDelete"
,
fileName
,
ref
);
if
(
ref
!=
null
)
{
String
f2
=
(
String
)
refMap
.
remove
(
ref
);
if
(
SysProperties
.
CHECK
&&
(
f2
==
null
||
!
f2
.
equals
(
fileName
)))
{
throw
Message
.
getInternalError
(
"f2:"
+
f2
+
" f:"
+
fileName
);
}
}
}
}
h2/src/main/org/h2/util/TempFileDeleter.java
deleted
100644 → 0
浏览文件 @
7b88d790
/*
* Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
util
;
import
java.lang.ref.PhantomReference
;
import
java.lang.ref.Reference
;
import
java.lang.ref.ReferenceQueue
;
import
java.util.HashMap
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.Message
;
/**
* This class deletes temporary files when they are not used any longer.
*/
public
class
TempFileDeleter
{
private
static
final
ReferenceQueue
QUEUE
=
new
ReferenceQueue
();
private
static
final
HashMap
REF_MAP
=
new
HashMap
();
public
static
synchronized
Reference
addFile
(
String
fileName
,
Object
file
)
{
FileUtils
.
trace
(
"TempFileDeleter.addFile"
,
fileName
,
file
);
PhantomReference
ref
=
new
PhantomReference
(
file
,
QUEUE
);
REF_MAP
.
put
(
ref
,
fileName
);
deleteUnused
();
return
ref
;
}
public
static
synchronized
void
deleteFile
(
Reference
ref
,
String
fileName
)
{
if
(
ref
!=
null
)
{
String
f2
=
(
String
)
REF_MAP
.
remove
(
ref
);
if
(
SysProperties
.
CHECK
&&
f2
!=
null
&&
fileName
!=
null
&&
!
f2
.
equals
(
fileName
))
{
throw
Message
.
getInternalError
(
"f2:"
+
f2
+
" f:"
+
fileName
);
}
}
if
(
fileName
!=
null
&&
FileUtils
.
exists
(
fileName
))
{
try
{
FileUtils
.
trace
(
"TempFileDeleter.deleteFile"
,
fileName
,
null
);
FileUtils
.
delete
(
fileName
);
}
catch
(
Exception
e
)
{
// TODO log such errors?
}
deleteUnused
();
}
}
public
static
void
deleteUnused
()
{
// Mystery: I don't know how QUEUE could get null, but two independent
// people reported NullPointerException here - if somebody understands
// how it could happen please report it!
// Environment: web application under Tomcat, exception occurs during undeploy
while
(
QUEUE
!=
null
)
{
Reference
ref
=
QUEUE
.
poll
();
if
(
ref
==
null
)
{
break
;
}
deleteFile
(
ref
,
null
);
}
}
public
static
void
stopAutoDelete
(
Reference
ref
,
String
fileName
)
{
FileUtils
.
trace
(
"TempFileDeleter.stopAutoDelete"
,
fileName
,
ref
);
if
(
ref
!=
null
)
{
String
f2
=
(
String
)
REF_MAP
.
remove
(
ref
);
if
(
SysProperties
.
CHECK
&&
(
f2
==
null
||
!
f2
.
equals
(
fileName
)))
{
throw
Message
.
getInternalError
(
"f2:"
+
f2
+
" f:"
+
fileName
);
}
}
deleteUnused
();
}
}
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
6acd8d14
...
...
@@ -179,6 +179,8 @@ conn3:
4) insert into bla
5) commit
after init, scan all storages and return those that don't belong to a live database object!!
Automate real power off tests
Extend tests that simulate power off
timer test
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
6acd8d14
...
...
@@ -146,6 +146,10 @@ public abstract class TestBase {
}
private
Connection
getConnectionInternal
(
String
url
,
String
user
,
String
password
)
throws
Exception
{
int
test
;
//System.out.println();
//System.out.println("connect to " + url);
Class
.
forName
(
"org.h2.Driver"
);
// url += ";DEFAULT_TABLE_TYPE=1";
// Class.forName("org.hsqldb.jdbcDriver");
...
...
h2/src/test/org/h2/test/db/TestIndex.java
浏览文件 @
6acd8d14
...
...
@@ -32,46 +32,58 @@ public class TestIndex extends TestBase {
}
public
void
test
()
throws
Exception
{
testDescIndex
();
int
teting
;
// testDescIndex();
//
if
(
config
.
networked
&&
config
.
big
)
{
return
;
}
random
.
setSeed
(
100
);
deleteDb
(
"index"
);
testWideIndex
(
147
);
testWideIndex
(
313
);
testWideIndex
(
979
);
testWideIndex
(
1200
);
testWideIndex
(
2400
);
if
(
config
.
big
&&
config
.
logMode
==
2
)
{
for
(
int
i
=
0
;
i
<
2000
;
i
++)
{
if
((
i
%
100
)
==
0
)
{
System
.
out
.
println
(
"width: "
+
i
);
}
testWideIndex
(
i
);
}
}
int
teting2
;
//
// random.setSeed(100);
//
// deleteDb("index");
// testWideIndex(147);
// testWideIndex(313);
// testWideIndex(979);
// testWideIndex(1200);
// testWideIndex(2400);
// if (config.big && config.logMode == 2) {
// for (int i = 0; i < 2000; i++) {
// if ((i % 100) == 0) {
// System.out.println("width: " + i);
// }
// testWideIndex(i);
// }
// }
//
// testLike();
// reconnect();
// testConstraint();
// testLargeIndex();
// testMultiColumnIndex();
// // long time;
// // time = System.currentTimeMillis();
// testHashIndex(true, false);
System
.
setProperty
(
"h2.logDeleteDelay"
,
"999999999"
);
int
testx
;
if
(
config
.
logMode
!=
2
)
{
return
;
}
testLike
();
reconnect
();
testConstraint
();
testLargeIndex
();
testMultiColumnIndex
();
// long time;
// time = System.currentTimeMillis();
testHashIndex
(
true
,
false
);
testHashIndex
(
false
,
false
);
// System.out.println("btree="+(System.currentTimeMillis()-time));
// time = System.currentTimeMillis();
//
// System.out.println("btree="+(System.currentTimeMillis()-time));
//
// time = System.currentTimeMillis();
testHashIndex
(
true
,
true
);
testHashIndex
(
false
,
true
);
// System.out.println("hash="+(System.currentTimeMillis()-time));
testMultiColumnHashIndex
();
conn
.
close
();
int
te3
;
// testMultiColumnHashIndex();
//
// conn.close();
}
void
testDescIndex
()
throws
Exception
{
...
...
@@ -217,6 +229,8 @@ public class TestIndex extends TestBase {
check
(
1
,
prep
.
executeUpdate
());
}
check
(
0
,
getValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
));
conn
.
close
();
conn
=
null
;
}
void
testMultiColumnIndex
()
throws
Exception
{
...
...
h2/src/test/org/h2/test/db/TestLob.java
浏览文件 @
6acd8d14
...
...
@@ -34,9 +34,10 @@ public class TestLob extends TestBase {
if
(
config
.
memory
)
{
return
;
}
testLobVariable
();
testLobDrop
();
testLobNoClose
();
int
test
;
// testLobVariable();
// testLobDrop();
// testLobNoClose();
testLobTransactions
(
10
);
testLobTransactions
(
10000
);
testLobRollbackStop
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论