提交 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> ...@@ -154,12 +154,14 @@ public class MVMap<K, V> extends AbstractMap<K, V>
Object k = p.getKey(at); Object k = p.getKey(at);
Page split = p.split(at); Page split = p.split(at);
Object[] keys = { k }; Object[] keys = { k };
long[] children = { p.getPos(), split.getPos() }; Page.PageReference[] children = {
Page[] childrenPages = { p, split }; new Page.PageReference(p, p.getPos()),
new Page.PageReference(split, split.getPos()),
};
long[] counts = { p.getTotalCount(), split.getTotalCount() }; long[] counts = { p.getTotalCount(), split.getTotalCount() };
p = Page.create(this, writeVersion, p = Page.create(this, writeVersion,
1, keys, null, 1, keys, null,
2, children, childrenPages, counts, 2, children, counts,
totalCount, 0, 0); totalCount, 0, 0);
return p; return p;
} }
......
...@@ -112,6 +112,9 @@ MVStore: ...@@ -112,6 +112,9 @@ MVStore:
a map lookup when reading old data; also, this a map lookup when reading old data; also, this
old data map needs to be cleaned up somehow; old data map needs to be cleaned up somehow;
maybe using an additional timeout 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 { ...@@ -823,11 +826,10 @@ public class MVStore {
/** /**
* Whether the chunk at the given position is live. * 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 * @return true if it is live
*/ */
boolean isChunkLive(long pos) { boolean isChunkLive(int chunkId) {
int chunkId = DataUtils.getPageChunkId(pos);
String s = meta.get(Chunk.getMetaKey(chunkId)); String s = meta.get(Chunk.getMetaKey(chunkId));
return s != null; return s != null;
} }
...@@ -2262,9 +2264,10 @@ public class MVStore { ...@@ -2262,9 +2264,10 @@ public class MVStore {
} }
/** /**
* Remove a 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 * @param map the map to remove
*/ */
public synchronized void removeMap(MVMap<?, ?> map) { public synchronized void removeMap(MVMap<?, ?> map) {
checkOpen(); checkOpen();
...@@ -2397,7 +2400,7 @@ public class MVStore { ...@@ -2397,7 +2400,7 @@ public class MVStore {
return; return;
} }
autoCommitDelay = millis; autoCommitDelay = millis;
if (fileStore == null) { if (fileStore == null || fileStore.isReadOnly()) {
return; return;
} }
stopBackgroundThread(); stopBackgroundThread();
......
...@@ -248,13 +248,16 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> { ...@@ -248,13 +248,16 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
Object k1 = getBounds(p); Object k1 = getBounds(p);
Object k2 = getBounds(split); Object k2 = getBounds(split);
Object[] keys = { k1, k2 }; Object[] keys = { k1, k2 };
long[] children = { p.getPos(), split.getPos(), 0 }; Page.PageReference[] children = {
Page[] childrenPages = { p, split, null }; new Page.PageReference(p, p.getPos()),
new Page.PageReference(split, split.getPos()),
new Page.PageReference(null, 0)
};
long[] counts = { p.getTotalCount(), long[] counts = { p.getTotalCount(),
split.getTotalCount(), 0 }; split.getTotalCount(), 0 };
p = Page.create(this, v, p = Page.create(this, v,
2, keys, null, 2, keys, null,
3, children, childrenPages, counts, 3, children, counts,
totalCount, 0, 0); totalCount, 0, 0);
// now p is a node; continues // now p is a node; continues
} }
...@@ -449,12 +452,22 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> { ...@@ -449,12 +452,22 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
} }
private Page newPage(boolean leaf, long writeVersion) { private Page newPage(boolean leaf, long writeVersion) {
Object[] values = leaf ? new Object[4] : null; Object[] values;
long[] c = leaf ? null : new long[1]; Page.PageReference[] refs;
Page[] cp = leaf ? null : new Page[1]; 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, return Page.create(this, writeVersion,
0, new Object[4], values, 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) { private static void move(Page source, Page target, int sourceIndex) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论