diff --git a/h2/src/main/org/h2/mvstore/RandomAccessStore.java b/h2/src/main/org/h2/mvstore/RandomAccessStore.java index 148d801fa9..4f6a14a1f5 100644 --- a/h2/src/main/org/h2/mvstore/RandomAccessStore.java +++ b/h2/src/main/org/h2/mvstore/RandomAccessStore.java @@ -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) {