提交 a7fe407e authored 作者: Thomas Mueller's avatar Thomas Mueller

Cache size limit could be exceeded for certain queries, leading to an…

Cache size limit could be exceeded for certain queries, leading to an OutOfMemoryError in some cases.
上级 a810da9f
......@@ -172,14 +172,20 @@ public abstract class PageBtree extends Page {
SearchRow row = rows[at];
if (row == null) {
row = index.readRow(data, offsets[at], onlyPosition, true);
memoryChange();
rows[at] = row;
} else if (!index.hasData(row)) {
row = index.readRow(row.getKey());
memoryChange();
rows[at] = row;
}
return row;
}
protected void memoryChange() {
// nothing to do
}
/**
* Split the index page at the given point.
*
......
......@@ -29,6 +29,8 @@ import org.h2.value.ValueNull;
*/
public class PageBtreeIndex extends PageIndex {
private static int memoryChangeRequired;
private PageStore store;
private RegularTable tableData;
private boolean needRebuild;
......@@ -448,4 +450,17 @@ public class PageBtreeIndex extends PageIndex {
}
}
/**
* Check if calculating the memory is required.
*
* @return true if it is
*/
public boolean isMemoryChangeRequired() {
if (memoryChangeRequired-- <= 0) {
memoryChangeRequired = 10;
return true;
}
return false;
}
}
......@@ -97,7 +97,9 @@ public class PageBtreeLeaf extends PageBtree {
}
int addRowTry(SearchRow row) {
return addRow(row, true);
int x = addRow(row, true);
memoryChange();
return x;
}
private int addRow(SearchRow row, boolean tryOnly) {
......@@ -159,7 +161,6 @@ public class PageBtreeLeaf extends PageBtree {
rows = insert(rows, entryCount, x, row);
entryCount++;
index.getPageStore().update(this);
memoryChange();
return -1;
}
......@@ -190,7 +191,6 @@ public class PageBtreeLeaf extends PageBtree {
offsets = remove(offsets, entryCount + 1, at);
add(offsets, at, entryCount, rowLength);
rows = remove(rows, entryCount + 1, at);
memoryChange();
}
int getEntryCount() {
......@@ -204,6 +204,8 @@ public class PageBtreeLeaf extends PageBtree {
p2.addRow(getRow(splitPoint), false);
removeRow(splitPoint);
}
memoryChange();
p2.memoryChange();
return p2;
}
......@@ -227,6 +229,7 @@ public class PageBtreeLeaf extends PageBtree {
return row;
}
removeRow(at);
memoryChange();
index.getPageStore().update(this);
if (at == entryCount) {
// the last row changed
......@@ -359,7 +362,10 @@ public class PageBtreeLeaf extends PageBtree {
store.free(getPos());
}
private void memoryChange() {
protected void memoryChange() {
if (!index.isMemoryChangeRequired()) {
return;
}
int memory = Constants.MEMORY_PAGE_BTREE + index.getPageStore().getPageSize();
if (rows != null) {
memory += getEntryCount() * (4 + Constants.MEMORY_POINTER);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论