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 kafka-preferred-replica-election.sh shell script (that simply uses kafka-run-class shell script to launch the command).

Table 1. Options
Option Description

admin.config

Config properties file to pass to the admin client

bootstrap-server

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

help

Prints usage information

path-to-json-file

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)

version

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 kafka-preferred-replica-election.sh shell script).

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

run Object Method

run(
  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.

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

electPreferredLeaders Method

electPreferredLeaders(
  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.

Note
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
Note
close is used exclusively when PreferredReplicaLeaderElectionCommand is requested to run.

results matching ""

    No results matching ""