提交 f8c24c4f authored 作者: Thomas Mueller's avatar Thomas Mueller

The .trace.db file is now only created if required.

上级 9ae1fcab
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Shell tool: improved PostgreSQL compatibility.
<ul><li>The .trace.db file is now only created if required.
</li><li>Shell tool: improved PostgreSQL compatibility.
</li><li>Trying to open a database in read-only mode when a .lock.db file exists will now fail
with a nice error message.
</li><li>H2 Console: data that is too long is now abbreviated as follows: text... (100000 characters).
......
......@@ -587,9 +587,9 @@ public class Database implements DataHandler {
}
boolean exists = existsData || existsPage;
if (readOnly) {
traceSystem = new TraceSystem(null, false);
traceSystem = new TraceSystem(null);
} else {
traceSystem = new TraceSystem(databaseName + Constants.SUFFIX_TRACE_FILE, true);
traceSystem = new TraceSystem(databaseName + Constants.SUFFIX_TRACE_FILE);
}
traceSystem.setLevelFile(traceLevelFile);
traceSystem.setLevelSystemOut(traceLevelSystemOut);
......@@ -656,7 +656,7 @@ public class Database implements DataHandler {
reserveLobFileObjectIds();
writer = WriterThread.create(this, writeDelay);
} else {
traceSystem = new TraceSystem(null, false);
traceSystem = new TraceSystem(null);
log = new LogSystem(null, null, false, null, null);
}
systemUser = new User(this, 0, Constants.DBA_NAME, true);
......
......@@ -681,7 +681,7 @@ public class Session extends SessionWithState {
traceModuleName = Trace.JDBC + "[" + id + "]";
}
if (closed) {
return new TraceSystem(null, false).getTrace(traceModuleName);
return new TraceSystem(null).getTrace(traceModuleName);
}
return database.getTrace(traceModuleName);
}
......
......@@ -276,7 +276,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
}
databaseName = name.substring(idx + 1);
String server = name.substring(0, idx);
traceSystem = new TraceSystem(null, false);
traceSystem = new TraceSystem(null);
try {
String traceLevelFile = ci.getProperty(SetTypes.TRACE_LEVEL_FILE, null);
if (traceLevelFile != null) {
......
......@@ -78,7 +78,7 @@ implements ObjectFactory
private TraceSystem getTraceSystem() {
synchronized (JdbcDataSourceFactory.class) {
if (cachedTraceSystem == null) {
cachedTraceSystem = new TraceSystem(SysProperties.CLIENT_TRACE_DIRECTORY + "h2datasource" + Constants.SUFFIX_TRACE_FILE, false);
cachedTraceSystem = new TraceSystem(SysProperties.CLIENT_TRACE_DIRECTORY + "h2datasource" + Constants.SUFFIX_TRACE_FILE);
cachedTraceSystem.setLevelFile(SysProperties.DATASOURCE_TRACE_LEVEL);
}
return cachedTraceSystem;
......
......@@ -100,20 +100,12 @@ public class TraceSystem implements TraceWriter {
* Create a new trace system object.
*
* @param fileName the file name
* @param init if the trace system should be initialized
*/
public TraceSystem(String fileName, boolean init) {
public TraceSystem(String fileName) {
this.fileName = fileName;
updateLevel();
traces = SmallLRUCache.newInstance(100);
dateFormat = new SimpleDateFormat("MM-dd HH:mm:ss ");
if (fileName != null && init) {
try {
openWriter();
} catch (Exception e) {
logWritingError(e);
}
}
}
private void updateLevel() {
......@@ -324,9 +316,6 @@ public class TraceSystem implements TraceWriter {
}
fileWriter = null;
}
if (fileName != null && FileUtils.length(fileName) == 0) {
FileUtils.tryDelete(fileName);
}
}
/**
......
......@@ -51,7 +51,7 @@ public class FileLister {
public static void tryUnlockDatabase(ArrayList<String> files, String message) throws SQLException {
for (String fileName : files) {
if (fileName.endsWith(Constants.SUFFIX_LOCK_FILE)) {
FileLock lock = new FileLock(new TraceSystem(null, false), fileName, Constants.LOCK_SLEEP);
FileLock lock = new FileLock(new TraceSystem(null), fileName, Constants.LOCK_SLEEP);
try {
lock.lock(FileLock.LOCK_FILE);
lock.unlock();
......
......@@ -400,7 +400,7 @@ public abstract class TestBase {
System.err.println("ERROR: " + s + " " + e.toString() + " ------------------------------");
e.printStackTrace();
try {
TraceSystem ts = new TraceSystem(null, false);
TraceSystem ts = new TraceSystem(null);
FileLock lock = new FileLock(ts, "error.lock", 1000);
lock.lock(FileLock.LOCK_FILE);
FileWriter fw = new FileWriter("error.txt", true);
......
......@@ -57,10 +57,15 @@ public class TestStatement extends TestBase {
}
Statement stat = conn.createStatement();
String fileName = baseDir + "/statement.trace.db";
FileObject trace = FileSystem.getInstance(fileName).openFileObject(fileName, "r");
stat.execute("DROP TABLE TEST IF EXISTS");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
stat.execute("INSERT INTO TEST VALUES(1)");
try {
stat.execute("ERROR");
} catch (SQLException e) {
// ignore
}
FileObject trace = FileSystem.getInstance(fileName).openFileObject(fileName, "r");
long start = trace.length();
try {
stat.execute("ERROR");
......
......@@ -57,14 +57,14 @@ public class TestFileLock extends TestBase implements Runnable {
f.delete();
f.createNewFile();
f.setLastModified(System.currentTimeMillis() + 10000);
FileLock lock = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
FileLock lock = new FileLock(new TraceSystem(null), FILE, Constants.LOCK_SLEEP);
lock.lock(FileLock.LOCK_FILE);
lock.unlock();
}
private void testSimple() throws SQLException {
FileLock lock1 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
FileLock lock2 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
FileLock lock1 = new FileLock(new TraceSystem(null), FILE, Constants.LOCK_SLEEP);
FileLock lock2 = new FileLock(new TraceSystem(null), FILE, Constants.LOCK_SLEEP);
lock1.lock(FileLock.LOCK_FILE);
try {
lock2.lock(FileLock.LOCK_FILE);
......@@ -73,7 +73,7 @@ public class TestFileLock extends TestBase implements Runnable {
// expected
}
lock1.unlock();
lock2 = new FileLock(new TraceSystem(null, false), FILE, Constants.LOCK_SLEEP);
lock2 = new FileLock(new TraceSystem(null), FILE, Constants.LOCK_SLEEP);
lock2.lock(FileLock.LOCK_FILE);
lock2.unlock();
}
......@@ -101,7 +101,7 @@ public class TestFileLock extends TestBase implements Runnable {
public void run() {
FileLock lock = null;
while (!stop) {
lock = new FileLock(new TraceSystem(null, false), FILE, 100);
lock = new FileLock(new TraceSystem(null), FILE, 100);
try {
lock.lock(allowSockets ? FileLock.LOCK_SOCKET : FileLock.LOCK_FILE);
base.trace(lock + " locked");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论