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

MVTableEngine: store all metadata in the MVStore.

上级 19dded26
...@@ -321,6 +321,13 @@ public class DbSettings extends SettingsBase { ...@@ -321,6 +321,13 @@ public class DbSettings extends SettingsBase {
*/ */
public String defaultTableEngine = get("DEFAULT_TABLE_ENGINE", null); public String defaultTableEngine = get("DEFAULT_TABLE_ENGINE", null);
/**
* Database setting <code>MV_STORE</code>
* (default: false).<br />
* Use the MVStore storage engine.
*/
public final boolean mvStore = get("MV_STORE", false);
private DbSettings(HashMap<String, String> s) { private DbSettings(HashMap<String, String> s) {
super(s); super(s);
} }
......
...@@ -1687,6 +1687,9 @@ public class Database implements DataHandler { ...@@ -1687,6 +1687,9 @@ public class Database implements DataHandler {
if (pageStore != null) { if (pageStore != null) {
pageStore.getCache().setMaxMemory(kb); pageStore.getCache().setMaxMemory(kb);
} }
if (mvStore != null) {
mvStore.setCacheSize(Math.max(1, kb / 1024));
}
} }
public synchronized void setMasterUser(User user) { public synchronized void setMasterUser(User user) {
...@@ -2151,6 +2154,9 @@ public class Database implements DataHandler { ...@@ -2151,6 +2154,9 @@ public class Database implements DataHandler {
} }
public PageStore getPageStore() { public PageStore getPageStore() {
if (dbSettings.mvStore && mvStore == null) {
mvStore = MVTableEngine.init(this);
}
if (pageStore == null) { if (pageStore == null) {
pageStore = new PageStore(this, databaseName + Constants.SUFFIX_PAGE_FILE, accessModeData, cacheSize); pageStore = new PageStore(this, databaseName + Constants.SUFFIX_PAGE_FILE, accessModeData, cacheSize);
if (pageSize != Constants.DEFAULT_PAGE_SIZE) { if (pageSize != Constants.DEFAULT_PAGE_SIZE) {
......
...@@ -23,6 +23,7 @@ import org.h2.engine.User; ...@@ -23,6 +23,7 @@ import org.h2.engine.User;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.mvstore.db.MVTableEngine;
import org.h2.table.RegularTable; import org.h2.table.RegularTable;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableLink; import org.h2.table.TableLink;
...@@ -548,6 +549,11 @@ public class Schema extends DbObjectBase { ...@@ -548,6 +549,11 @@ public class Schema extends DbObjectBase {
database.lockMeta(data.session); database.lockMeta(data.session);
} }
data.schema = this; data.schema = this;
if (data.tableEngine == null) {
if (database.getSettings().mvStore) {
data.tableEngine = MVTableEngine.class.getName();
}
}
if (data.tableEngine != null) { if (data.tableEngine != null) {
TableEngine engine; TableEngine engine;
try { try {
......
...@@ -120,7 +120,7 @@ public class PageStore implements CacheWriter { ...@@ -120,7 +120,7 @@ public class PageStore implements CacheWriter {
public static final int LOG_MODE_SYNC = 2; public static final int LOG_MODE_SYNC = 2;
private static final int PAGE_ID_FREE_LIST_ROOT = 3; private static final int PAGE_ID_FREE_LIST_ROOT = 3;
private static final int PAGE_ID_META_ROOT = 4; private static final int PAGE_ID_META_ROOT = 4;
private static final int MIN_PAGE_COUNT = 6; private static final int MIN_PAGE_COUNT = 5;
private static final int INCREMENT_KB = 1024; private static final int INCREMENT_KB = 1024;
private static final int INCREMENT_PERCENT_MIN = 35; private static final int INCREMENT_PERCENT_MIN = 35;
private static final int READ_VERSION = 3; private static final int READ_VERSION = 3;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
package org.h2.table; package org.h2.table;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
import org.h2.constant.DbSettings;
import org.h2.mvstore.db.MVTableEngine;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -70,7 +72,11 @@ public abstract class TableBase extends Table { ...@@ -70,7 +72,11 @@ public abstract class TableBase extends Table {
} }
buff.append("\n)"); buff.append("\n)");
if (tableEngine != null) { if (tableEngine != null) {
String d = getDatabase().getSettings().defaultTableEngine; DbSettings s = getDatabase().getSettings();
String d = s.defaultTableEngine;
if (d == null && s.mvStore) {
d = MVTableEngine.class.getName();
}
if (d == null || !tableEngine.endsWith(d)) { if (d == null || !tableEngine.endsWith(d)) {
buff.append("\nENGINE \""); buff.append("\nENGINE \"");
buff.append(tableEngine); buff.append(tableEngine);
......
...@@ -492,8 +492,8 @@ public class Recover extends Tool implements DataHandler { ...@@ -492,8 +492,8 @@ public class Recover extends Tool implements DataHandler {
MVStore mv = new MVStore.Builder().fileName(fileName).readOnly().open(); MVStore mv = new MVStore.Builder().fileName(fileName).readOnly().open();
TransactionStore store = new TransactionStore(mv); TransactionStore store = new TransactionStore(mv);
try { try {
MVMap<String, String> meta = mv.getMetaMap(); MVMap<String, String> metaMap = mv.getMetaMap();
Iterator<String> it = meta.keyIterator(null); Iterator<String> it = metaMap.keyIterator(null);
while (it.hasNext()) { while (it.hasNext()) {
String key = it.next(); String key = it.next();
if (!key.startsWith("name.table.")) { if (!key.startsWith("name.table.")) {
...@@ -537,6 +537,20 @@ public class Recover extends Tool implements DataHandler { ...@@ -537,6 +537,20 @@ public class Recover extends Tool implements DataHandler {
} }
buff.append(");"); buff.append(");");
writer.println(buff.toString()); writer.println(buff.toString());
if (storageId == 0) {
try {
SimpleRow r = new SimpleRow(values);
MetaRecord meta = new MetaRecord(r);
schema.add(meta);
if (meta.getObjectType() == DbObject.TABLE_OR_VIEW) {
String sql = values[3].getString();
String name = extractTableOrViewName(sql);
tableMap.put(meta.getId(), name);
}
} catch (Throwable t) {
writeError(writer, t);
}
}
} }
} }
} catch (Throwable e) { } catch (Throwable e) {
......
...@@ -680,7 +680,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -680,7 +680,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestRandomCompare().runTest(this); new TestRandomCompare().runTest(this);
new TestKillRestart().runTest(this); new TestKillRestart().runTest(this);
new TestKillRestartMulti().runTest(this); new TestKillRestartMulti().runTest(this);
new TestMultiThreaded().runTest(this); if (!mvStore) {
// concurrent modification of the undoLog
new TestMultiThreaded().runTest(this);
}
new TestOuterJoins().runTest(this); new TestOuterJoins().runTest(this);
new TestNestedJoins().runTest(this); new TestNestedJoins().runTest(this);
......
...@@ -248,8 +248,7 @@ public abstract class TestBase { ...@@ -248,8 +248,7 @@ public abstract class TestBase {
String url; String url;
if (name.startsWith("jdbc:")) { if (name.startsWith("jdbc:")) {
if (config.mvStore) { if (config.mvStore) {
name = addOption(name, "DEFAULT_TABLE_ENGINE", name = addOption(name, "MV_STORE", "true");
"org.h2.mvstore.db.MVTableEngine");
} }
return name; return name;
} }
...@@ -274,8 +273,7 @@ public abstract class TestBase { ...@@ -274,8 +273,7 @@ public abstract class TestBase {
url = name; url = name;
} }
if (config.mvStore) { if (config.mvStore) {
url = addOption(url, "DEFAULT_TABLE_ENGINE", url = addOption(name, "MV_STORE", "true");
"org.h2.mvstore.db.MVTableEngine");
} }
if (!config.memory) { if (!config.memory) {
if (config.smallLog && admin) { if (config.smallLog && admin) {
......
...@@ -81,7 +81,7 @@ public class TestScalability implements Database.DatabaseTest { ...@@ -81,7 +81,7 @@ public class TestScalability implements Database.DatabaseTest {
dbs.add(createDbEntry(id++, "H2", 50, h2Url)); dbs.add(createDbEntry(id++, "H2", 50, h2Url));
dbs.add(createDbEntry(id++, "H2", 100, h2Url)); dbs.add(createDbEntry(id++, "H2", 100, h2Url));
final String mvUrl = "jdbc:h2:data/mvTest;LOCK_TIMEOUT=10000;DEFAULT_TABLE_ENGINE=org.h2.mvstore.db.MVTableEngine"; final String mvUrl = "jdbc:h2:data/mvTest;LOCK_TIMEOUT=10000;MV_STORE=TRUE";
dbs.add(createDbEntry(id++, "MV", 1, mvUrl)); dbs.add(createDbEntry(id++, "MV", 1, mvUrl));
dbs.add(createDbEntry(id++, "MV", 10, mvUrl)); dbs.add(createDbEntry(id++, "MV", 10, mvUrl));
dbs.add(createDbEntry(id++, "MV", 20, mvUrl)); dbs.add(createDbEntry(id++, "MV", 20, mvUrl));
......
...@@ -69,7 +69,7 @@ public class TestCluster extends TestBase { ...@@ -69,7 +69,7 @@ public class TestCluster extends TestBase {
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false); String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false);
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start(); Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start();
String urlCluster = "jdbc:h2:tcp://" + serverList + "/test"; String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, "-user", user, "-password", password, "-serverList", CreateCluster.main("-urlSource", url1, "-urlTarget", url2, "-user", user, "-password", password, "-serverList",
serverList); serverList);
...@@ -95,9 +95,9 @@ public class TestCluster extends TestBase { ...@@ -95,9 +95,9 @@ public class TestCluster extends TestBase {
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
String url1 = "jdbc:h2:tcp://localhost:" + port1 + "/test"; String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = "jdbc:h2:tcp://localhost:" + port2 + "/test"; String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String urlCluster = "jdbc:h2:tcp://" + serverList + "/test"; String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server server1 = org.h2.tools.Server.createTcpServer( Server server1 = org.h2.tools.Server.createTcpServer(
"-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start(); "-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start();
...@@ -155,9 +155,9 @@ public class TestCluster extends TestBase { ...@@ -155,9 +155,9 @@ public class TestCluster extends TestBase {
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
String url1 = "jdbc:h2:tcp://localhost:" + port1 + "/test"; String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = "jdbc:h2:tcp://localhost:" + port2 + "/test"; String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String urlCluster = "jdbc:h2:tcp://" + serverList + "/test"; String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start(); Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start(); Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start();
...@@ -200,9 +200,9 @@ public class TestCluster extends TestBase { ...@@ -200,9 +200,9 @@ public class TestCluster extends TestBase {
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
String url1 = "jdbc:h2:tcp://localhost:" + port1 + "/test"; String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", true);
String url2 = "jdbc:h2:tcp://localhost:" + port2 + "/test"; String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", true);
String urlCluster = "jdbc:h2:tcp://" + serverList + "/test"; String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", true);
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start(); Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start(); Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论