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

MVTableEngine workaround (and a new test).

上级 c084d2ca
...@@ -236,6 +236,10 @@ public class TransactionStore { ...@@ -236,6 +236,10 @@ public class TransactionStore {
commitIfNeeded(); commitIfNeeded();
long[] undoKey = new long[] { t.getId(), logId }; long[] undoKey = new long[] { t.getId(), logId };
Object[] op = undoLog.get(undoKey); Object[] op = undoLog.get(undoKey);
if (op == null) {
int todoImprove;
continue;
}
int opType = (Integer) op[0]; int opType = (Integer) op[0];
if (opType == Transaction.OP_REMOVE) { if (opType == Transaction.OP_REMOVE) {
int mapId = (Integer) op[1]; int mapId = (Integer) op[1];
...@@ -337,6 +341,10 @@ public class TransactionStore { ...@@ -337,6 +341,10 @@ public class TransactionStore {
commitIfNeeded(); commitIfNeeded();
long[] undoKey = new long[] { t.getId(), logId }; long[] undoKey = new long[] { t.getId(), logId };
Object[] op = undoLog.get(undoKey); Object[] op = undoLog.get(undoKey);
if (op == null) {
int todoImprove;
continue;
}
int mapId = ((Integer) op[1]).intValue(); int mapId = ((Integer) op[1]).intValue();
MVMap<Object, VersionedValue> map = openMap(mapId); MVMap<Object, VersionedValue> map = openMap(mapId);
if (map != null) { if (map != null) {
...@@ -379,11 +387,15 @@ public class TransactionStore { ...@@ -379,11 +387,15 @@ public class TransactionStore {
while (logId >= toLogId) { while (logId >= toLogId) {
Object[] op = undoLog.get(new long[] { Object[] op = undoLog.get(new long[] {
t.getId(), logId }); t.getId(), logId });
logId--;
if (op == null) {
int todoImprove;
continue;
}
int mapId = ((Integer) op[1]).intValue(); int mapId = ((Integer) op[1]).intValue();
// TODO open map by id if possible // TODO open map by id if possible
Map<String, String> meta = store.getMetaMap(); Map<String, String> meta = store.getMetaMap();
String m = meta.get("map." + mapId); String m = meta.get("map." + mapId);
logId--;
if (m == null) { if (m == null) {
// map was removed later on // map was removed later on
} else { } else {
......
...@@ -27,7 +27,6 @@ import org.h2.tools.DeleteDbFiles; ...@@ -27,7 +27,6 @@ import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Recover; import org.h2.tools.Recover;
import org.h2.tools.Restore; import org.h2.tools.Restore;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.Profiler;
import org.h2.util.Task; import org.h2.util.Task;
/** /**
...@@ -46,7 +45,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -46,7 +45,7 @@ public class TestMVTableEngine extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
// testSpeed(); // testShrinkDatabaseFile();
testRecover(); testRecover();
testSeparateKey(); testSeparateKey();
testRollback(); testRollback();
...@@ -65,58 +64,28 @@ public class TestMVTableEngine extends TestBase { ...@@ -65,58 +64,28 @@ public class TestMVTableEngine extends TestBase {
testSimple(); testSimple();
} }
private void testSpeed() throws Exception { private void testShrinkDatabaseFile() throws Exception {
String dbName;
for (int i = 0; i < 10; i++) {
dbName = "mvstore";
dbName += ";LOCK_MODE=0";
// dbName += ";LOG=0";
testSpeed(dbName);
int test;
Profiler prof = new Profiler().startCollecting();
dbName = "mvstore" +
";MV_STORE=TRUE";
dbName += ";LOCK_MODE=0";
dbName += ";LOG=0";
testSpeed(dbName);
System.out.println(prof.getTop(10));
}
FileUtils.deleteRecursive(getBaseDir(), true);
}
private void testSpeed(String dbName) throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" +
";MV_STORE=TRUE";
Connection conn; Connection conn;
Statement stat; Statement stat;
String url = getURL(dbName, true); long maxSize = 0;
String user = getUser(); for (int i = 0; i < 20; i++) {
String password = getPassword(); conn = getConnection(dbName);
stat = conn.createStatement();
//Profiler prof = new Profiler(); stat.execute("create table test(id int primary key, data varchar)");
//prof.sumClasses=true; stat.execute("insert into test select x, space(1000) from system_range(1, 1000)");
//prof.startCollecting(); stat.execute("drop table test");
conn.close();
conn = DriverManager.getConnection(url, user, password); long size = FileUtils.size(getBaseDir() + "/mvstore"
stat = conn.createStatement(); + Constants.SUFFIX_MV_FILE);
long time = System.currentTimeMillis(); if (i < 10) {
// stat.execute( maxSize = (int) (Math.max(size, maxSize) * 1.1);
// "create table test(id int primary key, name varchar(255))" + } else if (size > maxSize) {
// "as select x, 'Hello World' from system_range(1, 200000)"); fail(i + " size: " + size + " max: " + maxSize);
stat.execute("create table test(id int primary key, name varchar)"); }
PreparedStatement prep = conn
.prepareStatement("insert into test values(?, ?)");
prep.setString(2, new String(new char[10]).replace((char) 0, 'x'));
// for (int i = 0; i < 20000; i++) {
for (int i = 0; i < 800000; i++) {
prep.setInt(1, i);
prep.execute();
} }
System.out.println((System.currentTimeMillis() - time) + " " + dbName + " before");
conn.close();
//System.out.println(prof.getTop(10));
System.out.println((System.currentTimeMillis() - time) + " " + dbName + " after");
} }
private void testRecover() throws Exception { private void testRecover() throws Exception {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论