经常有小伙伴有这样的疑问:为什么线上Kafka机器各个磁盘间的占用不均匀,经常出现“一边倒”的情形? 这是因为Kafka只保证分区数量在各个磁盘上均匀分布,但它无法知晓每个分区实际占用空间,故很有可能出现某些分区消息数量巨大导致占用大量磁盘空间的情况。在1.1版本之前,用户对此毫无办法,因为1.1之前Kafka只支持分区数据在不同broker间的重分配,而无法做到在同一个broker下的不同磁盘间做重分配。1.1版本正式支持副本在不同路径间的迁移,具体的实现细节详见KIP-113。本文简单演示一下该新功能的用法。

  假设我在Kafka broker的server.properties文件中配置了多个路径(代表多块磁盘),如下所示:

...

############################# Log Basics #############################

# A comma seperated list of directories under which to store log files

log.dirs=/Users/huxi/SourceCode/newenv/datalogs/kafka_1,/Users/huxi/SourceCode/newenv/datalogs/kafka_2,/Users/huxi/SourceCode/newenv/datalogs/kafka_3

...

  之后我创建了一个9分区的topic,并发送了9百万条消息。查询这些目录发现Kafka均匀地将9个分区分布到这三个路径上,如下所示:

ll kafka_1/ |grep test-topic

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-3

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-4

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-5

ll kafka_2/ |grep test-topic

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-0

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-1

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-2

ll kafka_3/ |grep test-topic

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-6

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-7

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-8

  现在我们想要将test-topic的6,7,8分区全部迁移到kafka_2路径下,并且把test-topic的1分区迁移到kafka_1下。若要实现这个需求,我们首先需要编写一个JSON文件,假定名为migrate-replica.json:

{"partitions":[{"topic": "test-topic","partition": 1,"replicas": [0],"log_dirs": ["/Users/huxi/SourceCode/newenv/datalogs/kafka_1"]},{"topic": "test-topic","partition": 6,"replicas": [0],"log_dirs": ["/Users/huxi/SourceCode/newenv/datalogs/kafka_2"]},{"topic": "test-topic","partition": 7,"replicas": [0],"log_dirs": ["/Users/huxi/SourceCode/newenv/datalogs/kafka_2"]},{"topic": "test-topic","partition": 8,"replicas": [0],"log_dirs": ["/Users/huxi/SourceCode/newenv/datalogs/kafka_2"]}],"version":1}

其中,replicas中的0表示broker ID,由于本文只启动了一个broker,且broker.id = 0,故这里只写0即可。实际上你可以指定多个broker实现为多个broker同时迁移副本的功能。另外当前的version固定是1.

保存好这个JSON后,我们执行以下命令执行副本迁移:

bin/kafka-reassign-partitions.sh  --zookeeper localhost:2181 --bootstrap-server localhost:9092 --reassignment-json-file ../migrate-replica.json --execute

Current partition replica assignment

{"version":1,"partitions":[{"topic":"test-topic","partition":8,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":4,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":5,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":2,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":6,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":3,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":1,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":7,"replicas":[0],"log_dirs":["any"]},{"topic":"test-topic","partition":0,"replicas":[0],"log_dirs":["any"]}]}

Save this to use as the --reassignment-json-file option during rollback

Successfully started reassignment of partitions.

再次查看路径副本分布:

ll kafka_1/ |grep test-topic

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:31 test-topic-1

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-3

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-4

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-5

ll kafka_2/ |grep test-topic

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-0

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:21 test-topic-2

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:31 test-topic-6

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:31 test-topic-7

drwxr-xr-x   6 huxi  staff  192 Jun 22 17:31 test-topic-8

ll kafka_3/ |grep test-topic

<empty>

显然,6,7,8已经被成功地迁移到kafka_2下,而分区1也迁移到了kafka_1下。值得一提的是,不仅所有的日志段、索引文件被迁移,实际上分区外层的checkpoint文件也会被更新。比如我们检查kafka_2下的replication-offset-checkpoint文件可以发现,现在该文件已经包含了6,7,8分区的位移数据,如下所示:

cat replication-offset-checkpoint

0

7

test-topic 8 1000000

test-topic 2 1000000

test 0 1285714

test-topic 6 1000000

test-topic 7 1000000

test-topic 0 1000000

test 2 1285714

以上就是对1.1新功能“副本跨路径迁移”的简单尝试,希望对有此困扰的用户有用~~

Kafka 1.1新功能:数据的路径间迁移的更多相关文章

  1. Kafka 0.11新功能介绍:空消费组延迟rebalance

    Kafka 0.11新功能介绍:空消费组延迟rebalance 在0.11之前的版本中,多个consumer实例加入到一个空消费组将导致多次的rebalance,这是由于每个consumer inst ...

  2. 什么,kafka能够从follower副本读数据了 —kafka新功能介绍

    最近看了kafka2.4新版本的一些功能特性,不得不说,在kafka2.0以后,kafka自身就比较少推出一些新的feature了,基本都是一些修修补补的东西.倒是kafka connect和kafk ...

  3. Tapdata Cloud 版本上新!率先支持数据校验、类型映射等6大新功能

    Tapdata Cloud cloud.tapdata.net Tapdata Cloud 是国内首家异构数据库实时同步云平台,目前支持 Oracle.MySQL.PG.SQL Server.Mong ...

  4. Dynamics CRM2016 新功能之从CRM APP中导出数据至EXCEL

    新版的CRM对移动端做了很多的改进,这归咎于微软对APP端的越来越重视.自己装了个IOS版的APP,体验了下基本的功能,比原来好用很多很顺滑,这里要介绍的是一个新的数据导出功能. 咱们进入case列表 ...

  5. Kafka 0.11版本新功能介绍 —— 空消费组延时rebalance

    在0.11之前的版本中,多个consumer实例加入到一个空消费组将导致多次的rebalance,这是由于每个consumer instance启动的时间不可控,很有可能超出coordinator确定 ...

  6. 初识 MySQL 5.6 新功能、参数

    摘要: 继上一篇的文章 初识 MySQL 5.5 新功能.参数 之后,现在MySQL5.6 针对 MySQL5.5 各个方面又提升了很多,特别在性能和一些新参数上面,现在看看大致提升了哪些方面(后续不 ...

  7. ActiveReports 9 新功能:借助目录(TOC)控件为报表添加目录功能

    在最新发布的ActiveReports 9报表控件中添加了多项新功能,以帮助你在更短的时间里创建外观绚丽.功能强大的报表系统,本文将重点介绍新增文档目录控件(TOC),通过拖拽操作便可添加报表目录. ...

  8. SCVMM之Windows Server2012 R2新功能

    在Windows Server 2012 R2中可以通过使用共享的虚拟硬盘VHDX文件的方法来模拟IP SAN,来为虚拟机创建群集提供共享存储.这样为虚拟机创建群集时就不用再像以前一样通过使用软件模拟 ...

  9. Red Hat Enterprise Linux 7的新功能

     简介红帽最新版本的旗舰平台交付显著增强的可用性. 性能和可靠性. 丰富的新功能为架构. 系统管理员和开发人员提供所需的资源以更高效地进行创新和管理.架构师: 红帽® 企业 Linux® 7 适合 ...

随机推荐

  1. [原创]PostMan接口测试神器

    [原创]PostMan接口测试神器 1 PostMan是什么?  Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件. 2 Postman工具下载及安装 官方网站: htt ...

  2. Windows下USB磁盘开发系列一:枚举系统中U盘的盘符

    个时候我们需要区分系统磁盘中,哪些是U盘,这样我们在访问的时候可以区别对待.具体方法如下: 1,调用GetLogicalDrives()返回系统盘符标记位 API GetLogicalDrives() ...

  3. android:碎片的概念

    碎片(Fragment)是一种可以嵌入在活动当中的 UI 片段,它能让程序更加合理和充分 地利用大屏幕的空间,因而在平板上应用的非常广泛.虽然碎片对你来说应该是个全新的概 念,但我相信你学习起来应该毫 ...

  4. android:如何通过自定义工程模板让新建的工程都默认支持lambda表达式

    首先参考这篇文章:自定义Android Studio工程模板,了解如何自定义模板   然后结合我们上一篇文章 android: 在android studio中使用retrolambda的步骤的要点, ...

  5. zeromq学习笔记2——简单的客户端和服务端测试程序

    1.前言 zeromq提供了guide,http://zguide.zeromq.org/,可以帮助新手快速上手,提供了C\C++\PHP等多种语言. 2.测试程序 使用zeromq给的hwserve ...

  6. eclipse中的yaml插件

    现在spring中推荐使用yaml格式的配置文件,扩展名为yml 在eclipse中编辑的话,可以安装yaml编辑插件,在Eclipse Marketpalce可以搜到两款: YEdit的推荐指数38 ...

  7. C#中使用log4net框架做日志输出

    一.用法 1.引入包:https://www.nuget.org/packages/log4net/ 2.Main函数 using System; using System.IO; using log ...

  8. CentOS 6.9下安装PostgreSQL

    操作系统:CentOS6.9_x64 PostgreSQL官方网址: https://www.postgresql.org/ 安装数据库 使用如下命令: yum install postgresql- ...

  9. excel随机函数

    =D7+RAND()*(8000-4250) 含义: 1.在D7数值的基础上,随机加一个数值,该数值的随机范围为4250——8000. 2.注意8000和4250要反着写

  10. (原)pycharm中使用CUDA_VISIBLE_DEVICES

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/8576825.html 如果使用多gpu运行程序,可以直接使用CUDA_VISIBLE_DEVICES= ...