【kafka系列教程26】kafka日志

本文详细介绍了Kafka日志的结构,包括日志的写入、读取过程,以及如何保障数据的耐久性。每个日志条目由消息长度和消息内容组成,使用消息offset作为唯一标识。日志采用配置参数控制文件大小和刷新策略,以确保最多丢失M条消息或S秒数据。读取时通过消息offset和最大块大小进行。日志还提供获取最新消息的功能,以及数据删除策略和保障措施,如CRC32校验防止数据损坏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

日志

 

A log for a topic named "my_topic" with two partitions consists of two directories (namely my_topic_0 and my_topic_1) populated with data files containing the messages for that topic. The format of the log files is a sequence of "log entries""; each log entry is a 4 byte integer Nstoring the message length which is followed by the Nmessage bytes. Each message is uniquely identified by a 64-bit integer offsetgiving the byte position of the start of this message in the stream of all messages ever sent to that topic on that partition. The on-disk format of each message is given below. Each log file is named with the offset of the first message it contains. So the first file created will be 00000000000.kafka, and each additional file will have an integer name roughly Sbytes from the previous file where Sis the max log file size given in the configuration.

假设有2个分区的主题“my_topic”,它将由2个目录构成(my_topic_0和my_topic_1),用于存放该主题消息的数据文件。日志文件的格式是一个“日志条目”序列。每条日志条目都由一个存储消息长度的4字节整型N和紧跟着的N字节消息组成。其中每条消息都有一个64位整型的唯一标识offset,offset(偏移量)代表了topic分区中所有消息流中该消息的起始字节位置。每条消息在磁盘上的格式如下:每个日志文件用第一条消息的offset来命名的,因此,创建的第一个文件将是00000000000.kafka,并且每个附加文件都将是上一个文件S字节的整数命名,其中S是配置中设置的最大日志文件大小。

 

The exact binary format for messages is versioned and maintained as a standard interface so message sets can be transfered between producer, broker, and client without recopying or conversion when desirable. This format is as follows:
消息是二进制格式并作为一个标准接口,所以消息可以在producer,broker,client之间传输,无需再copy或转换。格式如下:

On-disk format of a message

message length : 4 bytes (value: 1+4+n) 
"magic" value  : 1 byte
crc            : 4 bytes
payload        : n bytes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值