提交 73a8002d authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: support concurrent transactions (MVCC style, should match the behavior of PostgreSQL)

上级 c09306b0
......@@ -831,7 +831,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return store;
}
int getId() {
public int getId() {
return id;
}
......@@ -980,7 +980,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return root.getTotalCount();
}
long getCreateVersion() {
public long getCreateVersion() {
return createVersion;
}
......@@ -1010,7 +1010,10 @@ public class MVMap<K, V> extends AbstractMap<K, V>
Page newest = null;
// need to copy because it can change
Page r = root;
if (r.getVersion() <= version && r.getVersion() >= 0) {
if (version >= r.getVersion() &&
(r.getVersion() >= 0 ||
version <= createVersion ||
store.getFile() == null)) {
newest = r;
} else {
// find the newest page that has a getVersion() <= version
......
......@@ -42,6 +42,7 @@ public class TestMVStore extends TestBase {
FileUtils.deleteRecursive(getBaseDir(), true);
FileUtils.createDirectories(getBaseDir());
testOldVersion();
testAtomicOperations();
testWriteBuffer();
testWriteDelay();
......@@ -732,6 +733,31 @@ public class TestMVStore extends TestBase {
assertEquals("[10, 11, 12, 13, 14, 50, 100, 90, 91, 92]", list.toString());
s.close();
}
private void testOldVersion() {
MVStore s;
for (int op = 0; op <= 1; op++) {
for (int i = 0; i < 5; i++) {
s = openStore(null);
s.setRetainVersion(0);
MVMap<String, String> m;
m = s.openMap("data");
for (int j = 0; j < 5; j++) {
if (op == 1) {
m.put("1", "" + s.getCurrentVersion());
}
s.incrementVersion();
}
for (int j = 0; j < s.getCurrentVersion(); j++) {
MVMap<String, String> old = m.openVersion(j);
if (op == 1) {
assertEquals("" + j, old.get("1"));
}
}
s.close();
}
}
}
private void testVersion() {
String fileName = getBaseDir() + "/testVersion.h3";
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论