private void closeCurrent() throws IOException { if ( currentLogTransactionCursor != null ) { currentLogTransactionCursor.close(); currentLogTransactionCursor = null; } }
@Override public LogPosition position() { return currentLogTransactionCursor.position(); } }
RecoveryApplier recoveryVisitor = recoveryService.getRecoveryApplier( REVERSE_RECOVERY ) ) while ( transactionsToRecover.next() ) CommittedTransactionRepresentation transaction = transactionsToRecover.get(); if ( lastReversedTransaction == null ) RecoveryApplier recoveryVisitor = recoveryService.getRecoveryApplier( RECOVERY ) ) while ( transactionsToRecover.next() ) lastTransaction = transactionsToRecover.get(); long txId = lastTransaction.getCommitEntry().getTxId(); recoveryVisitor.visit( lastTransaction ); monitor.transactionRecovered( txId ); numberOfRecoveredTransactions++; recoveryToPosition = transactionsToRecover.position(); reportProgress(); recoveryToPosition = transactionsToRecover.position();
@Override public CommittedTransactionRepresentation get() { return currentLogTransactionCursor.get(); }
@Override public boolean next() throws IOException { while ( currentLogTransactionCursor == null || !currentLogTransactionCursor.next() ) { // We've run out of transactions in this log version, back up to a previous one currentVersion--; if ( currentVersion < backToPosition.getLogVersion() ) { return false; } closeCurrent(); LogPosition position = currentVersion > backToPosition.getLogVersion() ? start( currentVersion ) : backToPosition; currentLogTransactionCursor = cursorFactory.apply( position ); } return true; }
private static List<TransactionRepresentation> extractTransactions( GraphDatabaseAPI db ) throws IOException { LogicalTransactionStore txStore = db.getDependencyResolver().resolveDependency( LogicalTransactionStore.class ); List<TransactionRepresentation> transactions = new ArrayList<>(); try ( TransactionCursor cursor = txStore.getTransactions( TransactionIdStore.BASE_TX_ID + 1 ) ) { cursor.forAll( tx -> transactions.add( tx.getTransactionRepresentation() ) ); } return transactions; } }
RecoveryApplier recoveryVisitor = recoveryService.getRecoveryApplier( REVERSE_RECOVERY ) ) while ( transactionsToRecover.next() ) CommittedTransactionRepresentation transaction = transactionsToRecover.get(); if ( lastReversedTransaction == null ) RecoveryApplier recoveryVisitor = recoveryService.getRecoveryApplier( RECOVERY ) ) while ( transactionsToRecover.next() ) lastTransaction = transactionsToRecover.get(); long txId = lastTransaction.getCommitEntry().getTxId(); recoveryVisitor.visit( lastTransaction ); monitor.transactionRecovered( txId ); numberOfRecoveredTransactions++; recoveryToPosition = transactionsToRecover.position(); reportProgress(); recoveryToPosition = transactionsToRecover.position();
@Override public CommittedTransactionRepresentation get() { return currentLogTransactionCursor.get(); }
@Override public boolean next() throws IOException { while ( currentLogTransactionCursor == null || !currentLogTransactionCursor.next() ) { // We've run out of transactions in this log version, back up to a previous one currentVersion--; if ( currentVersion < backToPosition.getLogVersion() ) { return false; } closeCurrent(); LogPosition position = currentVersion > backToPosition.getLogVersion() ? start( currentVersion ) : backToPosition; currentLogTransactionCursor = cursorFactory.apply( position ); } return true; }
private void readNextChunk() throws IOException { assert chunkStartOffsetIndex > 0; // Start at lowOffsetIndex - 1 and count backwards until almost reaching the chunk size long highOffset = chunkStartOffsetIndex == offsetsLength ? totalSize : offsets[chunkStartOffsetIndex]; int newLowOffsetIndex = chunkStartOffsetIndex; while ( newLowOffsetIndex > 0 ) { long deltaOffset = highOffset - offsets[--newLowOffsetIndex]; if ( deltaOffset > CHUNK_SIZE ) { // We've now read more than the read-ahead size, let's call this the end of this chunk break; } } assert chunkStartOffsetIndex - newLowOffsetIndex > 0; // We've established the chunk boundaries. Initialize all offsets and read the transactions in this // chunk into actual transaction objects int chunkLength = chunkStartOffsetIndex - newLowOffsetIndex; chunkStartOffsetIndex = newLowOffsetIndex; channel.setCurrentPosition( offsets[chunkStartOffsetIndex] ); assert chunkTransactions.isEmpty(); for ( int i = 0; i < chunkLength; i++ ) { boolean success = transactionCursor.next(); assert success; chunkTransactions.push( transactionCursor.get() ); } }
@Override public void close() throws IOException { transactionCursor.close(); // closes the channel too }
@Override public LogPosition position() { return currentLogTransactionCursor.position(); } }
public static CommittedTransactionRepresentation[] exhaust( TransactionCursor cursor ) throws IOException { List<CommittedTransactionRepresentation> list = new ArrayList<>(); while ( cursor.next() ) { list.add( cursor.get() ); } return list.toArray( new CommittedTransactionRepresentation[list.size()] ); } }
@Override public void close() throws IOException { cursor.close(); }
private static CommittedTransactionRepresentation extractLastTransaction( GraphDatabaseAPI db ) throws IOException { LogicalTransactionStore txStore = db.getDependencyResolver().resolveDependency( LogicalTransactionStore.class ); CommittedTransactionRepresentation transaction = null; try ( TransactionCursor cursor = txStore.getTransactions( TransactionIdStore.BASE_TX_ID + 1 ) ) { while ( cursor.next() ) { transaction = cursor.get(); } } return transaction; }
@Override public void close() throws IOException { transactionCursor.close(); // closes the channel too }
@Test public void reportProgressOnRecovery() throws Throwable { RecoveryService recoveryService = mock( RecoveryService.class, Answers.RETURNS_MOCKS ); CorruptedLogsTruncator logsTruncator = mock( CorruptedLogsTruncator.class ); RecoveryMonitor recoveryMonitor = mock( RecoveryMonitor.class ); TransactionCursor reverseTransactionCursor = mock( TransactionCursor.class ); TransactionCursor transactionCursor = mock( TransactionCursor.class ); CommittedTransactionRepresentation transactionRepresentation = mock( CommittedTransactionRepresentation.class ); 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.getCommitEntry() ).thenReturn( new LogEntryCommit( lastCommittedTransactionId, 1L ) ); when( recoveryService.getRecoveryStartInformation() ).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, recoveryMonitor, progressReporter, true ); recovery.init(); progressReporter.verify(); }
@Override public void close() throws IOException { cursor.close(); }
private static List<TransactionRepresentation> createConstraintCreatingTransactions() throws Exception { GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase(); try { try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( LABEL ).assertPropertyIsUnique( KEY ).create(); tx.success(); } LogicalTransactionStore txStore = db.getDependencyResolver().resolveDependency( LogicalTransactionStore.class ); List<TransactionRepresentation> result = new ArrayList<>(); try ( TransactionCursor cursor = txStore.getTransactions( TransactionIdStore.BASE_TX_ID + 1 ) ) { while ( cursor.next() ) { result.add( cursor.get().getTransactionRepresentation() ); } } return result; } finally { db.shutdown(); } } }