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

Implement MVPrimaryIndex.getDiskSpaceUsed()

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