commitLog 删除文件的策略
指定时间到了,磁盘不足,人工删除,满足任一条件,判断文件是否过期或者磁盘严重不足(超过 85%),是则删除,一批次最多删除 10 个文件。

有个地方需要注意,mmap 写文件,windows 观察,发现文件的修改时间戳一直不变,linux 还未验证。

commitLog,consumeQueue,indexFile 的删除策略如下图:

rocketMQ 删除过期文件_apache

 

 

commitLog 尾部是有空洞的,当一个消息在当前文件放不下时,rocketmq 认为下一个文件一定能放下该消息,消息不会分隔保存。

commitLog 文件尾部存在至少 8 字节的空洞。

一般情况的尾部组成:maxBlank,BLANK_MAGIC_CODE,随机的内容

// org.apache.rocketmq.store.CommitLog.DefaultAppendMessageCallback#doAppend
if ((msgLen + END_FILE_MIN_BLANK_LENGTH) > maxBlank) {
this.resetByteBuffer(this.msgStoreItemMemory, maxBlank);
// 1 TOTALSIZE
this.msgStoreItemMemory.putInt(maxBlank);
// 2 MAGICCODE
this.msgStoreItemMemory.putInt(CommitLog.BLANK_MAGIC_CODE);
// 3 The remaining space may be any value
// Here the length of the specially set maxBlank
final long beginTimeMills = CommitLog.this.defaultMessageStore.now();
byteBuffer.put(this.msgStoreItemMemory.array(), 0, maxBlank);
return new AppendMessageResult(AppendMessageStatus.END_OF_FILE, wroteOffset, maxBlank, msgId, msgInner.getStoreTimestamp(),
queueOffset, CommitLog.this.defaultMessageStore.now() - beginTimeMills);
}