提交 2084502c authored 作者: Thomas Mueller's avatar Thomas Mueller

MVTableEngine: recovery

上级 5362d7af
......@@ -64,6 +64,7 @@ import org.h2.util.TempFileDeleter;
import org.h2.util.Tool;
import org.h2.util.Utils;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueLob;
import org.h2.value.ValueLobDb;
import org.h2.value.ValueLong;
......@@ -501,18 +502,41 @@ public class Recover extends Tool implements DataHandler {
String mapName = key.substring("name.".length());
String tableId = mapName.substring("table.".length());
ValueDataType keyType = new ValueDataType(
null, null, null);
null, this, null);
ValueDataType valueType = new ValueDataType(
null, null, null);
null, this, null);
MVMap.Builder<Value, Value> mapBuilder = new MVMap.Builder<Value, Value>().
keyType(keyType).
valueType(valueType);
TransactionMap<Value, Value> dataMap = store.begin().openMap(mapName, mapBuilder);
Iterator<Value> dataIt = dataMap.keyIterator(null);
boolean init = false;
while (dataIt.hasNext()) {
Value rowId = dataIt.next();
Value values = dataMap.get(rowId);
writer.println("-- insert into O_" + tableId + " key=" + rowId + " values=" + values);
Value[] values = ((ValueArray) dataMap.get(rowId)).getList();
recordLength = values.length;
if (!init) {
setStorage(Integer.parseInt(tableId));
// init the column types
for (valueId = 0; valueId < recordLength; valueId++) {
String columnName = storageName + "." + valueId;
getSQL(columnName, values[valueId]);
}
createTemporaryTable(writer);
init = true;
}
StringBuilder buff = new StringBuilder();
buff.append("INSERT INTO O_").append(tableId)
.append(" VALUES(");
for (valueId = 0; valueId < recordLength; valueId++) {
if (valueId > 0) {
buff.append(", ");
}
String columnName = storageName + "." + valueId;
buff.append(getSQL(columnName, values[valueId]));
}
buff.append(");");
writer.println(buff.toString());
}
}
} catch (Throwable e) {
......
......@@ -6,11 +6,6 @@
*/
package org.h2.test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.SQLException;
import java.util.Properties;
import org.h2.Driver;
......@@ -612,10 +607,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestReadOnly().runTest(this);
new TestRecursiveQueries().runTest(this);
new TestRights().runTest(this);
if (!mvStore) {
// Recover is not yet implemented
new TestRunscript().runTest(this);
}
new TestSQLInjection().runTest(this);
new TestSessionsLocks().runTest(this);
new TestSelectCountNonNullColumn().runTest(this);
......@@ -752,7 +744,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestPgServer().runTest(this);
new TestReader().runTest(this);
if (!mvStore) {
// Recover is not yet implemented
// Recover is not yet fully implemented
new TestRecovery().runTest(this);
}
new TestSampleApps().runTest(this);
......@@ -764,10 +756,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestStreams().runTest(this);
new TestStringCache().runTest(this);
new TestStringUtils().runTest(this);
if (!mvStore) {
// Recover is not yet implemented
new TestTools().runTest(this);
}
new TestTraceSystem().runTest(this);
new TestUpgrade().runTest(this);
new TestUtils().runTest(this);
......
......@@ -23,9 +23,9 @@ import org.h2.engine.Database;
import org.h2.jdbc.JdbcConnection;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Recover;
import org.h2.tools.Restore;
import org.h2.tools.Script;
import org.h2.util.Task;
/**
......@@ -45,7 +45,7 @@ public class TestMVTableEngine extends TestBase {
@Override
public void test() throws Exception {
// testSpeed();
// testRecover();
testRecover();
testSeparateKey();
testRollback();
testRollbackAfterCrash();
......@@ -122,21 +122,28 @@ int test;
Connection conn;
Statement stat;
String url = "mvstore;default_table_engine=org.h2.mvstore.db.MVTableEngine";
url = getURL(url, true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
stat.execute("insert into test values(1)");
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("insert into test values(1, 'Hello')");
stat.execute("create table test2(name varchar)");
stat.execute("insert into test2 values('Hello World')");
conn.close();
Recover.execute(getBaseDir(), "mvstore");
FileUtils.deleteRecursive(getBaseDir(), true);
Script.execute(url, getUser(), getPassword(), System.out);
DeleteDbFiles.execute(getBaseDir(), "mvstore", true);
conn = getConnection(url);
stat = conn.createStatement();
stat.execute("runscript from '" + getBaseDir() + "/mvstore.h2.sql'");
ResultSet rs;
rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
rs = stat.executeQuery("select * from test2");
assertTrue(rs.next());
assertEquals("Hello World", rs.getString(1));
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论