rocketMQ之StoreCheckpoint

一、 StoreCheckpoint
1、作用
记录commitLog、ConsumeQueue、Index文件的刷盘时间点,当上一次broker是异常结束时,会根据StoreCheckpoint的数据进行恢复
2、参数
private volatile long physicMsgTimestamp =  0;
private volatile long logicsMsgTimestamp =  0;
private volatile long indexMsgTimestamp = 0;
physicMsgTimestamp为刷盘点commitLog最新一条记录的存储时间
logicsMsgTimestamp为刷盘点ConsumeQueue最新一条记录的存储时间
indexMsgTimestamp为刷盘点最近一个已经写完的index的最后一条记录时间
 
3、flush代码
public void flush() {
    this.mappedByteBuffer.putLong(0,  this.physicMsgTimestamp);
    this.mappedByteBuffer.putLong(8,  this.logicsMsgTimestamp);
    this.mappedByteBuffer.putLong(16,  this.indexMsgTimestamp);
    this.mappedByteBuffer.force();
}
4、flush触发
1)ConsumeQueue刷盘时会触发
2)当更换index文件时触发
 
 
二、文件刷盘
1、 ConsumeQueue数据进行刷盘(FlushConsumeQueueService线程
频率参数
int interval =  DefaultMessageStore.this.getMessageStoreConfig().getFlushIntervalConsumeQueue();
int flushConsumeQueueLeastPages =  DefaultMessageStore.this.getMessageStoreConfig().getFlushConsumeQueueLeastPages();
int flushConsumeQueueThoroughInterval =DefaultMessageStore.this.getMessageStoreConfig().getFlushConsumeQueueThoroughInterval()
每隔interval时间,线程执行一次。判断数据写入是否大于flushConsumeQueueLeastPages,如果大于就对ConsumeQueue文件进行数据刷盘。如果多次执行间隔大于flushConsumeQueueThoroughInterval,就会进行一次StoreCheckpoint数据的刷盘与ConsumeQueue文件刷盘
 
2、CommitLog数据刷盘
if (FlushDiskType.SYNC_FLUSH ==  defaultMessageStore.getMessageStoreConfig().getFlushDiskType()) {
    this.flushCommitLogService = new  GroupCommitService();
} else {
    this.flushCommitLogService = new  FlushRealTimeService();
}
 
this.commitLogService = new  CommitRealTimeService();
如果broker配置的是同步刷盘,走GroupCommitService
如果broker配置的是异步刷盘,走FlushRealTimeService
如果broker还启动了TransientStorePool,先把数据提交到TransientStorePool中,然后通过commitLogService线程提交到 mappedByteBuffer,然后通过刷盘线程刷盘
2.1、FlushRealTimeService线程
int interval =  CommitLog.this.defaultMessageStore.getMessageStoreConfig().getFlushIntervalCommitLog();
int flushPhysicQueueLeastPages =  CommitLog.this.defaultMessageStore.getMessageStoreConfig().getFlushCommitLogLeastPages();
int  flushPhysicQueueThoroughInterval = CommitLog.this.defaultMessageStore.getMessageStoreConfig().getFlushCommitLogThoroughInterval();
每隔interval时间,线程执行一次。判断数据写入是否大于flushPhysicQueueLeastPages,如果大于就对CommitLog文件进行数据刷盘。如果多次执行间隔大于flushPhysicQueueThoroughInterval也会对CommitLog文件刷盘。线程每执行一次都会更新StoreCheckpoint中的PhysicMsgTimestamp值
 
2.2、GroupCommitService
每次写入一个文件,会生成一个GroupCommitRequest对象,GroupCommitService会根据GroupCommitRequest做刷盘操作
2.3、CommitRealTimeService
int interval =  CommitLog.this.defaultMessageStore.getMessageStoreConfig().getCommitIntervalCommitLog();
int commitDataLeastPages =  CommitLog.this.defaultMessageStore.getMessageStoreConfig().getCommitCommitLogLeastPages();
int commitDataThoroughInterval =CommitLog.this.defaultMessageStore.getMessageStoreConfig().getCommitCommitLogThoroughInterval();
将TransientStorePool中的数据刷到fileChannel中
 
 
 
 
 
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
RocketMQ 是一个开源的分布式消息中间件系统,它归属于 Apache 开源软件基金会。RocketMQ 主要用于解决异步消息通信的问题,可以支持高性能、高可靠的消息传递。 RocketMQ 的整体架构包括了四个核心组件:名称服务器(Name Server)、消息 Broker(Message Broker)、生产者(Producer)和消费者(Consumer)。 名称服务器(Name Server)的主要功能是注册和管理 Broker、Producer 和 Consumer,它负责维护整个 RocketMQ 的注册表。Producer 和 Consumer 在启动时会向名称服务器注册自己的信息,并且周期性地向名称服务器发送心跳,以保持注册信息的有效性。此外,名称服务器还负责将 Producer 发送的消息路由到相应的 Broker。 消息 Broker(Message Broker)是一个消息存储和转发的节点,它接收来自 Producer 的消息并持久化存储,并根据订阅关系将消息转发给 Consumer。RocketMQ 支持顺序消息和广播消息两种模式,顺序消息可以按照指定的顺序进行消费,广播消息则会被所有的 Consumer 所接收。 生产者(Producer)可以将消息发送到 Broker,生产者可以设置消息的发送模式、发送延迟等属性。在发送消息时,RocketMQ 会将消息存储在 Broker 中,并返回发送结果给生产者,生产者可以根据发送结果进行相应的处理。 消费者(Consumer)可以订阅和消费 Broker 中的消息,消费者可以按照一定的模式从 Broker 中订阅消息,并根据自己的需求进行消费。消费者可以设置消费模式、消费线程数等参数。 总的来说,RocketMQ 是一个功能强大、高性能、高可靠的分布式消息中间件系统,可以广泛应用于各种场景,如电子商务、大数据分析、日志处理等。它具有良好的水平扩展性和高吞吐量,能够满足大规模系统的消息通信需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风中情

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值