Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-05-21 Thread via GitHub


mannoopj commented on PR #20707:
URL: https://github.com/apache/kafka/pull/20707#issuecomment-4508617093

   I went with @kevin-wu24's suggestion here as it was the most straight 
forward solution. Restructuring the Test infra to avoid using BootstrapMetadata 
seems to me to be out of scope of this PR.


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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-05-19 Thread via GitHub


kevin-wu24 commented on PR #20707:
URL: https://github.com/apache/kafka/pull/20707#issuecomment-4492113746

   Hi @mannoopj,
   
   To me, the issue seems to be in step 4. In the current code, 
`KafkaClusterTestKit` formatting logic is using the 
`TestKitNodes.bootstrapMetadata` as the source of truth for feature levels, 
which does not mirror how the storage tool actually works. The storage tool 
takes the "defaults" from the supplied release-version, and then any manual 
feature overrides using `--feature=` take priority over that.
   
   I think a solution is that the `TestKitNodes` can have its 
`bootstrapMetadata`, but it should not be used within `KafkaClusterTestKit`. 
Instead, `TestKitNodes` should store `featureOverrides` and then the 
`KafkaClusterTestKit` formatting logic can match the logic of the storage tool. 
What do you think?


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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-05-19 Thread via GitHub


jsancio commented on PR #20707:
URL: https://github.com/apache/kafka/pull/20707#issuecomment-4491328374

   > This seems like an existing bug that never manifested. The problem now is 
Formatter needs a way to know if a feature is 0 or not. Since not writing 
FeatureLevelRecords set to 0 is correct and wanted behavior i think we need to 
pass in some sort of explicit list of features so that 
calculateEffectiveFeatureLevels can set these to 0.
   
   Yes, looks like the issue is with how the test is constructed. Can we avoid 
using BootstrapMetadata for bootstrapping the the cluster nodes? For example, 
can the test be configured using the Formatter directly?


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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-05-19 Thread via GitHub


mannoopj commented on PR #20707:
URL: https://github.com/apache/kafka/pull/20707#issuecomment-4491211040

   > @mannoopj there are test failures please take a look.
   
   The integration tests failure can be mapped out this way: 
   `On trunk:
 1. Test sets @ClusterFeature(feature = Feature.GROUP_VERSION, version = 0)
 2. RaftClusterInvocationContext builds newFeatureLevels map with 
group.version=0
 3. BootstrapMetadata.fromVersions() skips level 0 — 
nodes.bootstrapMetadata() has no GROUP_VERSION record (implicitly 0)
 4. KafkaClusterTestKit.formatNode() loops through 
bootstrapMetadata.records() — no GROUP_VERSION record found, so 
formatter.setFeatureLevel("group.version", 
 ...) is never called
 5. Formatter's calculateEffectiveFeatureLevels() sees GROUP_VERSION is 
missing, fills in default (e.g. 1) — writes bootstrap.checkpoint with 
GROUP_VERSION=1
 6. bootstrap.checkpoint is never read — KafkaClusterTestKit doesn't use 
KafkaRaftServer.initializeLogDirs() 
 7. ControllerServer gets nodes.bootstrapMetadata() directly — no 
GROUP_VERSION record
 8. ActivationRecordsGenerator writes bootstrapMetadata.records() to 
metadata log — no GROUP_VERSION record
 9. Broker sees no GROUP_VERSION in metadata log — level 0 — API disabled — 
test passes
 
 On your branch:
 1. Test sets @ClusterFeature(feature = Feature.GROUP_VERSION, version = 0)
 2. RaftClusterInvocationContext builds newFeatureLevels map with 
group.version=0
 3. BootstrapMetadata.fromVersions() skips level 0 — 
nodes.bootstrapMetadata() has no GROUP_VERSION record (implicitly 0)
 4. KafkaClusterTestKit.formatNode() loops through 
bootstrapMetadata.records() — no GROUP_VERSION record found, so 
formatter.setFeatureLevel("group.version", 
 ...) is never called
 5. Formatter's calculateEffectiveFeatureLevels() sees GROUP_VERSION is 
missing, fills in default (e.g. 1) — writes the zero checkpoint with 
GROUP_VERSION=1
 6. ControllerServer gets nodes.bootstrapMetadata() directly — no 
GROUP_VERSION record (still correct at this point)
 7. handleLoadBootstrap reads the zero checkpoint — finds GROUP_VERSION=1 — 
overwrites bootstrapMetadata with GROUP_VERSION=1
 8. ActivationRecordsGenerator writes the overwritten 
bootstrapMetadata.records() to metadata log — GROUP_VERSION=1
 9. Broker sees GROUP_VERSION=1 in metadata log — level 1 — API enabled — 
test fails`
 
   This seems like an existing bug that never manifested. The problem now is 
`Formatter' needs a way to know if a feature is 0 or not. Since not writing 
`FeatureLevelRecords` set to 0 is correct and wanted behavior i think we need 
to pass in some sort of explicit list of features so that 
`calculateEffectiveFeatureLevels` can set these to 0. 
   
   


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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-05-19 Thread via GitHub


jsancio commented on PR #20707:
URL: https://github.com/apache/kafka/pull/20707#issuecomment-4486522385

   @mannoopj there are test failures please take a look.


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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-05-14 Thread via GitHub


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


##
metadata/src/test/java/org/apache/kafka/metadata/bootstrap/BootstrapMetadataTest.java:
##
@@ -58,27 +53,27 @@ public class BootstrapMetadataTest {
 setFeatureLevel((short) 7), (short) 0));
 
 static class BootstrapTestDirectory implements AutoCloseable {
-File directory = null;
+private final Path directory;
 
-synchronized BootstrapTestDirectory createDirectory() {
-directory = TestUtils.tempDirectory("BootstrapTestDirectory");
-return this;
+static synchronized BootstrapTestDirectory createDirectory() {
+return new BootstrapTestDirectory();
 }

Review Comment:
   This was here originally from the already committed stand alone 
BootstrapTestDirectory file whose contents I copied over to 
BootstrapMetadataTest. I'll make this change as I agree, not sure why this was 
synchronized before. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-05-12 Thread via GitHub


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


##
metadata/src/test/java/org/apache/kafka/metadata/bootstrap/BootstrapMetadataTest.java:
##
@@ -58,27 +53,27 @@ public class BootstrapMetadataTest {
 setFeatureLevel((short) 7), (short) 0));
 
 static class BootstrapTestDirectory implements AutoCloseable {
-File directory = null;
+private final Path directory;
 
-synchronized BootstrapTestDirectory createDirectory() {
-directory = TestUtils.tempDirectory("BootstrapTestDirectory");
-return this;
+static synchronized BootstrapTestDirectory createDirectory() {
+return new BootstrapTestDirectory();
 }

Review Comment:
   Why is this synchronized? It does't read or modify any mutable shared state. 
This applies to all of the usage of the synchronized keyword in this type.



##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -477,6 +480,22 @@ private void formatNode(
 formatter.setIgnoreFormatted(false);
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
+
+List additionalRecords = new ArrayList<>();
+for (ApiMessageAndVersion record : 
nodes.bootstrapMetadata().records()) {
+if (record.message() instanceof FeatureLevelRecord 
featureRecord) {
+if 
(!featureRecord.name().equals(MetadataVersion.FEATURE_NAME)) {
+formatter.setFeatureLevel(featureRecord.name(), 
featureRecord.featureLevel());
+}
+} else if (!(record.message() instanceof 
UserScramCredentialRecord)) {
+additionalRecords.add(record);
+} else {
+throw new RuntimeException("UserScramCredentialRecord is 
not supported in " +

Review Comment:
   Okay. This should be an IllegalStateException, no?



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-04-22 Thread via GitHub


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


##
metadata/src/test/java/org/apache/kafka/metadata/bootstrap/BootstrapMetadataTest.java:
##
@@ -45,6 +57,31 @@ public class BootstrapMetadataTest {
 setName(FEATURE_NAME).
 setFeatureLevel((short) 7), (short) 0));
 
+static class BootstrapTestDirectory implements AutoCloseable {
+File directory = null;
+
+synchronized BootstrapTestDirectory createDirectory() {
+directory = TestUtils.tempDirectory("BootstrapTestDirectory");
+return this;
+}
+
+synchronized String path() {
+return directory.getAbsolutePath();
+}
+
+synchronized String binaryBootstrapPath() {
+return new File(directory, 
BootstrapMetadata.BINARY_BOOTSTRAP_FILENAME).getAbsolutePath();
+}
+
+@Override
+public synchronized void close() throws Exception {
+if (directory != null) {
+Utils.delete(directory);
+}
+directory = null;
+}

Review Comment:
   I didnt look into why they are synchronized and not sure why they were 
originally to be honest. I just copied over the previous code that was 
committed in `BootstrapDirectoryTest.java` which included these synchronized 
methods. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-04-22 Thread via GitHub


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


##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -483,23 +482,19 @@ private void formatNode(
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
 
-for (Feature feature : Feature.PRODUCTION_FEATURES) {
-String featureName = feature.featureName();
-// MetadataVersion is already set via setReleaseVersion above.
-// KRaftVersion is derived internally by the Formatter based 
on quorum configuration.
-if (featureName.equals(MetadataVersion.FEATURE_NAME) ||
-featureName.equals(KRaftVersion.FEATURE_NAME)) {
-continue;
+List additionalRecords = new ArrayList<>();
+for (ApiMessageAndVersion record : 
nodes.bootstrapMetadata().records()) {
+if (record.message() instanceof FeatureLevelRecord 
featureRecord) {
+// MetadataVersion is already set via setReleaseVersion 
above.
+// KRaftVersion is derived internally by the Formatter 
based on quorum configuration.
+if 
(!featureRecord.name().equals(MetadataVersion.FEATURE_NAME) &&
+
!featureRecord.name().equals(KRaftVersion.FEATURE_NAME)) {

Review Comment:
   I remember FormatterTest setting this via 
formatter.setFeatureLevel(KRaftVersion.FEATURE_NAME, ...). This is being done 
directly on the formatter itself but I thought that this meant this could also 
be done via FeatureLevelRecord so added this check. Will remove 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]



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-04-22 Thread via GitHub


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


##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/BootstrapMetadata.java:
##
@@ -63,10 +66,16 @@ public static BootstrapMetadata fromDirectory(Path 
directory) {
 }
 }
 Path binaryBootstrapPath = 
directory.resolve(BINARY_BOOTSTRAP_FILENAME);
-if (!Files.exists(binaryBootstrapPath)) {
-return fromVersion(MetadataVersion.latestProduction(), "the 
default bootstrap");
+if (Files.exists(binaryBootstrapPath)) {
+return fromCheckpointFile(binaryBootstrapPath);
+}
+Path partitionDir = directory.resolve(
+CLUSTER_METADATA_TOPIC_PARTITION.topic() + "-" + 
CLUSTER_METADATA_TOPIC_PARTITION.partition());
+Path zeroCheckpointPath = Snapshots.snapshotPath(partitionDir, 
Snapshots.BOOTSTRAP_SNAPSHOT_ID);
+if (Files.exists(zeroCheckpointPath)) {
+return fromCheckpointFile(zeroCheckpointPath);
 }

Review Comment:
   I added this for a test I added for the 0-0.checkpoint but realize now I 
don't need that new test as it is already being covered by 
`testListenerReceivesBootstrapSnapshot`



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-04-14 Thread via GitHub


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


##
metadata/src/test/java/org/apache/kafka/metadata/bootstrap/BootstrapMetadataTest.java:
##
@@ -45,6 +57,31 @@ public class BootstrapMetadataTest {
 setName(FEATURE_NAME).
 setFeatureLevel((short) 7), (short) 0));
 
+static class BootstrapTestDirectory implements AutoCloseable {
+File directory = null;
+
+synchronized BootstrapTestDirectory createDirectory() {
+directory = TestUtils.tempDirectory("BootstrapTestDirectory");
+return this;
+}
+
+synchronized String path() {
+return directory.getAbsolutePath();
+}
+
+synchronized String binaryBootstrapPath() {
+return new File(directory, 
BootstrapMetadata.BINARY_BOOTSTRAP_FILENAME).getAbsolutePath();
+}
+
+@Override
+public synchronized void close() throws Exception {
+if (directory != null) {
+Utils.delete(directory);
+}
+directory = null;
+}

Review Comment:
   Why are these methods synchronized? What the are the thread involved that 
need to be synchronized?



##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -483,23 +482,19 @@ private void formatNode(
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
 
-for (Feature feature : Feature.PRODUCTION_FEATURES) {
-String featureName = feature.featureName();
-// MetadataVersion is already set via setReleaseVersion above.
-// KRaftVersion is derived internally by the Formatter based 
on quorum configuration.
-if (featureName.equals(MetadataVersion.FEATURE_NAME) ||
-featureName.equals(KRaftVersion.FEATURE_NAME)) {
-continue;
+List additionalRecords = new ArrayList<>();
+for (ApiMessageAndVersion record : 
nodes.bootstrapMetadata().records()) {
+if (record.message() instanceof FeatureLevelRecord 
featureRecord) {
+// MetadataVersion is already set via setReleaseVersion 
above.
+// KRaftVersion is derived internally by the Formatter 
based on quorum configuration.
+if 
(!featureRecord.name().equals(MetadataVersion.FEATURE_NAME) &&
+
!featureRecord.name().equals(KRaftVersion.FEATURE_NAME)) {

Review Comment:
   Again, this should be an error or exception. Tests should not be setting the 
kraft.version using FeatureLevelRecord. What tests fail we turn this check into 
an error?



##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/BootstrapMetadata.java:
##
@@ -63,10 +66,16 @@ public static BootstrapMetadata fromDirectory(Path 
directory) {
 }
 }
 Path binaryBootstrapPath = 
directory.resolve(BINARY_BOOTSTRAP_FILENAME);
-if (!Files.exists(binaryBootstrapPath)) {
-return fromVersion(MetadataVersion.latestProduction(), "the 
default bootstrap");
+if (Files.exists(binaryBootstrapPath)) {
+return fromCheckpointFile(binaryBootstrapPath);
+}
+Path partitionDir = directory.resolve(
+CLUSTER_METADATA_TOPIC_PARTITION.topic() + "-" + 
CLUSTER_METADATA_TOPIC_PARTITION.partition());
+Path zeroCheckpointPath = Snapshots.snapshotPath(partitionDir, 
Snapshots.BOOTSTRAP_SNAPSHOT_ID);
+if (Files.exists(zeroCheckpointPath)) {
+return fromCheckpointFile(zeroCheckpointPath);
 }

Review Comment:
   Why do you need this? Ideally, Kafka components should not read kraft 
checkpoint directly. For bootstrap checkpoint they should use 
`RaftClient.Listener#handleLoadBootstrapCheckpoint`.
   
   The code in `src/main` should never read the 0-0.checkpoint directly, right? 
I should read it from `handleLoadBootstrap`, right?



##
metadata/src/test/java/org/apache/kafka/metadata/bootstrap/BootstrapMetadataTest.java:
##
@@ -45,6 +57,31 @@ public class BootstrapMetadataTest {
 setName(FEATURE_NAME).
 setFeatureLevel((short) 7), (short) 0));
 
+static class BootstrapTestDirectory implements AutoCloseable {
+File directory = null;
+
+synchronized BootstrapTestDirectory createDirectory() {
+directory = TestUtils.tempDirectory("BootstrapTestDirectory");
+return this;
+}

Review Comment:
   It sound like you want some kind of RAII. If you don't need to provide a 
prefix, how about:
   ```java
   public static BootstrapTestDirectory createDirectory() {
   return new BootstrapTestDirectory();
   }
   
   private 

Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-27 Thread via GitHub


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


##
core/src/test/scala/unit/kafka/server/KafkaRaftServerTest.scala:
##
@@ -272,20 +278,32 @@ class KafkaRaftServerTest {
   setDirectoryId(Uuid.fromString("4jm0e-YRYeB6CCKBvwoS8w")).
   build()
 
-val configProperties = new Properties
-configProperties.put(KRaftConfigs.PROCESS_ROLES_CONFIG, 
"broker,controller")
-configProperties.put(KRaftConfigs.NODE_ID_CONFIG, nodeId.toString)
-configProperties.put(SocketServerConfigs.LISTENERS_CONFIG, 
"PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093")
-configProperties.put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
s"$nodeId@localhost:9093")
-configProperties.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, "SSL")
+val logDir = TestUtils.tempDirectory()
+try {
+  writeMetaProperties(logDir, metaProperties)
+  writeBootstrapMetadata(logDir, MetadataVersion.IBP_3_3_IV3)
+
+  val configProperties = new Properties
+  configProperties.put(KRaftConfigs.PROCESS_ROLES_CONFIG, 
"broker,controller")
+  configProperties.put(KRaftConfigs.NODE_ID_CONFIG, nodeId.toString)
+  configProperties.put(SocketServerConfigs.LISTENERS_CONFIG, 
"PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093")
+  configProperties.put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
s"$nodeId@localhost:9093")
+  configProperties.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, 
"SSL")
+  configProperties.put(ServerLogConfigs.LOG_DIR_CONFIG, 
logDir.getAbsolutePath)
+  val config = KafkaConfig.fromProps(configProperties)
 
-val (metaPropertiesEnsemble, bootstrapMetadata) =
-  invokeLoadMetaProperties(metaProperties, configProperties, 
Some(MetadataVersion.IBP_3_3_IV3))
+  val (metaPropertiesEnsemble, _) =
+KafkaRaftServer.initializeLogDirs(config, MetaPropertiesEnsemble.LOG, 
"")

Review Comment:
   invokeLoadMetaProperties deletes the temp directory in the finally block. 
The test needs to read the bootstrap metadata from the zero checkpoint on disk 
after initializeLogDirs returns but the BootstrapMetadata returned by 
initializeLogDirs comes from fromDirectory() which reads the legacy 
bootstrap.checkpoint so it falls back to defaults.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-27 Thread via GitHub


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


##
core/src/test/scala/unit/kafka/server/KafkaRaftServerTest.scala:
##
@@ -272,20 +278,32 @@ class KafkaRaftServerTest {
   setDirectoryId(Uuid.fromString("4jm0e-YRYeB6CCKBvwoS8w")).
   build()
 
-val configProperties = new Properties
-configProperties.put(KRaftConfigs.PROCESS_ROLES_CONFIG, 
"broker,controller")
-configProperties.put(KRaftConfigs.NODE_ID_CONFIG, nodeId.toString)
-configProperties.put(SocketServerConfigs.LISTENERS_CONFIG, 
"PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093")
-configProperties.put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
s"$nodeId@localhost:9093")
-configProperties.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, "SSL")
+val logDir = TestUtils.tempDirectory()
+try {
+  writeMetaProperties(logDir, metaProperties)
+  writeBootstrapMetadata(logDir, MetadataVersion.IBP_3_3_IV3)
+
+  val configProperties = new Properties
+  configProperties.put(KRaftConfigs.PROCESS_ROLES_CONFIG, 
"broker,controller")
+  configProperties.put(KRaftConfigs.NODE_ID_CONFIG, nodeId.toString)
+  configProperties.put(SocketServerConfigs.LISTENERS_CONFIG, 
"PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093")
+  configProperties.put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
s"$nodeId@localhost:9093")
+  configProperties.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, 
"SSL")
+  configProperties.put(ServerLogConfigs.LOG_DIR_CONFIG, 
logDir.getAbsolutePath)
+  val config = KafkaConfig.fromProps(configProperties)
 
-val (metaPropertiesEnsemble, bootstrapMetadata) =
-  invokeLoadMetaProperties(metaProperties, configProperties, 
Some(MetadataVersion.IBP_3_3_IV3))
+  val (metaPropertiesEnsemble, _) =
+KafkaRaftServer.initializeLogDirs(config, MetaPropertiesEnsemble.LOG, 
"")

Review Comment:
   invokeLoadMetaProperties deletes the temp directory in the finally block. 
The test needs to read the bootstrap metadata from the zero checkpoint on disk 
after initializeLogDirs returns but the BootstrapMetadata returned by 
initializeLogDirs comes from fromDirectory() which reads the legacy 
bootstrap.checkpoint so it falls back to defaults. Will add a check for zero 
checkpoint



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-27 Thread via GitHub


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


##
core/src/test/scala/unit/kafka/server/KafkaRaftServerTest.scala:
##
@@ -272,20 +278,32 @@ class KafkaRaftServerTest {
   setDirectoryId(Uuid.fromString("4jm0e-YRYeB6CCKBvwoS8w")).
   build()
 
-val configProperties = new Properties
-configProperties.put(KRaftConfigs.PROCESS_ROLES_CONFIG, 
"broker,controller")
-configProperties.put(KRaftConfigs.NODE_ID_CONFIG, nodeId.toString)
-configProperties.put(SocketServerConfigs.LISTENERS_CONFIG, 
"PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093")
-configProperties.put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
s"$nodeId@localhost:9093")
-configProperties.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, "SSL")
+val logDir = TestUtils.tempDirectory()
+try {
+  writeMetaProperties(logDir, metaProperties)
+  writeBootstrapMetadata(logDir, MetadataVersion.IBP_3_3_IV3)
+
+  val configProperties = new Properties
+  configProperties.put(KRaftConfigs.PROCESS_ROLES_CONFIG, 
"broker,controller")
+  configProperties.put(KRaftConfigs.NODE_ID_CONFIG, nodeId.toString)
+  configProperties.put(SocketServerConfigs.LISTENERS_CONFIG, 
"PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093")
+  configProperties.put(QuorumConfig.QUORUM_VOTERS_CONFIG, 
s"$nodeId@localhost:9093")
+  configProperties.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, 
"SSL")
+  configProperties.put(ServerLogConfigs.LOG_DIR_CONFIG, 
logDir.getAbsolutePath)
+  val config = KafkaConfig.fromProps(configProperties)
 
-val (metaPropertiesEnsemble, bootstrapMetadata) =
-  invokeLoadMetaProperties(metaProperties, configProperties, 
Some(MetadataVersion.IBP_3_3_IV3))
+  val (metaPropertiesEnsemble, _) =
+KafkaRaftServer.initializeLogDirs(config, MetaPropertiesEnsemble.LOG, 
"")

Review Comment:
   invokeLoadMetaProperties deletes the temp directory in the finally block. 
The test needs to read the bootstrap metadata from the zero checkpoint on disk 
after initializeLogDirs returns but the BootstrapMetadata returned by 
initializeLogDirs comes from fromDirectory() which reads the legacy 
bootstrap.checkpoint so it falls back to defaults. I'll change fromDirectory() 
to also read the zero checkpoint if bootstrap.checkpoint doesnt exist. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-27 Thread via GitHub


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


##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -477,6 +482,26 @@ private void formatNode(
 formatter.setIgnoreFormatted(false);
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
+
+for (Feature feature : Feature.PRODUCTION_FEATURES) {
+String featureName = feature.featureName();
+// MetadataVersion is already set via setReleaseVersion above.
+// KRaftVersion is derived internally by the Formatter based 
on quorum configuration.
+if (featureName.equals(MetadataVersion.FEATURE_NAME) ||
+featureName.equals(KRaftVersion.FEATURE_NAME)) {

Review Comment:
   The tests that use `TestKitNodes.Builder()` have kraft version set by 
default via `Feature.PRODUCTION_FEATURES` which includes kraft version. So 
mainly the tests in `KRaftClusterTest.java`



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-27 Thread via GitHub


kevin-wu24 commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r3001077995


##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -477,6 +482,26 @@ private void formatNode(
 formatter.setIgnoreFormatted(false);
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
+
+for (Feature feature : Feature.PRODUCTION_FEATURES) {
+String featureName = feature.featureName();
+// MetadataVersion is already set via setReleaseVersion above.
+// KRaftVersion is derived internally by the Formatter based 
on quorum configuration.
+if (featureName.equals(MetadataVersion.FEATURE_NAME) ||
+featureName.equals(KRaftVersion.FEATURE_NAME)) {

Review Comment:
   I think it is `TestKitNodes.Builder`'s default constructor that makes a 
bootstrapMetadata with a kraft feature level record.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-27 Thread via GitHub


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


##
metadata/src/main/java/org/apache/kafka/metadata/util/BatchFileReader.java:
##
@@ -122,6 +124,17 @@ private BatchAndType 
nextControlBatch(FileChannelRecordBatch input) {
 messages.add(new ApiMessageAndVersion(message, (short) 
0));
 break;
 }
+case KRAFT_VERSION: {
+KRaftVersionRecord message = new KRaftVersionRecord();
+message.read(new ByteBufferAccessor(record.value()), 
(short) 0);
+messages.add(new ApiMessageAndVersion(message, (short) 
0));
+break;
+}
+case KRAFT_VOTERS:
+VotersRecord message =  new VotersRecord();
+message.read(new ByteBufferAccessor(record.value()), 
(short) 0);
+messages.add(new ApiMessageAndVersion(message, (short) 
0));
+break;

Review Comment:
   
https://issues.apache.org/jira/projects/KAFKA/issues/KAFKA-20364?filter=allissues



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-26 Thread via GitHub


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


##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -477,6 +482,26 @@ private void formatNode(
 formatter.setIgnoreFormatted(false);
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
+
+for (Feature feature : Feature.PRODUCTION_FEATURES) {
+String featureName = feature.featureName();
+// MetadataVersion is already set via setReleaseVersion above.
+// KRaftVersion is derived internally by the Formatter based 
on quorum configuration.
+if (featureName.equals(MetadataVersion.FEATURE_NAME) ||
+featureName.equals(KRaftVersion.FEATURE_NAME)) {

Review Comment:
   Isn't a bug if a test specifies a feature level for kraft.version? Do we 
know which test is specifying a feature level for the kraft version?



##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -477,6 +482,26 @@ private void formatNode(
 formatter.setIgnoreFormatted(false);
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
+
+for (Feature feature : Feature.PRODUCTION_FEATURES) {
+String featureName = feature.featureName();
+// MetadataVersion is already set via setReleaseVersion above.
+// KRaftVersion is derived internally by the Formatter based 
on quorum configuration.
+if (featureName.equals(MetadataVersion.FEATURE_NAME) ||
+featureName.equals(KRaftVersion.FEATURE_NAME)) {
+continue;
+}
+short level = 
nodes.bootstrapMetadata().featureLevel(featureName);
+formatter.setFeatureLevel(featureName, level);
+}
+
+// Filter out records already handled by the Formatter (feature 
levels and SCRAM).
+List additionalRecords = 
nodes.bootstrapMetadata().records().stream()

Review Comment:
   In line 494 above, you iterate over all of the records for each supported 
features. Here you iterate over all of the records looking for non feature 
level and scram records. Can we please change the implementation so that it 
only iterates over all of the record once?



##
metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java:
##
@@ -182,6 +187,11 @@ public Formatter setFeatureLevel(String featureName, Short 
level) {
 return this;
 }
 
+public Formatter setAdditionalBootstrapRecords(List 
additionalBootstrapRecords) {
+this.additionalBootstrapRecords = additionalBootstrapRecords;
+return this;
+}

Review Comment:
   Okay. In the near future, I am going to write a KIP to allow overriding 
configuration during bootstrap.



##
core/src/main/scala/kafka/server/KafkaRaftServer.scala:
##
@@ -181,8 +181,7 @@ object KafkaRaftServer {
 }
 
 // Load the BootstrapMetadata.
-val bootstrapDirectory = new BootstrapDirectory(config.metadataLogDir)
-val bootstrapMetadata = bootstrapDirectory.read()
+val bootstrapMetadata = 
BootstrapMetadata.fromDirectory(java.nio.file.Path.of(config.metadataLogDir))

Review Comment:
   Please import `java.nio.file.Path` instead.



##
metadata/src/test/java/org/apache/kafka/metadata/bootstrap/BootstrapTestUtils.java:
##
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.bootstrap;
+
+import java.nio.file.Path;
+
+import static 
org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION;
+import static org.apache.kafka.snapshot.Snapshots.BOOTSTRAP_SNAPSHOT_ID;
+import static org.apache.kafka.snapshot.Snapshots.snapshotPath;
+
+/**
+ * Utilities for testing classes that deal with bootstrap metadata.
+ */
+public class 

Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-26 Thread via GitHub


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


##
server/src/test/java/org/apache/kafka/server/KRaftClusterTest.java:
##
@@ -1406,33 +1405,6 @@ public void 
testDirectToControllerCommunicationFailsOnOlderMetadataVersion() thr
 }
 }
 
-@Test
-public void testStartupWithNonDefaultKControllerDynamicConfiguration() 
throws Exception {
-var bootstrapRecords = List.of(
-new ApiMessageAndVersion(new FeatureLevelRecord()
-.setName(MetadataVersion.FEATURE_NAME)
-.setFeatureLevel(MetadataVersion.IBP_3_7_IV0.featureLevel()), 
(short) 0),
-new ApiMessageAndVersion(new ConfigRecord()
-.setResourceType(ConfigResource.Type.BROKER.id())
-.setResourceName("")
-.setName("num.io.threads")
-.setValue("9"), (short) 0));
-try (KafkaClusterTestKit cluster = new KafkaClusterTestKit.Builder(
-new 
TestKitNodes.Builder(BootstrapMetadata.fromRecords(bootstrapRecords, 
"testRecords"))

Review Comment:
   I think i misunderstood you previous comment, thought you mean't this 
behavior was not valid within kafka. 
https://github.com/apache/kafka/pull/20707#discussion_r2765488945, added this 
test back



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-25 Thread via GitHub


mannoopj commented on PR #20707:
URL: https://github.com/apache/kafka/pull/20707#issuecomment-4129078889

   > What are these other threads that read bootstrapMetadata?
   Was working under the assumptions that the raft io thread was calling 
`listener.handleLoadBootstrap`. Didnt realize `appendRaftEvent` adds this to 
the controller event thread.  


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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-25 Thread via GitHub


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


##
metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java:
##
@@ -148,12 +149,24 @@ public void testDirectories(int numDirs) throws Exception 
{
 assertEquals(OptionalInt.of(DEFAULT_NODE_ID), ensemble.nodeId());
 assertEquals(Optional.of(DEFAULT_CLUSTER_ID.toString()), 
ensemble.clusterId());
 assertEquals(new HashSet<>(testEnv.directories), 
ensemble.logDirProps().keySet());
-BootstrapMetadata bootstrapMetadata =
-new BootstrapDirectory(testEnv.directory(0)).read();
+BootstrapMetadata bootstrapMetadata = 
BootstrapTestUtils.readBootstrapMetadata(testEnv.directory(0));
 assertEquals(MetadataVersion.latestProduction(), 
bootstrapMetadata.metadataVersion());
 }
 }
 
+@Test
+public void testSkipsBootstrapSnapshotWhenDisabled() throws Exception {
+try (TestEnv testEnv = new TestEnv(1)) {
+FormatterContext context = testEnv.newFormatter();
+context.formatter.setWriteBootstrapSnapshot(false);
+context.formatter.run();
+File clusterMetadataDir = new File(testEnv.directory(0), 
String.format("%s-%d",

Review Comment:
   LocalLog (and UnifiedLog) are in the storage module and would require adding 
a dependency for the metadata module to do that here. Didn't want to add a 
dependency for this 



##
server/src/test/java/org/apache/kafka/server/KRaftClusterTest.java:
##
@@ -1406,33 +1405,6 @@ public void 
testDirectToControllerCommunicationFailsOnOlderMetadataVersion() thr
 }
 }
 
-@Test
-public void testStartupWithNonDefaultKControllerDynamicConfiguration() 
throws Exception {
-var bootstrapRecords = List.of(
-new ApiMessageAndVersion(new FeatureLevelRecord()
-.setName(MetadataVersion.FEATURE_NAME)
-.setFeatureLevel(MetadataVersion.IBP_3_7_IV0.featureLevel()), 
(short) 0),
-new ApiMessageAndVersion(new ConfigRecord()
-.setResourceType(ConfigResource.Type.BROKER.id())
-.setResourceName("")
-.setName("num.io.threads")
-.setValue("9"), (short) 0));
-try (KafkaClusterTestKit cluster = new KafkaClusterTestKit.Builder(
-new 
TestKitNodes.Builder(BootstrapMetadata.fromRecords(bootstrapRecords, 
"testRecords"))

Review Comment:
   I think i misunderstood you previous comment, thought you mean't this 
behavior was not valid within kafka. 
https://github.com/apache/kafka/pull/20707#discussion_r2765488945



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-19 Thread via GitHub


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


##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/BootstrapDirectory.java:
##
@@ -32,52 +33,58 @@
 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.
+ * Reads bootstrap metadata from a binary checkpoint file.
  */
 public class BootstrapDirectory {
 public static final String BINARY_BOOTSTRAP_FILENAME = 
"bootstrap.checkpoint";
 
-private final String directoryPath;
+private final Path binaryBootstrapPath;
+private final boolean requireFile;
+
+/**
+ * Reads from {directoryPath}/bootstrap.checkpoint, falling back to 
defaults if missing.
+ */
+public BootstrapDirectory(String directoryPath) {
+this(Paths.get(directoryPath, BINARY_BOOTSTRAP_FILENAME), false);
+}
 
 /**
- * Create a new BootstrapDirectory object.
- *
- * @param directoryPath The path to the directory with the bootstrap 
file.
+ * Reads from the given path. If requireFile is true, throws when the file 
is missing.
  */
-public BootstrapDirectory(
-String directoryPath
-) {
-this.directoryPath = Objects.requireNonNull(directoryPath);
+public BootstrapDirectory(Path binaryBootstrapPath, boolean requireFile) {

Review Comment:
   The implementation and usage has changed substantially that it is not clear 
to me why you need this type.
   
   Why not add these static methods to BootstrapMetadata:
   ```java
   /**
* Make sure to document that it returns the "default" BootstrapMetadata if 
the bootstrap.checkpoint doesn't exist.
*/
   public static BootstrapMetadata fromDirectory(Path directory) { ... }
   
   /**
* Document this method
*/
   public static BootstrapMetadata fromCheckpointFile(Path file) { ... }
   ```



##
server/src/test/java/org/apache/kafka/server/KRaftClusterTest.java:
##
@@ -1406,33 +1405,6 @@ public void 
testDirectToControllerCommunicationFailsOnOlderMetadataVersion() thr
 }
 }
 
-@Test
-public void testStartupWithNonDefaultKControllerDynamicConfiguration() 
throws Exception {
-var bootstrapRecords = List.of(
-new ApiMessageAndVersion(new FeatureLevelRecord()
-.setName(MetadataVersion.FEATURE_NAME)
-.setFeatureLevel(MetadataVersion.IBP_3_7_IV0.featureLevel()), 
(short) 0),
-new ApiMessageAndVersion(new ConfigRecord()
-.setResourceType(ConfigResource.Type.BROKER.id())
-.setResourceName("")
-.setName("num.io.threads")
-.setValue("9"), (short) 0));
-try (KafkaClusterTestKit cluster = new KafkaClusterTestKit.Builder(
-new 
TestKitNodes.Builder(BootstrapMetadata.fromRecords(bootstrapRecords, 
"testRecords"))

Review Comment:
   Again, why are you removing this test? Isn't the solution to fix the 
bootstrapping of the TestKitNodes so that you pass something else besides a 
BootstrapMetadata?



##
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/KafkaClusterTestKit.java:
##
@@ -477,6 +480,17 @@ private void formatNode(
 formatter.setIgnoreFormatted(false);
 formatter.setControllerListenerName(controllerListenerName);
 formatter.setMetadataLogDirectory(ensemble.metadataLogDir().get());
+
+for (Feature feature : Feature.PRODUCTION_FEATURES) {
+String featureName = feature.featureName();
+if (featureName.equals(MetadataVersion.FEATURE_NAME) ||
+featureName.equals(KRaftVersion.FEATURE_NAME)) {
+continue;
+}

Review Comment:
   In a comment, please explain why you are skipping these features.



##
metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java:
##
@@ -148,12 +149,24 @@ public void testDirectories(int numDirs) throws Exception 
{
 assertEquals(OptionalInt.of(DEFAULT_NODE_ID), ensemble.nodeId());
 assertEquals(Optional.of(DEFAULT_CLUSTER_ID.toString()), 
ensemble.clusterId());
 assertEquals(new HashSet<>(testEnv.directories), 
ensemble.logDirProps().keySet());
-BootstrapMetadata bootstrapMetadata =
-new BootstrapDirectory(testEnv.directory(0)).read();
+BootstrapMetadata bootstrapMetadata = 
BootstrapTestUtils.readBootstrapMetadata(testEnv.directory(0));
 assertEquals(MetadataVersion.latestProduction(), 
bootstrapMetadata.metadataVersion());
 }
 }
 
+@Test
+public void 

Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-19 Thread via GitHub


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


##
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:
   Those are all unchecked exceptions that don't need to be declared in the 
method signature.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-19 Thread via GitHub


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


##
core/src/test/scala/unit/kafka/server/KafkaRaftServerTest.scala:
##
@@ -22,6 +22,12 @@ import java.util.{Optional, Properties}
 import org.apache.kafka.common.{KafkaException, Uuid}
 import org.apache.kafka.common.utils.Utils
 import org.apache.kafka.metadata.bootstrap.{BootstrapDirectory, 
BootstrapMetadata}
+
+import java.nio.file.Path
+
+import org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION

Review Comment:
   It does. Took a deeper check and it seems like there is no import checking 
done for scala files in the core module. Its only done for java. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-03-19 Thread via GitHub


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


##
core/src/test/scala/integration/kafka/server/KRaftClusterTest.scala:
##
@@ -1174,35 +1174,6 @@ class KRaftClusterTest {
 }
   }
 
-  @Test
-  def testStartupWithNonDefaultKControllerDynamicConfiguration(): Unit = {

Review Comment:
   I was leaning towards that but unsure since the it been approved and merged. 
I will get rid of 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]



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-02-05 Thread via GitHub


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


##
raft/src/main/java/org/apache/kafka/raft/RaftClient.java:
##
@@ -62,13 +62,26 @@ interface Listener {
  */
 void handleLoadSnapshot(SnapshotReader reader);
 
+/**
+ * Callback which is invoked when the Listener needs to load bootstrap 
metadata.
+ * Bootstrap snapshots are uncommitted and only used for initial 
cluster state.
+ *
+ * The default implementation delegates to {@link 
#handleLoadSnapshot(SnapshotReader)}.
+ *
+ * @param reader snapshot reader instance which must be iterated and 
closed
+ */
+default void handleLoadBootstrap(SnapshotReader reader) {
+handleLoadSnapshot(reader);
+}

Review Comment:
   Wouldn't this mean we basically have to duplicate every handleloadSnapshot 
implementation so far as handleLoadBootstrap since the 0-0.checkpoint is 
already passed into these functions as uncommitted? I was trying to avoid this 
duplication originally but I'm a bit confused. For example currently in 
MetadataLoader we update metrics, deltas, manifests, not considering the 
records themselves for the 0-0.checkpoint before this PR. I'm trying to clarify 
this behavior is incorrect or not and whether or not we have to duplicate these 
functions.
   



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-02-04 Thread via GitHub


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


##
raft/src/main/java/org/apache/kafka/raft/RaftClient.java:
##
@@ -62,13 +62,26 @@ interface Listener {
  */
 void handleLoadSnapshot(SnapshotReader reader);
 
+/**
+ * Callback which is invoked when the Listener needs to load bootstrap 
metadata.
+ * Bootstrap snapshots are uncommitted and only used for initial 
cluster state.
+ *
+ * The default implementation delegates to {@link 
#handleLoadSnapshot(SnapshotReader)}.
+ *
+ * @param reader snapshot reader instance which must be iterated and 
closed
+ */
+default void handleLoadBootstrap(SnapshotReader reader) {
+handleLoadSnapshot(reader);
+}

Review Comment:
   Please remove this default implementation. Again, `handleLoadSnapshot` 
should only receive committed snapshots. `handleLoadBootstrap` should only 
receive uncommitted snapshots.



##
raft/src/main/java/org/apache/kafka/snapshot/SnapshotReader.java:
##
@@ -57,6 +57,12 @@ public interface SnapshotReader extends AutoCloseable, 
Iterator> {
  */
 long lastContainedLogTimestamp();
 
+/**
+ * Returns true if the snapshot has been committed.
+ * Uncommitted bootstrap snapshots return false.
+ */
+boolean isCommittedSnapshot();
+

Review Comment:
   Let's just remove this new method.



##
core/src/test/scala/unit/kafka/server/KafkaRaftServerTest.scala:
##
@@ -22,6 +22,12 @@ import java.util.{Optional, Properties}
 import org.apache.kafka.common.{KafkaException, Uuid}
 import org.apache.kafka.common.utils.Utils
 import org.apache.kafka.metadata.bootstrap.{BootstrapDirectory, 
BootstrapMetadata}
+
+import java.nio.file.Path
+
+import org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION

Review Comment:
   Please remove the extra newline. Fix the import order. Does this pass AK's 
import checker?
   
   This comment applies to a few files in this PR.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-02-04 Thread via GitHub


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


##
core/src/test/scala/integration/kafka/server/KRaftClusterTest.scala:
##
@@ -1174,35 +1174,6 @@ class KRaftClusterTest {
 }
   }
 
-  @Test
-  def testStartupWithNonDefaultKControllerDynamicConfiguration(): Unit = {

Review Comment:
   I see. So it sounds like the test is not valid if Kafka doesn't support 
setting dynamic config during formatting/bootstrapping, no?



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-02-04 Thread via GitHub


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


##
raft/src/main/java/org/apache/kafka/snapshot/SnapshotReader.java:
##
@@ -57,6 +57,12 @@ public interface SnapshotReader extends AutoCloseable, 
Iterator> {
  */
 long lastContainedLogTimestamp();
 
+/**
+ * Returns true if the snapshot has been committed.
+ * Uncommitted bootstrap snapshots return false.
+ */
+boolean isCommittedSnapshot();

Review Comment:
   Thanks. I think that returning uncommitted snapshot through 
`RaftListener.handleLoadSnapshot` has a high probability of the 
user/application handling it wrong. Instead of changing the semantic of 
`handleLoadSnapshot` to return uncommitted snapshots. I think that we should 
add another callback to `RaftListener`, for example 
`handleLoadBootstrap(SnapshotReader)`. This make it clearer to the user the 
semantic difference between the two snapshots.
   
   If we don't do this, all KRaft application need to remember to check if the 
returned snapshot is uncommitted or committed. Which is not clear from the 
`RaftListener` interface and the documentation of that interface.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-02-02 Thread via GitHub


kevin-wu24 commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r2755435424


##
core/src/main/scala/kafka/tools/StorageTool.scala:
##
@@ -123,6 +123,7 @@ object StorageTool extends Logging {
 val formatter = new Formatter().
   setPrintStream(printStream).
   setNodeId(config.nodeId).
+  
setWriteBootstrapSnapshot(config.processRoles.contains(ProcessRole.ControllerRole)).

Review Comment:
   Updated the KIP.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-02-02 Thread via GitHub


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


##
core/src/test/scala/integration/kafka/server/KRaftClusterTest.scala:
##
@@ -1174,35 +1174,6 @@ class KRaftClusterTest {
 }
   }
 
-  @Test
-  def testStartupWithNonDefaultKControllerDynamicConfiguration(): Unit = {

Review Comment:
   Originally this test used KafkaClusterTestKit which passed the full 
BootstrapMetadata (with injected ConfigRecord) into 
ControllerServer/QuorumController, and on an empty metadata log the controller 
appends and replays those bootstrap records, so the config takes effect at 
startup. With the changes in this PR KafkaClusterTestKit.format() drives 
Formatter, and Formatter only generates bootstrap records from release version 
+ feature levels (+ SCRAM) and does not accept arbitrary ConfigRecords, so 
injecting a ConfigRecord through BootstrapMetadata.fromRecords() doesn't work 
and doesn't get picked up. I moved it to DynamicBrokerReconfigurationTest as it 
seemed like the closest fit of where i could move this test without running 
into this issue. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-02-02 Thread via GitHub


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


##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/TestBootstrapDirectory.java:
##
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.bootstrap;
+
+import java.io.FileNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+import static 
org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION;
+
+/**
+ * Test-only implementation that reads bootstrap metadata from the metadata 
partition snapshot.
+ */
+public class TestBootstrapDirectory implements BootstrapDirectory {

Review Comment:
   Yes Im ok with that, I will just actually add this all back into 
BootstrapDirectory and get rid of the implementations. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-28 Thread via GitHub


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


##
core/src/test/scala/integration/kafka/server/DynamicBrokerReconfigurationTest.scala:
##
@@ -178,6 +178,20 @@ class DynamicBrokerReconfigurationTest extends 
QuorumTestHarness with SaslSetup
 closeSasl()
   }
 
+  @ParameterizedTest(name = 
TestInfoUtils.TestWithParameterizedGroupProtocolNames)
+  @MethodSource(Array("getTestGroupProtocolParametersAll"))
+  def testNonDefaultKControllerDynamicConfiguration(groupProtocol: String): 
Unit = {
+val props = new Properties
+props.put(ServerConfigs.NUM_IO_THREADS_CONFIG, "9")
+reconfigureServers(props, perBrokerConfig = false, 
(ServerConfigs.NUM_IO_THREADS_CONFIG, "9"))
+
+val controller = controllerServer
+TestUtils.retry(6) {
+  assertNotNull(controller.controllerApisHandlerPool)
+  assertEquals(9, 
controller.controllerApisHandlerPool.threadPoolSize.get())
+}
+  }
+

Review Comment:
   What is this testing? Why is this part of this PR/change?



##
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:
   Can this be done with static method in a utility package? Again, it is odd 
to have an interface that abstract the construction of BootstrapMetadata. And 
at the same time the interface has a defined method that constructs a bootstrap 
metadata that all of the implementation use. 



##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/TestBootstrapDirectory.java:
##
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with

Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-26 Thread via GitHub


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


##
metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java:
##
@@ -492,27 +497,36 @@ static DirectoryType calculate(
 }
 }
 
-static void writeDynamicQuorumSnapshot(
+public static void writeBoostrapSnapshot(
 String writeLogDir,
-DynamicVoters initialControllers,
+BootstrapMetadata bootstrapMetadata,
+Optional initialControllers,
 short kraftVersion,
 String controllerListenerName
 ) {
-File parentDir = new File(writeLogDir);
-File clusterMetadataDirectory = new File(parentDir, 
String.format("%s-%d",
-CLUSTER_METADATA_TOPIC_PARTITION.topic(),
-CLUSTER_METADATA_TOPIC_PARTITION.partition()));
-VoterSet voterSet = 
initialControllers.toVoterSet(controllerListenerName);
-RecordsSnapshotWriter.Builder builder = new 
RecordsSnapshotWriter.Builder().
-setLastContainedLogTimestamp(Time.SYSTEM.milliseconds()).
-setMaxBatchSizeBytes(KafkaRaftClient.MAX_BATCH_SIZE_BYTES).
-setRawSnapshotWriter(FileRawSnapshotWriter.create(
-clusterMetadataDirectory.toPath(),
-Snapshots.BOOTSTRAP_SNAPSHOT_ID)).
-setKraftVersion(KRaftVersion.fromFeatureLevel(kraftVersion)).
-setVoterSet(Optional.of(voterSet));
-try (RecordsSnapshotWriter writer = 
builder.build(new MetadataRecordSerde())) {
-writer.freeze();
+try {
+File parentDir = new File(writeLogDir);
+File clusterMetadataDirectory = new File(parentDir, 
String.format("%s-%d",
+CLUSTER_METADATA_TOPIC_PARTITION.topic(),
+CLUSTER_METADATA_TOPIC_PARTITION.partition()));
+RecordsSnapshotWriter.Builder builder = new 
RecordsSnapshotWriter.Builder().
+setLastContainedLogTimestamp(Time.SYSTEM.milliseconds()).
+setMaxBatchSizeBytes(KafkaRaftClient.MAX_BATCH_SIZE_BYTES).
+setRawSnapshotWriter(FileRawSnapshotWriter.create(
+clusterMetadataDirectory.toPath(),
+Snapshots.BOOTSTRAP_SNAPSHOT_ID)).
+setKraftVersion(KRaftVersion.fromFeatureLevel(kraftVersion));
+if (initialControllers.isPresent()) {
+VoterSet voterSet = 
initialControllers.get().toVoterSet(controllerListenerName);
+builder.setVoterSet(Optional.of(voterSet));
+}
+try (RecordsSnapshotWriter writer = 
builder.build(new MetadataRecordSerde())) {
+writer.append(bootstrapMetadata.records());
+writer.freeze();
+}
+} catch (UncheckedIOException e) {

Review Comment:
   I added it I think originally to add more context for 
(disk/path/permissions) causes of UncheckedIOException. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-26 Thread via GitHub


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]



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-26 Thread via GitHub


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


##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/TestBootstrapDirectory.java:
##
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.bootstrap;
+
+import java.io.FileNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+import static 
org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION;
+
+/**
+ * Test-only implementation that reads bootstrap metadata from the metadata 
partition snapshot.
+ */
+public class TestBootstrapDirectory implements BootstrapDirectory {
+private static final String BINARY_BOOTSTRAP_CHECKPOINT_FILENAME = 
"-00.checkpoint";

Review Comment:
   We need this to help validate some of the tests. For example the 
FormatterTests we need a way to check if the information formatted is correct. 
Previously this was done with BootstrapDirectory which was also used in prod 
but that was for when formatting was done with bootstrap.checkpoint. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-26 Thread via GitHub


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]



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-26 Thread via GitHub


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


##
metadata/src/main/java/org/apache/kafka/metadata/util/BatchFileReader.java:
##
@@ -122,6 +124,17 @@ private BatchAndType 
nextControlBatch(FileChannelRecordBatch input) {
 messages.add(new ApiMessageAndVersion(message, (short) 
0));
 break;
 }
+case KRAFT_VERSION: {
+KRaftVersionRecord message = new KRaftVersionRecord();
+message.read(new ByteBufferAccessor(record.value()), 
(short) 0);
+messages.add(new ApiMessageAndVersion(message, (short) 
0));
+break;
+}
+case KRAFT_VOTERS:
+VotersRecord message =  new VotersRecord();
+message.read(new ByteBufferAccessor(record.value()), 
(short) 0);
+messages.add(new ApiMessageAndVersion(message, (short) 
0));
+break;

Review Comment:
   ```
   kafka.tools.StorageToolTest.testBootstrapScramRecords()
   kafka.tools.StorageToolTest.testFormatWithMultipleFeatures()
   kafka.tools.StorageToolTest.testFormatWithReleaseVersionAndFeatureOverride()
   ```
   These were the tests that failed without this code included. 



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-07 Thread via GitHub


kevin-wu24 commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r2670662776


##
core/src/main/scala/kafka/tools/StorageTool.scala:
##
@@ -123,6 +123,7 @@ object StorageTool extends Logging {
 val formatter = new Formatter().
   setPrintStream(printStream).
   setNodeId(config.nodeId).
+  
setWriteBootstrapSnapshot(config.processRoles.contains(ProcessRole.ControllerRole)).

Review Comment:
   I think we realized this behavior makes more sense after starting the 
implementation. Pre-KIP-1170 during formatting, brokers would also write 
`bootstrap.checkpoint` (which is not used since broker-only processes cannot 
write this data to the metadata log), but only KIP-853 bootstrap controllers 
would write `0-0.checkpoint`. 
   
   Now that we are moving towards only a `0-0.checkpoint` with both metadata 
and control records, I don't think it makes sense to have brokers write the 
`0-0.checkpoint`. Only controllers should write this file to disk when 
formatting.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-07 Thread via GitHub


kevin-wu24 commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r2670651896


##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/TestBootstrapDirectory.java:
##
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.bootstrap;
+
+import java.io.FileNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+import static 
org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION;
+
+/**
+ * Test-only implementation that reads bootstrap metadata from the metadata 
partition snapshot.
+ */
+public class TestBootstrapDirectory implements BootstrapDirectory {

Review Comment:
   There is one difference, in that the `LegacyBootstrapDirectory#read()` 
(which reads `bootstrap.checkpoint`, will default to the 
`readFromConfiguration()` so that the returned `BootstrapMetadata` object is 
never null. 
   
   I felt that `TestBootstrapDirectory` should not have a similar behavior as 
above. The main reason we need that functionality is to verify the contents of 
the `0-0.checkpoint` file within unit test files.



##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/TestBootstrapDirectory.java:
##
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.bootstrap;
+
+import java.io.FileNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+import static 
org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION;
+
+/**
+ * Test-only implementation that reads bootstrap metadata from the metadata 
partition snapshot.
+ */
+public class TestBootstrapDirectory implements BootstrapDirectory {

Review Comment:
   There is one difference, in that the `LegacyBootstrapDirectory#read()` 
(which reads `bootstrap.checkpoint`), will default to the 
`readFromConfiguration()` so that the returned `BootstrapMetadata` object is 
never null. 
   
   I felt that `TestBootstrapDirectory` should not have a similar behavior as 
above. The main reason we need that functionality is to verify the contents of 
the `0-0.checkpoint` file within unit test files.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-07 Thread via GitHub


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


##
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:
   The type Exception is too generic. What are the actual exception that it can 
return? Having said that it is better to throw unchecked exceptions if the 
caller cannot handle the exceptions.



##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/TestBootstrapDirectory.java:
##
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.bootstrap;
+
+import java.io.FileNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+import static 
org.apache.kafka.common.internals.Topic.CLUSTER_METADATA_TOPIC_PARTITION;
+
+/**
+ * Test-only implementation that reads bootstrap metadata from the metadata 
partition snapshot.
+ */
+public class TestBootstrapDirectory implements BootstrapDirectory {

Review Comment:
   Is this is used only for test then the implementation should live in the 
test configuration.
   
   Having said the name of type should match the implementation not the context 
in which it is used. Test is the context but the implementation seem be based 
on the filename 00..-00...checkpoint.
   
   Does it make send to have different implementation when the only difference 
is the file name? Seem like avoidable code duplication.



##
core/src/main/scala/kafka/tools/StorageTool.scala:
##
@@ -123,6 +123,7 @@ object StorageTool 

Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2026-01-07 Thread via GitHub


jsancio commented on PR #20707:
URL: https://github.com/apache/kafka/pull/20707#issuecomment-3719818486

   Thanks for the changes @mannoopj 
   
   Ideally the PR description should answer the following 3 questions: Why is 
the PR required? What does the PR change? How does the PR change Kafka?
   
   > StorageTool.scala now checks to see if we the role is Controller before 
formatting metadata
   Why is this needed? The KIP doesn't mention this change.
   
   > Implementations of RaftClient.handleLoadSnapshot were adjusting to now 
account for the presence of metadata records within in the zero checkpoint
   
   Technically RaftClient.handleLoadSnapshot is not a definition 
(implementation) and instead a declaration. Do you mean to say that you changed 
the implementation of that method in the quorum controller?


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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2025-12-04 Thread via GitHub


kevin-wu24 commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r2589940261


##
core/src/main/scala/kafka/tools/DumpLogSegments.scala:
##
@@ -271,7 +271,7 @@ object DumpLogSegments {
   val startOffset = file.getName.split("\\.")(0).toLong
   println(s"Log starting offset: $startOffset")
 } else if (file.getName.endsWith(Snapshots.SUFFIX)) {
-  if (file.getName == BootstrapDirectory.BINARY_BOOTSTRAP_FILENAME) {
+  if (file.getName == LegacyBootstrapDirectory.BINARY_BOOTSTRAP_FILENAME) {
 println("KRaft bootstrap snapshot")

Review Comment:
   nit but let's change this to say `KRaft legacy bootstrap snapshot`.



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



Re: [PR] KAFKA-19648: KIP-1170 Unify cluster metadata bootstrapping [kafka]

2025-12-03 Thread via GitHub


kevin-wu24 commented on code in PR #20707:
URL: https://github.com/apache/kafka/pull/20707#discussion_r2586026292


##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/BootstrapDirectory.java:
##
@@ -19,65 +19,36 @@
 
 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";
+public interface BootstrapDirectory {
+String BINARY_BOOTSTRAP_FILENAME = "bootstrap.checkpoint";

Review Comment:
   I think we should move these static constants referencing the file names to 
the respective implementations right?



##
core/src/main/scala/kafka/server/KafkaRaftServer.scala:
##
@@ -181,7 +181,7 @@ object KafkaRaftServer {
 }
 
 // Load the BootstrapMetadata.
-val bootstrapDirectory = new BootstrapDirectory(config.metadataLogDir)
+val bootstrapDirectory: LegacyBootstrapDirectory = new 
LegacyBootstrapDirectory(config.metadataLogDir)

Review Comment:
   ```suggestion
   val bootstrapDirectory = new 
LegacyBootstrapDirectory(config.metadataLogDir)
   ```
   That should work right?



##
metadata/src/main/java/org/apache/kafka/metadata/bootstrap/TestBootstrapDirectory.java:
##
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.bootstrap;
+

Review Comment:
   Please remove the extra whitespace.



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