@@ -320,15 +320,15 @@ public boolean getLastMappedFile(final long startOffset) {
320
320
*
321
321
* @throws RocksDBException only in rocksdb mode
322
322
*/
323
- public void recoverNormally (long maxPhyOffsetOfConsumeQueue ) throws RocksDBException {
323
+ public void recoverNormally (long dispatchFromPhyOffset ) throws RocksDBException {
324
324
boolean checkCRCOnRecover = this .defaultMessageStore .getMessageStoreConfig ().isCheckCRCOnRecover ();
325
325
boolean checkDupInfo = this .defaultMessageStore .getMessageStoreConfig ().isDuplicationEnable ();
326
326
final List <MappedFile > mappedFiles = this .mappedFileQueue .getMappedFiles ();
327
327
if (!mappedFiles .isEmpty ()) {
328
328
int index = mappedFiles .size () - 1 ;
329
329
while (index > 0 ) {
330
330
MappedFile mappedFile = mappedFiles .get (index );
331
- if (mappedFile . getFileFromOffset () <= maxPhyOffsetOfConsumeQueue ) {
331
+ if (isMappedFileMatchedRecover ( mappedFile , true ) ) {
332
332
// It's safe to recover from this mapped file
333
333
break ;
334
334
}
@@ -344,7 +344,7 @@ public void recoverNormally(long maxPhyOffsetOfConsumeQueue) throws RocksDBExcep
344
344
while (true ) {
345
345
DispatchRequest dispatchRequest = this .checkMessageAndReturnSize (byteBuffer , checkCRCOnRecover , checkDupInfo );
346
346
int size = dispatchRequest .getMsgSize ();
347
- boolean doDispatch = dispatchRequest .getCommitLogOffset () > maxPhyOffsetOfConsumeQueue ;
347
+ boolean doDispatch = dispatchRequest .getCommitLogOffset () > dispatchFromPhyOffset ;
348
348
// Normal data
349
349
if (dispatchRequest .isSuccess () && size > 0 ) {
350
350
lastValidMsgPhyOffset = processOffset + mappedFileOffset ;
@@ -394,10 +394,7 @@ else if (!dispatchRequest.isSuccess()) {
394
394
}
395
395
396
396
// Clear ConsumeQueue redundant data
397
- if (maxPhyOffsetOfConsumeQueue >= processOffset ) {
398
- log .warn ("maxPhyOffsetOfConsumeQueue({}) >= processOffset({}), truncate dirty logic files" , maxPhyOffsetOfConsumeQueue , processOffset );
399
- this .defaultMessageStore .truncateDirtyLogicFiles (processOffset );
400
- }
397
+ this .defaultMessageStore .truncateDirtyLogicFiles (processOffset );
401
398
402
399
this .mappedFileQueue .setFlushedWhere (processOffset );
403
400
this .mappedFileQueue .setCommittedWhere (processOffset );
@@ -715,7 +712,7 @@ public void recoverAbnormally(long maxPhyOffsetOfConsumeQueue) throws RocksDBExc
715
712
MappedFile mappedFile = null ;
716
713
for (; index >= 0 ; index --) {
717
714
mappedFile = mappedFiles .get (index );
718
- if (this .isMappedFileMatchedRecover (mappedFile )) {
715
+ if (this .isMappedFileMatchedRecover (mappedFile , false )) {
719
716
log .info ("recover from this mapped file " + mappedFile .getFileName ());
720
717
break ;
721
718
}
@@ -802,10 +799,7 @@ else if (size == 0) {
802
799
}
803
800
804
801
// Clear ConsumeQueue redundant data
805
- if (maxPhyOffsetOfConsumeQueue >= processOffset ) {
806
- log .warn ("maxPhyOffsetOfConsumeQueue({}) >= processOffset({}), truncate dirty logic files" , maxPhyOffsetOfConsumeQueue , processOffset );
807
- this .defaultMessageStore .truncateDirtyLogicFiles (processOffset );
808
- }
802
+ this .defaultMessageStore .truncateDirtyLogicFiles (processOffset );
809
803
810
804
this .mappedFileQueue .setFlushedWhere (processOffset );
811
805
this .mappedFileQueue .setCommittedWhere (processOffset );
@@ -839,7 +833,8 @@ protected void onCommitLogAppend(MessageExtBrokerInner msg, AppendMessageResult
839
833
this .getMessageStore ().onCommitLogAppend (msg , result , commitLogFile );
840
834
}
841
835
842
- private boolean isMappedFileMatchedRecover (final MappedFile mappedFile ) throws RocksDBException {
836
+ private boolean isMappedFileMatchedRecover (final MappedFile mappedFile ,
837
+ boolean recoverNormally ) throws RocksDBException {
843
838
ByteBuffer byteBuffer = mappedFile .sliceByteBuffer ();
844
839
845
840
int magicCode = byteBuffer .getInt (MessageDecoder .MESSAGE_MAGIC_CODE_POSITION );
@@ -854,16 +849,16 @@ private boolean isMappedFileMatchedRecover(final MappedFile mappedFile) throws R
854
849
if (0 == storeTimestamp ) {
855
850
return false ;
856
851
}
852
+ long phyOffset = byteBuffer .getLong (MessageDecoder .MESSAGE_PHYSIC_OFFSET_POSITION );
857
853
858
- if (this .defaultMessageStore .getMessageStoreConfig ().isMessageIndexEnable ()
859
- && this .defaultMessageStore .getMessageStoreConfig ().isMessageIndexSafe ()
860
- && storeTimestamp > this .defaultMessageStore .getStoreCheckpoint ().getIndexMsgTimestamp ()) {
854
+ if (this .defaultMessageStore .getMessageStoreConfig ().isMessageIndexEnable () &&
855
+ this .defaultMessageStore .getMessageStoreConfig ().isMessageIndexSafe () &&
856
+ storeTimestamp > this .defaultMessageStore .getStoreCheckpoint ().getIndexMsgTimestamp ()) {
861
857
return false ;
862
858
}
863
859
864
- long phyOffset = byteBuffer .getLong (MessageDecoder .MESSAGE_PHYSIC_OFFSET_POSITION );
865
860
return this .defaultMessageStore .getQueueStore ()
866
- .isMappedFileMatchedRecover (phyOffset , storeTimestamp );
861
+ .isMappedFileMatchedRecover (phyOffset , storeTimestamp , recoverNormally );
867
862
}
868
863
869
864
public boolean resetOffset (long offset ) {
0 commit comments