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

MVStore: support for volatile maps (that don't store changes).

上级 8f043e40
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>MVStore mode: in-memory databases now also use the MVStore.
<ul><li>MVStore: support for volatile maps (that don't store changes).
</li><li>MVStore mode: in-memory databases now also use the MVStore.
</li><li>In server mode, appending ";autocommit=false" to the database URL was working,
but the return value of Connection.getAutoCommit() was wrong.
</li><li>OSGi: the import package declaration of org.h2 excluded version 1.4.
......
......@@ -58,6 +58,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
private boolean closed;
private boolean readOnly;
private boolean isVolatile;
protected MVMap(DataType keyType, DataType valueType) {
this.keyType = keyType;
......@@ -917,6 +918,26 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return readOnly;
}
/**
* Set the volatile flag of the map.
*
* @param isVolatile the volatile flag
*/
public void setVolatile(boolean isVolatile) {
this.isVolatile = isVolatile;
}
/**
* Whether this is volatile map, meaning that changes
* are not persisted. By default (even if the store is not persisted),
* maps are not volatile.
*
* @return whether this map is volatile
*/
public boolean isVolatile() {
return isVolatile;
}
/**
* This method is called before writing to the map. The default
* implementation checks whether writing is allowed, and tries
......
......@@ -952,6 +952,9 @@ public class MVStore {
// the map was created after storing started
continue;
}
if (m.isVolatile()) {
continue;
}
if (v >= 0 && v >= lastStoredVersion) {
m.waitUntilWritten(storeVersion);
MVMap<?, ?> r = m.openVersion(storeVersion);
......
......@@ -74,6 +74,9 @@ public class MVPrimaryIndex extends BaseIndex {
mapName = "table." + getId();
dataMap = mvTable.getTransaction(null).openMap(mapName, keyType,
valueType);
if (!table.isPersistData()) {
dataMap.map.setVolatile(true);
}
Value k = dataMap.lastKey();
lastKey = k == null ? 0 : k.getLong();
}
......
......@@ -30,7 +30,6 @@ import org.h2.mvstore.db.TransactionStore.Transaction;
import org.h2.store.InDoubtTransaction;
import org.h2.store.fs.FileChannelInputStream;
import org.h2.store.fs.FileUtils;
import org.h2.table.RegularTable;
import org.h2.table.TableBase;
import org.h2.util.New;
......@@ -118,10 +117,6 @@ public class MVTableEngine implements TableEngine {
@Override
public TableBase createTable(CreateTableData data) {
Database db = data.session.getDatabase();
if (!data.persistData) {
; // TODO need in-memory tables for persistent stores
return new RegularTable(data);
}
Store store = init(db);
MVTable table = new MVTable(data, store);
table.init(data.session);
......
......@@ -52,6 +52,7 @@ public class TestMVStore extends TestBase {
public void test() throws Exception {
FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir());
testVolatileMap();
testEntrySet();
testCompressEmptyPage();
testCompressed();
......@@ -110,6 +111,28 @@ public class TestMVStore extends TestBase {
testLargerThan2G();
}
private void testVolatileMap() {
String fileName = getBaseDir() + "/testVolatile.h3";
MVStore store = new MVStore.Builder().
fileName(fileName).
open();
MVMap<String, String> map = store.openMap("test");
assertFalse(map.isVolatile());
map.setVolatile(true);
assertTrue(map.isVolatile());
map.put("1", "Hello");
assertEquals("Hello", map.get("1"));
assertEquals(1, map.size());
store.close();
store = new MVStore.Builder().
fileName(fileName).
open();
assertTrue(store.hasMap("test"));
map = store.openMap("test");
assertEquals(0, map.size());
store.close();
}
private void testEntrySet() {
MVStore s = new MVStore.Builder().open();
MVMap<Integer, Integer> map;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论