Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the number of replicas of a Kafka topic?

Tags:

apache-kafka

After a Kafka topic has been created by a producer or an administrator, how would you change the number of replicas of this topic?

like image 250
GuruPo Avatar asked Jun 22 '16 07:06

GuruPo


People also ask

Can we increase Kafka replication?

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.

Can we decrease the replication factor in Kafka?

Kafka does not currently support reducing the number of partitions for a topic or changing the replication factor.

What is replica count in Kafka?

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.


1 Answers

To increase the number of replicas for a given topic you have to:

1. Specify the extra replicas in a custom reassignment json file

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]} ]} 

2. Use the file with the --execute option of the kafka-reassign-partitions tool

[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 

3. Verify the replication factor with the kafka-topics tool

[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.

like image 121
Łukasz Dumiszewski Avatar answered Oct 04 '22 05:10

Łukasz Dumiszewski