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


##########
core/src/main/scala/kafka/zk/KafkaZkClient.scala:
##########
@@ -166,60 +166,74 @@ class KafkaZkClient private[zk] (zooKeeperClient: 
ZooKeeperClient, isSecure: Boo
    * the migration.
    *
    * To ensure that the KRaft controller epoch exceeds the current ZK 
controller epoch, this registration algorithm
-   * uses a conditional update on the /controller_epoch znode. If a new ZK 
controller is elected during this method,
-   * the conditional update on /controller_epoch fails which causes the whole 
multi-op transaction to fail.
+   * uses a conditional update on the /controller and /controller_epoch znodes.
+   *
+   * If a new controller is registered concurrently with this registration, 
one of the two will fail the CAS
+   * operation on /controller_epoch. For KRaft, we have an extra guard against 
the registered KRaft epoch going
+   * backwards. If a KRaft controller had previously registered, an additional 
CAS operation is done on the /controller
+   * ZNode to ensure that the KRaft epoch being registered is newer.
    *
    * @param kraftControllerId ID of the KRaft controller node
    * @param kraftControllerEpoch Epoch of the KRaft controller node
-   * @return An optional of the new zkVersion of /controller_epoch. None if we 
could not register the KRaft controller.
+   * @return An optional of the written epoch and new zkVersion of 
/controller_epoch. None if we could not register the KRaft controller.
    */
-  def tryRegisterKRaftControllerAsActiveController(kraftControllerId: Int, 
kraftControllerEpoch: Int): Option[Int] = {
+  def tryRegisterKRaftControllerAsActiveController(kraftControllerId: Int, 
kraftControllerEpoch: Int): Option[(Int, Int)] = {

Review Comment:
   As discussed offline, the controller epoch and zkVersion are both ints



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to