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

MVStore: closing a map and making it read-only is now only a marker and not…

MVStore: closing a map and making it read-only is now only a marker and not enforced, to allow concurrent store operations
上级 ff013fdb
...@@ -529,15 +529,11 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -529,15 +529,11 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
/** /**
* Close the map, making it read only and release the memory. This method * Close the map. Accessing the data is still possible (to allow concurrent
* may only be called when closing the store or when removing the map, as * reads), but it is marked as closed.
* further writes are not possible.
*/ */
void close() { void close() {
closed = true; closed = true;
readOnly = true;
removeAllOldVersions();
root = null;
} }
public boolean isClosed() { public boolean isClosed() {
...@@ -873,15 +869,6 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -873,15 +869,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
} }
} }
/**
* Forget all old versions.
*/
private void removeAllOldVersions() {
// create a new instance
// because another thread might iterate over it
oldRoots = new ArrayList<Page>();
}
/** /**
* Forget those old versions that are no longer needed. * Forget those old versions that are no longer needed.
*/ */
...@@ -906,10 +893,6 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -906,10 +893,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
oldRoots = list; oldRoots = list;
} }
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public boolean isReadOnly() { public boolean isReadOnly() {
return readOnly; return readOnly;
} }
......
...@@ -35,7 +35,6 @@ public class SequenceMap extends MVMap<Long, Long> { ...@@ -35,7 +35,6 @@ public class SequenceMap extends MVMap<Long, Long> {
@Override @Override
public void init(MVStore store, HashMap<String, String> config) { public void init(MVStore store, HashMap<String, String> config) {
super.init(store, config); super.init(store, config);
setReadOnly(true);
} }
@Override @Override
......
...@@ -44,6 +44,7 @@ public class TestConcurrent extends TestMVStore { ...@@ -44,6 +44,7 @@ public class TestConcurrent extends TestMVStore {
FileUtils.deleteRecursive(getBaseDir(), true); FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir()); FileUtils.createDirectories(getBaseDir());
testConcurrentStoreAndRemoveMap();
testConcurrentStoreAndClose(); testConcurrentStoreAndClose();
testConcurrentOnlineBackup(); testConcurrentOnlineBackup();
testConcurrentMap(); testConcurrentMap();
...@@ -52,6 +53,33 @@ public class TestConcurrent extends TestMVStore { ...@@ -52,6 +53,33 @@ public class TestConcurrent extends TestMVStore {
testConcurrentRead(); testConcurrentRead();
} }
private void testConcurrentStoreAndRemoveMap() throws InterruptedException {
String fileName = getBaseDir() + "/testConcurrentStoreAndRemoveMap.h3";
final MVStore s = openStore(fileName);
int count = 100;
for (int i = 0; i < count; i++) {
MVMap<Integer, Integer> m = s.openMap("d" + i);
m.put(1, 1);
}
Task task = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
s.store();
}
}
};
task.execute();
Thread.sleep(1);
for (int i = 0; i < count; i++) {
MVMap<Integer, Integer> m = s.openMap("d" + i);
m.put(1, 10);
m.removeMap();
}
task.get();
s.close();
}
private void testConcurrentStoreAndClose() throws InterruptedException { private void testConcurrentStoreAndClose() throws InterruptedException {
String fileName = getBaseDir() + "/testConcurrentStoreAndClose.h3"; String fileName = getBaseDir() + "/testConcurrentStoreAndClose.h3";
final MVStore s = openStore(fileName); final MVStore s = openStore(fileName);
......
...@@ -1231,7 +1231,6 @@ public class TestMVStore extends TestBase { ...@@ -1231,7 +1231,6 @@ public class TestMVStore extends TestBase {
assertNull(m0.get("1")); assertNull(m0.get("1"));
assertTrue(m1.isClosed()); assertTrue(m1.isClosed());
assertFalse(m0.isReadOnly()); assertFalse(m0.isReadOnly());
assertTrue(m1.isReadOnly());
s.close(); s.close();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论