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/05/20 08:32:31 UTC
[GitHub] [kafka] dajac opened a new pull request, #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
dajac opened a new pull request, #12187:
URL: https://github.com/apache/kafka/pull/12187
WIP
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r880176824
##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -706,7 +706,7 @@ class Partition(val topicPartition: TopicPartition,
s"and partition state $partitionState since it is already a follower with leader epoch $leaderEpoch.")
}
- leaderReplicaIdOpt = Some(partitionState.leader)
+ leaderReplicaIdOpt = Option(partitionState.leader)
Review Comment:
Good idea.
--
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
[GitHub] [kafka] hachikuji commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r881165574
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2118,36 +2124,39 @@ class ReplicaManager(val config: KafkaConfig,
newImage: MetadataImage,
delta: TopicsDelta,
offsetCheckpoints: OffsetCheckpoints,
- newLocalFollowers: mutable.Map[TopicPartition, LocalReplicaChanges.PartitionInfo]
+ localFollowers: mutable.Map[TopicPartition, LocalReplicaChanges.PartitionInfo]
): Unit = {
- stateChangeLogger.info(s"Transitioning ${newLocalFollowers.size} partition(s) to " +
+ stateChangeLogger.info(s"Transitioning ${localFollowers.size} partition(s) to " +
"local followers.")
val shuttingDown = isShuttingDown.get()
- val partitionsToMakeFollower = new mutable.HashMap[TopicPartition, Partition]
- val newFollowerTopicSet = new mutable.HashSet[String]
- newLocalFollowers.forKeyValue { (tp, info) =>
+ val partitionsToStartFetching = new mutable.HashMap[TopicPartition, Partition]
+ val partitionsToStopFetching = new mutable.HashMap[TopicPartition, Boolean]
+ val followerTopicSet = new mutable.HashSet[String]
+ localFollowers.forKeyValue { (tp, info) =>
getOrCreatePartition(tp, delta, info.topicId).foreach { case (partition, isNew) =>
try {
- newFollowerTopicSet.add(tp.topic)
+ followerTopicSet.add(tp.topic)
if (shuttingDown) {
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
- stateChangeLogger.trace(s"Unable to start fetching $tp with topic ID ${info.topicId} " +
- s"from leader $leader because it is not alive.")
-
- // Create the local replica even if the leader is unavailable. This is required
- // to ensure that we include the partition's high watermark in the checkpoint
- // file (see KAFKA-1647).
- partition.createLogIfNotExists(isNew, false, offsetCheckpoints, Some(info.topicId))
- } else {
- val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
- if (partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))) {
- partitionsToMakeFollower.put(tp, partition)
- }
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
+ partitionsToStopFetching.put(tp, false)
Review Comment:
One of the things we do in the `ReplicaManager.stopPartitions` is force complete purgatory operations. Since we are not leader anymore, they can be completed immediately with an error. I might have missed it, but it seems like we don't have similar logic down this path.
--
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
[GitHub] [kafka] hachikuji commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r879971283
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2141,23 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- if (isInControlledShutdown && !info.partition.isr.contains(config.brokerId)) {
- // If we are in controlled shutdown and the replica is not in the ISR,
- // we stop the replica.
+ // We always update the follower state.
Review Comment:
Good change here. I do like keeping the state up-to-date even if we cannot start fetching. Hard to know when a dependence on that state will emerge.
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2134,20 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
- stateChangeLogger.trace(s"Unable to start fetching $tp with topic ID ${info.topicId} " +
- s"from leader $leader because it is not alive.")
-
- // Create the local replica even if the leader is unavailable. This is required
- // to ensure that we include the partition's high watermark in the checkpoint
- // file (see KAFKA-1647).
- partition.createLogIfNotExists(isNew, false, offsetCheckpoints, Some(info.topicId))
- } else {
- val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
- if (partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))) {
- partitionsToMakeFollower.put(tp, partition)
- }
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
+ partitionsToStop.put(tp, false)
+ } else if (isNewLeaderEpoch) {
+ // Otherwise, fetcher is restarted if the leader epoch has changed.
+ partitionsToStart.put(tp, partition)
}
}
changedPartitions.add(partition)
Review Comment:
We're maintaining this collection for the start of the log dir fetchers. Similar to the replica fetchers, I guess we only want to update log dir fetchers when there is an epoch bump (leader or follower). Since we're not yet supporting JBOD anyway in KRaft, it seems tempting to get rid of this logic.
##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -706,7 +706,7 @@ class Partition(val topicPartition: TopicPartition,
s"and partition state $partitionState since it is already a follower with leader epoch $leaderEpoch.")
}
- leaderReplicaIdOpt = Some(partitionState.leader)
+ leaderReplicaIdOpt = Option(partitionState.leader)
Review Comment:
Is it worth adding the current leader to the "Follower $topicPartition starts at ..." log message above?
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2170,33 +2179,47 @@ class ReplicaManager(val config: KafkaConfig,
}
}
- // Stopping the fetchers must be done first in order to initialize the fetch
- // position correctly.
- replicaFetcherManager.removeFetcherForPartitions(partitionsToMakeFollower.keySet)
- stateChangeLogger.info(s"Stopped fetchers as part of become-follower for ${partitionsToMakeFollower.size} partitions")
-
- val listenerName = config.interBrokerListenerName.value
- val partitionAndOffsets = new mutable.HashMap[TopicPartition, InitialFetchState]
- partitionsToMakeFollower.forKeyValue { (topicPartition, partition) =>
- val node = partition.leaderReplicaIdOpt
- .flatMap(leaderId => Option(newImage.cluster.broker(leaderId)))
- .flatMap(_.node(listenerName).asScala)
- .getOrElse(Node.noNode)
- val log = partition.localLogOrException
- partitionAndOffsets.put(topicPartition, InitialFetchState(
- log.topicId,
- new BrokerEndPoint(node.id, node.host, node.port),
- partition.getLeaderEpoch,
- initialFetchOffset(log)
- ))
- }
+ if (partitionsToStart.nonEmpty) {
+ // Stopping the fetchers must be done first in order to initialize the fetch
+ // position correctly.
+ replicaFetcherManager.removeFetcherForPartitions(partitionsToStart.keySet)
+ stateChangeLogger.info(s"Stopped fetchers as part of become-follower for ${partitionsToStart.size} partitions")
+
+ val listenerName = config.interBrokerListenerName.value
+ val partitionAndOffsets = new mutable.HashMap[TopicPartition, InitialFetchState]
+
+ partitionsToStart.forKeyValue { (topicPartition, partition) =>
+ val nodeOpt = partition.leaderReplicaIdOpt
+ .flatMap(leaderId => Option(newImage.cluster.broker(leaderId)))
+ .flatMap(_.node(listenerName).asScala)
+
+ nodeOpt match {
+ case Some(node) =>
+ val log = partition.localLogOrException
+ partitionAndOffsets.put(topicPartition, InitialFetchState(
+ log.topicId,
+ new BrokerEndPoint(node.id, node.host, node.port),
+ partition.getLeaderEpoch,
+ initialFetchOffset(log)
+ ))
+ case None =>
+ stateChangeLogger.trace(s"Unable to start fetching $topicPartition with topic ID ${partition.topicId} " +
+ s"from leader ${partition.leaderReplicaIdOpt} because it is not alive.")
+ }
+ }
- replicaFetcherManager.addFetcherForPartitions(partitionAndOffsets)
- stateChangeLogger.info(s"Started fetchers as part of become-follower for ${partitionsToMakeFollower.size} partitions")
+ replicaFetcherManager.addFetcherForPartitions(partitionAndOffsets)
+ stateChangeLogger.info(s"Started fetchers as part of become-follower for ${partitionsToStart.size} partitions")
- partitionsToMakeFollower.keySet.foreach(completeDelayedFetchOrProduceRequests)
+ partitionsToStart.keySet.foreach(completeDelayedFetchOrProduceRequests)
Review Comment:
Borderline too verbose perhaps, but how about `partitionsToStartFetching`?
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2123,7 +2129,8 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.info(s"Transitioning ${newLocalFollowers.size} partition(s) to " +
"local followers.")
val shuttingDown = isShuttingDown.get()
- val partitionsToMakeFollower = new mutable.HashMap[TopicPartition, Partition]
+ val partitionsToStart = new mutable.HashMap[TopicPartition, Partition]
+ val partitionsToStop = new mutable.HashMap[TopicPartition, Boolean]
val newFollowerTopicSet = new mutable.HashSet[String]
Review Comment:
Not from this PR, but I find the naming of `newLocalFollowers` in the parameter list confusing given the presence of the `isNew` flag. I guess it's really representing new or updated followers.
--
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
[GitHub] [kafka] dajac commented on pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on PR #12187:
URL: https://github.com/apache/kafka/pull/12187#issuecomment-1136124352
@hachikuji Thanks for your review. I have updated the PR to address your comments.
--
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
[GitHub] [kafka] hachikuji merged pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji merged PR #12187:
URL: https://github.com/apache/kafka/pull/12187
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r880181278
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2170,33 +2179,47 @@ class ReplicaManager(val config: KafkaConfig,
}
}
- // Stopping the fetchers must be done first in order to initialize the fetch
- // position correctly.
- replicaFetcherManager.removeFetcherForPartitions(partitionsToMakeFollower.keySet)
- stateChangeLogger.info(s"Stopped fetchers as part of become-follower for ${partitionsToMakeFollower.size} partitions")
-
- val listenerName = config.interBrokerListenerName.value
- val partitionAndOffsets = new mutable.HashMap[TopicPartition, InitialFetchState]
- partitionsToMakeFollower.forKeyValue { (topicPartition, partition) =>
- val node = partition.leaderReplicaIdOpt
- .flatMap(leaderId => Option(newImage.cluster.broker(leaderId)))
- .flatMap(_.node(listenerName).asScala)
- .getOrElse(Node.noNode)
- val log = partition.localLogOrException
- partitionAndOffsets.put(topicPartition, InitialFetchState(
- log.topicId,
- new BrokerEndPoint(node.id, node.host, node.port),
- partition.getLeaderEpoch,
- initialFetchOffset(log)
- ))
- }
+ if (partitionsToStart.nonEmpty) {
+ // Stopping the fetchers must be done first in order to initialize the fetch
+ // position correctly.
+ replicaFetcherManager.removeFetcherForPartitions(partitionsToStart.keySet)
+ stateChangeLogger.info(s"Stopped fetchers as part of become-follower for ${partitionsToStart.size} partitions")
+
+ val listenerName = config.interBrokerListenerName.value
+ val partitionAndOffsets = new mutable.HashMap[TopicPartition, InitialFetchState]
+
+ partitionsToStart.forKeyValue { (topicPartition, partition) =>
+ val nodeOpt = partition.leaderReplicaIdOpt
+ .flatMap(leaderId => Option(newImage.cluster.broker(leaderId)))
+ .flatMap(_.node(listenerName).asScala)
+
+ nodeOpt match {
+ case Some(node) =>
+ val log = partition.localLogOrException
+ partitionAndOffsets.put(topicPartition, InitialFetchState(
+ log.topicId,
+ new BrokerEndPoint(node.id, node.host, node.port),
+ partition.getLeaderEpoch,
+ initialFetchOffset(log)
+ ))
+ case None =>
+ stateChangeLogger.trace(s"Unable to start fetching $topicPartition with topic ID ${partition.topicId} " +
+ s"from leader ${partition.leaderReplicaIdOpt} because it is not alive.")
+ }
+ }
- replicaFetcherManager.addFetcherForPartitions(partitionAndOffsets)
- stateChangeLogger.info(s"Started fetchers as part of become-follower for ${partitionsToMakeFollower.size} partitions")
+ replicaFetcherManager.addFetcherForPartitions(partitionAndOffsets)
+ stateChangeLogger.info(s"Started fetchers as part of become-follower for ${partitionsToStart.size} partitions")
- partitionsToMakeFollower.keySet.foreach(completeDelayedFetchOrProduceRequests)
+ partitionsToStart.keySet.foreach(completeDelayedFetchOrProduceRequests)
Review Comment:
That seems like a reasonable ask.
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r879677034
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2141,23 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- if (isInControlledShutdown && !info.partition.isr.contains(config.brokerId)) {
- // If we are in controlled shutdown and the replica is not in the ISR,
- // we stop the replica.
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
partitionsToStop.put(tp, false)
- } else if (newImage.cluster.broker(info.partition.leader) == null) {
Review Comment:
It should be handled a bit later, at L2192. If we have no leader, `nodeOpt` will be `None` and we don't start the fetcher. It seems to be similar to the previous implementation to me but I may have missed something.
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r880193539
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2134,20 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
- stateChangeLogger.trace(s"Unable to start fetching $tp with topic ID ${info.topicId} " +
- s"from leader $leader because it is not alive.")
-
- // Create the local replica even if the leader is unavailable. This is required
- // to ensure that we include the partition's high watermark in the checkpoint
- // file (see KAFKA-1647).
- partition.createLogIfNotExists(isNew, false, offsetCheckpoints, Some(info.topicId))
- } else {
- val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
- if (partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))) {
- partitionsToMakeFollower.put(tp, partition)
- }
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
+ partitionsToStop.put(tp, false)
+ } else if (isNewLeaderEpoch) {
+ // Otherwise, fetcher is restarted if the leader epoch has changed.
+ partitionsToStart.put(tp, partition)
}
}
changedPartitions.add(partition)
Review Comment:
I don't have a strong opinion on this but removing unused logic seems appropriate. That will force us to think it through when we implement it. Do you mind if we do this separately? I would like to keep this PR focused on its primary goal.
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r881333085
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2118,36 +2124,39 @@ class ReplicaManager(val config: KafkaConfig,
newImage: MetadataImage,
delta: TopicsDelta,
offsetCheckpoints: OffsetCheckpoints,
- newLocalFollowers: mutable.Map[TopicPartition, LocalReplicaChanges.PartitionInfo]
+ localFollowers: mutable.Map[TopicPartition, LocalReplicaChanges.PartitionInfo]
): Unit = {
- stateChangeLogger.info(s"Transitioning ${newLocalFollowers.size} partition(s) to " +
+ stateChangeLogger.info(s"Transitioning ${localFollowers.size} partition(s) to " +
"local followers.")
val shuttingDown = isShuttingDown.get()
- val partitionsToMakeFollower = new mutable.HashMap[TopicPartition, Partition]
- val newFollowerTopicSet = new mutable.HashSet[String]
- newLocalFollowers.forKeyValue { (tp, info) =>
+ val partitionsToStartFetching = new mutable.HashMap[TopicPartition, Partition]
+ val partitionsToStopFetching = new mutable.HashMap[TopicPartition, Boolean]
+ val followerTopicSet = new mutable.HashSet[String]
+ localFollowers.forKeyValue { (tp, info) =>
getOrCreatePartition(tp, delta, info.topicId).foreach { case (partition, isNew) =>
try {
- newFollowerTopicSet.add(tp.topic)
+ followerTopicSet.add(tp.topic)
if (shuttingDown) {
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
- stateChangeLogger.trace(s"Unable to start fetching $tp with topic ID ${info.topicId} " +
- s"from leader $leader because it is not alive.")
-
- // Create the local replica even if the leader is unavailable. This is required
- // to ensure that we include the partition's high watermark in the checkpoint
- // file (see KAFKA-1647).
- partition.createLogIfNotExists(isNew, false, offsetCheckpoints, Some(info.topicId))
- } else {
- val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
- if (partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))) {
- partitionsToMakeFollower.put(tp, partition)
- }
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
+ partitionsToStopFetching.put(tp, false)
Review Comment:
`ReplicaManager.stopPartitions` is called at L220. `stopPartitions` stops the fetchers and calls `completeDelayedFetchOrProduceRequests` to force complete the pending purgatory operations.
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r880180144
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2123,7 +2129,8 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.info(s"Transitioning ${newLocalFollowers.size} partition(s) to " +
"local followers.")
val shuttingDown = isShuttingDown.get()
- val partitionsToMakeFollower = new mutable.HashMap[TopicPartition, Partition]
+ val partitionsToStart = new mutable.HashMap[TopicPartition, Partition]
+ val partitionsToStop = new mutable.HashMap[TopicPartition, Boolean]
val newFollowerTopicSet = new mutable.HashSet[String]
Review Comment:
That's right. How about `localFollowers`? `newOrUpdatedLocalFollowers` seems a bit long to me.
--
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
[GitHub] [kafka] hachikuji commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r879668233
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2141,23 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- if (isInControlledShutdown && !info.partition.isr.contains(config.brokerId)) {
- // If we are in controlled shutdown and the replica is not in the ISR,
- // we stop the replica.
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
partitionsToStop.put(tp, false)
- } else if (newImage.cluster.broker(info.partition.leader) == null) {
Review Comment:
Did we lose this case? It is possible to have no leader when we are not shutting down.
--
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
[GitHub] [kafka] hachikuji commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r881158834
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2134,20 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
- stateChangeLogger.trace(s"Unable to start fetching $tp with topic ID ${info.topicId} " +
- s"from leader $leader because it is not alive.")
-
- // Create the local replica even if the leader is unavailable. This is required
- // to ensure that we include the partition's high watermark in the checkpoint
- // file (see KAFKA-1647).
- partition.createLogIfNotExists(isNew, false, offsetCheckpoints, Some(info.topicId))
- } else {
- val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
- if (partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))) {
- partitionsToMakeFollower.put(tp, partition)
- }
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
+ partitionsToStop.put(tp, false)
+ } else if (isNewLeaderEpoch) {
+ // Otherwise, fetcher is restarted if the leader epoch has changed.
+ partitionsToStart.put(tp, partition)
}
}
changedPartitions.add(partition)
Review Comment:
Yeah, we can do it separately.
--
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
[GitHub] [kafka] hachikuji commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r878712671
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2134,10 +2141,13 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
+ if (isInControlledShutdown && !info.partition.isr.contains(config.brokerId)) {
Review Comment:
I wonder if we should also count the case when the replica is in the ISR, but no leader is defined. I think this is what we would see if the shutting down replica is the last member of the ISR.
--
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
[GitHub] [kafka] Beverly21024 commented on pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by "Beverly21024 (via GitHub)" <gi...@apache.org>.
Beverly21024 commented on PR #12187:
URL: https://github.com/apache/kafka/pull/12187#issuecomment-1436279689
Good post. Someone stole $70,000 from me once (crypto). It took me
1 month with the help of Wizesafetyrecovery @ gmail com and a bunch of stress to finally get it back but it was a learning experience. Ever since then I have had to tighten up my online presence. If anyone reading this has a similar issue, I recommend using them to recover your lost funds.
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r879162306
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2134,10 +2141,13 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
+ if (isInControlledShutdown && !info.partition.isr.contains(config.brokerId)) {
Review Comment:
That makes sense. I forgot about this case.
--
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
[GitHub] [kafka] hachikuji commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r879681829
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2141,23 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- if (isInControlledShutdown && !info.partition.isr.contains(config.brokerId)) {
- // If we are in controlled shutdown and the replica is not in the ISR,
- // we stop the replica.
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
partitionsToStop.put(tp, false)
- } else if (newImage.cluster.broker(info.partition.leader) == null) {
Review Comment:
Ah, I see.
--
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
[GitHub] [kafka] dajac commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
dajac commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r880194784
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2141,23 +2141,22 @@ class ReplicaManager(val config: KafkaConfig,
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- if (isInControlledShutdown && !info.partition.isr.contains(config.brokerId)) {
- // If we are in controlled shutdown and the replica is not in the ISR,
- // we stop the replica.
+ // We always update the follower state.
Review Comment:
Yeah. That seems to be the right thing to do. I have looked at the dependencies on that state and I haven't identified any issues so far.
--
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
[GitHub] [kafka] hachikuji commented on a diff in pull request #12187: KAFKA-13858; Kraft should not shutdown metadata listener until controller shutdown is finished
Posted by GitBox <gi...@apache.org>.
hachikuji commented on code in PR #12187:
URL: https://github.com/apache/kafka/pull/12187#discussion_r881909778
##########
core/src/main/scala/kafka/server/ReplicaManager.scala:
##########
@@ -2118,36 +2124,39 @@ class ReplicaManager(val config: KafkaConfig,
newImage: MetadataImage,
delta: TopicsDelta,
offsetCheckpoints: OffsetCheckpoints,
- newLocalFollowers: mutable.Map[TopicPartition, LocalReplicaChanges.PartitionInfo]
+ localFollowers: mutable.Map[TopicPartition, LocalReplicaChanges.PartitionInfo]
): Unit = {
- stateChangeLogger.info(s"Transitioning ${newLocalFollowers.size} partition(s) to " +
+ stateChangeLogger.info(s"Transitioning ${localFollowers.size} partition(s) to " +
"local followers.")
val shuttingDown = isShuttingDown.get()
- val partitionsToMakeFollower = new mutable.HashMap[TopicPartition, Partition]
- val newFollowerTopicSet = new mutable.HashSet[String]
- newLocalFollowers.forKeyValue { (tp, info) =>
+ val partitionsToStartFetching = new mutable.HashMap[TopicPartition, Partition]
+ val partitionsToStopFetching = new mutable.HashMap[TopicPartition, Boolean]
+ val followerTopicSet = new mutable.HashSet[String]
+ localFollowers.forKeyValue { (tp, info) =>
getOrCreatePartition(tp, delta, info.topicId).foreach { case (partition, isNew) =>
try {
- newFollowerTopicSet.add(tp.topic)
+ followerTopicSet.add(tp.topic)
if (shuttingDown) {
stateChangeLogger.trace(s"Unable to start fetching $tp with topic " +
s"ID ${info.topicId} because the replica manager is shutting down.")
} else {
- val leader = info.partition.leader
- if (newImage.cluster.broker(leader) == null) {
- stateChangeLogger.trace(s"Unable to start fetching $tp with topic ID ${info.topicId} " +
- s"from leader $leader because it is not alive.")
-
- // Create the local replica even if the leader is unavailable. This is required
- // to ensure that we include the partition's high watermark in the checkpoint
- // file (see KAFKA-1647).
- partition.createLogIfNotExists(isNew, false, offsetCheckpoints, Some(info.topicId))
- } else {
- val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
- if (partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))) {
- partitionsToMakeFollower.put(tp, partition)
- }
+ // We always update the follower state.
+ // - This ensure that a replica with no leader can step down;
+ // - This also ensures that the local replica is created even if the leader
+ // is unavailable. This is required to ensure that we include the partition's
+ // high watermark in the checkpoint file (see KAFKA-1647).
+ val state = info.partition.toLeaderAndIsrPartitionState(tp, isNew)
+ val isNewLeaderEpoch = partition.makeFollower(state, offsetCheckpoints, Some(info.topicId))
+
+ if (isInControlledShutdown && (info.partition.leader == NO_LEADER ||
+ !info.partition.isr.contains(config.brokerId))) {
+ // During controlled shutdown, replica with no leaders and replica
+ // where this broker is not in the ISR are stopped.
+ partitionsToStopFetching.put(tp, false)
Review Comment:
Ah, yeah. I think I saw that in the first pass and then forgot.
--
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