cmccabe commented on code in PR #12513:
URL: https://github.com/apache/kafka/pull/12513#discussion_r949680410


##########
metadata/src/main/java/org/apache/kafka/controller/QuorumController.java:
##########
@@ -1118,6 +1059,65 @@ private void updateWriteOffset(long offset) {
         }
     }
 
+    private void claim(int epoch) {
+        try {
+            if (curClaimEpoch != -1) {
+                throw new RuntimeException("Cannot claim leadership because we 
are already the " +
+                        "active controller.");
+            }
+            curClaimEpoch = epoch;
+            controllerMetrics.setActive(true);
+            updateWriteOffset(lastCommittedOffset);
+            clusterControl.activate();
+
+            // Before switching to active, create an in-memory snapshot at the 
last committed
+            // offset. This is required because the active controller assumes 
that there is always
+            // an in-memory snapshot at the last committed offset.
+            snapshotRegistry.getOrCreateSnapshot(lastCommittedOffset);
+
+            // Prepend the activate event. It is important that this event go 
at the beginning
+            // of the queue rather than the end (hence prepend rather than 
append). It's also
+            // important not to use prepend for anything else, to preserve the 
ordering here.
+            queue.prepend(new ControllerWriteEvent<>("completeActivation[" + 
epoch + "]",
+                    new CompleteActivationEvent()));
+        } catch (Throwable e) {
+            fatalFaultHandler.handleFault("exception while claiming 
leadership", e);
+        }
+    }
+
+    class CompleteActivationEvent implements ControllerWriteOperation<Void> {
+        @Override
+        public ControllerResult<Void> generateRecordsAndResult() throws 
Exception {
+            List<ApiMessageAndVersion> records = new ArrayList<>();
+            if (logReplayTracker.empty()) {
+                // If no records have been replayed, we need to write out the 
bootstrap records.
+                // This will include the new metadata.version, as well as 
things like SCRAM
+                // initialization, etc.
+                log.warn("The metadata log appears to be empty. Appending {} 
bootstrap record(s) " +

Review Comment:
   Ehh... `warn` seems appropriate. We are upgrading your `metadata.version`, 
it's kind of a big deal. You will also only ever see this once



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to