磁盘存储文件-rw-r–r– 1 root root 0 Jan 18 11:54 abort-rw-r–r– 1 root root 4.0K Mar 14 17:39 checkpointdrwxr-xr-x 2 root root 34 Feb 14 14:33 commitlogdrwxr-xr-x 2 root root 280 Mar 14 17:40 configdrwxr-xr-x 7 root root 138 Feb 20 10:28 consumequeuedrwxr-xr-x 2 root root 31 Feb 20 10:18 index-rw-r–r– 1 root root 4 Feb 20 10:18 lockabort:RocketMQ 启动时生成,正常关闭时删除,如果启动时存在该文件,代表 RocketMQ 被异常关闭checkpoint:文件检查点,存储 commitlog 、consumequeue、indexfile 最后一次刷盘时间或时间戳index:消息索引文件存储目录consumequeue:消息消费队列存储目录commitlog:消息存储目录config:运行时的配置信息,包含主席消息过滤信息、集群消费模式消息消费进度、延迟消息队列拉取进度、消息消费组配置信息、topic配置属性等CommitLog 文件drwxr-xr-x 2 root root 34 Feb 14 14:33 .drwxr-xr-x 6 root root 113 Feb 14 13:59 ..-rw-r–r– 1 root root 1.0G Mar 14 17:48 00000000000000000000-rw-r–r– 1 root root 1.0G Mar 19 21:33 00000000006000000000文件名为 20 位数字组织,以该文件第一条消息的偏移量为文件名,长度不足 20 的在前面补 0。文件默认大小为 1G,可根据 mappedFileSizeCommitLog 属性改变文件大小。存储所有消息内容,写满一个文件后生成新的 commitlog 文件。所有 topic 的数据存储在一起,逻辑视图如下:ConsumeQueue 文件RocketMQ 基于主题的订阅模式实现消息消费,由于同一主题的消息不连续的存储在 CommitLog 文件中,遍历 CommitLog 文件会导致效率非常低下,为了适应消息消费的检索需求,设计了消息消费队列文件。一个 ConsumeQueue 文件可以作为检索指定 topic 的消息索引。[root@xxxx consumequeue]# tree -L 3|– smsCallbackReply| |– 0| | -- 00000000000000000000| |-- 1| | – 00000000000000000000| |– 2| | -- 00000000000000000000| – 3| -- 00000000000000000000|-- smsCallbackStatus| |-- 0| | |-- 00000000000000000000| | – 00000000000006000000| |– 1| | |– 00000000000000000000| | -- 00000000000006000000| |-- 2| | |-- 00000000000000000000| | – 00000000000006000000| -- 3| |-- 00000000000000000000| – 00000000000006000000ConsumeQueue 文件存储消息的逻辑偏移量,而不存储消息的全部内容,存储格式如下:Index 索引文件RocketMQ 引入了 Hash 索引机制为消息建立索引,对 CommitLog 进行数据索引。索引文件布局如下:IndexHead 数据:beginTimestamp:该索引文件包含消息的最小存储时间endTimestamp:该索引文件包含消息的最大存储时间beginPhyoffset:该索引文件中包含消息的最小物理偏移量(commitlog 文件偏移量)endPhyoffset:该索引文件中包含消息的最大物理偏移量(commitlog 文件偏移量)hashSlotCount:hashslot个数,并不是 hash 槽使用的个数,在这里意义不大,indexCount:已使用的 Index 条目个数Hash 槽:一个 IndexFile 默认包含 500W 个 Hash 槽,每个 Hash 槽存储的是落在该 Hash 槽的 hashcode 最新的 Index 的索引Index 条目列表hashcode:key 的 hashcodephyoffset:消息对应的物理偏移量timedif:该消息存储时间与第一条消息的时间戳的差值,小于 0 表示该消息无效preIndexNo:该条目的前一条记录的 Index 索引,hash 冲突时,根据该值构建链表结构Checkpoint 文件记录 CommitLog,ConsumeQueue,IndexFile 的刷盘时间点,文件固定长度为 4k,其中只用该文件的前 24个字节,存储格式如下: