mannoopj commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r2728085348
##########
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/BootstrapDirectory.java:
##########
@@ -19,65 +19,33 @@
import org.apache.kafka.metadata.util.BatchFileReader;
import org.apache.kafka.metadata.util.BatchFileReader.BatchAndType;
-import org.apache.kafka.metadata.util.BatchFileWriter;
import org.apache.kafka.server.common.ApiMessageAndVersion;
-import org.apache.kafka.server.common.MetadataVersion;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Objects;
-
-import static java.nio.file.StandardCopyOption.ATOMIC_MOVE;
-import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
/**
- * A read-only class that holds the controller bootstrap metadata. A file
named "bootstrap.checkpoint" is used and the
- * format is the same as a KRaft snapshot.
+ * Abstraction for reading controller bootstrap metadata from disk.
*/
-public class BootstrapDirectory {
- public static final String BINARY_BOOTSTRAP_FILENAME =
"bootstrap.checkpoint";
-
- private final String directoryPath;
+public interface BootstrapDirectory {
/**
- * Create a new BootstrapDirectory object.
+ * Read the bootstrap metadata from the configured location.
*
- * @param directoryPath The path to the directory with the bootstrap
file.
+ * @return the loaded {@link BootstrapMetadata}
+ * @throws Exception if the metadata cannot be read
*/
- public BootstrapDirectory(
- String directoryPath
- ) {
- this.directoryPath = Objects.requireNonNull(directoryPath);
- }
-
- public BootstrapMetadata read() throws Exception {
- Path path = Paths.get(directoryPath);
- if (!Files.isDirectory(path)) {
- if (Files.exists(path)) {
- throw new RuntimeException("Path " + directoryPath + " exists,
but is not " +
- "a directory.");
- } else {
- throw new RuntimeException("No such directory as " +
directoryPath);
- }
- }
- Path binaryBootstrapPath = Paths.get(directoryPath,
BINARY_BOOTSTRAP_FILENAME);
- if (!Files.exists(binaryBootstrapPath)) {
- return readFromConfiguration();
- } else {
- return readFromBinaryFile(binaryBootstrapPath.toString());
- }
- }
-
- BootstrapMetadata readFromConfiguration() {
- return
BootstrapMetadata.fromVersion(MetadataVersion.latestProduction(), "the default
bootstrap");
- }
+ BootstrapMetadata read() throws Exception;
- BootstrapMetadata readFromBinaryFile(String binaryPath) throws Exception {
+ /**
+ * Read bootstrap metadata from the given binary file path.
+ *
+ * @param binaryPath the path to the binary bootstrap file
+ * @return the loaded {@link BootstrapMetadata}
+ * @throws Exception if the metadata cannot be read
+ */
+ default BootstrapMetadata readFromBinaryFile(String binaryPath) throws
Exception {
Review Comment:
If a read() implementation decides to read from a binary checkpoint file, it
can reuse the shared helper BootstrapDirectory.readFromBinaryFile to parse it.
Both LegacyBootstrapDirectory and TestBootstrapDirectory use it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]