apache kafka系列之replication设计机制

概览:

其中一个broker被选举作为整个集群控制器,他将负责几个方面工作:

1.管理或领导分区变化.

2.create topic,delete topic

3.replicas(执行复制计划,复制partition)

集群控制器做出决定以后,操作信息或状态将永久注册并存储在zookeeper上,并且也可以通过RPC方式发送新的决定操作broker。控制器发布的决定来源真实,他将用于client请求路由和broker的重启或恢复状态。

如果有一个新的broker加入或启动。controller会通过RPC调用发出新的决定。

潜在的优点:

1.当leader发生变化时,更容易集中到一个地方做调试(排除故障)。

2.当leader发生变化时,ZK可以把读取/写状态信息成批广播到其他broker,因此当leader failover的时候会减少broker之间恢复的延迟时间。

3.需要更少的监听器。

4.使用更高效的RPC通信方式,代替在zookeeper中队列实现方式。

潜在的缺点:

需要考虑controller failover

zookeeper中路径列表说明

1.Controller path:存储当前controller信息.

/controller --> {brokerid} (ephemeral; created by controller)

2.Broker path:存储当前所有活着的brokers信息。

/brokers/ids/[broker_id] --> host:port (ephemeral; created by admin)

3.存储一个主题的所有分区副本任务。对于每一个副本,我们存储的副本指派一个broker ID。第一个副本是首选的复制品。注意,对于一个给定的分区,在一个broker上有至多一个副本。因此,broker ID可以作副本标识.

/brokers/topics/[topic] --> {part1: [broker1, broker2], part2: [broker2, broker3] ...}  (created by admin)

4.LeaderAndISR path:存储一个分区leader and ISR

/brokers/topics/[topic]/[partition_id]/leaderAndISR --> {leader_epoc: epoc, leader: broker_id, ISR: {broker1, broker2}}
此路径被controller或leader修改,当前leader只修改ISR一部分信息。当更新path需要使用条件同步到zookeeper上。

5.分区分配path:当我们重新分配某些分区到不同的brokers时,此path会被使用。对于每个分区重新分配,他将会存储一个新副本列表和他们相应的brokers信息。

每当某个管理员操作如下命令成功后,且这个分区迁移到目标broker成功后,源broker上的分区会自动删除。

/admin/partitions_add/[topic]/[partition_id] --> {broker_id …} (created by admin)
/admin/partitions_remove/[topic]/[partition_id] (created by admin)

kafka中专有词语解释:

AR(assign replicas):分配副本  ISR(in-sync replicas):在同步中的副本

Replica {                                 // 一个分区副本信息
   broker_id               :  int
   partition               : Partition     //分区信息
   log                     : Log           //本地日志与副本关联信息
   hw                      :  long          //最后被commit的message的offset信息
   leo                     :  long          // 日志结尾offset
   isLeader                : Boolean       //是否为该副本的leader
}
  
Partition {                               //topic名称
   topic                   : string
   partition_id            :  int
   leader                  : Replica       // 这个分区的leader副本
   ISR                     : Set[Replica]  // 正在同步中的副本集合
   AR                      : Set[Replica]  // 这个分区的所有副本分配集合
   LeaderAndISRVersionInZK :  long          // version id of the LeaderAndISR path; used for conditionally update the LeaderAndISR path in ZK
}
  
LeaderAndISRRequest {
   request_type_id         : int16  // 当前request的版本
   version_id              : int16  // request的版本号
   client_id               : int32  // this can be the broker id of the controller
   ack_timeout             : int32  // the time in ms to wait for a response
   isInit                  :  byte   // whether this is the first command issued by a controller
   leaderAndISRMap         : Map[(topic: String, partitionId: int32) => LeaderAndISR)  // a map of LeaderAndISR
}
  
LeaderAndISR {
   leader                  : int32           // leader的broker编号
   leaderEpoc              : int32           // leader epoc, incremented on each leadership change
   ISR                     : Set[int32]      // 所有在ISR复制副本的broker集合
   zkVersion               : int64           // version of the LeaderAndISR path in ZK
}
  
LeaderAndISRResponse {
   version_id              : int16  // 当前request的版本
   responseMap             : Map[(topic: String, partitionId: int32) => int16)  // error code表
}
  
StopReplicaRequest {
   request_type_id         : int16  // request id
   version_id              : int16  // 当前request的版本
   client_id               : int32  // this can be the broker id of the controller
   ack_timeout             : int32  // ack响应时间,单位为毫秒
   stopReplicaSet          : Set[(topic: String, partitionId:  int ))  // 需要停止的分区集合
}
  
StopReplicaResponse {
   version_id              : int16  // 当前request的版本
   responseMap             : Map[(topic: String, partitionId: int32) => int16)  //error code表
}

 请注明转载自: http://blog.csdn.net/lizhitao/article/details/24491551

后续.....

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值