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

More efficient "file size in use" calculation

上级 df217319
...@@ -355,6 +355,10 @@ public class FileStore { ...@@ -355,6 +355,10 @@ public class FileStore {
return freeSpace.getFirstFree(); return freeSpace.getFirstFree();
} }
long getFileLengthInUse() {
return freeSpace.getLastFree();
}
/** /**
* Mark the file as empty. * Mark the file as empty.
*/ */
......
...@@ -170,6 +170,15 @@ public class FreeSpaceBitSet { ...@@ -170,6 +170,15 @@ public class FreeSpaceBitSet {
return getPos(set.nextClearBit(0)); return getPos(set.nextClearBit(0));
} }
/**
* Get the position of the last (infinite) free space.
*
* @return the position.
*/
public long getLastFree() {
return getPos(set.previousSetBit(set.size()-1) + 1);
}
@Override @Override
public String toString() { public String toString() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
......
...@@ -1527,19 +1527,24 @@ public final class MVStore { ...@@ -1527,19 +1527,24 @@ public final class MVStore {
} }
/** /**
* Get the position of the last used byte. * Get the position right after the last used byte.
* *
* @return the position * @return the position
*/ */
private long getFileLengthInUse() { private long getFileLengthInUse() {
long size = 2 * BLOCK_SIZE; long result = fileStore.getFileLengthInUse();
assert result == _getFileLengthInUse() : result + " != " + _getFileLengthInUse();
return result;
}
private long _getFileLengthInUse() {
long size = 2;
for (Chunk c : chunks.values()) { for (Chunk c : chunks.values()) {
if (c.len != Integer.MAX_VALUE) { if (c.len != Integer.MAX_VALUE) {
long x = (c.block + c.len) * BLOCK_SIZE; size = Math.max(size, c.block + c.len);
size = Math.max(size, x);
} }
} }
return size; return size * BLOCK_SIZE;
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论