mannoopj commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r2728104431


##########
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;

Review Comment:
   `read()` can throw UncheckedIOException, IllegalStateException for a missing 
or non-directory path, and RuntimeException for invalid bootstrap contents.



-- 
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]

Reply via email to