本文介绍在kafka中,增加分区partition的方法,不能减少分区数量,只能增加
原始TOPIC分区partition
根本没分区。
[root@rh7_210 kafka]# bin/kafka-topics.sh --describe --topic gbase8a --bootstrap-server localhost:9092
Topic: gbase8a TopicId: pGWySKY_SWehGsMXihJhkA PartitionCount: 1 ReplicationFactor: 1 Configs: segment.bytes=1073741824
Topic: gbase8a Partition: 0 Leader: 0 Replicas: 0 Isr: 0
[root@rh7_210 kafka]#
增加分区partition
通过–alter命令,和–partition 参数指定新分区数量。注意只能增加。
[root@rh7_210 kafka]# bin/kafka-topics.sh --alter --partitions 3 --topic gbase8a --bootstrap-server localhost:9092
查看TOPIC增加分区partition的效果
变成了3个分区。
[root@rh7_210 kafka]# bin/kafka-topics.sh --describe --topic gbase8a --bootstrap-server localhost:9092
Topic: gbase8a TopicId: pGWySKY_SWehGsMXihJhkA PartitionCount: 3 ReplicationFactor: 1 Configs: segment.bytes=1073741824
Topic: gbase8a Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: gbase8a Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: gbase8a Partition: 2 Leader: 0 Replicas: 0 Isr: 0
[root@rh7_210 kafka]#
减少TOPIC的分区partition
报错,原有分区数量大于请求数量。Topic currently has 3 partitions, which is higher than the requested 2.
[root@rh7_210 kafka]# bin/kafka-topics.sh --alter --partitions 2 --topic gbase8a --bootstrap-server localhost:9092
Error while executing topic command : Topic currently has 3 partitions, which is higher than the requested 2.
[2021-07-16 16:05:36,893] ERROR org.apache.kafka.common.errors.InvalidPartitionsException: Topic currently has 3 partitions, which is higher than the requested 2.
(kafka.admin.TopicCommand$)
[root@rh7_210 kafka]
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




