From b452722de6b9530e30ad644201f19cabf2d5526d Mon Sep 17 00:00:00 2001 From: Andrei Tokar Date: Mon, 8 Jul 2024 22:51:54 -0400 Subject: [PATCH] write "clean shutdown" mark into backup --- h2/src/main/org/h2/mvstore/FileStore.java | 1 + .../main/org/h2/mvstore/RandomAccessStore.java | 18 +++++++++++++----- .../main/org/h2/mvstore/SingleFileStore.java | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/h2/src/main/org/h2/mvstore/FileStore.java b/h2/src/main/org/h2/mvstore/FileStore.java index fd71ed51f4..90fe77bb10 100644 --- a/h2/src/main/org/h2/mvstore/FileStore.java +++ b/h2/src/main/org/h2/mvstore/FileStore.java @@ -806,6 +806,7 @@ protected void writeCleanShutdown() { if (!isReadOnly()) { saveChunkLock.lock(); try { + shrinkStoreIfPossible(0); writeCleanShutdownMark(); sync(); assert validateFileLength("on close"); diff --git a/h2/src/main/org/h2/mvstore/RandomAccessStore.java b/h2/src/main/org/h2/mvstore/RandomAccessStore.java index 146d6594b7..43d55ffbb6 100644 --- a/h2/src/main/org/h2/mvstore/RandomAccessStore.java +++ b/h2/src/main/org/h2/mvstore/RandomAccessStore.java @@ -406,23 +406,31 @@ private boolean shouldWriteStoreHeader(SFChunk c, boolean storeAtEndOfFile) { } } - if (storeHeader.remove(HDR_CLEAN) != null) { + if (clearCleanShutdownMark()) { writeStoreHeader = true; } return writeStoreHeader; } + private boolean clearCleanShutdownMark() { + return storeHeader.remove(HDR_CLEAN) != null; + } + + protected final void removeCleanShutdownMark() { + if (clearCleanShutdownMark()) { + writeStoreHeader(); + } + } + @Override protected final void writeCleanShutdownMark() { - shrinkStoreIfPossible(0); storeHeader.put(HDR_CLEAN, 1); writeStoreHeader(); } @Override protected final void adjustStoreToLastChunk() { - storeHeader.put(HDR_CLEAN, 1); - writeStoreHeader(); + writeCleanShutdownMark(); readStoreHeader(false); } @@ -594,7 +602,7 @@ private void compactMoveChunks(Iterable move) { } } - private void writeStoreHeader() { + protected final void writeStoreHeader() { StringBuilder buff = new StringBuilder(112); if (hasPersistentData()) { storeHeader.put(HDR_BLOCK, lastChunk.block); diff --git a/h2/src/main/org/h2/mvstore/SingleFileStore.java b/h2/src/main/org/h2/mvstore/SingleFileStore.java index c4d42533bd..76522fabce 100644 --- a/h2/src/main/org/h2/mvstore/SingleFileStore.java +++ b/h2/src/main/org/h2/mvstore/SingleFileStore.java @@ -243,6 +243,9 @@ public void backup(ZipOutputStream out) throws IOException { mvStore.executeFilestoreOperation(() -> { try { IOUtils.copy(in, copied, out); + writeCleanShutdownMark(); + IOUtils.copy(in, out, 0, 2 * BLOCK_SIZE); + removeCleanShutdownMark(); } catch (IOException ex) { throw new RuntimeException(ex); }