Skip to content

Commit

Permalink
fix for #3909
Browse files Browse the repository at this point in the history
  • Loading branch information
andreitokar committed Mar 23, 2024
1 parent 9faf805 commit b3c20eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/mvstore/FileStore.java
Expand Up @@ -423,7 +423,7 @@ public final void setAutoCommitDelay(int millis) {
stopBackgroundThread(millis >= 0);
// start the background thread if needed
if (millis > 0 && mvStore.isOpen()) {
int sleep = Math.max(1, millis / 5);
int sleep = Math.max(10, millis / 3);
BackgroundWriterThread t = new BackgroundWriterThread(this, sleep, toString());
if (backgroundWriterThread.compareAndSet(null, t)) {
t.start();
Expand Down
18 changes: 6 additions & 12 deletions h2/src/main/org/h2/mvstore/RandomAccessStore.java
Expand Up @@ -44,7 +44,6 @@ public abstract class RandomAccessStore extends FileStore<SFChunk>
private long reservedLow;
private long reservedHigh;
private boolean stopIdleHousekeeping;
private int restoreHousekeepingAtRate;

public RandomAccessStore(Map<String, Object> config) {
super(config);
Expand Down Expand Up @@ -705,11 +704,13 @@ private void shrinkIfPossible(int minPercent) {
protected void doHousekeeping(MVStore mvStore) throws InterruptedException {
boolean idle = isIdle();
int rewritableChunksFillRate = getRewritableChunksFillRate();
if (idle && stopIdleHousekeeping && rewritableChunksFillRate > restoreHousekeepingAtRate) {
if (idle && stopIdleHousekeeping) {
return;
}
int autoCommitMemory = mvStore.getAutoCommitMemory();
if (isFragmented() && getFillRate() < getAutoCompactFillRate()) {
int fileFillRate = getFillRate();
long chunksTotalSize = size() * fileFillRate / 100;
if (isFragmented() && fileFillRate < getAutoCompactFillRate()) {
mvStore.tryExecuteUnderStoreLock(() -> {
int moveSize = 2 * autoCommitMemory;
if (idle) {
Expand Down Expand Up @@ -739,15 +740,8 @@ protected void doHousekeeping(MVStore mvStore) throws InterruptedException {
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;
}
long currentTotalChunksSize = size() * getFillRate() / 100;
stopIdleHousekeeping = currentTotalChunksSize > chunksTotalSize || currentTotalChunksSize == chunksTotalSize && currentChunksFillRate <= chunksFillRate;
}
}

Expand Down

0 comments on commit b3c20eb

Please sign in to comment.