PreferredReplicaLeaderElectionCommand Standalone Application

kafka.admin.PreferredReplicaLeaderElectionCommand is a standalone application to trigger preferred replica leader election for all or some partitions.

PreferredReplicaLeaderElectionCommand uses AdminClient internally and is simply a command-line front-end to AdminClient.electPreferredLeaders.

PreferredReplicaLeaderElectionCommand is usually executed on command line using shell script (that simply uses kafka-run-class shell script to launch the command).

Table 1. Options
Option Description


Config properties file to pass to the admin client


(required) Brokers to connect to as a comma-separated list of host:port URLs


Prints usage information


JSON file with partitions

Default: (empty) (all partitions)

The format of the JSON file should be as follows:

{ "partitions":
    { "topic": "foo", "partition": 1 },
    { "topic": "foobar", "partition": 2 }

The JSON file should not be empty and has no duplicate partitions (or AdminOperationException is thrown)


Displays Kafka version

Executing Standalone Application — main Object Method

main(args: Array[String]): Unit

main is the entry point of the PreferredReplicaLeaderElectionCommand when launched on command line (e.g. using shell script).

Internally, main simply run (with the default timeout of 30000).

run Object Method

  args: Array[String],
  timeout: Int = 30000): Unit

run reads the options from the command line.

run prints out the following for no command-line options, --help or --version:

This tool helps to causes leadership for each partition to be transferred back to the 'preferred replica', it can be used to balance leadership among the servers.

run creates a new AdminClientCommand (with the admin.config properties file when specified).

In the end, run requests the AdminClientCommand to electPreferredLeaders and then close.

run is used exclusively when PreferredReplicaLeaderElectionCommand command-line application is executed.

electPreferredLeaders Method

  partitionsFromUser: Option[Set[TopicPartition]]): Unit

electPreferredLeaders prints out the following DEBUG message to the logs:

Calling AdminClient.electPreferredLeaders([partitions])

electPreferredLeaders creates a new AdminClient and requests to electPreferredLeaders.

electPreferredLeaders is used exclusively when PreferredReplicaLeaderElectionCommand is requested to run.

Closing AdminClient — close Method

close(): Unit

close prints out the following DEBUG message to the logs and requests the AdminClient to close.

Closing AdminClient
close is used exclusively when PreferredReplicaLeaderElectionCommand is requested to run.

results matching ""

    No results matching ""