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 10, 2025
1 parent 49efad9 commit b6ea053
Showing 1 changed file with 25 additions and 1 deletion.
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 @@ -81,7 +84,7 @@ public void initialize(DBStore store, DBCheckpointMetrics metrics,
Collection<String> allowedAdminUsers,
Collection<String> allowedAdminGroups,
boolean isSpnegoAuthEnabled)
throws ServletException {
throws ServletException, IOException {

dbStore = store;
dbMetrics = metrics;
Expand All @@ -107,6 +110,9 @@ public void initialize(DBStore store, DBCheckpointMetrics metrics,
}
bootstrapTempData = Paths.get(tempData,
"temp-bootstrap-data").toFile();
if (bootstrapTempData.exists()) {
deleteContents(bootstrapTempData.toPath());
}
if (!bootstrapTempData.exists() &&
!bootstrapTempData.mkdirs()) {
throw new ServletException("Failed to make:" + bootstrapTempData);
Expand All @@ -123,6 +129,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 b6ea053

Please sign in to comment.