Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,24 @@ public void correctMinOffset(long minCommitLogOffset) {
SelectMappedBufferResult lastRecord = null;
try {
int maxReadablePosition = lastMappedFile.getReadPosition();
lastRecord = lastMappedFile.selectMappedBuffer(maxReadablePosition - ConsumeQueue.CQ_STORE_UNIT_SIZE,
ConsumeQueue.CQ_STORE_UNIT_SIZE);
if (null != lastRecord) {
ByteBuffer buffer = lastRecord.getByteBuffer();
long commitLogOffset = buffer.getLong();
if (commitLogOffset < minCommitLogOffset) {
// Keep the largest known consume offset, even if this consume-queue contains no valid entries at
// all. Let minLogicOffset point to a future slot.
this.minLogicOffset = lastMappedFile.getFileFromOffset() + maxReadablePosition;
log.info("ConsumeQueue[topic={}, queue-id={}] contains no valid entries. Min-offset is assigned as: {}.",
topic, queueId, getMinOffsetInQueue());
return;
/*
if maxReadablePosition is less than ConsumeQueue.CQ_STORE_UNIT_SIZE,
it means the last file is empty and we need skip it otherwise selectMappedBuffer will throw IllegalArgumentException
*/
if (maxReadablePosition >= ConsumeQueue.CQ_STORE_UNIT_SIZE) {
lastRecord = lastMappedFile.selectMappedBuffer(maxReadablePosition - ConsumeQueue.CQ_STORE_UNIT_SIZE,
ConsumeQueue.CQ_STORE_UNIT_SIZE);
if (null != lastRecord) {
ByteBuffer buffer = lastRecord.getByteBuffer();
long commitLogOffset = buffer.getLong();
if (commitLogOffset < minCommitLogOffset) {
// Keep the largest known consume offset, even if this consume-queue contains no valid entries at
// all. Let minLogicOffset point to a future slot.
this.minLogicOffset = lastMappedFile.getFileFromOffset() + maxReadablePosition;
log.info("ConsumeQueue[topic={}, queue-id={}] contains no valid entries. Min-offset is assigned as: {}.",
topic, queueId, getMinOffsetInQueue());
return;
}
}
}
} finally {
Expand Down
Loading