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

A persistent tree map (work in progress).

上级 dcc2163b
...@@ -663,6 +663,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -663,6 +663,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
private void testUnit() { private void testUnit() {
// store // store
new TestTreeMapStore().runTest(this); new TestTreeMapStore().runTest(this);
new TestCache().runTest(this);
// unit // unit
new TestAutoReconnect().runTest(this); new TestAutoReconnect().runTest(this);
......
...@@ -108,6 +108,13 @@ public class RowType implements DataType { ...@@ -108,6 +108,13 @@ public class RowType implements DataType {
return buff.toString(); return buff.toString();
} }
/**
* Convert a row type to a row.
*
* @param t the type string
* @param factory the data type factory
* @return the row type
*/
static RowType fromString(String t, DataTypeFactory factory) { static RowType fromString(String t, DataTypeFactory factory) {
if (!t.startsWith("r(") || !t.endsWith(")")) { if (!t.startsWith("r(") || !t.endsWith(")")) {
throw new RuntimeException("Unknown type: " + t); throw new RuntimeException("Unknown type: " + t);
......
...@@ -705,4 +705,5 @@ clusterable shortcut quota wcslen flyway cacao tea memcpy someone iced ...@@ -705,4 +705,5 @@ clusterable shortcut quota wcslen flyway cacao tea memcpy someone iced
korea cpp raspberry inttypes korean hmac swprintf ptr agile rawtypes belgium korea cpp raspberry inttypes korean hmac swprintf ptr agile rawtypes belgium
jia laurent midori stdc macros clocks xaltjvm teruo dylan debian counted jia laurent midori stdc macros clocks xaltjvm teruo dylan debian counted
serializes semantics advances severe defensive maintaining collision serializes semantics advances severe defensive maintaining collision
authenticating authenticating song lir evict edge adjusts recency lirs prune heads sigmetrics
resident guard hir jiang resistance zhang xiaodong
...@@ -37,6 +37,7 @@ public class BtreeMap<K, V> { ...@@ -37,6 +37,7 @@ public class BtreeMap<K, V> {
* @param <K> the key type * @param <K> the key type
* @param <V> the value type * @param <V> the value type
* @param store the tree store * @param store the tree store
* @param id the map id
* @param name the name of the map * @param name the name of the map
* @param keyClass the key class * @param keyClass the key class
* @param valueClass the value class * @param valueClass the value class
......
...@@ -51,7 +51,7 @@ public interface DataType { ...@@ -51,7 +51,7 @@ public interface DataType {
* Write the object. * Write the object.
* *
* @param buff the target buffer * @param buff the target buffer
* @param x the value * @param obj the value
*/ */
void write(ByteBuffer buff, Object obj); void write(ByteBuffer buff, Object obj);
......
...@@ -138,6 +138,14 @@ public class DataUtils { ...@@ -138,6 +138,14 @@ public class DataUtils {
buff.put((byte) x); buff.put((byte) x);
} }
/**
* Copy the elements of an array, with a gap.
*
* @param src the source array
* @param dst the target array
* @param oldSize the size of the old array
* @param gapIndex the index of the gap
*/
static void copyWithGap(Object src, Object dst, int oldSize, int gapIndex) { static void copyWithGap(Object src, Object dst, int oldSize, int gapIndex) {
if (gapIndex > 0) { if (gapIndex > 0) {
System.arraycopy(src, 0, dst, 0, gapIndex); System.arraycopy(src, 0, dst, 0, gapIndex);
...@@ -147,6 +155,14 @@ public class DataUtils { ...@@ -147,6 +155,14 @@ public class DataUtils {
} }
} }
/**
* Copy the elements of an array, and remove one element.
*
* @param src the source array
* @param dst the target array
* @param oldSize the size of the old array
* @param removeIndex the index of the entry to remove
*/
static void copyExcept(Object src, Object dst, int oldSize, int removeIndex) { static void copyExcept(Object src, Object dst, int oldSize, int removeIndex) {
if (removeIndex > 0 && oldSize > 0) { if (removeIndex > 0 && oldSize > 0) {
System.arraycopy(src, 0, dst, 0, removeIndex); System.arraycopy(src, 0, dst, 0, removeIndex);
......
...@@ -8,6 +8,7 @@ package org.h2.dev.store.btree; ...@@ -8,6 +8,7 @@ package org.h2.dev.store.btree;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader; import java.io.StringReader;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
...@@ -23,6 +24,16 @@ public class Dump { ...@@ -23,6 +24,16 @@ public class Dump {
private static int blockSize = 4 * 1024; private static int blockSize = 4 * 1024;
/**
* Runs this tool.
* Options are case sensitive. Supported options are:
* <table>
* <tr><td>[-file]</td>
* <td>The database file name</td></tr>
* </table>
*
* @param args the command line arguments
*/
public static void main(String... args) { public static void main(String... args) {
String fileName = "test.h3"; String fileName = "test.h3";
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
...@@ -30,12 +41,18 @@ public class Dump { ...@@ -30,12 +41,18 @@ public class Dump {
fileName = args[++i]; fileName = args[++i];
} }
} }
dump(fileName); dump(fileName, new PrintWriter(System.out));
} }
public static void dump(String fileName) { /**
* Dump the contents of the file.
*
* @param fileName the name of the file
* @param writer the print writer
*/
public static void dump(String fileName, PrintWriter writer) {
if (!FileUtils.exists(fileName)) { if (!FileUtils.exists(fileName)) {
System.out.println("File not found: " + fileName); writer.println("File not found: " + fileName);
return; return;
} }
FileChannel file = null; FileChannel file = null;
...@@ -48,9 +65,9 @@ public class Dump { ...@@ -48,9 +65,9 @@ public class Dump {
Properties prop = new Properties(); Properties prop = new Properties();
prop.load(new ByteArrayInputStream(header)); prop.load(new ByteArrayInputStream(header));
prop.load(new StringReader(new String(header, "UTF-8"))); prop.load(new StringReader(new String(header, "UTF-8")));
System.out.println("file " + fileName); writer.println("file " + fileName);
System.out.println(" length " + fileLength); writer.println(" length " + fileLength);
System.out.println(" " + prop); writer.println(" " + prop);
ByteBuffer block = ByteBuffer.wrap(new byte[16]); ByteBuffer block = ByteBuffer.wrap(new byte[16]);
for (long pos = 0; pos < fileLength;) { for (long pos = 0; pos < fileLength;) {
file.position(pos); file.position(pos);
...@@ -64,7 +81,7 @@ public class Dump { ...@@ -64,7 +81,7 @@ public class Dump {
int length = block.getInt(); int length = block.getInt();
int chunkId = block.getInt(); int chunkId = block.getInt();
int metaRootOffset = block.getInt(); int metaRootOffset = block.getInt();
System.out.println(" chunk " + chunkId + " at " + pos + writer.println(" chunk " + chunkId + " at " + pos +
" length " + length + " offset " + metaRootOffset); " length " + length + " offset " + metaRootOffset);
ByteBuffer chunk = ByteBuffer.allocate(length); ByteBuffer chunk = ByteBuffer.allocate(length);
file.position(pos); file.position(pos);
...@@ -83,16 +100,16 @@ public class Dump { ...@@ -83,16 +100,16 @@ public class Dump {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
children[i] = chunk.getLong(); children[i] = chunk.getLong();
} }
System.out.println(" map " + mapId + " at " + p + " node, " + count + " children: " + Arrays.toString(children)); writer.println(" map " + mapId + " at " + p + " node, " + count + " children: " + Arrays.toString(children));
} else { } else {
System.out.println(" map " + mapId + " at " + p + " leaf, " + count + " rows"); writer.println(" map " + mapId + " at " + p + " leaf, " + count + " rows");
} }
p += len; p += len;
length -= len; length -= len;
} }
} }
} catch (IOException e) { } catch (IOException e) {
System.out.println("ERROR: " + e); writer.println("ERROR: " + e);
} finally { } finally {
try { try {
file.close(); file.close();
...@@ -100,7 +117,7 @@ public class Dump { ...@@ -100,7 +117,7 @@ public class Dump {
// ignore // ignore
} }
} }
System.out.println(); writer.println();
} }
} }
...@@ -482,7 +482,7 @@ public class Page { ...@@ -482,7 +482,7 @@ public class Page {
buff.getInt(); buff.getInt();
long id = buff.getLong(); long id = buff.getLong();
if (id != map.getId()) { if (id != map.getId()) {
throw new RuntimeException("Page map id missmatch, expected " + map.getId() + " got " + id); throw new RuntimeException("Page map id mismatch, expected " + map.getId() + " got " + id);
} }
boolean node = buff.get() == 1; boolean node = buff.get() == 1;
if (node) { if (node) {
...@@ -541,7 +541,6 @@ public class Page { ...@@ -541,7 +541,6 @@ public class Page {
/** /**
* Get the maximum length in bytes to store temporary records, recursively. * Get the maximum length in bytes to store temporary records, recursively.
* *
* @param pageId the new page id
* @return the next page id * @return the next page id
*/ */
int getMaxLengthTempRecursive() { int getMaxLengthTempRecursive() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论