Skip to content

Commit

Permalink
write "clean shutdown" mark into backup
Browse files Browse the repository at this point in the history
  • Loading branch information
andreitokar committed Jul 9, 2024
1 parent d621df2 commit b452722
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions h2/src/main/org/h2/mvstore/FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ protected void writeCleanShutdown() {
if (!isReadOnly()) {
saveChunkLock.lock();
try {
shrinkStoreIfPossible(0);
writeCleanShutdownMark();
sync();
assert validateFileLength("on close");
Expand Down
18 changes: 13 additions & 5 deletions h2/src/main/org/h2/mvstore/RandomAccessStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -594,7 +602,7 @@ private void compactMoveChunks(Iterable<SFChunk> move) {
}
}

private void writeStoreHeader() {
protected final void writeStoreHeader() {
StringBuilder buff = new StringBuilder(112);
if (hasPersistentData()) {
storeHeader.put(HDR_BLOCK, lastChunk.block);
Expand Down
3 changes: 3 additions & 0 deletions h2/src/main/org/h2/mvstore/SingleFileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b452722

Please sign in to comment.