//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void reportProgressOnRecovery() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ReportProgressOnRecovery() { RecoveryService recoveryService = mock(typeof(RecoveryService), Answers.RETURNS_MOCKS); CorruptedLogsTruncator logsTruncator = mock(typeof(CorruptedLogsTruncator)); RecoveryMonitor recoveryMonitor = mock(typeof(RecoveryMonitor)); TransactionCursor reverseTransactionCursor = mock(typeof(TransactionCursor)); TransactionCursor transactionCursor = mock(typeof(TransactionCursor)); CommittedTransactionRepresentation transactionRepresentation = mock(typeof(CommittedTransactionRepresentation)); int transactionsToRecover = 5; int expectedMax = transactionsToRecover * 2; int lastCommittedTransactionId = 14; LogPosition recoveryStartPosition = LogPosition.start(0); int firstTxIdAfterLastCheckPoint = 10; RecoveryStartInformation startInformation = new RecoveryStartInformation(recoveryStartPosition, firstTxIdAfterLastCheckPoint); when(reverseTransactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover)); when(transactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover)); when(reverseTransactionCursor.get()).thenReturn(transactionRepresentation); when(transactionCursor.get()).thenReturn(transactionRepresentation); when(transactionRepresentation.CommitEntry).thenReturn(new LogEntryCommit(lastCommittedTransactionId, 1L)); when(recoveryService.RecoveryStartInformation).thenReturn(startInformation); when(recoveryService.GetTransactionsInReverseOrder(recoveryStartPosition)).thenReturn(reverseTransactionCursor); when(recoveryService.GetTransactions(recoveryStartPosition)).thenReturn(transactionCursor); AssertableProgressReporter progressReporter = new AssertableProgressReporter(expectedMax); Recovery recovery = new Recovery(recoveryService, logsTruncator, new LifecycleAdapter(), recoveryMonitor, progressReporter, true); Recovery.init(); progressReporter.Verify(); }
private void InitProgressReporter(RecoveryStartInformation recoveryStartInformation, CommittedTransactionRepresentation lastReversedTransaction) { long numberOfTransactionToRecover = GetNumberOfTransactionToRecover(recoveryStartInformation, lastReversedTransaction); // since we will process each transaction twice (doing reverse and direct detour) we need to // multiply number of transactions that we want to recover by 2 to be able to report correct progress _progressReporter.start(numberOfTransactionToRecover * 2); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero() public virtual void ShouldRecoverFromStartOfLogZeroIfThereAreNoCheckPointAndOldestLogIsVersionZero() { // given when(_tailScanner.TailInformation).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.RecoveryPosition); assertEquals(10L, recoveryStartInformation.FirstTxIdAfterLastCheckPoint); assertTrue(recoveryStartInformation.RecoveryRequired); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnUnspecifiedIfThereIsNoNeedForRecovery() public virtual void ShouldReturnUnspecifiedIfThereIsNoNeedForRecovery() { // given when(_tailScanner.TailInformation).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.RecoveryPosition); assertEquals(NO_TRANSACTION_ID, recoveryStartInformation.FirstTxIdAfterLastCheckPoint); assertFalse(recoveryStartInformation.RecoveryRequired); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnLogPositionToRecoverFromIfNeeded() public virtual void ShouldReturnLogPositionToRecoverFromIfNeeded() { // given LogPosition checkPointLogPosition = new LogPosition(1L, 4242); when(_tailScanner.TailInformation).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.RecoveryPosition); assertEquals(10L, recoveryStartInformation.FirstTxIdAfterLastCheckPoint); assertTrue(recoveryStartInformation.RecoveryRequired); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void init() throws Throwable public override void Init() { RecoveryStartInformation recoveryStartInformation = _recoveryService.RecoveryStartInformation; if (!recoveryStartInformation.RecoveryRequired) { // If there is nothing to recovery, then the schema is initialised immediately. _schemaLife.init(); return; } LogPosition recoveryPosition = recoveryStartInformation.RecoveryPosition; _monitor.recoveryRequired(recoveryPosition); _recoveryService.startRecovery(); LogPosition recoveryToPosition = recoveryPosition; CommittedTransactionRepresentation lastTransaction = null; CommittedTransactionRepresentation lastReversedTransaction = null; try { long lowestRecoveredTxId = Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID; using (TransactionCursor transactionsToRecover = _recoveryService.getTransactionsInReverseOrder(recoveryPosition), RecoveryApplier recoveryVisitor = _recoveryService.getRecoveryApplier(REVERSE_RECOVERY)) { while (transactionsToRecover.next()) { CommittedTransactionRepresentation transaction = transactionsToRecover.get(); if (lastReversedTransaction == null) { lastReversedTransaction = transaction; InitProgressReporter(recoveryStartInformation, lastReversedTransaction); } recoveryVisitor.visit(transaction); lowestRecoveredTxId = transaction.CommitEntry.TxId; ReportProgress(); } } _monitor.reverseStoreRecoveryCompleted(lowestRecoveredTxId); // We cannot initialise the schema (tokens, schema cache, indexing service, etc.) until we have returned the store to a consistent state. // We need to be able to read the store before we can even figure out what indexes, tokens, etc. we have. Hence we defer the initialisation // of the schema life until after we've done the reverse recovery. _schemaLife.init(); using (TransactionCursor transactionsToRecover = _recoveryService.getTransactions(recoveryPosition), RecoveryApplier recoveryVisitor = _recoveryService.getRecoveryApplier(RECOVERY)) { while (transactionsToRecover.next()) { lastTransaction = transactionsToRecover.get(); long txId = lastTransaction.CommitEntry.TxId; recoveryVisitor.visit(lastTransaction); _monitor.transactionRecovered(txId); _numberOfRecoveredTransactions++; recoveryToPosition = transactionsToRecover.Position(); ReportProgress(); } recoveryToPosition = transactionsToRecover.Position(); } } catch (Exception e) when(e is Exception || e is ClosedByInterruptException) { // We do not want to truncate logs based on these exceptions. Since users can influence them with config changes // the users are able to workaround this if truncations is really needed. throw e; } catch (Exception t) { if (_failOnCorruptedLogFiles) { ThrowUnableToCleanRecover(t); } if (lastTransaction != null) { LogEntryCommit commitEntry = lastTransaction.CommitEntry; _monitor.failToRecoverTransactionsAfterCommit(t, commitEntry, recoveryToPosition); } else { _monitor.failToRecoverTransactionsAfterPosition(t, recoveryPosition); recoveryToPosition = recoveryPosition; } } _progressReporter.completed(); _logsTruncator.truncate(recoveryToPosition); _recoveryService.transactionsRecovered(lastTransaction, recoveryToPosition); _monitor.recoveryCompleted(_numberOfRecoveredTransactions); }
private long GetNumberOfTransactionToRecover(RecoveryStartInformation recoveryStartInformation, CommittedTransactionRepresentation lastReversedTransaction) { return(lastReversedTransaction.CommitEntry.TxId - recoveryStartInformation.FirstTxIdAfterLastCheckPoint + 1); }