After a Kafka topic has been created by a producer or an administrator, how would you change the number of replicas of this topic?
Increasing the replication factor can be done via the kafka-reassign-partitions tool. Specify the extra replicas in the custom reassignment json file and use it with the --execute option to increase the replication factor of the specified partitions.
Kafka does not currently support reducing the number of partitions for a topic or changing the replication factor.
Kafka replication: 0 to 60 in 1 minute Replication in Kafka happens at the partition granularity where the partition's write-ahead log is replicated in order to n servers. Out of the n replicas, one replica is designated as the leader while others are followers.
To increase the number of replicas for a given topic you have to:
For example, you could create increase-replication-factor.json and put this content in it:
{"version":1, "partitions":[ {"topic":"signals","partition":0,"replicas":[0,1,2]}, {"topic":"signals","partition":1,"replicas":[0,1,2]}, {"topic":"signals","partition":2,"replicas":[0,1,2]} ]}
[or kafka-reassign-partitions.sh - depending on the kafka package]
For example:
$ kafka-reassign-partitions --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute
[or kafka-topics.sh - depending on the kafka package]
$ kafka-topics --zookeeper localhost:2181 --topic signals --describe Topic:signals PartitionCount:3 ReplicationFactor:3 Configs:retention.ms=1000000000 Topic: signals Partition: 0 Leader: 2 Replicas: 0,1,2 Isr: 2,0,1 Topic: signals Partition: 1 Leader: 2 Replicas: 0,1,2 Isr: 2,0,1 Topic: signals Partition: 2 Leader: 2 Replicas: 0,1,2 Isr: 2,0,1
See also: the part of the official documentation that describes how to increase the replication factor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With