美文网首页
消息队列Offset和CommitLog

消息队列Offset和CommitLog

作者: JBryan | 来源:发表于2020-04-26 16:20 被阅读0次

1、消息偏移量Offset

1.1、什么是Offset

message queue是无限长的数组,一条消息进来下标就会涨1,下标就是offset,消息在某个MessageQueue里的位置,通过offset的值可以定位到这条消息,或者指示Consumer从这条消息开始向后处理。

message queue中的maxOffset表示消息的最大offset, maxOffset并不是最新的那条消息的offset,而是最新消息的offset+1,minOffset则是现存在的最小offset。

fileReserveTime=48 默认消息存储48小时后,消费会被物理地从磁盘删除,message queue的min offset也就对应增长。所以比minOffset还要小的那些消息已经不在broker上了,就无法被消费

1.2、类型

本地文件类型
DefaultMQPushConsumer的BROADCASTING模式,各个Consumer没有互相干扰,使用LoclaFileOffsetStore,把Offset存储在本地

Broker代存储类型
DefaultMQPushConsumer的CLUSTERING模式,由Broker端存储和控制Offset的值,使用RemoteBrokerOffsetStore

建议采用pushConsumer,RocketMQ自动维护OffsetStore,如果用另外一种pullConsumer需要自己进行维护OffsetStore

2、CommitLog分析

消息存储是由ConsumeQueue和CommitLog配合完成

2.1、ConsumeQueue

Topic下的每个message queue都有对应的ConsumeQueue文件,这个ConsumeQueue可以理解为索引,记录的是一个地址,这个地址指向message queue的消息在CommitLog中的位置。
默认地址:store/consumequeue/{topicName}/{queueid}/fileName

[root@localhost ~]# cd 
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1243 Apr 18 15:55 anaconda-ks.cfg
drwxr-xr-x. 3 root root   26 Apr 19 15:39 logs
drwxr-xr-x. 6 root root  100 Apr 26 15:41 store
[root@localhost ~]# cd store
[root@localhost store]# ll
total 8
-rw-r--r--. 1 root root 4096 Apr 26 15:41 checkpoint
drwxr-xr-x. 2 root root   34 Apr 20 15:13 commitlog
drwxr-xr-x. 2 root root  280 Apr 26 15:41 config
drwxr-xr-x. 7 root root  145 Apr 26 11:20 consumequeue
drwxr-xr-x. 2 root root   31 Apr 26 10:04 index
-rw-r--r--. 1 root root    4 Apr 26 10:04 lock
[root@localhost store]# cd consumequeue/
[root@localhost consumequeue]# ll
total 0
drwxr-xr-x. 5 root root 33 Apr 26 11:20 JESSIE_PAY_ORDERLY_TEST_TOPIC
drwxr-xr-x. 6 root root 42 Apr 26 10:17 JESSIE_PAY_TEST_TOPIC
drwxr-xr-x. 3 root root 15 Apr 20 17:17 %RETRY%consumer_group
drwxr-xr-x. 5 root root 33 Apr 26 10:17 SCHEDULE_TOPIC_XXXX
drwxr-xr-x. 6 root root 42 Apr 19 15:53 TopicTest
[root@localhost consumequeue]# cd JESSIE_PAY_TEST_TOPIC/
[root@localhost JESSIE_PAY_TEST_TOPIC]# ll
total 0
drwxr-xr-x. 2 root root 34 Apr 19 15:54 0
drwxr-xr-x. 2 root root 34 Apr 26 10:17 1
drwxr-xr-x. 2 root root 34 Apr 26 10:10 2
drwxr-xr-x. 2 root root 34 Apr 20 15:26 3
2.2、CommitLog

消息的存储文件

生成规则:
每个文件的默认1G =1024 * 1024 * 1024,commitlog的文件名fileName,名字长度为20位,左边补零,剩余为起始偏移量;比如00000000000000000000代表了第一个文件,起始偏移量为0,文件大小为1G=1 073 741 824Byte;当这个文件满了,第二个文件名字为00000000001073741824,起始偏移量为1073741824, 消息存储的时候会顺序写入文件,当文件满了则写入下一个文件

判断消息存储在哪个CommitLog上
例如 1073742827 为物理偏移量,则其对应的相对偏移量为 1003 = 1073742827 - 1073741824,并且该偏移量位于第二个 CommitLog。

相关文章

  • 消息队列Offset和CommitLog

    1、消息偏移量Offset 1.1、什么是Offset message queue是无限长的数组,一条消息进来下标...

  • rocketmq之消息拉取

    rocketmq将消息存储在commitlog中,为了快速的读取当前topic以及对应队列的内容信息,rocket...

  • 7:RocketMq原理 高效能的RocketMQ(Consu

    1:什么是Offset 2:什么是CommitLog 3:高性能分析之ZeroCopy零拷贝技术讲解

  • rocketMQ -- offset管理

    rocketMQ--offset offset 在rocketMQ中,offset用来管理每个消费队列的不同消费组...

  • rocketmq-1

    rocketmq-1 rocketmq的存储文件: CommitLog ConsumeQueue 消费队列文件 C...

  • Kafka Consumer

    新版本consumer 新版本consumer不再使用ZK保存消费位移(offset),而是使用内部的消息队列。因...

  • 定位消息

    寻找最新的offset 从指定的offset检索消息 实际检索消息的代码

  • Kafka常见问题解决

    概要:我们使用消息队列,就需要知道为什么要用消息队列,什么场景需要用消息队列,使用消息队列能带来哪些好处和消息队列...

  • 进程间通信(下)

    消息队列 在UNP第二卷中详细介绍了两种消息队列:Posix消息队列和System V消息队列。这两种消息队列很相...

  • RocketMQ消息存储

    RocketMQ消息存储 1 CommitLog 要想知道RocketMQ如何存储消息,我们先看看CommitLo...

网友评论

      本文标题:消息队列Offset和CommitLog

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