Skip to content

Commit

Permalink
Merge pull request h2database#4094 from andreitokar/issue_4075
Browse files Browse the repository at this point in the history
Issue 4075
  • Loading branch information
andreitokar authored Jul 31, 2024
2 parents 9d533f1 + 693590d commit 74ed2b5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion h2/src/main/org/h2/mvstore/FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,9 @@ private boolean isSeasonedChunk(C chunk, long time) {
}

private boolean isRewritable(C chunk, long time) {
return chunk.isRewritable() && isSeasonedChunk(chunk, time);
return chunk.isRewritable() && isSeasonedChunk(chunk, time)
// to prevent last saved chunk from being re-written as it may cause "endless" re-write loop
&& chunk.version < getMvStore().getCurrentVersion() - 1;
}

/**
Expand Down
1 change: 1 addition & 0 deletions h2/src/main/org/h2/mvstore/MVStoreTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public static void dump(String fileName, Writer writer, boolean details) {
Chunk c;
try {
c = new SFChunk(Chunk.readChunkHeader(buffer));
c.block = pos / blockSize;
} catch (MVStoreException e) {
// Chunks are not always contiguous (due to chunk compaction/move/drop and space re-use)
// Blocks following a chunk can therefore contain something else than a valid chunk header
Expand Down
4 changes: 2 additions & 2 deletions h2/src/main/org/h2/mvstore/RandomAccessStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,11 @@ private boolean moveChunk(SFChunk chunk, long reservedAreaLow, long reservedArea
assert reservedAreaHigh > 0 || block <= chunk.block : block + " " + chunk;
ByteBuffer readBuff = readFully(chunk, start, length);
writeFully(null, pos, readBuff);
free(start, length);
// can not set chunk's new block/len until it's fully written at new location,
// can not set chunk's new block until it's fully written at new location,
// because concurrent reader can pick it up prematurely,
chunk.block = block;
chunk.next = 0;
free(start, length);
saveChunkMetadataChanges(chunk);
return true;
}
Expand Down

0 comments on commit 74ed2b5

Please sign in to comment.