Skip to content

Commit

Permalink
fix for h2database#3909
Browse files Browse the repository at this point in the history
  • Loading branch information
andreitokar committed Feb 24, 2024
1 parent d280e30 commit 9faf805
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions h2/src/main/org/h2/mvstore/RandomAccessStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,26 +721,34 @@ protected void doHousekeeping(MVStore mvStore) throws InterruptedException {
}

int chunksFillRate = getChunksFillRate();
int adjustedChunksFillRate = 50 + rewritableChunksFillRate / 2;
int fillRateToCompare = idle ? rewritableChunksFillRate : adjustedChunksFillRate;
int adjustedUpFillRate = 50 + rewritableChunksFillRate / 2;
int fillRateToCompare = idle ? rewritableChunksFillRate : adjustedUpFillRate;
if (fillRateToCompare < getTargetFillRate(idle)) {
int targetFillRate = idle ? adjustedUpFillRate : rewritableChunksFillRate;
mvStore.tryExecuteUnderStoreLock(() -> {
int writeLimit = autoCommitMemory;
if (!idle) {
writeLimit /= 4;
}
if (rewriteChunks(writeLimit, idle ? adjustedChunksFillRate : rewritableChunksFillRate)) {
if (rewriteChunks(writeLimit, targetFillRate)) {
dropUnusedChunks();
}
return true;
});
}
stopIdleHousekeeping = idle && getChunksFillRate() < chunksFillRate;
if (stopIdleHousekeeping) {
// this rate can change with the time, even when database is idle,
// since chunks become older and may become eligible for re-writing
restoreHousekeepingAtRate = getRewritableChunksFillRate() - 2;
}
stopIdleHousekeeping = false;
if (idle) {
int currentChunksFillRate = getChunksFillRate();
stopIdleHousekeeping = currentChunksFillRate <= chunksFillRate;
if (stopIdleHousekeeping) {
// this rate can change with the time, even when database is idle,
// since chunks become older and may become eligible for re-writing
rewritableChunksFillRate = getRewritableChunksFillRate();
restoreHousekeepingAtRate = rewritableChunksFillRate > currentChunksFillRate ?
(currentChunksFillRate + rewritableChunksFillRate) / 2 :
rewritableChunksFillRate - 2;
}
}
}

private int getTargetFillRate(boolean idle) {
Expand Down

0 comments on commit 9faf805

Please sign in to comment.