• 在Kafka中修改Topic的preferred replica


    参考site:https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools

    目前我们的topic  test-add-replication-topic中partition 0的replicas为[1,2],则1为preferred replica,应该成为leader。 
    这时我们期望2为preferred replica,并变成leader。

    操作步骤:

    1. 查看当前topic详细信息:

      > bin/kafka-topics.sh --describe --zookeeper h1:2181 --topic test-add-replication-topic

        Topic:test-add-replication-topic PartitionCount:3 ReplicationFactor:3 Configs:

          Topic: test-add-replication-topic Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2

          Topic: test-add-replication-topic Partition: 1 Leader: 2 Replicas: 2,0,1 Isr: 0,1,2
          Topic: test-add-replication-topic Partition: 2 Leader: 0 Replicas: 0,1 Isr: 0,1

    2. 修改replicas顺序

      > cat partitions-to-move.json 

        

          "version":1,
          "partitions":
          [
          {
            "topic":"test-add-replication-topic",
            "partition":0,
            "replicas":[2,1]
          }
          ]
        }

      > bin/kafka-reassign-partitions.sh --zookeeper h1:2181 --reassignment-json-file partitions-to-move.json --execute

        Current partition replica assignment

        {"version":1,"partitions":[{"topic":"test-add-replication-topic","partition":1,"replicas":[2,0,1]},{"topic":"test-add-replication-topic","partition":2,"replicas":[0,1]},

        {"topic":"test-add-replication-topic","partition":0,"replicas":[1,2]}]}

        Save this to use as the --reassignment-json-file option during rollback
        Successfully started reassignment of partitions {"version":1,"partitions":[{"topic":"test-add-replication-topic","partition":0,"replicas":[2,1]}]}

    3. 更改leader

      > cat topicPartition.json 

        {
          "version":1,
          "partitions":
          [
          {
            "topic":"test-add-replication-topic",
            "partition":0
          }
          ]
        }

      > bin/kafka-preferred-replica-election.sh --zookeeper h1:2181 --path-to-json-file topicPartition.json 

        Successfully started preferred replica election for partitions Set([test-add-replication-topic,0])

    4.检查replicas leader切换情况 

      > bin/kafka-topics.sh --describe --zookeeper h1:2181 --topic test-add-replication-topic

        Topic:test-add-replication-topic PartitionCount:3 ReplicationFactor:3 Configs:

          Topic: test-add-replication-topic Partition: 0 Leader: 2 Replicas: 2,1 Isr: 1,2
          Topic: test-add-replication-topic Partition: 1 Leader: 2 Replicas: 2,0,1 Isr: 0,1,2
          Topic: test-add-replication-topic Partition: 2 Leader: 0 Replicas: 0,1 Isr: 0,1

      到此,partition 0中的leader已经修改成功。

     

  • 相关阅读:
    SQL 脚本 重复执行 约束
    xiami 精选集
    PHP 5 环境配置
    Thread线程类
    创建线程
    C#中简单的正则表达式(也经常会用到的)
    线程的挂起与恢复
    C#操作INI文件
    多线程简介
    单线程简介
  • 原文地址:https://www.cnblogs.com/yinchengzhe/p/5121329.html
Copyright © 2020-2023  润新知