提交 74c90932 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVRTreeMap: never free a page twice

上级 5c475c6f
......@@ -74,7 +74,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
/**
* Create a copy of a page, if the write version is higher than the current
* version.
* version. If a copy is created, the old page is marked as deleted.
*
* @param p the page
* @param writeVersion the write version
......@@ -674,7 +674,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
if (p.getKeyCount() == 0) {
p.setChild(index, c);
p.setCounts(index, c);
removePage(p.getPos());
p.removePage();
} else {
p.remove(index);
}
......
......@@ -273,7 +273,7 @@ public class Page {
* @return a page with the given version
*/
public Page copy(long version) {
map.removePage(pos);
removePage();
Page newPage = create(map, version,
keyCount, keys, values, children, childrenPages,
counts, totalCount,
......@@ -552,7 +552,7 @@ public class Page {
}
}
}
map.removePage(pos);
removePage();
}
/**
......@@ -934,4 +934,11 @@ public class Page {
this.version = version;
}
/**
* Remove the page.
*/
public void removePage() {
map.removePage(pos);
}
}
......@@ -155,7 +155,7 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
result = p.getValue(i);
p.remove(i);
if (p.getKeyCount() == 0) {
removePage(p.getPos());
p.removePage();
}
break;
}
......@@ -165,9 +165,14 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
for (int i = 0; i < p.getKeyCount(); i++) {
if (contains(p, i, key)) {
Page cOld = p.getChildPage(i);
// this will mark the old page as deleted
// so we need to update the parent in any case
// (otherwise the old page might be deleted again)
Page c = copyOnWrite(cOld, writeVersion);
long oldSize = c.getTotalCount();
result = remove(c, writeVersion, key);
p.setChild(i, c);
p.setCounts(i, c);
if (oldSize == c.getTotalCount()) {
continue;
}
......@@ -175,7 +180,7 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
// this child was deleted
p.remove(i);
if (p.getKeyCount() == 0) {
removePage(p.getPos());
p.removePage();
}
break;
}
......@@ -183,8 +188,6 @@ public class MVRTreeMap<V> extends MVMap<SpatialKey, V> {
if (!keyType.isInside(key, oldBounds)) {
p.setKey(i, getBounds(c));
}
p.setChild(i, c);
p.setCounts(i, c);
break;
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论