You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/08/19 14:07:41 UTC

[GitHub] [kafka] mumrah commented on a diff in pull request #12513: MINOR: some fixes to the KRaft bootstrap logic

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


##########
metadata/src/main/java/org/apache/kafka/controller/LogReplayTracker.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.controller;
+
+import java.util.Optional;
+
+import org.apache.kafka.common.protocol.ApiMessage;
+import org.apache.kafka.common.utils.LogContext;
+import org.apache.kafka.metadata.bootstrap.BootstrapMetadata;
+import org.apache.kafka.server.common.MetadataVersion;
+import org.slf4j.Logger;
+
+
+public class LogReplayTracker {

Review Comment:
   Brief javadoc would be nice. Should probably mention this is not thread safe



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

Review Comment:
   "Activation" is sort of unclear here. How about CompleteLeadershipClaim or something to indicate this happens as a result of becoming leader.



-- 
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-unsubscribe@kafka.apache.org

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