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 ); }
public boolean isRecoveryRequiredAt( DatabaseLayout databaseLayout ) throws IOException { // We need config to determine where the logical log files are if ( !NeoStores.isStorePresent( pageCache, databaseLayout ) ) { return false; } LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(); LogFiles logFiles = LogFilesBuilder.activeFilesBuilder( databaseLayout, fs, pageCache ) .withConfig( config ) .withLogEntryReader( reader ).build(); LogTailScanner tailScanner = new LogTailScanner( logFiles, reader, monitors ); return new RecoveryStartInformationProvider( tailScanner, NO_MONITOR ).get().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 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 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() ); }
@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() ); }
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 ); }
public boolean isRecoveryRequiredAt( DatabaseLayout databaseLayout ) throws IOException { // We need config to determine where the logical log files are if ( !NeoStores.isStorePresent( pageCache, databaseLayout ) ) { return false; } LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(); LogFiles logFiles = LogFilesBuilder.activeFilesBuilder( databaseLayout, fs, pageCache ) .withConfig( config ) .withLogEntryReader( reader ).build(); LogTailScanner tailScanner = new LogTailScanner( logFiles, reader, monitors ); return new RecoveryStartInformationProvider( tailScanner, NO_MONITOR ).get().isRecoveryRequired(); }