public DefaultRecoveryService( StorageEngine storageEngine, LogTailScanner logTailScanner, TransactionIdStore transactionIdStore, LogicalTransactionStore logicalTransactionStore, LogVersionRepository logVersionRepository, RecoveryStartInformationProvider.Monitor monitor ) { this.storageEngine = storageEngine; this.transactionIdStore = transactionIdStore; this.logicalTransactionStore = logicalTransactionStore; this.logVersionRepository = logVersionRepository; this.recoveryStartInformationProvider = new RecoveryStartInformationProvider( logTailScanner, monitor ); }
@Override public RecoveryStartInformation getRecoveryStartInformation() { return recoveryStartInformationProvider.get(); }
private RecoveryStartInformation createRecoveryInformation( LogPosition logPosition, long firstTxId ) { return new RecoveryStartInformation( logPosition, firstTxId ); } }
@Test public void latestLogEmptyStartEntryBeforeAndAfterCheckPointInTheLastButOneLog() { // given long txId = 432; setupLogFiles( logFile( start(), checkPoint(), start(), commit( txId ) ), logFile() ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, true, txId, startLogVersion, logTailInformation ); }
private LogTailScanner getTailScanner( LogFiles logFiles, LogEntryReader<ReadableClosablePositionAwareChannel> reader ) { return new LogTailScanner( logFiles, reader, monitors, false ); }
@Test public void noLogFilesFound() { // given no files setupLogFiles(); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( false, false, NO_TRANSACTION_ID, -1, logTailInformation ); }
@Override protected ExtractedTransactionRecord extractFirstTxIdAfterPosition( LogPosition initialPosition, long maxLogVersion ) { return new ExtractedTransactionRecord( txId ); } }
@Override public RecoveryApplier getRecoveryApplier( TransactionApplicationMode mode ) throws Exception { return new RecoveryVisitor( storageEngine, mode ); }
@Test public void olderLogFileContainingAStartAndNewerFileContainingACheckPointPointingToALaterPositionThanStart() { // given PositionEntry position = position(); setupLogFiles( logFile( start(), commit( 3 ), position ), logFile( checkPoint( position ) ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, false, NO_TRANSACTION_ID, endLogVersion, logTailInformation ); }
@Test public void twoLogFilesNoCheckPointsTwoCommits() { // given long txId = 21; setupLogFiles( logFile(), logFile( start(), commit( txId ), start(), commit( txId + 1 ) ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( false, true, txId, startLogVersion, logTailInformation ); }
@Test public void olderLogFileContainingAStartAndNewerFileContainingACheckPointPointingToAPreviousPositionThanStart() { // given long txId = 123; StartEntry start = start(); setupLogFiles( logFile( start, commit( txId ) ), logFile( checkPoint( start ) ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, true, txId, endLogVersion, logTailInformation ); }
@Test public void olderLogFileContainingACheckPointAndNewerFileIsEmpty() { // given StartEntry start = start(); setupLogFiles( logFile( start, checkPoint() ), logFile() ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, true, NO_TRANSACTION_ID, startLogVersion, logTailInformation ); }
@Test public void olderLogFileContainingAStartAndNewerFileContainingACheckPointPointingToAPreviousPositionThanStartWithoutCommit() { // given StartEntry start = start(); setupLogFiles( logFile( start ), logFile( checkPoint( start ) ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, false, NO_TRANSACTION_ID, endLogVersion, logTailInformation ); }
@Test public void latestLogFileContainingMultipleCheckPointsOneStartInBetween() { // given setupLogFiles( logFile( checkPoint(), start(), checkPoint() ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, false, NO_TRANSACTION_ID, endLogVersion, logTailInformation ); }
@Test public void twoLogFilesNoCheckPointsOneStartWithoutCommit() { // given setupLogFiles( logFile(), logFile( start() ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( false, true, NO_TRANSACTION_ID, startLogVersion, logTailInformation ); }
@Test public void oneLogFileNoCheckPointsOneStart() { // given long txId = 10; setupLogFiles( logFile( start(), commit( txId ) ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( false, true, txId, endLogVersion, logTailInformation ); }
@Test public void latestLogFileContainingACheckPointAndAStartBefore() { // given setupLogFiles( logFile( start(), checkPoint() ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, false, NO_TRANSACTION_ID, endLogVersion, logTailInformation ); }
@Test public void latestLogFileContainingACheckPointAndAStartWithoutCommitAfter() { // given StartEntry start = start(); setupLogFiles( logFile( start, checkPoint( start ) ) ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( true, true, NO_TRANSACTION_ID, endLogVersion, logTailInformation ); }
@Test public void twoLogFilesNoCheckPoints() { // given setupLogFiles( logFile(), logFile() ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( false, true, NO_TRANSACTION_ID, startLogVersion, logTailInformation ); }
@Test public void oneLogFileNoCheckPoints() { // given setupLogFiles( logFile() ); // when LogTailInformation logTailInformation = tailScanner.getTailInformation(); // then assertLatestCheckPoint( false, true, NO_TRANSACTION_ID, endLogVersion, logTailInformation ); }