提交 06e97e0e authored 作者: Thomas Mueller's avatar Thomas Mueller

A persistent tree map.

上级 4550a0f6
......@@ -39,11 +39,10 @@ public class TestTreeMapStore extends TestBase {
}
private void testBtreeStore() {
String fileName = getBaseDir() + "/data.h3";
String fileName = getBaseDir() + "/testBtreeStore.h3";
FileUtils.delete(fileName);
BtreeMapStore s = BtreeMapStore.open(fileName);
BtreeMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
// int count = 0;
int count = 2000;
// Profiler p = new Profiler();
// p.startCollecting();
......@@ -84,7 +83,7 @@ public class TestTreeMapStore extends TestBase {
}
private void testDefragment() {
String fileName = getBaseDir() + "/data.h3";
String fileName = getBaseDir() + "/testDefragment.h3";
FileUtils.delete(fileName);
long initialLength = 0;
for (int j = 0; j < 20; j++) {
......@@ -125,7 +124,7 @@ public class TestTreeMapStore extends TestBase {
}
private void testReuseSpace() {
String fileName = getBaseDir() + "/data.h3";
String fileName = getBaseDir() + "/testReuseSpace.h3";
FileUtils.delete(fileName);
long initialLength = 0;
for (int j = 0; j < 10; j++) {
......@@ -150,7 +149,7 @@ public class TestTreeMapStore extends TestBase {
}
private void testRandom() {
String fileName = getBaseDir() + "/data.h3";
String fileName = getBaseDir() + "/testRandom.h3";
FileUtils.delete(fileName);
BtreeMapStore s = BtreeMapStore.open(fileName);
BtreeMap<Integer, Integer> m = s.openMap("data", Integer.class, Integer.class);
......@@ -198,7 +197,7 @@ public class TestTreeMapStore extends TestBase {
}
private void testKeyValueClasses() {
String fileName = getBaseDir() + "/data.h3";
String fileName = getBaseDir() + "/testKeyValueClasses.h3";
FileUtils.delete(fileName);
BtreeMapStore s = BtreeMapStore.open(fileName);
BtreeMap<Integer, String> is = s.openMap("intString", Integer.class, String.class);
......@@ -235,7 +234,7 @@ public class TestTreeMapStore extends TestBase {
}
private void testIterate() {
String fileName = getBaseDir() + "/data.h3";
String fileName = getBaseDir() + "/testIterate.h3";
FileUtils.delete(fileName);
BtreeMapStore s = BtreeMapStore.open(fileName);
BtreeMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
......@@ -268,7 +267,7 @@ public class TestTreeMapStore extends TestBase {
}
private void testSimple() {
String fileName = getBaseDir() + "/data.h3";
String fileName = getBaseDir() + "/testSimple.h3";
FileUtils.delete(fileName);
BtreeMapStore s = BtreeMapStore.open(fileName);
BtreeMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
......
......@@ -81,8 +81,6 @@ public class BtreeMapStore {
private int lastBlockId;
private int loadCount;
// TODO support quota (per map, per storage)
// TODO support r-tree
// TODO support triggers and events (possibly on a different layer)
......@@ -210,16 +208,12 @@ public class BtreeMapStore {
}
}
public String toString() {
return "cache size: " + cache.size() + " loadCount: " + loadCount + "\n" + blocks.toString().replace('\n', ' ');
}
private static RuntimeException convert(Exception e) {
throw new RuntimeException("Exception: " + e, e);
}
/**
* Close the file.
* Close the file. Uncommitted changes are ignored.
*/
public void close() {
store();
......@@ -249,14 +243,16 @@ public class BtreeMapStore {
}
/**
* Persist all changes to disk.
* Commit all changes and persist them to disk.
*
* @return the transaction id
*/
public void store() {
public long store() {
if (!meta.isChanged() && mapsChanged.size() == 0) {
// TODO truncate file if empty
return;
return transaction;
}
commit();
long trans = commit();
// the length estimate is not correct,
// as we don't know the exact positions and entry counts
......@@ -359,6 +355,7 @@ public class BtreeMapStore {
writeHeader();
mapsChanged.clear();
temp.clear();
return trans;
}
private long allocateBlock(long length) {
......@@ -697,7 +694,7 @@ public class BtreeMapStore {
*
* @param string the string to log
*/
public void log(String string) {
void log(String string) {
// TODO logging
// System.out.println(string);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论