提交 5534ad39 authored 作者: Thomas Mueller's avatar Thomas Mueller

When killing the process after creating and dropping many tables (specially…

When killing the process after creating and dropping many tables (specially temporary tables), the database could not be opened sometimes.
上级 5dd78b05
......@@ -18,7 +18,11 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>CAST(NULL AS ...) doesn't forget the data type, precision, and scale any longer.
<ul><li>After deleting a lot of data (for example by dropping or altering tables, or indexes,
or after a large transaction), opening a large database was very slow. Fixed.
</li><li>When killing the process after creating and dropping many tables (specially temporary tables),
the database could not be opened sometimes.
</li><li>CAST(NULL AS ...) doesn't forget the data type, precision, and scale any longer.
</li><li>Experimental support for recursive queries (see 'Advanced' - 'Recursive Queries' for details).
</li><li>Problems with JDK 1.6.0_18 have been reports in the class StringUtils.quoteRemarkSQL. This method is now changed.
</li><li>The "small jar" distribution did not include the CompressTool,
......
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.todo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Random;
import org.h2.test.unit.TestReopen;
import org.h2.test.utils.RecordingFileSystem;
import org.h2.tools.DeleteDbFiles;
/**
* Test crashing a database by creating a lot of temporary tables.
*/
public class TestTempTableCrash {
/**
* Run just this test.
*
* @param args ignored
*/
public static void main(String[] args) throws Exception {
new TestTempTableCrash().test();
}
private void test() throws Exception {
Connection conn;
Statement stat;
System.setProperty("h2.delayWrongPasswordMin", "0");
System.setProperty("h2.check2", "false");
System.setProperty("h2.lobInDatabase", "true");
System.setProperty("h2.analyzeAuto", "100");
System.setProperty("h2.pageSize", "64");
RecordingFileSystem.register();
System.setProperty("reopenShift", "4");
TestReopen reopen = new TestReopen();
RecordingFileSystem.setRecorder(reopen);
String url = "jdbc:h2:" + RecordingFileSystem.PREFIX +
"memFS:data;PAGE_SIZE=64";
// String url = "jdbc:h2:" + RecordingFileSystem.PREFIX +
// "data/test;PAGE_SIZE=64";
Class.forName("org.h2.Driver");
DeleteDbFiles.execute("data", "test", true);
conn = DriverManager.getConnection(url, "sa", "sa");
stat = conn.createStatement();
Random random = new Random(1);
long start = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
long now = System.currentTimeMillis();
if (now > start + 1000) {
System.out.println("i: " + i);
start = now;
}
int x;
x = random.nextInt(100);
stat.execute("drop table if exists test" + x);
String type = random.nextBoolean() ? "temp" : "";
// String type = "";
stat.execute("create " + type + " table test" + x + "(id int primary key, name varchar)");
if (random.nextBoolean()) {
stat.execute("create index idx_" + x + " on test" + x + "(name, id)");
}
if (random.nextBoolean()) {
stat.execute("insert into test" + x + " select x, x from system_range(1, " + random.nextInt(100) + ")");
}
if (random.nextInt(10) == 1) {
conn.close();
conn = DriverManager.getConnection(url, "sa", "sa");
stat = conn.createStatement();
}
}
conn.close();
}
}
......@@ -19,6 +19,7 @@ import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
import org.h2.test.utils.Recorder;
import org.h2.test.utils.RecordingFileSystem;
import org.h2.tools.Recover;
import org.h2.util.IOUtils;
import org.h2.util.New;
import org.h2.util.Profiler;
......@@ -136,6 +137,11 @@ public class TestReopen extends TestBase implements Recorder {
e.printStackTrace(System.out);
}
System.out.println("begin ------------------------------ " + writeCount);
try {
Recover.execute(fileName.substring(0, fileName.lastIndexOf('/')), null);
} catch (SQLException e) {
// ignore
}
testDatabase += "X";
FileSystem.getInstance(fileName).copy(fileName, testDatabase + Constants.SUFFIX_PAGE_FILE);
try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论