提交 224cefae authored 作者: Thomas Mueller's avatar Thomas Mueller

MVTableEngine

上级 d50a6d4b
...@@ -18,7 +18,10 @@ Change Log ...@@ -18,7 +18,10 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>To compile user defined functions, the javax.tools.JavaCompiler is now used if available, <ul><li>To use the MVStore storage engine (which is still work in progress), append
";mv_store=true" to the database URL. Using the MVTableEngine when creating the table
is no longer recommended.
</li><li>To compile user defined functions, the javax.tools.JavaCompiler is now used if available,
and no temporary files are created. This should solve problems when and no temporary files are created. This should solve problems when
multiple H2 database concurrently compile the same user defined functions. multiple H2 database concurrently compile the same user defined functions.
To disable, system the system property "h2.javaSystemCompiler" to false. To disable, system the system property "h2.javaSystemCompiler" to false.
......
...@@ -41,7 +41,7 @@ MVStore ...@@ -41,7 +41,7 @@ MVStore
<a href="#encryption">- Encrypted Files</a><br /> <a href="#encryption">- Encrypted Files</a><br />
<a href="#tools">- Tools</a><br /> <a href="#tools">- Tools</a><br />
<a href="#exceptionHandling">- Exception Handling</a><br /> <a href="#exceptionHandling">- Exception Handling</a><br />
<a href="#tableEngine">- Table Engine for H2</a><br /> <a href="#storageEngine">- Storage Engine for H2</a><br />
<a href="#differences"> <a href="#differences">
Similar Projects and Differences to Other Storage Engines</a><br /> Similar Projects and Differences to Other Storage Engines</a><br />
...@@ -461,7 +461,7 @@ The following exceptions can occur: ...@@ -461,7 +461,7 @@ The following exceptions can occur:
</li><li><code>ConcurrentModificationException</code> if the object is modified concurrently. </li><li><code>ConcurrentModificationException</code> if the object is modified concurrently.
</li></ul> </li></ul>
<h3 id="tableEngine">Table Engine for H2</h3> <h3 id="storageEngine">Storage Engine for H2</h3>
<p> <p>
The plan is to use the MVStore as the default storage engine for the H2 database The plan is to use the MVStore as the default storage engine for the H2 database
in the future (supporting SQL, JDBC, transactions, MVCC, and so on). in the future (supporting SQL, JDBC, transactions, MVCC, and so on).
......
...@@ -879,7 +879,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -879,7 +879,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* Forget those old versions that are no longer needed. * Forget those old versions that are no longer needed.
*/ */
void removeUnusedOldVersions() { void removeUnusedOldVersions() {
long oldest = store.getRetainVersion(); long oldest = store.getRetainOrStoreVersion();
if (oldest == -1) { if (oldest == -1) {
return; return;
} }
......
...@@ -47,6 +47,8 @@ TestMVStoreDataLoss ...@@ -47,6 +47,8 @@ TestMVStoreDataLoss
MVTableEngine: MVTableEngine:
- use StreamStore - use StreamStore
- when the MVStore was enabled before, use it again
(probably by checking existence of the mvstore file)
TransactionStore: TransactionStore:
...@@ -1528,6 +1530,21 @@ public class MVStore { ...@@ -1528,6 +1530,21 @@ public class MVStore {
return v; return v;
} }
/**
* Get the oldest version to retain in memory, which is the manually set
* retain version, or the current store version (whatever is older).
*
* @return the version
*/
long getRetainOrStoreVersion() {
long v = retainVersion;
long storeVersion = currentStoreVersion;
if (storeVersion > -1) {
v = Math.min(v, storeVersion);
}
return v;
}
/** /**
* Check whether all data can be read from this version. This requires that * Check whether all data can be read from this version. This requires that
* all chunks referenced by this version are still available (not * all chunks referenced by this version are still available (not
......
...@@ -374,10 +374,9 @@ public class TestMVTableEngine extends TestBase { ...@@ -374,10 +374,9 @@ public class TestMVTableEngine extends TestBase {
Connection conn; Connection conn;
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
conn = getConnection("mvstore"); conn = getConnection("mvstore;MV_STORE=TRUE");
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id int) " + stat.execute("create table test(id int)");
"engine \"org.h2.mvstore.db.MVTableEngine\"");
stat.execute("set write_delay 0"); stat.execute("set write_delay 0");
stat.execute("insert into test values(1)"); stat.execute("insert into test values(1)");
stat.execute("shutdown immediately"); stat.execute("shutdown immediately");
...@@ -386,8 +385,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -386,8 +385,7 @@ public class TestMVTableEngine extends TestBase {
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
conn = getConnection("mvstore;MV_STORE=TRUE");
conn = getConnection("mvstore");
stat = conn.createStatement(); stat = conn.createStatement();
rs = stat.executeQuery("select * from test"); rs = stat.executeQuery("select * from test");
assertTrue(rs.next()); assertTrue(rs.next());
...@@ -399,11 +397,10 @@ public class TestMVTableEngine extends TestBase { ...@@ -399,11 +397,10 @@ public class TestMVTableEngine extends TestBase {
Connection conn; Connection conn;
Statement stat; Statement stat;
ResultSet rs; ResultSet rs;
conn = getConnection("mvstore"); conn = getConnection("mvstore;MV_STORE=TRUE");
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar) " stat.execute("create table test(id int primary key, name varchar)");
+ "engine \"org.h2.mvstore.db.MVTableEngine\"");
stat.execute("create index on test(name)"); stat.execute("create index on test(name)");
conn.setAutoCommit(false); conn.setAutoCommit(false);
stat.execute("insert into test values(1, 'Hello')"); stat.execute("insert into test values(1, 'Hello')");
...@@ -433,12 +430,11 @@ public class TestMVTableEngine extends TestBase { ...@@ -433,12 +430,11 @@ public class TestMVTableEngine extends TestBase {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
Connection conn; Connection conn;
Statement stat; Statement stat;
conn = getConnection("mvstore"); conn = getConnection("mvstore;MV_STORE=TRUE");
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("create table test(id int, name varchar) " stat.execute("create table test(id int, name varchar)");
+ "engine \"org.h2.mvstore.db.MVTableEngine\"");
conn.close(); conn.close();
conn = getConnection("mvstore"); conn = getConnection("mvstore;MV_STORE=TRUE");
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("drop table test"); stat.execute("drop table test");
conn.close(); conn.close();
...@@ -446,8 +442,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -446,8 +442,7 @@ public class TestMVTableEngine extends TestBase {
private void testBlob() throws SQLException, IOException { private void testBlob() throws SQLException, IOException {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn; Connection conn;
Statement stat; Statement stat;
conn = getConnection(dbName); conn = getConnection(dbName);
...@@ -474,8 +469,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -474,8 +469,7 @@ public class TestMVTableEngine extends TestBase {
private void testEncryption() throws Exception { private void testEncryption() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn; Connection conn;
Statement stat; Statement stat;
String url = getURL(dbName + ";CIPHER=AES", true); String url = getURL(dbName + ";CIPHER=AES", true);
...@@ -495,8 +489,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -495,8 +489,7 @@ public class TestMVTableEngine extends TestBase {
private void testExclusiveLock() throws Exception { private void testExclusiveLock() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn, conn2; Connection conn, conn2;
Statement stat, stat2; Statement stat, stat2;
conn = getConnection(dbName); conn = getConnection(dbName);
...@@ -519,8 +512,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -519,8 +512,7 @@ public class TestMVTableEngine extends TestBase {
private void testReadOnly() throws Exception { private void testReadOnly() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn; Connection conn;
Statement stat; Statement stat;
conn = getConnection(dbName); conn = getConnection(dbName);
...@@ -537,8 +529,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -537,8 +529,7 @@ public class TestMVTableEngine extends TestBase {
private void testReuseDiskSpace() throws Exception { private void testReuseDiskSpace() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn; Connection conn;
Statement stat; Statement stat;
long maxSize = 0; long maxSize = 0;
...@@ -563,8 +554,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -563,8 +554,7 @@ public class TestMVTableEngine extends TestBase {
private void testDataTypes() throws Exception { private void testDataTypes() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn = getConnection(dbName); Connection conn = getConnection(dbName);
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
...@@ -713,8 +703,7 @@ public class TestMVTableEngine extends TestBase { ...@@ -713,8 +703,7 @@ public class TestMVTableEngine extends TestBase {
private void testLocking() throws Exception { private void testLocking() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn = getConnection(dbName); Connection conn = getConnection(dbName);
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("set lock_timeout 1000"); stat.execute("set lock_timeout 1000");
...@@ -750,12 +739,9 @@ public class TestMVTableEngine extends TestBase { ...@@ -750,12 +739,9 @@ public class TestMVTableEngine extends TestBase {
private void testSimple() throws Exception { private void testSimple() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
String dbName = "mvstore" + String dbName = "mvstore;MV_STORE=TRUE";
";MV_STORE=TRUE";
Connection conn = getConnection(dbName); Connection conn = getConnection(dbName);
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
// create table test(id int, name varchar)
// engine "org.h2.mvstore.db.MVStoreTableEngine"
stat.execute("create table test(id int primary key, name varchar)"); stat.execute("create table test(id int primary key, name varchar)");
stat.execute("insert into test values(1, 'Hello'), (2, 'World')"); stat.execute("insert into test values(1, 'Hello'), (2, 'World')");
ResultSet rs = stat.executeQuery("select *, _rowid_ from test"); ResultSet rs = stat.executeQuery("select *, _rowid_ from test");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论