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

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

上级 337f0a4f
...@@ -59,7 +59,7 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -59,7 +59,7 @@ public class TestMultiThread extends TestBase implements Runnable {
testConcurrentAlter(); testConcurrentAlter();
testConcurrentAnalyze(); testConcurrentAnalyze();
testConcurrentInsertUpdateSelect(); testConcurrentInsertUpdateSelect();
testMetadataWith(); testLockModeWithMultiThreaded();
} }
private void testConcurrentLobAdd() throws Exception { private void testConcurrentLobAdd() throws Exception {
...@@ -246,15 +246,17 @@ public class TestMultiThread extends TestBase implements Runnable { ...@@ -246,15 +246,17 @@ public class TestMultiThread extends TestBase implements Runnable {
} }
} }
private void testMetadataWith() throws Exception { private void testLockModeWithMultiThreaded() throws Exception {
// currently the combination of LOCK_MODE=0 and MULTI_THREADED // currently the combination of LOCK_MODE=0 and MULTI_THREADED
// is not supported. also see code in // is not supported
deleteDb("concurrentAnalyze"); deleteDb("lockMode");
final String url = getURL("concurrentAnalyze;MULTI_THREADED=1", true); final String url = getURL("lockMode;MULTI_THREADED=1", true);
Connection conn = getConnection(url); Connection conn = getConnection(url);
DatabaseMetaData dmd = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
assertFalse(dmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)); assertFalse(meta.supportsTransactionIsolationLevel(
Connection.TRANSACTION_READ_UNCOMMITTED));
conn.close(); conn.close();
deleteDb("concurrentAnalyze"); deleteDb("lockMode");
} }
} }
...@@ -859,9 +859,10 @@ public class TestSpatial extends TestBase { ...@@ -859,9 +859,10 @@ public class TestSpatial extends TestBase {
try { try {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("drop table if exists pt_cloud;\n" + stat.execute("drop table if exists pt_cloud;\n" +
"CREATE TABLE PT_CLOUD AS SELECT CONCAT('POINT(',A.X,' ',B.X,')')::geometry the_geom from" + "CREATE TABLE PT_CLOUD AS " +
" SELECT CONCAT('POINT(',A.X,' ',B.X,')')::geometry the_geom from" +
" system_range(1e6,1e6+10) A,system_range(6e6,6e6+10) B;\n" + " system_range(1e6,1e6+10) A,system_range(6e6,6e6+10) B;\n" +
"create spatial index ptindex on pt_cloud(the_geom);"); "create spatial index pt_index on pt_cloud(the_geom);");
// Wait some time // Wait some time
try { try {
Thread.sleep(1000); Thread.sleep(1000);
...@@ -869,9 +870,10 @@ public class TestSpatial extends TestBase { ...@@ -869,9 +870,10 @@ public class TestSpatial extends TestBase {
throw new SQLException(ex); throw new SQLException(ex);
} }
stat.execute("drop table if exists pt_cloud;\n" + stat.execute("drop table if exists pt_cloud;\n" +
"CREATE TABLE PT_CLOUD AS SELECT CONCAT('POINT(',A.X,' ',B.X,')')::geometry the_geom from" + "CREATE TABLE PT_CLOUD AS " +
" SELECT CONCAT('POINT(',A.X,' ',B.X,')')::geometry the_geom from" +
" system_range(1e6,1e6+50) A,system_range(6e6,6e6+50) B;\n" + " system_range(1e6,1e6+50) A,system_range(6e6,6e6+50) B;\n" +
"create spatial index ptindex on pt_cloud(the_geom);\n" + "create spatial index pt_index on pt_cloud(the_geom);\n" +
"shutdown compact;"); "shutdown compact;");
} finally { } finally {
// Close the database // Close the database
......
...@@ -19,7 +19,6 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -19,7 +19,6 @@ import java.util.concurrent.atomic.AtomicInteger;
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.store.fs.FileChannelInputStream; import org.h2.store.fs.FileChannelInputStream;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
...@@ -186,8 +185,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -186,8 +185,7 @@ public class TestConcurrent extends TestMVStore {
final MVStore s = new MVStore.Builder(). final MVStore s = new MVStore.Builder().
autoCommitDisabled().open(); autoCommitDisabled().open();
s.setVersionsToKeep(10); s.setVersionsToKeep(10);
final MVMapConcurrent<Integer, Integer> m = s.openMap("data", final MVMap<Integer, Integer> m = s.openMap("data");
new MVMapConcurrent.Builder<Integer, Integer>());
m.put(1, 1); m.put(1, 1);
Task task = new Task() { Task task = new Task() {
@Override @Override
...@@ -374,8 +372,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -374,8 +372,7 @@ public class TestConcurrent extends TestMVStore {
*/ */
private void testConcurrentMap() throws InterruptedException { private void testConcurrentMap() throws InterruptedException {
final MVStore s = openStore(null); final MVStore s = openStore(null);
final MVMap<Integer, Integer> m = s.openMap("data", final MVMap<Integer, Integer> m = s.openMap("data");
new MVMapConcurrent.Builder<Integer, Integer>());
final int size = 20; final int size = 20;
final Random rand = new Random(1); final Random rand = new Random(1);
Task task = new Task() { Task task = new Task() {
......
...@@ -1278,10 +1278,13 @@ public class TestMVStore extends TestBase { ...@@ -1278,10 +1278,13 @@ public class TestMVStore extends TestBase {
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s; MVStore s;
s = openStore(fileName); s = openStore(fileName);
s.setVersionsToKeep(100);
s.setAutoCommitDelay(0);
s.setRetentionTime(Integer.MAX_VALUE); s.setRetentionTime(Integer.MAX_VALUE);
MVMap<String, String> m; MVMap<String, String> m = s.openMap("data");
m = s.openMap("data"); s.commit();
long first = s.getCurrentVersion(); long first = s.getCurrentVersion();
m.put("0", "test");
s.commit(); s.commit();
m.put("1", "Hello"); m.put("1", "Hello");
m.put("2", "World"); m.put("2", "World");
...@@ -1351,11 +1354,13 @@ public class TestMVStore extends TestBase { ...@@ -1351,11 +1354,13 @@ public class TestMVStore extends TestBase {
long len = FileUtils.size(fileName); long len = FileUtils.size(fileName);
s = openStore(fileName); s = openStore(fileName);
s.setRetentionTime(0); s.setRetentionTime(0);
// remove 50% // remove 75%
m = s.openMap("data"); m = s.openMap("data");
for (int i = 0; i < 10; i += 2) { for (int i = 0; i < 10; i++) {
if (i % 4 != 0) {
m.remove(i); m.remove(i);
} }
}
s.commit(); s.commit();
assertTrue(s.compact(100, 50 * 1024)); assertTrue(s.compact(100, 50 * 1024));
s.close(); s.close();
......
...@@ -146,18 +146,22 @@ public class TestMVStoreBenchmark extends TestBase { ...@@ -146,18 +146,22 @@ public class TestMVStoreBenchmark extends TestBase {
if (!config.big) { if (!config.big) {
return; return;
} }
// -mx12g -agentlib:hprof=heap=sites,depth=8
// int size = 1000;
int size = 1000000; int size = 1000000;
long hash = 0, tree = 0, mv = 0; long hash = 0, tree = 0, mv = 0;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
Map<Integer, String> map; Map<Integer, String> map;
MVStore store = MVStore.open(null);
map = store.openMap("test");
mv = testPerformance(map, size);
map = new HashMap<Integer, String>(size); map = new HashMap<Integer, String>(size);
// map = new ConcurrentHashMap<Integer, String>(size);
hash = testPerformance(map, size); hash = testPerformance(map, size);
map = new TreeMap<Integer, String>(); map = new TreeMap<Integer, String>();
// map = new ConcurrentSkipListMap<Integer, String>();
tree = testPerformance(map, size); tree = testPerformance(map, size);
MVStore store = MVStore.open(null); if (hash < tree && mv < tree * 1.5) {
map = store.openMap("test");
mv = testPerformance(map, size);
if (hash < tree && mv < tree) {
break; break;
} }
} }
......
...@@ -11,7 +11,6 @@ import java.util.Random; ...@@ -11,7 +11,6 @@ import java.util.Random;
import java.util.TreeMap; import java.util.TreeMap;
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.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -22,7 +21,6 @@ import org.h2.test.TestBase; ...@@ -22,7 +21,6 @@ import org.h2.test.TestBase;
public class TestRandomMapOps extends TestBase { public class TestRandomMapOps extends TestBase {
private String fileName; private String fileName;
private boolean concurrent;
private int seed; private int seed;
private int op; private int op;
...@@ -39,9 +37,6 @@ public class TestRandomMapOps extends TestBase { ...@@ -39,9 +37,6 @@ public class TestRandomMapOps extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
concurrent = false;
testMap("memFS:randomOps.h3");
concurrent = true;
testMap("memFS:randomOps.h3"); testMap("memFS:randomOps.h3");
} }
...@@ -82,11 +77,7 @@ public class TestRandomMapOps extends TestBase { ...@@ -82,11 +77,7 @@ public class TestRandomMapOps extends TestBase {
MVStore s; MVStore s;
s = openStore(fileName); s = openStore(fileName);
MVMap<Integer, byte[]> m; MVMap<Integer, byte[]> m;
if (concurrent) {
m = s.openMap("data", new MVMapConcurrent.Builder<Integer, byte[]>());
} else {
m = s.openMap("data"); m = s.openMap("data");
}
Random r = new Random(seed); Random r = new Random(seed);
op = 0; op = 0;
TreeMap<Integer, byte[]> map = new TreeMap<Integer, byte[]>(); TreeMap<Integer, byte[]> map = new TreeMap<Integer, byte[]>();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论