commitlog 加载
当我们把 broker
重启后,RocketMQ
是如何重新将磁盘的 commitlog
文件重新加载到磁盘中的呢?带着这个疑问,我们来看一下 commitlog
的加载流程
commitlog
的加载流程大致如下:
我们在这里主要关心 第1,2 个流程。第 3 个流程,在讲解完 ConsumeQueue
, IndexFile
会重点说明。
稍微带下第3个流程,第 3 个流程逻辑为,将 commitlog
存入到 consumeQueue
。 这里的 commitlog
是未被转发存储到 consumeQueue
中的消息
DefaultMessageStore 初始化
在 RocketMQ
中,commitlog
被抽象为 CommitLog
类。每个文件被抽象为 MappedFile
。DefaultMessageStore
则作为一个 ‘聚合类’, 统筹着所有文件的加载。
该类在初始化时,会顺带把 CommitLog
也初始化了
public DefaultMessageStore(final MessageStoreConfig messageStoreConfig, final BrokerStatsManager brokerStatsManager,
final MessageArrivingListener messageArrivingListener, final BrokerConfig brokerConfig) throws IOException {
// ...
// 初始化 commitLog
if (messageStoreConfig.isEnableDLegerCommitLog()) {
this.commitLog = new DLedgerCommitLog(this);
} else {