提交 8c93fb4d authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: support for concurrent reads and writes is now enabled by default.

上级 65449074
...@@ -17,15 +17,22 @@ Change Log ...@@ -17,15 +17,22 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>H2 Console and server mode: SSL is now disabled and TLS is used <ul><li>H2 Console: the built-in web server did not work properly
to protect against the POODLE SSLv3 vulnerability. if an unknown file was requested.
</li><li>MVStore: the jar file is renamed to "h2-mvstore-*.jar" and is
deployed to Maven separately.
</li><li>MVStore: support for concurrent reads and writes is now enabled by default.
</li><li>Server mode: the transfer buffer size has been changed from 16 KB to 64 KB,
after it was found that this improves performance on Linux quite a lot.
</li><li>H2 Console and server mode: SSL is now disabled and TLS is used
to protect against the Poodle SSLv3 vulnerability.
The system property to disable secure anonymous connections is now The system property to disable secure anonymous connections is now
"h2.enableAnonymousTLS". "h2.enableAnonymousTLS".
The default certificate is still self-signed, so you need to manually install The default certificate is still self-signed, so you need to manually install
another one if you want to avoid man in the middle attacks. another one if you want to avoid man in the middle attacks.
</li><li>MVStore: the R-tree did not correctly measure the memory usage. </li><li>MVStore: the R-tree did not correctly measure the memory usage.
</li><li>MVStore: compacting a store with an R-tree did not always work. </li><li>MVStore: compacting a store with an R-tree did not always work.
<ul><li>Issue 581: When running in LOCK_MODE=0, </li><li>Issue 581: When running in LOCK_MODE=0,
JdbcDatabaseMetaData#supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED) JdbcDatabaseMetaData#supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED)
should return false should return false
</li></ul> </li></ul>
......
...@@ -54,14 +54,15 @@ MVStore ...@@ -54,14 +54,15 @@ MVStore
<h2 id="overview">Overview</h2> <h2 id="overview">Overview</h2>
<p> <p>
The MVStore is work in progress, and is planned to be the next storage subsystem of H2. The MVStore is a persistent, log structured key-value store.
But it can also be used directly within an application, without using JDBC or SQL. It is planned to be the next storage subsystem of H2,
but it can also be used directly within an application, without using JDBC or SQL.
</p> </p>
<ul><li>MVStore stands for "multi-version store". <ul><li>MVStore stands for "multi-version store".
</li><li>Each store contains a number of maps that can be accessed using the <code>java.util.Map</code> interface. </li><li>Each store contains a number of maps that can be accessed using the <code>java.util.Map</code> interface.
</li><li>Both file-based persistence and in-memory operation are supported. </li><li>Both file-based persistence and in-memory operation are supported.
</li><li>It is intended to be fast, simple to use, and small. </li><li>It is intended to be fast, simple to use, and small.
</li><li>Old versions of the data can be read concurrently with all other operations. </li><li>Concurrent read and write operations are supported.
</li><li>Transactions are supported (including concurrent transactions and 2-phase commit). </li><li>Transactions are supported (including concurrent transactions and 2-phase commit).
</li><li>The tool is very modular. </li><li>The tool is very modular.
It supports pluggable data types and serialization, It supports pluggable data types and serialization,
...@@ -185,8 +186,8 @@ the key of the map must also contain the primary key). ...@@ -185,8 +186,8 @@ the key of the map must also contain the primary key).
A version is a snapshot of all the data of all maps at a given point in time. A version is a snapshot of all the data of all maps at a given point in time.
Creating a snapshot is fast: only those pages that are changed after a snapshot are copied. Creating a snapshot is fast: only those pages that are changed after a snapshot are copied.
This behavior is also called COW (copy on write). This behavior is also called COW (copy on write).
Old versions are readable.
Rollback to an old version is supported. Rollback to an old version is supported.
Old versions are readable until old data is purged.
</p><p> </p><p>
The following sample code show how to create a store, open a map, add some data, The following sample code show how to create a store, open a map, add some data,
and access the current and an old version: and access the current and an old version:
...@@ -241,8 +242,8 @@ For common use cases, the storage overhead of this utility is very small compare ...@@ -241,8 +242,8 @@ For common use cases, the storage overhead of this utility is very small compare
<h3 id="inMemory">In-Memory Performance and Usage</h3> <h3 id="inMemory">In-Memory Performance and Usage</h3>
<p> <p>
Performance of in-memory operations is a bit slower than Performance of in-memory operations is about 50% slower than
<code>java.util.TreeMap</code>, and slower than <code>java.util.HashMap</code>. <code>java.util.TreeMap</code>.
</p><p> </p><p>
The memory overhead for large maps is slightly better than for the regular The memory overhead for large maps is slightly better than for the regular
map implementations, but there is a higher overhead per map. map implementations, but there is a higher overhead per map.
...@@ -296,28 +297,18 @@ and a multi-version R-tree map implementation for spatial operations. ...@@ -296,28 +297,18 @@ and a multi-version R-tree map implementation for spatial operations.
<h3 id="caching">Concurrent Operations and Caching</h3> <h3 id="caching">Concurrent Operations and Caching</h3>
<p> <p>
The default map implementation supports concurrent reads on old versions of the data. Concurrent reads and writes are supported.
All such read operations can occur in parallel. Concurrent reads from the page cache, All such read operations can occur in parallel. Concurrent reads from the page cache,
as well as concurrent reads from the file system are supported. as well as concurrent reads from the file system are supported.
Write operations first read the relevant pages from disk to memory
(this can happen concurrently), and only then modify the data.
The in-memory parts of write operations are synchronized.
Writing changes to the file can occur concurrently to modifying the data, Writing changes to the file can occur concurrently to modifying the data,
as writing operates on a snapshot. as writing operates on a snapshot.
</p><p> </p><p>
Caching is done on the page level. Caching is done on the page level.
The page cache is a concurrent LIRS cache, which should be resistant against scan operations. The page cache is a concurrent LIRS cache, which should be resistant against scan operations.
</p><p> </p><p>
The default map implementation does not support concurrent modification
operations on a map (the same as <code>HashMap</code> and <code>TreeMap</code>).
Similar to those classes, the map tries to detect concurrent modifications.
</p><p>
With the <code>MVMapConcurrent</code> implementation,
read operations even on the newest version can happen concurrently with all other
operations, without risk of corruption.
This comes with slightly reduced speed in single threaded mode,
the same as with other <code>ConcurrentHashMap</code> implementations.
Write operations first read the relevant pages from disk to memory
(this can happen concurrently), and only then modify the data.
The in-memory parts of write operations are synchronized.
</p><p>
For fully scalable concurrent write operations to a map (in-memory and to disk), For fully scalable concurrent write operations to a map (in-memory and to disk),
the map could be split into multiple maps in different stores ('sharding'). the map could be split into multiple maps in different stores ('sharding').
The plan is to add such a mechanism later when needed. The plan is to add such a mechanism later when needed.
......
...@@ -161,9 +161,7 @@ public class MVTableEngine implements TableEngine { ...@@ -161,9 +161,7 @@ public class MVTableEngine implements TableEngine {
this.store = builder.open(); this.store = builder.open();
this.transactionStore = new TransactionStore( this.transactionStore = new TransactionStore(
store, store,
new ValueDataType(null, db, null), new ValueDataType(null, db, null));
db.isMultiThreaded()
);
} }
public MVStore getStore() { public MVStore getStore() {
......
...@@ -15,7 +15,6 @@ import java.util.Map.Entry; ...@@ -15,7 +15,6 @@ import java.util.Map.Entry;
import org.h2.mvstore.Cursor; import org.h2.mvstore.Cursor;
import org.h2.mvstore.DataUtils; import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap; import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVMapConcurrent;
import org.h2.mvstore.MVStore; import org.h2.mvstore.MVStore;
import org.h2.mvstore.WriteBuffer; import org.h2.mvstore.WriteBuffer;
import org.h2.mvstore.type.DataType; import org.h2.mvstore.type.DataType;
...@@ -50,11 +49,6 @@ public class TransactionStore { ...@@ -50,11 +49,6 @@ public class TransactionStore {
*/ */
final MVMap<Long, Object[]> undoLog; final MVMap<Long, Object[]> undoLog;
/**
* Whether concurrent maps should be used.
*/
private final boolean concurrent;
/** /**
* The map of maps. * The map of maps.
*/ */
...@@ -78,7 +72,7 @@ public class TransactionStore { ...@@ -78,7 +72,7 @@ public class TransactionStore {
* @param store the store * @param store the store
*/ */
public TransactionStore(MVStore store) { public TransactionStore(MVStore store) {
this(store, new ObjectDataType(), false); this(store, new ObjectDataType());
} }
/** /**
...@@ -86,12 +80,10 @@ public class TransactionStore { ...@@ -86,12 +80,10 @@ public class TransactionStore {
* *
* @param store the store * @param store the store
* @param dataType the data type for map keys and values * @param dataType the data type for map keys and values
* @param concurrent whether concurrent maps should be used
*/ */
public TransactionStore(MVStore store, DataType dataType, boolean concurrent) { public TransactionStore(MVStore store, DataType dataType) {
this.store = store; this.store = store;
this.dataType = dataType; this.dataType = dataType;
this.concurrent = concurrent;
preparedTransactions = store.openMap("openTransactions", preparedTransactions = store.openMap("openTransactions",
new MVMap.Builder<Integer, Object[]>()); new MVMap.Builder<Integer, Object[]>());
VersionedValueType oldValueType = new VersionedValueType(dataType); VersionedValueType oldValueType = new VersionedValueType(dataType);
...@@ -363,17 +355,10 @@ public class TransactionStore { ...@@ -363,17 +355,10 @@ public class TransactionStore {
} }
VersionedValueType vt = new VersionedValueType(valueType); VersionedValueType vt = new VersionedValueType(valueType);
MVMap<K, VersionedValue> map; MVMap<K, VersionedValue> map;
if (concurrent) {
MVMapConcurrent.Builder<K, VersionedValue> builder =
new MVMapConcurrent.Builder<K, VersionedValue>().
keyType(keyType).valueType(vt);
map = store.openMap(name, builder);
} else {
MVMap.Builder<K, VersionedValue> builder = MVMap.Builder<K, VersionedValue> builder =
new MVMap.Builder<K, VersionedValue>(). new MVMap.Builder<K, VersionedValue>().
keyType(keyType).valueType(vt); keyType(keyType).valueType(vt);
map = store.openMap(name, builder); map = store.openMap(name, builder);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
MVMap<Object, VersionedValue> m = (MVMap<Object, VersionedValue>) map; MVMap<Object, VersionedValue> m = (MVMap<Object, VersionedValue>) map;
maps.put(map.getId(), m); maps.put(map.getId(), m);
......
...@@ -19,7 +19,6 @@ import org.h2.engine.Constants; ...@@ -19,7 +19,6 @@ import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.mvstore.MVMap; import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVMapConcurrent;
import org.h2.mvstore.MVStore; import org.h2.mvstore.MVStore;
import org.h2.mvstore.StreamStore; import org.h2.mvstore.StreamStore;
import org.h2.mvstore.db.MVTableEngine.Store; import org.h2.mvstore.db.MVTableEngine.Store;
...@@ -91,12 +90,9 @@ public class LobStorageMap implements LobStorageInterface { ...@@ -91,12 +90,9 @@ public class LobStorageMap implements LobStorageInterface {
} else { } else {
mvStore = s.getStore(); mvStore = s.getStore();
} }
lobMap = mvStore.openMap("lobMap", lobMap = mvStore.openMap("lobMap");
new MVMapConcurrent.Builder<Long, Object[]>()); refMap = mvStore.openMap("lobRef");
refMap = mvStore.openMap("lobRef", dataMap = mvStore.openMap("lobData");
new MVMapConcurrent.Builder<Object[], Boolean>());
dataMap = mvStore.openMap("lobData",
new MVMapConcurrent.Builder<Long, byte[]>());
streamStore = new StreamStore(dataMap); streamStore = new StreamStore(dataMap);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论