kafka-reassign-partitions
Learn about the kafka-reassign-partitions
tool, which is used to
reassign partitions between brokers in a cluster.
This tool provides substantial control over partitions in a Kafka cluster. It is mainly used to balance storage loads across brokers through the following reassignment actions:
- Change the ordering of the partition assignment list. Used to control leader imbalances between brokers.
- Reassign partitions from one broker to another. Used to expand existing clusters.
- Increase the replication factor of partitions. Used to expand existing clusters.
- Reassign partitions between log directories on the same broker. Used to resolve storage load imbalance among available disks in the broker.
- Reassign partitions between log directories across multiple brokers. Used to resolve storage load imbalance across multiple brokers.
- Topics-to-Move JSON
- Reassignment Configuration JSON
- Topics-to-Move JSON
- This JSON file specifies the topics that you want to reassign. This a simple file that
tells the
kafka-reassign-partitions
tool which partitions it should look at when generating a proposal for the reassignment configuration. The user has to create the topics-to-move JSON file from scratch.The format of the file is the following:{"topics": [{"topic": "mytopic1"}, {"topic": "mytopic2"}], "version":1 }
- Reassignment Configuration JSON
- This JSON file is a configuration file that contains the parameters used in the
reassignment process. This file is created by the user, however, a proposal for its
contents is generated by the tool. When the
kafka-reasssign-partitions
tool is executed with the--generate
option, it generates a proposed configuration which can be fine-tuned and saved as a JSON file. The file created this way is the reassignment configuration JSON. To generate a proposal, the tool requires a topics-to-move file as input.The format of the file is the following:{"version":1, "partitions": [{"topic":"mytopic1","partition":3,"replicas":[4,5],"log_dirs":["any","any"]}, {"topic":"mytopic1","partition":1,"replicas":[5,4],"log_dirs":["any","any"]}, {"topic":"mytopic2","partition":2,"replicas":[6,5],"log_dirs":["any","any"]}] }
The reassignment configuration contains multiple properties that each control and specify an aspect of the configuration. The Reassignment Configuration Properties table lists each property and its description.
Property | Description |
---|---|
topic |
Specifies the topic. |
partition |
Specifies the partition. |
replicas |
Specifies the brokers that the selected partition is assigned to. The brokers are listed in order, which means that the first broker in the list is always the leader for that partition. Change the order of brokers to resolve any leader balancing issues among brokers. Change the broker IDs to reassign partitions to different brokers. |
log_dirs |
Specifies the log directory of the brokers. The log directories are listed in the
same order as the brokers. By default any is specified as the log
directory, which means that the broker is free to choose where it places the replica.
By default, the current broker implementation selects the log directory using a
round-robin algorithm. An absolute path beginning with a / can be
used to explicitly set where to store the partition replica. |
Notes and Recommendations:
- Cloudera recommends that you minimize the volume of replica changes per command instance. Instead of moving 10 replicas with a single command, move two at a time in order to save cluster resources.
- This tool cannot be used to make an out-of-sync replica into the leader partition.
- Use this tool only when all brokers and topics are healthy.
- Anticipate system growth. Redistribute the load when the system is at 70% capacity. Waiting until redistribution becomes necessary due to reaching resource limits can make the redistribution process extremely time consuming.
Tool usage
Learn how to reassign partitions with the
kafka-reassign-partitions-tool
.
Reassignment examples
A collection of examples that demonstrate how users can modify the proposed
configuration file generated by the kafka-reassign-partitions
.
There are multiple ways to modify the configuration file. The following list of examples shows how a user can modify a proposed configuration and what these changes do.
kafka-reassign-partitions
tool generated the following
proposed reassignment
configuration:{"version":1,
"partitions":
[{"topic":"mytopic1","partition":0,"replicas":[1,2],"log_dirs":["any","any"]}]}
Now
let's look at how this reassignment configuration has to be changed in different reassignment
scenarios. - Reassign partitions between brokers
-
To reassign partitions from one broker to another, change the broker ID specified in
replicas
. For example:{"topic":"mytopic1","partition":0,"replicas":[5,2],"log_dirs":["any","any"]}
This reassignment configuration moves partition mytopic1-0 from broker 1 to broker 5.
- Reassign partitions to another log directory on the same broker
- To reassign partitions between log directories on the same broker, change the
appropriate
any
entry to an absolute path. For example:{"topic":"mytopic1","partition":0,"replicas":[1,2],"log_dirs":["/log/directory1","any"]}
This reassignment configuration moves partition mytopic1-0 to the /log/directory1 log directory.
- Reassign partitions between log directories across multiple brokers
- To reassign partitions between log directories across multiple brokers, change the
broker ID specified in
replicas
and the appropriateany
entry to an absolute path. For example:{"topic":"mytopic1","partition":0,"replicas":[5,2],"log_dirs":["/log/directory1","any"]}
This reassignment configuration moves partition mytopic1-0 to /log/directory1 on broker 5.
- Change partition assignment order (elect a new leader)
-
To change the ordering of the partition assignment list, change the order of the brokers in
replicas
. For example:{"topic":"mytopic1","partition":0,"replicas":[2,1],"log_dirs":["any","any"]}
This reassignment configuration elects broker 2 as the new leader.
- Increase the replication factor of a topic
-
To increase the replication factor of a topic, add one or more new brokers to
replicas
. For example:{"topic":"mytopic1","partition":0,"replicas":[1,2,3],"log_dirs":["any","any","any"]}