Kafka学习之Replication tools之Reassign Partitions Tool

原文链接:https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools#Replicationtools-6.ReassignPartitionsTool

此工具能做啥?

此工具的作用跟Referred Replica Leader Election工具类似,都是为了平衡集群的负载。但工具不仅为某一个partition从assigned replica中选举一个新的leader,还改变partition的assigned replica,回忆一下,follower需要从leader上fetch数据为了保持同步,因此有时仅仅平衡leadershipi的负载是不够的(还需要考虑follower的负载)。下面是此工具工作的步骤:

1,此工具更新ZK的路径"/admin/reassign_partitions",写入一个topic的partition列表和一个new assigned replica列表(如果设置了json文件了的话)。


2,controller监听ZK上的路径。当数据update时被触发,controller从ZK读取更新的topic partition的列表和它们的assigned replicas。


3,对于每一个topic的partition,controller做如下的事情:
3.1. 开始一个新的replicas,由RAR - AR(RAR中存在,AR中不存在的replica)组成(RAR = Reassigned Replicas, AR = original list of Assigned Replicas)。
3.2. 在新的replica跟leader同步之前保持等待状态。
3.3. 如果leader不在RAR中,从RAR选举一个新的leader。
3.4 4. 停止老的replicas,由AR - RAR(AR中存在,RAR中不存在的replica)组成。
3.5. 写入新的AR。
3.6. 从/admin/reassign_partitions删除partition。

注意此工具只更新zk并退出,controller异步为partitions reassign replicas。

此工具现在只在0.8分支中提供。

如何使用?

警告:此工具在0.8的beta版本释出,并有一些bug,在0.8.1版本中是稳定的。

扫描二维码关注公众号,回复: 615658 查看本文章
bin/kafka-reassign-partitions.sh
 
Option                                  Description
------                                  -----------
--broker-list <brokerlist>              The list of brokers to which the
                                          partitions need to be reassigned in
                                          the form "0,1,2". This is required
                                          for automatic topic reassignment.
--execute [execute]                     This option does the actual
                                          reassignment. By default, the tool
                                          does a dry run
--manual-assignment-json-file <manual   The JSON file with the list of manual
  assignment json file path>              reassignments.This option or topics-
                                          to-move-json-file needs to be
                                          specified. The format to use is -
                                        {"partitions":
                                            [{"topic": "foo",
                                              "partition": 1,
                                              "replicas": [1,2,3] }],
                                        "version":1
                                        }
--topics-to-move-json-file <topics to   The JSON file with the list of topics
  reassign json file path>                to reassign.This option or manual-
                                          assignment-json-file needs to be
                                          specified. The format to use is -
                                        {"topics":
                                            [{"topic": "foo"},{"topic": "foo1"}],
                                        "version":1
                                        }
--zookeeper <urls>                      REQUIRED: The connection string for
                                          the zookeeper connection in the form
                                          host:port. Multiple URLS can be
                                          given to allow fail-over.

注意此工具默认运行在dry-run(预演)模式下,并不会初始化partiton movement。只有打开--execute选项,此工具才会开始执行。

集群扩展

在0.8版本中,此工具可以用来扩展(expand)一个已存在的集群。集群扩展涉及到引入了新的broker id。通常当为一个集群中新增一个broker时,它们不会从现存的topic接收到任何数据,直到使用这个工具把现存的topics/partitions assign到新的broker上。此工具使用2个选项来让批量转移topic到新的broker变得更简单,这2个选项分别为:a)要转移的topics;b)新增的broker的列表。使用这2个选项,此工具能自动的确定这些topic的partitions的位置。下面的例子把2个topic(foo1,foo2)转移到新增的broker(id为5,6,7)。

nnarkhed$ ./bin/kafka-reassign-partitions.sh --topics-to-move-json-file topics-to-move.json --broker-list "5,6,7" --execute
 
nnarkhed$ cat topics-to-move.json
{"topics":
     [{"topic": "foo1"},{"topic": "foo2"}],
     "version":1
}

选择一些partition进行转移

此工具也可以有选择的把一些特定的partition的一些replica转移到一个特定的broker。如果你有一个不负载不均衡的集群,你可以使用这个工具来有选择的转移一些partition。在这种模式下,此工具使用一个文件,文件包含了要转移的partition的列表,还有转移后replica分布的broker id列表。

下面的例子把一个partition的replica从broker 1,2,3转移到了broker 1,2,4上。

nnarkhed$ ./bin/kafka-reassign-partitions.sh --manual-assignment-json-file partitions-to-move.json --execute
 
nnarkhed$ cat partitions-to-move.json
{"partitions":
             [{"topic": "foo",
               "partition": 1,
               "replicas": [1,2,4] }],     
原文链接:https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools#Replicationtools-6.ReassignPartitionsTool

此工具能做啥?

此工具的作用跟Referred Replica Leader Election工具类似,都是为了平衡集群的负载。但工具不仅为某一个partition从assigned replica中选举一个新的leader,还改变partition的assigned replica,回忆一下,follower需要从leader上fetch数据为了保持同步,因此有时仅仅平衡leadershipi的负载是不够的(还需要考虑follower的负载)。下面是此工具工作的步骤:

1,此工具更新ZK的路径"/admin/reassign_partitions",写入一个topic的partition列表和一个new assigned replica列表(如果设置了json文件了的话)。


2,controller监听ZK上的路径。当数据update时被触发,controller从ZK读取更新的topic partition的列表和它们的assigned replicas。


3,对于每一个topic的partition,controller做如下的事情:
3.1. 开始一个新的replicas,由RAR - AR(RAR中存在,AR中不存在的replica)组成(RAR = Reassigned Replicas, AR = original list of Assigned Replicas)。
3.2. 在新的replica跟leader同步之前保持等待状态。
3.3. 如果leader不在RAR中,从RAR选举一个新的leader。
3.4 4. 停止老的replicas,由AR - RAR(AR中存在,RAR中不存在的replica)组成。
3.5. 写入新的AR。
3.6. 从/admin/reassign_partitions删除partition。

注意此工具只更新zk并退出,controller异步为partitions reassign replicas。

此工具现在只在0.8分支中提供。

如何使用?

警告:此工具在0.8的beta版本释出,并有一些bug,在0.8.1版本中是稳定的。

bin/kafka-reassign-partitions.sh
 
Option                                  Description
------                                  -----------
--broker-list <brokerlist>              The list of brokers to which the
                                          partitions need to be reassigned in
                                          the form "0,1,2". This is required
                                          for automatic topic reassignment.
--execute [execute]                     This option does the actual
                                          reassignment. By default, the tool
                                          does a dry run
--manual-assignment-json-file <manual   The JSON file with the list of manual
  assignment json file path>              reassignments.This option or topics-
                                          to-move-json-file needs to be
                                          specified. The format to use is -
                                        {"partitions":
                                            [{"topic": "foo",
                                              "partition": 1,
                                              "replicas": [1,2,3] }],
                                        "version":1
                                        }
--topics-to-move-json-file <topics to   The JSON file with the list of topics
  reassign json file path>                to reassign.This option or manual-
                                          assignment-json-file needs to be
                                          specified. The format to use is -
                                        {"topics":
                                            [{"topic": "foo"},{"topic": "foo1"}],
                                        "version":1
                                        }
--zookeeper <urls>                      REQUIRED: The connection string for
                                          the zookeeper connection in the form
                                          host:port. Multiple URLS can be
                                          given to allow fail-over.

注意此工具默认运行在dry-run(预演)模式下,并不会初始化partiton movement。只有打开--execute选项,此工具才会开始执行。

集群扩展

在0.8版本中,此工具可以用来扩展(expand)一个已存在的集群。集群扩展涉及到引入了新的broker id。通常当为一个集群中新增一个broker时,它们不会从现存的topic接收到任何数据,直到使用这个工具把现存的topics/partitions assign到新的broker上。此工具使用2个选项来让批量转移topic到新的broker变得更简单,这2个选项分别为:a)要转移的topics;b)新增的broker的列表。使用这2个选项,此工具能自动的确定这些topic的partitions的位置。下面的例子把2个topic(foo1,foo2)转移到新增的broker(id为5,6,7)。

nnarkhed$ ./bin/kafka-reassign-partitions.sh --topics-to-move-json-file topics-to-move.json --broker-list "5,6,7" --execute
 
nnarkhed$ cat topics-to-move.json
{"topics":
     [{"topic": "foo1"},{"topic": "foo2"}],
     "version":1
}

选择一些partition进行转移

此工具也可以有选择的把一些特定的partition的一些replica转移到一个特定的broker。如果你有一个不负载不均衡的集群,你可以使用这个工具来有选择的转移一些partition。在这种模式下,此工具使用一个文件,文件包含了要转移的partition的列表,还有转移后replica分布的broker id列表。

下面的例子把一个partition的replica从broker 1,2,3转移到了broker 1,2,4上。

nnarkhed$ ./bin/kafka-reassign-partitions.sh --manual-assignment-json-file partitions-to-move.json --execute
 
nnarkhed$ cat partitions-to-move.json
{"partitions":
             [{"topic": "foo",
               "partition": 1,
               "replicas": [1,2,4] }],     

猜你喜欢

转载自damacheng009.iteye.com/blog/2088427