提交 8e520ee6 authored 作者: andrei's avatar andrei

put assertion in place first

filestore.clear() added, verifyLastChunk() moved to make assertions happy
上级 ea42b4a7
...@@ -99,6 +99,8 @@ public class FreeSpaceBitSet { ...@@ -99,6 +99,8 @@ public class FreeSpaceBitSet {
int start = set.nextClearBit(i); int start = set.nextClearBit(i);
int end = set.nextSetBit(start + 1); int end = set.nextSetBit(start + 1);
if (end < 0 || end - start >= blocks) { if (end < 0 || end - start >= blocks) {
assert set.nextSetBit(start) == -1 || set.nextSetBit(start) >= start + blocks :
"Double alloc: " + Integer.toHexString(start) + "/" + Integer.toHexString(blocks) + " " + this;
set.set(start, start + blocks); set.set(start, start + blocks);
return getPos(start); return getPos(start);
} }
...@@ -115,6 +117,8 @@ public class FreeSpaceBitSet { ...@@ -115,6 +117,8 @@ public class FreeSpaceBitSet {
public void markUsed(long pos, int length) { public void markUsed(long pos, int length) {
int start = getBlock(pos); int start = getBlock(pos);
int blocks = getBlockCount(length); int blocks = getBlockCount(length);
assert set.nextSetBit(start) == -1 || set.nextSetBit(start) >= start + blocks :
"Double mark: " + Integer.toHexString(start) + "/" + Integer.toHexString(blocks) + " " + this;
set.set(start, start + blocks); set.set(start, start + blocks);
} }
...@@ -127,6 +131,8 @@ public class FreeSpaceBitSet { ...@@ -127,6 +131,8 @@ public class FreeSpaceBitSet {
public void free(long pos, int length) { public void free(long pos, int length) {
int start = getBlock(pos); int start = getBlock(pos);
int blocks = getBlockCount(length); int blocks = getBlockCount(length);
assert set.nextClearBit(start) >= start + blocks :
"Double free: " + Integer.toHexString(start) + "/" + Integer.toHexString(blocks) + " " + this;
set.clear(start, start + blocks); set.clear(start, start + blocks);
} }
......
...@@ -664,8 +664,8 @@ public final class MVStore { ...@@ -664,8 +664,8 @@ public final class MVStore {
loadChunkMeta(); loadChunkMeta();
// read all chunk headers and footers within the retention time, // read all chunk headers and footers within the retention time,
// to detect unwritten data after a power failure // to detect unwritten data after a power failure
verifyLastChunks();
// build the free space list // build the free space list
fileStore.clear();
for (Chunk c : chunks.values()) { for (Chunk c : chunks.values()) {
if (c.pageCountLive == 0) { if (c.pageCountLive == 0) {
// remove this chunk in the next save operation // remove this chunk in the next save operation
...@@ -675,6 +675,9 @@ public final class MVStore { ...@@ -675,6 +675,9 @@ public final class MVStore {
int length = c.len * BLOCK_SIZE; int length = c.len * BLOCK_SIZE;
fileStore.markUsed(start, length); fileStore.markUsed(start, length);
} }
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse();
verifyLastChunks();
} }
private void loadChunkMeta() { private void loadChunkMeta() {
...@@ -1143,6 +1146,8 @@ public final class MVStore { ...@@ -1143,6 +1146,8 @@ public final class MVStore {
c.block = filePos / BLOCK_SIZE; c.block = filePos / BLOCK_SIZE;
c.len = length / BLOCK_SIZE; c.len = length / BLOCK_SIZE;
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse() + " " + c;
c.metaRootPos = metaRoot.getPos(); c.metaRootPos = metaRoot.getPos();
// calculate and set the likely next position // calculate and set the likely next position
if (reuseSpace) { if (reuseSpace) {
...@@ -1257,6 +1262,8 @@ public final class MVStore { ...@@ -1257,6 +1262,8 @@ public final class MVStore {
long start = c.block * BLOCK_SIZE; long start = c.block * BLOCK_SIZE;
int length = c.len * BLOCK_SIZE; int length = c.len * BLOCK_SIZE;
fileStore.free(start, length); fileStore.free(start, length);
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse();
} else { } else {
if (c.unused == 0) { if (c.unused == 0) {
c.unused = time; c.unused = time;
...@@ -2304,6 +2311,8 @@ public final class MVStore { ...@@ -2304,6 +2311,8 @@ public final class MVStore {
long start = c.block * BLOCK_SIZE; long start = c.block * BLOCK_SIZE;
int length = c.len * BLOCK_SIZE; int length = c.len * BLOCK_SIZE;
fileStore.free(start, length); fileStore.free(start, length);
assert fileStore.getFileLengthInUse() == measureFileLengthInUse() :
fileStore.getFileLengthInUse() + " != " + measureFileLengthInUse();
// overwrite the chunk, // overwrite the chunk,
// so it is not be used later on // so it is not be used later on
WriteBuffer buff = getWriteBuffer(); WriteBuffer buff = getWriteBuffer();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论