@Test public void shouldReturnUnspecifiedIfThereIsNoNeedForRecovery() { // given when( tailScanner.getTailInformation() ).thenReturn( new LogTailScanner.LogTailInformation( false, NO_TRANSACTION_ID, logVersion, currentLogVersion, LogEntryVersion.CURRENT ) ); // when RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider( tailScanner, monitor ).get(); // then verify( monitor ).noCommitsAfterLastCheckPoint( null ); assertEquals( LogPosition.UNSPECIFIED, recoveryStartInformation.getRecoveryPosition() ); assertEquals( NO_TRANSACTION_ID, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint() ); assertFalse( recoveryStartInformation.isRecoveryRequired() ); }
@Test public void shouldFailIfThereAreNoCheckPointsAndOldestLogVersionInNotZero() { // given long oldestLogVersionFound = 1L; when( tailScanner.getTailInformation() ).thenReturn( new LogTailScanner.LogTailInformation( true, 10L, oldestLogVersionFound, currentLogVersion, LogEntryVersion.CURRENT ) ); // when try { new RecoveryStartInformationProvider( tailScanner, monitor ).get(); } catch ( UnderlyingStorageException ex ) { // then final String expectedMessage = "No check point found in any log file from version " + oldestLogVersionFound + " to " + logVersion; assertEquals( expectedMessage, ex.getMessage() ); } } }
@Test public void shouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero() { // given when( tailScanner.getTailInformation() ).thenReturn( new LogTailInformation( true, 10L, INITIAL_LOG_VERSION, currentLogVersion, LogEntryVersion.CURRENT ) ); // when RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider( tailScanner, monitor ).get(); // then verify( monitor ).noCheckPointFound(); assertEquals( LogPosition.start( INITIAL_LOG_VERSION ), recoveryStartInformation.getRecoveryPosition() ); assertEquals( 10L, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint() ); assertTrue( recoveryStartInformation.isRecoveryRequired() ); }
return new LogTailInformation( corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound, highestLogVersion, latestLogEntryVersion );
protected LogTailInformation checkpointTailInformation( long highestLogVersion, LogEntryStart latestStartEntry, long oldestVersionFound, LogEntryVersion latestLogEntryVersion, CheckPoint latestCheckPoint, boolean corruptedTransactionLogs ) throws IOException { LogPosition checkPointLogPosition = latestCheckPoint.getLogPosition(); ExtractedTransactionRecord transactionRecord = extractFirstTxIdAfterPosition( checkPointLogPosition, highestLogVersion ); long firstTxIdAfterPosition = transactionRecord.getId(); boolean startRecordAfterCheckpoint = (firstTxIdAfterPosition != NO_TRANSACTION_ID) || ((latestStartEntry != null) && (latestStartEntry.getStartPosition().compareTo( latestCheckPoint.getLogPosition() ) >= 0)); boolean corruptedLogs = transactionRecord.isFailure() || corruptedTransactionLogs; return new LogTailInformation( latestCheckPoint, corruptedLogs || startRecordAfterCheckpoint, firstTxIdAfterPosition, oldestVersionFound, highestLogVersion, latestLogEntryVersion ); }
return new LogTailInformation( corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound, highestLogVersion, latestLogEntryVersion );
@Test public void shouldReturnLogPositionToRecoverFromIfNeeded() { // given LogPosition checkPointLogPosition = new LogPosition( 1L, 4242 ); when( tailScanner.getTailInformation() ) .thenReturn( new LogTailInformation( new CheckPoint( checkPointLogPosition ), true, 10L, logVersion, currentLogVersion, LogEntryVersion.CURRENT ) ); // when RecoveryStartInformation recoveryStartInformation = new RecoveryStartInformationProvider( tailScanner, monitor ).get(); // then verify( monitor ).commitsAfterLastCheckPoint( checkPointLogPosition, 10L ); assertEquals( checkPointLogPosition, recoveryStartInformation.getRecoveryPosition() ); assertEquals( 10L, recoveryStartInformation.getFirstTxIdAfterLastCheckPoint() ); assertTrue( recoveryStartInformation.isRecoveryRequired() ); }
protected LogTailInformation checkpointTailInformation( long highestLogVersion, LogEntryStart latestStartEntry, long oldestVersionFound, LogEntryVersion latestLogEntryVersion, CheckPoint latestCheckPoint, boolean corruptedTransactionLogs ) throws IOException { LogPosition checkPointLogPosition = latestCheckPoint.getLogPosition(); ExtractedTransactionRecord transactionRecord = extractFirstTxIdAfterPosition( checkPointLogPosition, highestLogVersion ); long firstTxIdAfterPosition = transactionRecord.getId(); boolean startRecordAfterCheckpoint = (firstTxIdAfterPosition != NO_TRANSACTION_ID) || ((latestStartEntry != null) && (latestStartEntry.getStartPosition().compareTo( latestCheckPoint.getLogPosition() ) >= 0)); boolean corruptedLogs = transactionRecord.isFailure() || corruptedTransactionLogs; return new LogTailInformation( latestCheckPoint, corruptedLogs || startRecordAfterCheckpoint, firstTxIdAfterPosition, oldestVersionFound, highestLogVersion, latestLogEntryVersion ); }