提交 5e703674 authored 作者: Thomas Mueller's avatar Thomas Mueller

A persistent multi-version map (work in progress) - rename to MVStore / MVMap

上级 d5cc1876
......@@ -105,7 +105,7 @@ import org.h2.test.server.TestWeb;
import org.h2.test.server.TestInit;
import org.h2.test.store.TestCacheLIRS;
import org.h2.test.store.TestDataUtils;
import org.h2.test.store.TestBtreeMapStore;
import org.h2.test.store.TestMVStore;
import org.h2.test.store.TestRtree;
import org.h2.test.synth.TestBtreeIndex;
import org.h2.test.synth.TestCrashAPI;
......@@ -665,7 +665,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
private void testUnit() {
// store
new TestBtreeMapStore().runTest(this);
new TestMVStore().runTest(this);
new TestCacheLIRS().runTest(this);
new TestDataUtils().runTest(this);
new TestRtree().runTest(this);
......
......@@ -7,8 +7,8 @@
package org.h2.test.store;
import java.util.ArrayList;
import org.h2.dev.store.btree.BtreeMap;
import org.h2.dev.store.btree.BtreeMapStore;
import org.h2.dev.store.btree.MVMap;
import org.h2.dev.store.btree.MVStore;
import org.h2.dev.store.btree.Cursor;
import org.h2.dev.store.btree.CursorPos;
import org.h2.dev.store.btree.DataType;
......@@ -21,12 +21,12 @@ import org.h2.util.New;
* @param <K> the key class
* @param <V> the value class
*/
public class RtreeMap<K, V> extends BtreeMap<K, V> {
public class RtreeMap<K, V> extends MVMap<K, V> {
private final SpatialType keyType;
private boolean quadraticSplit;
RtreeMap(BtreeMapStore store, int id, String name, DataType keyType,
RtreeMap(MVStore store, int id, String name, DataType keyType,
DataType valueType, long createVersion) {
super(store, id, name, keyType, valueType, createVersion);
this.keyType = (SpatialType) keyType;
......
......@@ -9,8 +9,8 @@ package org.h2.test.store;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Set;
import org.h2.dev.store.btree.BtreeMap;
import org.h2.dev.store.btree.BtreeMapStore;
import org.h2.dev.store.btree.MVMap;
import org.h2.dev.store.btree.MVStore;
import org.h2.dev.store.btree.DataType;
/**
......@@ -19,11 +19,11 @@ import org.h2.dev.store.btree.DataType;
* @param <K> the key type
* @param <V> the key type
*/
public class SequenceMap<K, V> extends BtreeMap<K, V> {
public class SequenceMap<K, V> extends MVMap<K, V> {
int min = 1, max = 10;
SequenceMap(BtreeMapStore store, int id, String name, DataType keyType,
SequenceMap(MVStore store, int id, String name, DataType keyType,
DataType valueType, long createVersion) {
super(store, id, name, keyType, valueType, createVersion);
setReadOnly(true);
......
......@@ -5,8 +5,8 @@
*/
package org.h2.test.store;
import org.h2.dev.store.btree.BtreeMap;
import org.h2.dev.store.btree.BtreeMapStore;
import org.h2.dev.store.btree.MVMap;
import org.h2.dev.store.btree.MVStore;
import org.h2.dev.store.btree.DataType;
import org.h2.dev.store.btree.MapFactory;
import org.h2.dev.store.btree.StringType;
......@@ -17,7 +17,7 @@ import org.h2.dev.store.btree.StringType;
public class TestMapFactory implements MapFactory {
@Override
public <K, V> BtreeMap<K, V> buildMap(String mapType, BtreeMapStore store,
public <K, V> MVMap<K, V> buildMap(String mapType, MVStore store,
int id, String name, DataType keyType, DataType valueType,
long createVersion) {
if (mapType.equals("s")) {
......
......@@ -14,7 +14,7 @@ import java.util.Random;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import org.h2.dev.store.btree.BtreeMapStore;
import org.h2.dev.store.btree.MVStore;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase;
import org.h2.util.New;
......@@ -22,7 +22,7 @@ import org.h2.util.New;
/**
* Tests the r-tree.
*/
public class TestRtree extends TestBtreeMapStore {
public class TestRtree extends TestMVStore {
/**
* Run just this test.
......@@ -43,7 +43,7 @@ public class TestRtree extends TestBtreeMapStore {
private void testRtreeMany() {
String fileName = getBaseDir() + "/testRtree.h3";
FileUtils.delete(fileName);
BtreeMapStore s;
MVStore s;
s = openStore(fileName);
// s.setMaxPageSize(50);
RtreeMap<SpatialKey, String> r = s.openMap("data", "r", "s2", "");
......@@ -106,7 +106,7 @@ public class TestRtree extends TestBtreeMapStore {
private void testRtree() {
String fileName = getBaseDir() + "/testRtree.h3";
FileUtils.delete(fileName);
BtreeMapStore s;
MVStore s;
s = openStore(fileName);
RtreeMap<SpatialKey, String> r = s.openMap("data", "r", "s2", "");
add(r, "Bern", 46.57, 7.27, 124381);
......@@ -198,7 +198,7 @@ public class TestRtree extends TestBtreeMapStore {
private void testRandomRtree() {
String fileName = getBaseDir() + "/testRtreeRandom.h3";
FileUtils.delete(fileName);
BtreeMapStore s = openStore(fileName);
MVStore s = openStore(fileName);
RtreeMap<SpatialKey, String> m = s.openMap("data", "r", "s2", "");
HashMap<SpatialKey, String> map = new HashMap<SpatialKey, String>();
Random rand = new Random(1);
......@@ -240,7 +240,7 @@ public class TestRtree extends TestBtreeMapStore {
private void testCustomMapType() {
String fileName = getBaseDir() + "/testMapType.h3";
FileUtils.delete(fileName);
BtreeMapStore s;
MVStore s;
s = openStore(fileName);
SequenceMap<Integer, String> seq = s.openMap("data", "s", "i", "");
StringBuilder buff = new StringBuilder();
......
......@@ -16,7 +16,7 @@ public class ChangeCursor<K, V> extends Cursor<K, V> {
private final long minVersion;
ChangeCursor(BtreeMap<K, V> map, long minVersion) {
ChangeCursor(MVMap<K, V> map, long minVersion) {
super(map);
this.minVersion = minVersion;
}
......
......@@ -17,12 +17,12 @@ import java.util.Iterator;
*/
public class Cursor<K, V> implements Iterator<K> {
protected final BtreeMap<K, V> map;
protected final MVMap<K, V> map;
protected final ArrayList<CursorPos> parents = new ArrayList<CursorPos>();
protected CursorPos currentPos;
protected K current;
Cursor(BtreeMap<K, V> map) {
Cursor(MVMap<K, V> map) {
this.map = map;
}
......
......@@ -17,9 +17,9 @@ import java.util.TreeMap;
* @param <K> the key class
* @param <V> the value class
*/
public class BtreeMap<K, V> {
public class MVMap<K, V> {
protected final BtreeMapStore store;
protected final MVStore store;
protected Page root;
private final int id;
......@@ -36,7 +36,7 @@ public class BtreeMap<K, V> {
private boolean closed;
private boolean readOnly;
protected BtreeMap(BtreeMapStore store, int id, String name,
protected MVMap(MVStore store, int id, String name,
DataType keyType, DataType valueType, long createVersion) {
this.store = store;
this.id = id;
......@@ -469,19 +469,19 @@ public class BtreeMap<K, V> {
@Override
public Iterator<K> iterator() {
Cursor<K, V> c = new Cursor<K, V>(BtreeMap.this);
Cursor<K, V> c = new Cursor<K, V>(MVMap.this);
c.start(root, null);
return c;
}
@Override
public int size() {
return BtreeMap.this.size();
return MVMap.this.size();
}
@Override
public boolean contains(Object o) {
return BtreeMap.this.containsKey(o);
return MVMap.this.containsKey(o);
}
};
......@@ -505,7 +505,7 @@ public class BtreeMap<K, V> {
return name;
}
BtreeMapStore getStore() {
MVStore getStore() {
return store;
}
......@@ -597,7 +597,7 @@ public class BtreeMap<K, V> {
store.removePage(p.getPos());
}
public BtreeMap<K, V> openVersion(long version) {
public MVMap<K, V> openVersion(long version) {
if (version < createVersion) {
throw new IllegalArgumentException("Unknown version");
}
......@@ -605,7 +605,7 @@ public class BtreeMap<K, V> {
return store.openMapVersion(version, name);
}
Page root = oldRoots.get(version);
BtreeMap<K, V> m = new BtreeMap<K, V>(store, id, name, keyType, valueType, createVersion);
MVMap<K, V> m = new MVMap<K, V>(store, id, name, keyType, valueType, createVersion);
m.readOnly = true;
m.root = root;
return m;
......
......@@ -23,8 +23,8 @@ public interface MapFactory {
* @param createVersion when the map was created
* @return the map
*/
<K, V> BtreeMap<K, V> buildMap(
String mapType, BtreeMapStore store, int id, String name,
<K, V> MVMap<K, V> buildMap(
String mapType, MVStore store, int id, String name,
DataType keyType, DataType valueType, long createVersion);
/**
......
......@@ -27,7 +27,7 @@ public class Page {
private static final int SHARED_KEYS = 1, SHARED_VALUES = 2, SHARED_CHILDREN = 4, SHARED_COUNTS = 8;
private final BtreeMap<?, ?> map;
private final MVMap<?, ?> map;
private final long version;
private long pos;
private long totalCount;
......@@ -49,7 +49,7 @@ public class Page {
private Page[] childrenPages;
private long[] counts;
private Page(BtreeMap<?, ?> map, long version) {
private Page(MVMap<?, ?> map, long version) {
this.map = map;
this.version = version;
}
......@@ -64,7 +64,7 @@ public class Page {
* @param children the children
* @return the page
*/
public static Page create(BtreeMap<?, ?> map, long version,
public static Page create(MVMap<?, ?> map, long version,
int keyCount, Object[] keys,
Object[] values, long[] children, Page[] childrenPages, long[] counts,
long totalCount, int sharedFlags) {
......@@ -89,7 +89,7 @@ public class Page {
* @param buff the source buffer
* @return the page
*/
static Page read(FileChannel file, BtreeMap<?, ?> map,
static Page read(FileChannel file, MVMap<?, ?> map,
long filePos, long pos) {
int maxLength = DataUtils.getPageMaxLength(pos), length = maxLength;
ByteBuffer buff;
......@@ -300,7 +300,7 @@ public class Page {
}
public long getTotalCount() {
if (BtreeMapStore.ASSERT) {
if (MVStore.ASSERT) {
long check = 0;
if (isLeaf()) {
check = keyCount;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论