[英]What happens after modifying Kafka topic replication factor?
According to the docs , you just modify a topic to increase the replication factor. 根据docs ,您只需修改主题以增加复制因子。
> bin/kafka-topics.sh --zookeeper zk_host:port/chroot --create --topic my_topic_name
--partitions 20 --replication-factor 3 --config x=y
Unfortunately, it doesn't specify what happens then after you modify the topic. 不幸的是,它没有指定修改主题后会发生什么。 Do existing log segments get replicated to the new replicas, or only new messages?
是否将现有日志段复制到新副本或仅复制到新消息?
For kafka 10 you need to invoke the kafka-reassign-partitions.sh script to change the replication factor of the topic. 对于kafka 10,您需要调用kafka-reassign-partitions.sh脚本来更改主题的复制因子。 Here is a demo of a script that will display the topic before and after the change:
这是一个脚本演示,将显示更改前后的主题:
updateTopicReplication() {
TOPIC_NAME=$1
REPLICAS=$2
echo "****************************************"
echo "describe $TOPIC_NAME"
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic $TOPIC_NAME
JSON_FILE=./configChanges/${TOPIC_NAME}-update.json
echo $JSON_FILE
[ -e $JSON_FILE ] && rm $JSON_FILE
touch $JSON_FILE
echo -e "{\"version\":1, \"partitions\":[{\"topic\":\"${TOPIC_NAME}\",\"partition\":0,\"replicas\":[${REPLICAS}]}]}" >> $JSON_FILE
echo "****************************************"
echo "updateing $TOPIC_NAME"
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file $JSON_FILE --execute
echo "****************************************"
echo "describe $TOPIC_NAME"
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic $TOPIC_NAME
}
根据我在问题中提到的同一份文档,似乎kafka实际上不支持增加(或减少)主题的复制因子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.