...
Code Block |
---|
|
package org.apache.kafka.clients.admin;
public abstract class AdminClient ... {
...
/**
* Attempt...
to elect a new leader* for@deprecated eachSince of the topic partition inTBD. Use {@code@link partitionElections#electLeaders}.
The type of elections supported are*/
@Deprecated
* document in thepublic {@linkabstract TopicPartitionElection} type.ElectPreferredLeadersResult electPreferredLeaders(Collection<TopicPartition> partitions,
*
* If {@code partitionElections} is null, then attempt to elect the preferred replica for all of the partitions.
*
* @param partitionElections The partitions and the type of elections to conduct.
* @param options ElectPreferredLeadersOptions options);
/**
The options to use* whenAttempt electingto theelect leaders.
a new leader for each *of @returnthe topic partition in {@code partitionElections}. The type of elections supported are
* document in the {@link The ElectLeadersResultTopicPartitionElection} type.
*/
public abstract ElectLeadersResult electLeaders(
Collection<TopicPartitionElection> partitionElections, * If {@code partitionElections} is null, then attempt to elect the preferred replica for all of the partitions.
*
* @param partitionElections ElectLeadersOptions options);
} |
TopicPartitionElection Class
Code Block |
---|
|
package org.apache.kafka.common;
public final class TopicPartitionElectionThe {
partitions and the type publicof staticelections enumto ElectionTypeconduct.
{
* @param options PREFERRED((byte) 0), UNCLEANED((byte) 1);
public final byte value;
The options to use when electing ElectionType(byte value) {
the leaders.
* @return this.value = value;
}
}
The ElectLeadersResult.
public final TopicPartition topicPartition;*/
public finalabstract ElectionTypeElectLeadersResult electionType;electLeaders(
...
} |
Admin Command
The command kafka-preferred-replica-election.{sh,bat} will be deprecated and the following command will be added.
Collection<TopicPartitionElection> partitionElections,
ElectLeadersOptions options);
} |
TopicPartitionElection Class
Code Block |
---|
|
package org.apache.kafka.common;
public final class TopicPartitionElection {
public static enum ElectionType {
PREFERRED((byte) 0), UNCLEANED((byte) 1);
public final byte value;
ElectionType(byte value) {
this.value = value;
}
}
public final TopicPartition topicPartition;
public final ElectionType electionType;
...
} |
Admin Command
The command kafka-preferred-replica-election.{sh,bat} will be deprecated and the following command will be added.
Code Block |
---|
|
$ bin/kafka-leader-election.sh --help
This tool attempts to elect a new leader for a set of topic partitions. The type of elections supported are preferred replicas and unclean replica.
Option Description
------ -----------
--admin.config <String: config file> Admin client config properties file to
pass to the admin client when --
bootstrap-server is given.
--bootstrap-server <String: host:port> A host name and port for the broker to
connect to, in the form host:port.
Multiple comma-separated URLs can be
given. REQUIRED unless --zookeeper
is given.
--election-type <String: election> Type of election to attempt. Possible values are 0
(or "preferred") for preferred election or 1 (or
"uncleaned") for uncleaned election. The default value
is 0 (or "preferred"), if --topic or --partition is
|
Code Block |
---|
|
$ bin/kafka-leader-election.sh --help
This tool attempts to elect a new leader for a set of topic partitions. The type of elections supported are preferred replicas and unclean replica.
Option specified . Not allowed if Description
--path-to--json-file is
-----------
--admin.config <String: config file> Admin client config properties file to
specified.
--topic <String: topic> Name of topic for which to perform an election.
pass to the admin client when --
REQUIRED if --partition is specified. Not allowed
bootstrap-server is given.
--bootstrap-server <String: host:port> A host name and port for the broker to
if --path-to-json-file is specified.
--partition <Integer: partition id> Partition id for which to perform an election.
connect to, in the form host:port.
REQUIRED if --topic is specified. Not Multiple comma-separated URLs can be
allowed if
--path-to-json-file is givenspecified. REQUIRED unless --zookeeper
--help Print usage is giveninformation.
--path--help to-json-file <String: list of The JSON file with the list of
partitions for which replica partitions for which leader election
leader election needs to be Print usage information.
--path-to-json-file <String: list of should Thebe JSONdone. fileSupported withelections
the listtriggered> of
partitions for which replica partitions for which leader election
leader election needs to be are 0 for preferred and 1 for uncleaned.
should be done. Supported elections
triggered> are 0 forIf preferredan andelection 1is fornot uncleaned.specified,
preferred If an electionis the default. This is not specified,an
preferredexample isformat.
the default. This is an
{"partitions":
example format.
[{"partitionstopic": "foo", "partition": 1},
[{"topic": "foofoobar", "partition": 2, "election": 1},]
}
{"topic": "foobar", "partition": 2, "election": 1}]
Defaults to preferred election to all existing partitions if
}
--topic and --partition flags Defaultsare to all existing partitionsnot specified. |
Proposed Changes
In addition to the protocol and client changes enumerated above, the Controller will be extended to allow unclean leader election requests to come from the admin client. Currently the controller only supports preferred leader election from the admin client. Unclean leader election can only be enabled through either a topic configuration change or a broker configuration change.
...