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

review comments from @grandinj

上级 c4ce9e65
...@@ -361,7 +361,11 @@ public class Page { ...@@ -361,7 +361,11 @@ public class Page {
* @return the page with the entries after the split index * @return the page with the entries after the split index
*/ */
Page split(int at) { Page split(int at) {
return isLeaf() ? splitLeaf(at) : splitNode(at); Page page = isLeaf() ? splitLeaf(at) : splitNode(at);
if(isPersistent()) {
recalculateMemory();
}
return page;
} }
private Page splitLeaf(int at) { private Page splitLeaf(int at) {
...@@ -382,10 +386,6 @@ public class Page { ...@@ -382,10 +386,6 @@ public class Page {
bKeys, bValues, bKeys, bValues,
null, null,
b, 0); b, 0);
if(isPersistent()) {
recalculateMemory();
newPage.recalculateMemory();
}
return newPage; return newPage;
} }
...@@ -417,10 +417,6 @@ public class Page { ...@@ -417,10 +417,6 @@ public class Page {
bKeys, null, bKeys, null,
bChildren, bChildren,
t, 0); t, 0);
if(isPersistent()) {
recalculateMemory();
newPage.recalculateMemory();
}
return newPage; return newPage;
} }
...@@ -918,30 +914,24 @@ public class Page { ...@@ -918,30 +914,24 @@ public class Page {
} }
private void addMemory(int mem) { private void addMemory(int mem) {
if(!isPersistent()) {
throw DataUtils.newIllegalStateException(
DataUtils.ERROR_INTERNAL, "Memory calculation error2");
}
memory += mem; memory += mem;
} }
private void recalculateMemory() { private void recalculateMemory() {
if(isPersistent()) { int mem = DataUtils.PAGE_MEMORY;
int mem = DataUtils.PAGE_MEMORY; DataType keyType = map.getKeyType();
DataType keyType = map.getKeyType(); for (int i = 0; i < keys.length; i++) {
mem += keyType.getMemory(keys[i]);
}
if (this.isLeaf()) {
DataType valueType = map.getValueType();
for (int i = 0; i < keys.length; i++) { for (int i = 0; i < keys.length; i++) {
mem += keyType.getMemory(keys[i]); mem += valueType.getMemory(values[i]);
} }
if (this.isLeaf()) { } else {
DataType valueType = map.getValueType(); mem += this.getRawChildPageCount() * DataUtils.PAGE_MEMORY_CHILD;
for (int i = 0; i < keys.length; i++) {
mem += valueType.getMemory(values[i]);
}
} else {
mem += this.getRawChildPageCount() * DataUtils.PAGE_MEMORY_CHILD;
}
addMemory(mem - memory);
} }
addMemory(mem - memory);
} }
void setVersion(long version) { void setVersion(long version) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论