kafka优选副本切换办法

南墨2年前技术文章544

      1. 以topic test为例,假设test的分布为以下状态。

Topic:test PartitionCount:3 ReplicationFactor:2 Configs:

Topic: test Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2

Topic: test Partition: 1 Leader: 2 Replicas: 2,3 Isr: 2,3

Topic: test Partition: 2 Leader: 3 Replicas: 3,1 Isr: 1,3

2.  假设现在broker-1节点出现问题,希望parititon-0的优先副本发生切换,即由Replicas: 1,2变为

Replicas: 2,1,于此同时,leader由1切换到2。

首先编写迁移文件move.json,内容如下:

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

其中,文件的意义是:修改调换partition 0 的replicas的顺序为[2,1]

3.  执行迁移脚本

sh kafka-reassign-partitions.sh --zookeeper zookeeper_IP:24002/kafka --reassignment-json-file move.json --execute

执行完成后的结果为:

Topic:test PartitionCount:3 ReplicationFactor:2 Configs:

Topic: test Partition: 0 Leader: 1 Replicas: 2,1 Isr: 1,2

Topic: test Partition: 1 Leader: 2 Replicas: 2,3 Isr: 2,3

Topic: test Partition: 2 Leader: 3 Replicas: 3,1 Isr: 1,3

此时,partition-0的副本顺序变为了Replicas: 2,1

构建副本切换文件

创建excution.json,内容为:

{"partitions":[{"topic": "test", "partition": 0}]}

执行副本切换脚本

kafka-preferred-replica-election.sh --zookeeper zookeeper_IP:24002/kafka --path-to-json-file excution.json

执行后结果如下:

Topic:test PartitionCount:3 ReplicationFactor:2 Configs:

Topic: test Partition: 0 Leader: 2 Replicas: 2,1 Isr: 1,2

Topic: test Partition: 1 Leader: 2 Replicas: 2,3 Isr: 2,3

Topic: test Partition: 2 Leader: 3 Replicas: 3,1 Isr: 1,3

此时,leader已切换broker-2


kafka-preferred-replica-election.sh 可以不加后面的副本切换脚本而直接执行,例如:

kafka-preferred-replica-election.sh --zookeeper zookeeper_IP:2181/kafka,这样会将真个集群的leader全部调整到优选副本


相关文章

oracle11g db打补丁

1 升级opatch升级的方式就是解压安装包到ORACLE_HOME即可。oracle下执行Plain Text复制代码su - oracle1.备份原opatchcd $ORACLE_HOMEmv...

canal原理及使用

canal原理及使用

什么是canalcanal,主要用途是基于 MySQL 数据库增量日志解析,提供增量数据订阅和消费。这里我们可以简单地把canal理解为一个用来同步增量数据的一个工具。工作原理MySQL主备复制原理M...

Hudi集成Spark

Hudi集成Spark

环境准备安装Spark1)Hudi支持的Spark版本HudiSupported Spark 3 version0.12.x3.3.x,3.2.x,3.1.x0.11.x3.2.x(default b...

flink集成iceberg访问hive catalog任务报错

flink集成iceberg访问hive catalog任务报错

问题现象flink在集成iceberg后访问hive catalog任务无法执行,但flink自身任务正常,iceberg表任务无法执行,报错如下:Caused by: java....

hive创建hbase映射表

hive创建hbase映射表

hbase创建表,导入数据/opt/app/hbase-2.1.0/bin/hbase shell查看已有表,创建新表,查看表结构listcreate 'student', 'info', 'scor...

Nginx-Ingress和traefik区别

Nginx-Ingress和traefik区别

Nginx-Ingress和traefik区别1. Ingress Controllerk8s 是通过一个又一个的 controller 来负责监控、维护集群状态。Ingress Controller...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。