美文网首页
尚硅谷大数据技术之Kafka

尚硅谷大数据技术之Kafka

作者: 尚硅谷教育 | 来源:发表于2018-12-07 11:44 被阅读12次

    3.1.3 副本(Replication)
    同一个partition可能会有多个replication(对应 server.properties 配置中的 default.replication.factor=N)。没有replication的情况下,一旦broker 宕机,其上所有 patition 的数据都不可被消费,同时producer也不能再将数据存于其上的patition。引入replication之后,同一个partition可能会有多个replication,而这时需要在这些replication之间选出一个leader,producer和consumer只与这个leader交互,其它replication作为follower从leader 中复制数据。
    3.1.4 写入流程
    producer写入消息流程如下:

    image.png
    1)producer先从broker-list节点找到该partition的leader
    2)producer将消息发送给该leader
    3)leader将消息写入本地log
    4)followers从leader pull消息,写入本地log后向leader发送ACK
    5)leader收到所有ISR中的replication的ACK后,增加HW(high watermark,最后commit 的offset)并向producer发送ACK
    3.2 Broker 保存消息
    3.2.1 存储方式
    物理上把topic分成一个或多个patition(对应 server.properties 中的num.partitions=3配置),每个patition物理上对应一个文件夹(该文件夹存储该patition的所有消息和索引文件),如下:
    [atguigu@hadoop102 logs] ll drwxrwxr-x. 2 atguigu atguigu 4096 8月 6 14:37 first-0 drwxrwxr-x. 2 atguigu atguigu 4096 8月 6 14:35 first-1 drwxrwxr-x. 2 atguigu atguigu 4096 8月 6 14:37 first-2 [atguigu@hadoop102 logs] cd first-0
    [atguigu@hadoop102 first-0]$ ll
    -rw-rw-r--. 1 atguigu atguigu 10485760 8月 6 14:33 00000000000000000000.index
    -rw-rw-r--. 1 atguigu atguigu 219 8月 6 15:07 00000000000000000000.log
    -rw-rw-r--. 1 atguigu atguigu 10485756 8月 6 14:33 00000000000000000000.timeindex
    -rw-rw-r--. 1 atguigu atguigu 8 8月 6 14:37 leader-epoch-checkpoint
    3.2.2 存储策略
    无论消息是否被消费,kafka都会保留所有消息。有两种策略可以删除旧数据:
    1)基于时间:log.retention.hours=168
    2)基于大小:log.retention.bytes=1073741824
    需要注意的是,因为Kafka读取特定消息的时间复杂度为O(1),即与文件大小无关,所以这里删除过期文件与提高 Kafka 性能无关。

    本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源,欢迎大家关注尚硅谷公众号(atguigu)了解更多。

    相关文章

      网友评论

          本文标题:尚硅谷大数据技术之Kafka

          本文链接:https://www.haomeiwen.com/subject/lkqthqtx.html