RongtongJin commented on a change in pull request #1405: [ISSUE #1397]Add
abnormal recover for dleger modle
URL: https://github.com/apache/rocketmq/pull/1405#discussion_r317426711
##########
File path:
store/src/main/java/org/apache/rocketmq/store/dledger/DLedgerCommitLog.java
##########
@@ -261,24 +258,96 @@ private void recover(long maxPhyOffsetOfConsumeQueue) {
if (mappedFile != null) {
disableDeleteDledger();
}
- long maxPhyOffset = dLedgerFileList.getMaxWrotePosition();
+ List<MmapFile> mmapFiles = dLedgerFileList.getMappedFiles();
+ int index = mmapFiles.size() - 1;
+ MmapFile mmapFile = null;
+ for (; index >= 0; index--) {
+ mmapFile = mmapFiles.get(index);
+ if (isMappedFileMatchedRecover(mmapFile)) {
+ log.info("Recover from this dleger mapped file " +
mmapFile.getFileName());
+ break;
+ }
+ }
+ if (index < 0) {
+ index = 0;
+ mmapFile = mmapFiles.get(index);
+ }
+
+ ByteBuffer byteBuffer = mmapFile.sliceByteBuffer();
+ long processOffset = mmapFile.getFileFromOffset();
+ long mappedFileOffset = 0;
+ while (true) {
+ DispatchRequest dispatchRequest =
this.checkMessageAndReturnSize(byteBuffer, checkCRCOnRecover);
+ int size = dispatchRequest.getMsgSize();
+
+ if (dispatchRequest.isSuccess()) {
+ if (size > 0) {
+ mappedFileOffset += size;
+ if
(this.defaultMessageStore.getMessageStoreConfig().isDuplicationEnable()) {
+ if (dispatchRequest.getCommitLogOffset() <
this.defaultMessageStore.getConfirmOffset()) {
+
this.defaultMessageStore.doDispatch(dispatchRequest);
+ }
+ } else {
+
this.defaultMessageStore.doDispatch(dispatchRequest);
+ }
+ } else if (size == 0) {
+ index++;
+ if (index >= mmapFiles.size()) {
+ log.info("Recover physics dleger file over, last
mapped file " + mmapFile.getFileName());
+ break;
+ } else {
+ mmapFile = mmapFiles.get(index);
+ byteBuffer = mmapFile.sliceByteBuffer();
+ processOffset = mmapFile.getFileFromOffset();
+ mappedFileOffset = 0;
+ log.info("Recover next physics dleger file, " +
mmapFile.getFileName());
+ }
+ }
+ } else {
+ log.info("Recover physics file end, " +
mmapFile.getFileName() + " pos=" + byteBuffer.position());
+ break;
+ }
+ }
+
+ processOffset += mappedFileOffset;
+
// Clear ConsumeQueue redundant data
- if (maxPhyOffsetOfConsumeQueue >= maxPhyOffset) {
- log.warn("[TruncateCQ]maxPhyOffsetOfConsumeQueue({}) >=
processOffset({}), truncate dirty logic files", maxPhyOffsetOfConsumeQueue,
maxPhyOffset);
- this.defaultMessageStore.truncateDirtyLogicFiles(maxPhyOffset);
+ if (maxPhyOffsetOfConsumeQueue >= processOffset) {
+ log.warn("maxPhyOffsetOfConsumeQueue({}) >= processOffset({}),
truncate dirty logic files", maxPhyOffsetOfConsumeQueue, processOffset);
+
this.defaultMessageStore.truncateDirtyLogicFiles(processOffset);
}
return;
}
//Indicate that, it is the first time to load mixed commitlog, need to
recover the old commitlog
isInrecoveringOldCommitlog = true;
//No need the abnormal recover
Review comment:
Comment and code are inconsistent.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services