接上篇:正好offset是到44的,说明和我的猜想几乎一致,就是不知道如果建立不同时间段的log,在依次过期的时候,日志文件是如何变化的。

所以我又做了个实验,就是我在18:51通过mqtt客户端发布了一条消息,也就在19:51会过期;在19:21的时候又发布了一条,也就是在20:21会过期。

18:51 ==> 19:51

19:21 ==> 20:21

1.   19:56 的时候 第一条还是能查到

已加载 kafka_client
连接成功 ---2019-03-28 19:56:24
{ topic: 'Processing',
  value: '{"action":"message_publish","device_id":"1103262d-ff94-4609-b578-8018721e740c1553647524324","username":"mosl","topic":"/mosl","payload":"我是xxx hello hello hello 201903281851","ts":1553797789}',
  offset: 45,
  partition: 0,
  highWaterOffset: 47,
  key: null }
{ topic: 'Processing',
  value: '{"action":"message_publish","device_id":"1103262d-ff94-4609-b578-8018721e740c1553647524324","username":"mosl","topic":"/mosl","payload":"我是xxx hello hello hello 201903281921","ts":1553799624}',
  offset: 46,
  partition: 0,
  highWaterOffset: 47,
  key: null }

2. 20:11的时候 第一条还是能查到

已加载 kafka_client
连接成功 ---2019-03-28 20:11:41
{ topic: 'Processing',
  value: '{"action":"message_publish","device_id":"1103262d-ff94-4609-b578-8018721e740c1553647524324","username":"mosl","topic":"/mosl","payload":"我是莫世林 hello hello hello 201903281851","ts":1553797789}',
  offset: 45,
  partition: 0,
  highWaterOffset: 47,
  key: null }
{ topic: 'Processing',
  value: '{"action":"message_publish","device_id":"1103262d-ff94-4609-b578-8018721e740c1553647524324","username":"mosl","topic":"/mosl","payload":"我是莫世林 hello hello hello 201903281921","ts":1553799624}',
  offset: 46,
  partition: 0,
  highWaterOffset: 47,
  key: null }

日志名字也还是没变化

【服务器篇笔记03-kafka】

3. 20:15的时候还是

已加载 kafka_client
连接成功 ---2019-03-28 20:15:26
{ topic: 'Processing',
  value: '{"action":"message_publish","device_id":"1103262d-ff94-4609-b578-8018721e740c1553647524324","username":"mosl","topic":"/mosl","payload":"我是莫世林 hello hello hello 201903281851","ts":1553797789}',
  offset: 45,
  partition: 0,
  highWaterOffset: 47,
  key: null }
{ topic: 'Processing',
  value: '{"action":"message_publish","device_id":"1103262d-ff94-4609-b578-8018721e740c1553647524324","username":"mosl","topic":"/mosl","payload":"我是莫世林 hello hello hello 201903281921","ts":1553799624}',
  offset: 46,
  partition: 0,
  highWaterOffset: 47,
  key: null }

4. 20:27的时候就查不到数据了

【服务器篇笔记03-kafka】

中间没打印出数据

服务器的日志文件变化了

【服务器篇笔记03-kafka】

总结:

这样是不是就可以下结论了,kafka的日志过期,是要等全部日志过期了,就会删除并生成新的log文件。并且名字就是之前的offset+1。那我也很奇怪,要是一直有数据刷进日志,那岂不是就算我设置很短的日志过期时间,比如一小时,日志也不会过期。就像第一条数据一样,按理它到19:51就要过期了,但是日志并没有刷新,而是等到第二条过期了,也就是数据全部过期了,才重新生成了日志文件。以后再探究吧~~

后来找到了一篇博客,能做出一些解释~~【apache Kafka是如何实现删除数据文件(日志)的】

 

 

 

 

相关文章:

  • 2021-09-01
  • 2021-07-17
  • 2021-11-23
  • 2022-01-06
  • 2021-09-11
  • 2022-12-23
  • 2021-12-26
  • 2022-01-17
猜你喜欢
  • 2021-05-09
  • 2021-09-24
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-02-20
相关资源
相似解决方案