You can either create multiple .json
files or use a single file that contains reassignment details for more than one topic:
{
"version":1,
"partitions":[
{"topic":"topic_1","partition":0,"replicas":[0,1]},
{"topic":"topic_1","partition":1,"replicas":[1,0]},
{"topic":"topic_2","partition":0,"replicas":[0,1]},
{"topic":"topic_2","partition":1,"replicas":[1,0]}
]
}
And then run
./bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute
Your topics should look like below:
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic topic_1
Topic:demo-topic PartitionCount:2 ReplicationFactor:2 Configs:
Topic: topic_1 Partition: 0 Leader: 0 Replicas: 0,1 Isr: 0,1
Topic: topic_1 Partition: 1 Leader: 1 Replicas: 1,0 Isr: 1,0
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic topic_2
Topic:demo-topic PartitionCount:2 ReplicationFactor:2 Configs:
Topic: topic_2 Partition: 0 Leader: 0 Replicas: 0,1 Isr: 0,1
Topic: topic_2 Partition: 1 Leader: 1 Replicas: 1,0 Isr: 1,0
Finally, Finally, the --verify option can be used with the tool to check the status of the partition reassignment. Note that the same expand-cluster-reassignment.json (used with the --execute option) should be used with the --verify option
> bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --verify
Status of partition reassignment:
Reassignment of partition [topic_1,0] completed successfully
Reassignment of partition [topic_1,1] is in progress
Reassignment of partition [topic_2,0] completed successfully
Reassignment of partition [topic_2,1] completed successfully