Skip to content

Removing entries from the shuttingdownBrokerIds upon broker startup - #187

Merged
gitlw merged 1 commit into
linkedin:2.4-lifrom
gitlw:controlled_shutdown_blocked
Jul 26, 2021
Merged

Removing entries from the shuttingdownBrokerIds upon broker startup#187
gitlw merged 1 commit into
linkedin:2.4-lifrom
gitlw:controlled_shutdown_blocked

Conversation

@gitlw

@gitlw gitlw commented Jul 23, 2021

Copy link
Copy Markdown

Consider a cluster having two brokers (id=0 and id=1) configured with

<property name="kafka.controlledShutdownEnable" value="true">
<property name="kafka.controlledShutdownMaxRetries" value="2147483640">
<property name="kafka.controlledShutdownSafetyCheckEnable" value="true">
<property name="kafka.controlledShutdownSafetyCheckRedundancyFactor" value="0">

and a partition having two replicas on these two brokers.

If broker1 goes through the controlled shutdown process and starts up, the current implementation uses the following logic to update the shuttingdownBrokerIds:

shuttingDownBrokerIds = shuttingDownBrokerIds.filter(b =>
      liveBrokerEpochs.contains(b._1) && b._2 < liveBrokerEpochs(b._1))

which means broker1's previous shutting epoch is still retained in the shuttingDownBrokerIds after it restarts.

Later on, if broker0 needs to restart, the controller uses the leaderForControlledShutdown method to elect a new leader for partitions led by broker0:

def leaderForControlledShutdown(controllerContext: ControllerContext,
                                  leaderAndIsrs: Seq[(TopicPartition, LeaderAndIsr)]): Seq[ElectionResult] = {
    val shuttingDownBrokerIdSet = controllerContext.shuttingDownBrokerIds.keySet.toSet
    leaderAndIsrs.map { case (partition, leaderAndIsr) =>
      leaderForControlledShutdown(partition, leaderAndIsr, shuttingDownBrokerIdSet, controllerContext)
    }
  }

The leaderForControlledShutdown would still treat broker1 as a shutting down broker, and therefore won't be able to transfer the leadership to broker1, despite its readiness to serve as the leader.

This PR resolves the problem by changing the update logic of shuttingDownBrokerIds such that the entry of a restarted broker would be removed from it.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@gitlw
gitlw requested a review from ambroff July 23, 2021 23:26
@gitlw

gitlw commented Jul 24, 2021

Copy link
Copy Markdown
Author

The failed tests are being resolved at #188

@ambroff ambroff left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Thanks for fixing this. That's a good catch, I just had the logic wrong in that filter predicate.

scala> val liveBrokerEpochs = Map(0 -> 5, 1 -> 10)
val liveBrokerEpochs: scala.collection.immutable.Map[Int,Int] = Map(0 -> 5, 1 -> 10)

scala> liveBrokerEpochs(0)
val res0: Int = 5

scala> val shuttingDownBrokerIds = Map(1 -> 9)
val shuttingDownBrokerIds: scala.collection.immutable.Map[Int,Int] = Map(1 -> 9)

scala> shuttingDownBrokerIds.filter(b => liveBrokerEpochs.contains(b._1) && b._2 < liveBrokerEpochs(b._1))
val res1: scala.collection.immutable.Map[Int,Int] = Map(1 -> 9)

scala> shuttingDownBrokerIds.filter(b => liveBrokerEpochs.contains(b._1) && b._2 > liveBrokerEpochs(b._1))
val res2: scala.collection.immutable.Map[Int,Int] = Map()

scala> shuttingDownBrokerIds.filter(b => liveBrokerEpochs.contains(b._1) && b._2 > liveBrokerEpochs(b._1))
val res3: scala.collection.immutable.Map[Int,Int] = Map()

scala> shuttingDownBrokerIds.filter(b => liveBrokerEpochs.contains(b._1) && b._2 > liveBrokerEpochs(b._1))
val res4: scala.collection.immutable.Map[Int,Int] = Map()

@gitlw
gitlw force-pushed the controlled_shutdown_blocked branch from 9d68691 to 35da48a Compare July 26, 2021 15:44
@gitlw
gitlw merged commit 24be3bb into linkedin:2.4-li Jul 26, 2021
@gitlw
gitlw deleted the controlled_shutdown_blocked branch January 28, 2022 05:27
wyuka pushed a commit that referenced this pull request Feb 4, 2022
…er startup (#187)

TICKET = N/A
LI_DESCRIPTION = Removing entries from the shuttingdownBrokerIds upon broker startup
EXIT_CRITERIA = N/A
lmr3796 pushed a commit to lmr3796/kafka that referenced this pull request Feb 9, 2022
…er startup (linkedin#187)

TICKET = N/A
LI_DESCRIPTION = Removing entries from the shuttingdownBrokerIds upon broker startup
EXIT_CRITERIA = N/A
lmr3796 pushed a commit to lmr3796/kafka that referenced this pull request Mar 25, 2022
…er startup (linkedin#187)

TICKET = N/A
LI_DESCRIPTION = Removing entries from the shuttingdownBrokerIds upon broker startup
EXIT_CRITERIA = N/A
lmr3796 pushed a commit to lmr3796/kafka that referenced this pull request Jun 2, 2022
… startup (linkedin#187)

TICKET = N/A
LI_DESCRIPTION = Removing entries from the shuttingdownBrokerIds upon broker startup
EXIT_CRITERIA = N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants