Skip to content

Commit

Permalink
HDDS-12065. Checkpoint directory should be cleared on startup
Browse files Browse the repository at this point in the history
Change-Id: Ie840ca2d5ccbce02f7a19c66f10eb7b7f810d9f6
  • Loading branch information
swamirishi committed Jan 16, 2025
1 parent 49efad9 commit 00e354c
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -107,6 +110,13 @@ public void initialize(DBStore store, DBCheckpointMetrics metrics,
}
bootstrapTempData = Paths.get(tempData,
"temp-bootstrap-data").toFile();
if (bootstrapTempData.exists()) {
try {
deleteContents(bootstrapTempData.toPath());
} catch (IOException e) {
throw new ServletException(e);
}
}
if (!bootstrapTempData.exists() &&
!bootstrapTempData.mkdirs()) {
throw new ServletException("Failed to make:" + bootstrapTempData);
Expand All @@ -123,6 +133,24 @@ private boolean hasPermission(UserGroupInformation user) {
}
}

private void deleteContents(Path directory) throws IOException {
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file); // Delete file
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (!dir.equals(directory)) { // Skip deleting the root directory
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
}
});
}

/**
* Generates Snapshot checkpoint as tar ball.
* @param request the HTTP servlet request
Expand Down

0 comments on commit 00e354c

Please sign in to comment.