RocketMQ消息存储四:逻辑对象层ConsumeQueue

概述ConsumeQueue存储逻辑消费队列,每个ConsumeQueue对应一个topic的一个queue。存储文件信息ConsumeQueue与CommtLog一样,也包含MappedFileQueu。ConsumeQueue存储目录为HOME/store/consumequeue/HOME/store/consumequeue/HOME/store/consumequeue/{topi...
摘要由CSDN通过智能技术生成

概述

ConsumeQueue存储逻辑消费队列,每个ConsumeQueue对应一个topic的一个queue。

存储文件信息

ConsumeQueue与CommtLog一样,也包含MappedFileQueu。ConsumeQueue存储目录为 H O M E / s t o r e / c o n s u m e q u e u e / HOME/store/consumequeue/ HOME/store/consumequeue/{topic}/${queueid},每个文件大小为1G,不满则填充空白。每个文件名字长度为20,具体命名为文件偏移量,左边补0。如第一个文件为00000000000000000000,第二个文件为00000000001073741824。

ConsumeQueue消息格式

ConsumeQueue消息长度是固定的20个字节,前8个字节存储消息在CommitLog中的offset,中间4个字节存储消息长度,后面8个字节存储消息的tagcode。消费消息时会使用tagcode过滤。格式如图:
在这里插入图片描述

属性介绍

// 默认存储实现
    private final DefaultMessageStore defaultMessageStore;
    // MappedFile队列
    private final MappedFileQueue mappedFileQueue;
    private final String topic;
    private final int queueId;
    // 写操作用到的ByteBuffer
    private final ByteBuffer byteBufferIndex;
    private final String storePath;
    private final int mappedFileSize;
    // 最后消息对应的offset
    private long maxPhysicOffset = -1;
    private volatile long minLogicOffset = 0;
    // 额外信息存储
    private ConsumeQueueExt consumeQueueExt = null;

方法介绍

getOffsetInQueueByTime

/**
     * 根据时间查询消息的offset
     * 1、先根据时间查询文件
     * 2、在文件中按照时间二分查找消息
     */
    public long getOffsetInQueueByTime(final long timestamp) {
   
        MappedFile mappedFile = this.mappedFileQueue.getMappedFileByTime(timestamp);
        if (mappedFile != null) {
   
            long offset = 0;
            int low = minLogicOffset > mappedFile.getFileFromOffset() ? (int) (minLogicOffset - mappedFile.getFileFromOffset()) : 0;
            int high = 0;
            int midOffset = -1, targetOffset = -1, leftOffset = -1, rightOffset = -1;
            long leftIndexValue = -1L, rightIndexValue = -1L;
            long minPhysicOffset = this.defaultMessageStore.getMinPhyOffset(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值