提交 932f95ac authored 作者: Thomas Mueller's avatar Thomas Mueller

Make changes to page references atomic

上级 79798338
......@@ -154,12 +154,14 @@ public class MVMap<K, V> extends AbstractMap<K, V>
Object k = p.getKey(at);
Page split = p.split(at);
Object[] keys = { k };
long[] children = { p.getPos(), split.getPos() };
Page[] childrenPages = { p, split };
Page.PageReference[] children = {
new Page.PageReference(p, p.getPos()),
new Page.PageReference(split, split.getPos()),
};
long[] counts = { p.getTotalCount(), split.getTotalCount() };
p = Page.create(this, writeVersion,
1, keys, null,
2, children, childrenPages, counts,
2, children, counts,
totalCount, 0, 0);
return p;
}
......
......@@ -57,7 +57,7 @@ public class MVMapConcurrent<K, V> extends MVMap<K, V> {
afterWrite();
}
}
@Override
protected void waitUntilWritten(long version) {
// no need to wait
......
......@@ -112,6 +112,9 @@ MVStore:
a map lookup when reading old data; also, this
old data map needs to be cleaned up somehow;
maybe using an additional timeout
- rollback of removeMap should restore the data -
which has big consequences, as the metadata map
would probably need references to the root nodes of all maps
*/
......@@ -823,11 +826,10 @@ public class MVStore {
/**
* Whether the chunk at the given position is live.
*
* @param pos the position of the page
* @param the chunk id
* @return true if it is live
*/
boolean isChunkLive(long pos) {
int chunkId = DataUtils.getPageChunkId(pos);
boolean isChunkLive(int chunkId) {
String s = meta.get(Chunk.getMetaKey(chunkId));
return s != null;
}
......@@ -2262,9 +2264,10 @@ public class MVStore {
}
/**
* Remove a map.
*
* @param map the map
* Remove a map. Please note rolling back this operation does not restore
* the data; if you need this ability, use Map.clear().
*
* @param map the map to remove
*/
public synchronized void removeMap(MVMap<?, ?> map) {
checkOpen();
......@@ -2397,7 +2400,7 @@ public class MVStore {
return;
}
autoCommitDelay = millis;
if (fileStore == null) {
if (fileStore == null || fileStore.isReadOnly()) {
return;
}
stopBackgroundThread();
......
......@@ -248,13 +248,16 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
Object k1 = getBounds(p);
Object k2 = getBounds(split);
Object[] keys = { k1, k2 };
long[] children = { p.getPos(), split.getPos(), 0 };
Page[] childrenPages = { p, split, null };
Page.PageReference[] children = {
new Page.PageReference(p, p.getPos()),
new Page.PageReference(split, split.getPos()),
new Page.PageReference(null, 0)
};
long[] counts = { p.getTotalCount(),
split.getTotalCount(), 0 };
p = Page.create(this, v,
2, keys, null,
3, children, childrenPages, counts,
3, children, counts,
totalCount, 0, 0);
// now p is a node; continues
}
......@@ -449,12 +452,22 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
}
private Page newPage(boolean leaf, long writeVersion) {
Object[] values = leaf ? new Object[4] : null;
long[] c = leaf ? null : new long[1];
Page[] cp = leaf ? null : new Page[1];
Object[] values;
Page.PageReference[] refs;
long[] c;
if (leaf) {
values = new Object[4];
refs = null;
c = null;
} else {
values = null;
refs = new Page.PageReference[] {
new Page.PageReference(null, 0)};
c = new long[1];
}
return Page.create(this, writeVersion,
0, new Object[4], values,
leaf ? 0 : 1, c, cp, c, 0, 0, 0);
leaf ? 0 : 1, refs, c, 0, 0, 0);
}
private static void move(Page source, Page target, int sourceIndex) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论