Skip to content

Commit

Permalink
feat(issues1169): prevent re-open partition when the broker is shutti…
Browse files Browse the repository at this point in the history
…ng down (#1210)

Signed-off-by: Robin Han <[email protected]>
  • Loading branch information
superhx authored May 5, 2024
1 parent 4663443 commit 9806741
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class ElasticReplicaManager(
*/
private val partitionOpMap = new ConcurrentHashMap[TopicPartition, CompletableFuture[Void]]()

private var fenced: Boolean = false

override def startup(): Unit = {
super.startup()
val haltBrokerOnFailure = metadataCache.metadataVersion().isLessThan(MetadataVersion.IBP_1_0_IV0)
Expand Down Expand Up @@ -1067,8 +1069,12 @@ class ElasticReplicaManager(
}

if (ElasticLogManager.enabled()) {
// applyDelta must sync operate, cause of BrokerMetadataPublisher#updateCoordinator will rely on log created.
doPartitionLeadingOrFollowing(true)
// When the brokers scale into zero, there isr/replica will set to the last broker.
// We use fenced state to prevent the last broker re-open partition when the broker shutting down.
if (!this.fenced) {
// applyDelta must sync operate, cause of BrokerMetadataPublisher#updateCoordinator will rely on log created.
doPartitionLeadingOrFollowing(true)
}
} else {
doPartitionLeadingOrFollowing(false)
}
Expand Down Expand Up @@ -1178,6 +1184,7 @@ class ElasticReplicaManager(
def awaitAllPartitionShutdown(): Unit = {
val start = System.currentTimeMillis()
replicaStateChangeLock.synchronized {
this.fenced = true
// When there are any other alive brokers, partitions will be transferred to them and deleted in the method [[asyncApplyDelta]].
// However when there are no other alive brokers, we need to delete partitions by ourselves here.
// In summary, a partition may be deleted twice during shutdown. But it is safe as the method [[stopPartitions]]
Expand Down

0 comments on commit 9806741

Please sign in to comment.