提交 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>
}
/**
* Close the map, making it read only and release the memory. This method
* may only be called when closing the store or when removing the map, as
* further writes are not possible.
* Close the map. Accessing the data is still possible (to allow concurrent
* reads), but it is marked as closed.
*/
void close() {
closed = true;
readOnly = true;
removeAllOldVersions();
root = null;
}
public boolean isClosed() {
......@@ -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.
*/
......@@ -906,10 +893,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
oldRoots = list;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public boolean isReadOnly() {
return readOnly;
}
......
......@@ -35,7 +35,6 @@ public class SequenceMap extends MVMap<Long, Long> {
@Override
public void init(MVStore store, HashMap<String, String> config) {
super.init(store, config);
setReadOnly(true);
}
@Override
......
......@@ -44,6 +44,7 @@ public class TestConcurrent extends TestMVStore {
FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir());
testConcurrentStoreAndRemoveMap();
testConcurrentStoreAndClose();
testConcurrentOnlineBackup();
testConcurrentMap();
......@@ -51,6 +52,33 @@ public class TestConcurrent extends TestMVStore {
testConcurrentWrite();
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 {
String fileName = getBaseDir() + "/testConcurrentStoreAndClose.h3";
......
......@@ -1231,7 +1231,6 @@ public class TestMVStore extends TestBase {
assertNull(m0.get("1"));
assertTrue(m1.isClosed());
assertFalse(m0.isReadOnly());
assertTrue(m1.isReadOnly());
s.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论