提交 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
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>H2 Console and server mode: SSL is now disabled and TLS is used
to protect against the POODLE SSLv3 vulnerability.
<ul><li>H2 Console: the built-in web server did not work properly
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
"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.
</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.
<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)
should return false
</li></ul>
......
......@@ -54,14 +54,15 @@ MVStore
<h2 id="overview">Overview</h2>
<p>
The MVStore is work in progress, and 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.
The MVStore is a persistent, log structured key-value store.
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>
<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>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>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>The tool is very modular.
It supports pluggable data types and serialization,
......@@ -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.
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).
Old versions are readable.
Rollback to an old version is supported.
Old versions are readable until old data is purged.
</p><p>
The following sample code show how to create a store, open a map, add some data,
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
<h3 id="inMemory">In-Memory Performance and Usage</h3>
<p>
Performance of in-memory operations is a bit slower than
<code>java.util.TreeMap</code>, and slower than <code>java.util.HashMap</code>.
Performance of in-memory operations is about 50% slower than
<code>java.util.TreeMap</code>.
</p><p>
The memory overhead for large maps is slightly better than for the regular
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.
<h3 id="caching">Concurrent Operations and Caching</h3>
<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,
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,
as writing operates on a snapshot.
</p><p>
Caching is done on the page level.
The page cache is a concurrent LIRS cache, which should be resistant against scan operations.
</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),
the map could be split into multiple maps in different stores ('sharding').
The plan is to add such a mechanism later when needed.
......
......@@ -161,9 +161,7 @@ public class MVTableEngine implements TableEngine {
this.store = builder.open();
this.transactionStore = new TransactionStore(
store,
new ValueDataType(null, db, null),
db.isMultiThreaded()
);
new ValueDataType(null, db, null));
}
public MVStore getStore() {
......
......@@ -15,7 +15,6 @@ import java.util.Map.Entry;
import org.h2.mvstore.Cursor;
import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVMapConcurrent;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.WriteBuffer;
import org.h2.mvstore.type.DataType;
......@@ -50,11 +49,6 @@ public class TransactionStore {
*/
final MVMap<Long, Object[]> undoLog;
/**
* Whether concurrent maps should be used.
*/
private final boolean concurrent;
/**
* The map of maps.
*/
......@@ -78,7 +72,7 @@ public class TransactionStore {
* @param store the store
*/
public TransactionStore(MVStore store) {
this(store, new ObjectDataType(), false);
this(store, new ObjectDataType());
}
/**
......@@ -86,12 +80,10 @@ public class TransactionStore {
*
* @param store the store
* @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.dataType = dataType;
this.concurrent = concurrent;
preparedTransactions = store.openMap("openTransactions",
new MVMap.Builder<Integer, Object[]>());
VersionedValueType oldValueType = new VersionedValueType(dataType);
......@@ -363,17 +355,10 @@ public class TransactionStore {
}
VersionedValueType vt = new VersionedValueType(valueType);
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 =
new MVMap.Builder<K, VersionedValue>().
keyType(keyType).valueType(vt);
map = store.openMap(name, builder);
}
MVMap.Builder<K, VersionedValue> builder =
new MVMap.Builder<K, VersionedValue>().
keyType(keyType).valueType(vt);
map = store.openMap(name, builder);
@SuppressWarnings("unchecked")
MVMap<Object, VersionedValue> m = (MVMap<Object, VersionedValue>) map;
maps.put(map.getId(), m);
......
......@@ -19,7 +19,6 @@ import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.message.DbException;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVMapConcurrent;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.StreamStore;
import org.h2.mvstore.db.MVTableEngine.Store;
......@@ -91,12 +90,9 @@ public class LobStorageMap implements LobStorageInterface {
} else {
mvStore = s.getStore();
}
lobMap = mvStore.openMap("lobMap",
new MVMapConcurrent.Builder<Long, Object[]>());
refMap = mvStore.openMap("lobRef",
new MVMapConcurrent.Builder<Object[], Boolean>());
dataMap = mvStore.openMap("lobData",
new MVMapConcurrent.Builder<Long, byte[]>());
lobMap = mvStore.openMap("lobMap");
refMap = mvStore.openMap("lobRef");
dataMap = mvStore.openMap("lobData");
streamStore = new StreamStore(dataMap);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论