Skip to content

Commit

Permalink
Merge pull request #3952 from andreitokar/issue-3909
Browse files Browse the repository at this point in the history
Prevent non-stop page rewriting within an idle database
  • Loading branch information
andreitokar committed Dec 22, 2023
2 parents 97fd15c + 0cc81db commit 3525a20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions h2/src/main/org/h2/mvstore/MVStore.java
Expand Up @@ -123,7 +123,7 @@ to a map (possibly the metadata map) -
/**
* A persistent storage for maps.
*/
public class MVStore implements AutoCloseable {
public final class MVStore implements AutoCloseable {

/**
* Store is open.
Expand Down Expand Up @@ -1265,8 +1265,8 @@ void beforeWrite(MVMap<?, ?> map) {
fileStore.isRegularMap(map)) {
saveNeeded = false;
// check again, because it could have been written by now
if (autoCommitMemory > 0 && needStore()) {
// if unsaved memory creation rate is to high,
if (needStore()) {
// if unsaved memory creation rate is too high,
// some back pressure need to be applied
// to slow things down and avoid OOME
if (requireStore() && !map.isSingleWriter()) {
Expand Down
8 changes: 6 additions & 2 deletions h2/src/main/org/h2/mvstore/RandomAccessStore.java
Expand Up @@ -43,7 +43,7 @@ public abstract class RandomAccessStore extends FileStore<SFChunk>

private long reservedLow;
private long reservedHigh;

private boolean stopIdleHousekeeping;

public RandomAccessStore(Map<String, Object> config) {
super(config);
Expand Down Expand Up @@ -702,10 +702,13 @@ private void shrinkIfPossible(int minPercent) {

@Override
protected void doHousekeeping(MVStore mvStore) throws InterruptedException {
boolean idle = isIdle();
if (idle && stopIdleHousekeeping) {
return;
}
int autoCommitMemory = mvStore.getAutoCommitMemory();
int fillRate = getFillRate();
if (isFragmented() && fillRate < getAutoCompactFillRate()) {

mvStore.tryExecuteUnderStoreLock(() -> {
int moveSize = 2 * autoCommitMemory;
if (isIdle()) {
Expand All @@ -731,6 +734,7 @@ protected void doHousekeeping(MVStore mvStore) throws InterruptedException {
return true;
});
}
stopIdleHousekeeping = idle && getFillRate() <= fillRate && getRewritableChunksFillRate() <= chunksFillRate;
}

private int getTargetFillRate() {
Expand Down

0 comments on commit 3525a20

Please sign in to comment.