提交 747b2489 authored 作者: Thomas Mueller's avatar Thomas Mueller

A persistent multi-version map (work in progress): r-tree

上级 ccaa8179
...@@ -14,7 +14,7 @@ import org.h2.dev.store.btree.DataType; ...@@ -14,7 +14,7 @@ import org.h2.dev.store.btree.DataType;
import org.h2.dev.store.btree.Page; import org.h2.dev.store.btree.Page;
/** /**
* An r-tree implementation. * An r-tree implementation. It uses the quadratic split algorithm.
* *
* @param <K> the key class * @param <K> the key class
* @param <V> the value class * @param <V> the value class
...@@ -38,10 +38,6 @@ public class RtreeMap<K, V> extends BtreeMap<K, V> { ...@@ -38,10 +38,6 @@ public class RtreeMap<K, V> extends BtreeMap<K, V> {
return (V) getSpatial(root, key); return (V) getSpatial(root, key);
} }
private boolean overlap(Page p, int index, Object key) {
return keyType.isOverlap(p.getKey(index), key);
}
private boolean contains(Page p, int index, Object key) { private boolean contains(Page p, int index, Object key) {
return keyType.contains(p.getKey(index), key); return keyType.contains(p.getKey(index), key);
} }
...@@ -205,6 +201,7 @@ public class RtreeMap<K, V> extends BtreeMap<K, V> { ...@@ -205,6 +201,7 @@ public class RtreeMap<K, V> extends BtreeMap<K, V> {
throw KEY_ALREADY_EXISTS; throw KEY_ALREADY_EXISTS;
} }
} }
p = p.copyOnWrite(writeVersion);
p.insert(p.getKeyCount(), key, value, 0, 0); p.insert(p.getKeyCount(), key, value, 0, 0);
return p; return p;
} }
......
...@@ -65,19 +65,33 @@ public class TestBtreeMapStore extends TestBase { ...@@ -65,19 +65,33 @@ public class TestBtreeMapStore extends TestBase {
FileUtils.delete(fileName); FileUtils.delete(fileName);
BtreeMapStore s; BtreeMapStore s;
s = openStore(fileName); s = openStore(fileName);
// s.setMaxPageSize(100); // s.setMaxPageSize(50);
RtreeMap<SpatialKey, String> r = s.openMap("data", "r", "s2", ""); RtreeMap<SpatialKey, String> r = s.openMap("data", "r", "s2", "");
Random rand = new Random(1); Random rand = new Random(1);
for (int i = 0; i < 1000; i++) { int len = 1000;
for (int i = 0; i < len; i++) {
float x = rand.nextFloat(), y = rand.nextFloat(); float x = rand.nextFloat(), y = rand.nextFloat();
float p = (float) (rand.nextFloat() * 0.01); float p = (float) (rand.nextFloat() * 0.01);
SpatialKey k = SpatialKey.create(i, x - p, x + p, y - p, y + p); SpatialKey k = SpatialKey.create(i, x - p, x + p, y - p, y + p);
r.put(k, "" + i); r.put(k, "" + i);
if (i > 0 && i % 10000 == 0) { if (i > 0 && (i % 100) == 0) {
s.store();
}
if (i > 0 && (i % 10000) == 0) {
render(r, getBaseDir() + "/test.png"); render(r, getBaseDir() + "/test.png");
} }
} }
s.store();
s.close(); s.close();
s = openStore(fileName);
r = s.openMap("data", "r", "s2", "");
rand = new Random(1);
for (int i = 0; i < len; i++) {
float x = rand.nextFloat(), y = rand.nextFloat();
float p = (float) (rand.nextFloat() * 0.01);
SpatialKey k = SpatialKey.create(i, x - p, x + p, y - p, y + p);
assertEquals("" + i, r.get(k));
}
} }
private void testRtree() { private void testRtree() {
...@@ -422,6 +436,8 @@ public class TestBtreeMapStore extends TestBase { ...@@ -422,6 +436,8 @@ public class TestBtreeMapStore extends TestBase {
String fileName = getBaseDir() + "/testBtreeStore.h3"; String fileName = getBaseDir() + "/testBtreeStore.h3";
FileUtils.delete(fileName); FileUtils.delete(fileName);
BtreeMapStore s = openStore(fileName); BtreeMapStore s = openStore(fileName);
s.close();
s = openStore(fileName);
BtreeMap<Integer, String> m = s.openMap("data", Integer.class, String.class); BtreeMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
int count = 2000; int count = 2000;
// Profiler p = new Profiler(); // Profiler p = new Profiler();
......
...@@ -41,12 +41,10 @@ TODO: ...@@ -41,12 +41,10 @@ TODO:
- ability to diff / merge versions - ability to diff / merge versions
- map.getVersion and opening old maps read-only - map.getVersion and opening old maps read-only
- limited support for writing to old versions (branches) - limited support for writing to old versions (branches)
- Serializer instead of DataType, (serialize, deserialize)
- implement complete java.util.Map interface - implement complete java.util.Map interface
- maybe rename to MVStore, MVMap, TestMVStore - maybe rename to MVStore, MVMap, TestMVStore
- atomic test-and-set (when supporting concurrent writes) - atomic test-and-set (when supporting concurrent writes)
- support background writes (store old version) - support background writes (store old version)
- re-use map ids that were not used for a very long time
- file header could be a regular chunk, end of file the second - file header could be a regular chunk, end of file the second
- possibly split chunk data into immutable and mutable - possibly split chunk data into immutable and mutable
- test with very small chunks, possibly speed up very small transactions - test with very small chunks, possibly speed up very small transactions
...@@ -285,7 +283,9 @@ public class BtreeMapStore { ...@@ -285,7 +283,9 @@ public class BtreeMapStore {
writeHeader(); writeHeader();
} else { } else {
readHeader(); readHeader();
readMeta(); if (rootChunkStart > 0) {
readMeta();
}
} }
} catch (Exception e) { } catch (Exception e) {
throw convert(e); throw convert(e);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论