Preferred Replica Leader Election (Preferred Replica Election)

Preferred Replica Leader Election (Preferred Replica Election) is a process…​FIXME

Tip
Read up on Preferred Replica Leader Election in the official documentation.

Preferred Replica Election is triggered using kafka-leader-election.sh shell script for partitions as defined in a JSON file.

Preferred Replica Election can also be triggered using AdminClient that sends out the request to the controller broker (that simply requests the ReplicaManager to trigger the election)

Tip

Use KafkaController logging to monitor the process.

INFO [Controller id=1001] Starting preferred replica leader election for partitions  (kafka.controller.KafkaController)
DEBUG [Controller id=1001] PreferredReplicaLeaderElection waiting: Set(), results: Map(t1-0 -> ApiError(error=NONE, message=null), t1-1 -> ApiError(error=NONE, message=null)) (kafka.controller.KafkaController)

In the very end, it is one of the many responsibilities of the controller broker to actually perform Preferred Replica Leader Election.

ACL

Either tool requires a principal to be authorized to perform Alter operation on cluster resource.

$ kafka-acls.sh \
    --authorizer-properties zookeeper.connect=zookeeper:2181 \
    --list

// Disable Alter on cluster resource
// The principal type is always User for the simple authorizer
$ kafka-acls.sh \
    --authorizer-properties zookeeper.connect=zookeeper:2181 \
    --add \
    --cluster \
    --operation Alter \
    --deny-principal User:ANONYMOUS
Adding ACLs for resource `Cluster:LITERAL:kafka-cluster`:
 	User:ANONYMOUS has Deny permission for operations: Alter from hosts: *

Current ACLs for resource `Cluster:LITERAL:kafka-cluster`:
 	User:ANONYMOUS has Deny permission for operations: Alter from hosts: *

$ kafka-acls.sh \
    --authorizer-properties zookeeper.connect=zookeeper:2181 \
    --list
Current ACLs for resource `Cluster:LITERAL:kafka-cluster`:
 	User:ANONYMOUS has Deny permission for operations: Alter from hosts: *

$ kafka-preferred-replica-election.sh \
    --bootstrap-server :9092 \
    --path-to-json-file parts.json
Error completing preferred replica election for partition t1-1: org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
Error completing preferred replica election for partition t1-0: org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
Exception in thread "main" kafka.common.AdminCommandFailedException: 2 preferred replica(s) could not be elected
	at kafka.admin.PreferredReplicaLeaderElectionCommand$AdminClientCommand.electPreferredLeaders(PreferredReplicaLeaderElectionCommand.scala:263)
	at kafka.admin.PreferredReplicaLeaderElectionCommand$.run(PreferredReplicaLeaderElectionCommand.scala:78)
	at kafka.admin.PreferredReplicaLeaderElectionCommand$.main(PreferredReplicaLeaderElectionCommand.scala:42)
	at kafka.admin.PreferredReplicaLeaderElectionCommand.main(PreferredReplicaLeaderElectionCommand.scala)
	Suppressed: org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
	[CIRCULAR REFERENCE:org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.]

$ kafka-acls.sh \
    --authorizer-properties zookeeper.connect=zookeeper:2181 \
    --remove \
    --cluster \
    --operation Alter \
    --deny-principal User:ANONYMOUS \
    --force

$ kafka-acls.sh \
    --authorizer-properties zookeeper.connect=zookeeper:2181 \
    --list

$ kafka-preferred-replica-election.sh \
    --bootstrap-server :9092 \
    --path-to-json-file parts.json
Successfully completed preferred replica election for partitions t1-1, t1-0

results matching ""

    No results matching ""