提交 c81ea7f4 authored 作者: andrei's avatar andrei

fix DEFRAG

上级 9ca551f6
...@@ -1104,36 +1104,26 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1104,36 +1104,26 @@ public class MVMap<K, V> extends AbstractMap<K, V>
*/ */
final void copyFrom(MVMap<K, V> sourceMap) { final void copyFrom(MVMap<K, V> sourceMap) {
beforeWrite(); beforeWrite();
setRoot(copy(sourceMap.getRootPage(), null)); setRoot(copy(sourceMap.getRootPage()));
} }
private Page copy(Page source, CursorPos parent) { private Page copy(Page source) {
Page target = source.copy(this); Page target = source.copy(this);
store.registerUnsavedPage(target.getMemory()); store.registerUnsavedPage(target.getMemory());
if (!source.isLeaf()) { if (!source.isLeaf()) {
CursorPos pos = new CursorPos(target, 0, parent);
for (int i = 0; i < getChildPageCount(target); i++) { for (int i = 0; i < getChildPageCount(target); i++) {
if (source.getChildPagePos(i) != 0) { if (source.getChildPagePos(i) != 0) {
// position 0 means no child // position 0 means no child
// (for example the last entry of an r-tree node) // (for example the last entry of an r-tree node)
// (the MVMap is also used for r-trees for compacting) // (the MVMap is also used for r-trees for compacting)
pos.index = i; Page child = copy(source.getChildPage(i));
Page child = copy(source.getChildPage(i), pos);
target.setChild(i, child); target.setChild(i, child);
pos.page = target;
} }
} }
if(store.isSaveNeeded()) { setRoot(target);
Page child = target;
for(CursorPos p = parent; p != null; p = p.parent) {
p.page.setChild(p.index, child);
child = p.page;
}
setRoot(child);
beforeWrite(); beforeWrite();
} }
}
return target; return target;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论