提交 6b846676 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Implement MVPrimaryIndex.getDiskSpaceUsed()

上级 1393df91
......@@ -54,6 +54,11 @@ public abstract class Page implements Cloneable
*/
private int memory;
/**
* Amount of used disk space by this page only in persistent case.
*/
private int diskSpaceUsed;
/**
* The keys.
*/
......@@ -672,6 +677,7 @@ public abstract class Page implements Cloneable
if (isLeaf()) {
readPayLoad(buff);
}
diskSpaceUsed = maxLength;
recalculateMemory();
}
......@@ -748,7 +754,7 @@ public abstract class Page implements Cloneable
// for a longer time
store.cachePage(this);
}
long max = DataUtils.getPageMaxLength(pos);
int max = DataUtils.getPageMaxLength(pos);
chunk.maxLen += max;
chunk.maxLenLive += max;
chunk.pageCount++;
......@@ -759,6 +765,7 @@ public abstract class Page implements Cloneable
// when the next chunk is stored
map.removePage(pos, memory);
}
diskSpaceUsed = max != DataUtils.PAGE_LARGE ? max : pageLength;
return typePos + 1;
}
......@@ -805,6 +812,27 @@ public abstract class Page implements Cloneable
return 0;
}
/**
* Amount of used disk space in persistent case including child pages.
*
* @return amount of used disk space in persistent case
*/
public long getDiskSpaceUsed() {
long r = 0;
if (isPersistent()) {
r += diskSpaceUsed;
}
if (!isLeaf()) {
for (int i = 0; i < getRawChildPageCount(); i++) {
long pos = getChildPagePos(i);
if (pos != 0) {
r += getChildPage(i).getDiskSpaceUsed();
}
}
}
return r;
}
final void addMemory(int mem) {
memory += mem;
}
......
......@@ -19,8 +19,10 @@ import org.h2.index.BaseIndex;
import org.h2.index.Cursor;
import org.h2.index.IndexType;
import org.h2.message.DbException;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.tx.Transaction;
import org.h2.mvstore.tx.TransactionMap;
import org.h2.mvstore.tx.VersionedValue;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
......@@ -358,8 +360,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public long getDiskSpaceUsed() {
// TODO estimate disk space usage
return 0;
return dataMap.map.getRootPage().getDiskSpaceUsed();
}
public String getMapName() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论