private TransactionRepresentation transaction( Collection<StorageCommand> commands, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted ) { PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( commands ); tx.setHeader( additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1 ); return tx; }
private void visitSchemaRuleCommand( BatchTransactionApplier applier, SchemaRuleCommand command ) throws Exception { TransactionToApply tx = new TransactionToApply( new PhysicalTransactionRepresentation( singletonList( command ) ), txId ); CommandHandlerContract.apply( applier, tx ); } }
@Test public void shouldExecuteCommandsInTheSameOrderRegardlessOfItBeingRecoveredOrNot() throws Exception { // Given TransactionRecordState tx = injectAllPossibleCommands(); // When PhysicalTransactionRepresentation commands = transactionRepresentationOf( tx ); // Then final OrderVerifyingCommandHandler orderVerifyingCommandHandler = new OrderVerifyingCommandHandler(); commands.accept( element -> ((Command)element).handle( orderVerifyingCommandHandler ) ); }
private PhysicalTransactionRepresentation transactionRepresentationOf( TransactionRecordState tx ) throws TransactionFailureException { List<StorageCommand> commands = new ArrayList<>(); tx.extractCommands( commands ); return new PhysicalTransactionRepresentation( commands ); }
ptx.accept( command -> ((Command)command).handle( new CommandVisitor.Adapter()
public static TransactionRepresentation transactionRepresentation( Collection<StorageCommand> commands ) { PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( commands ); tx.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return tx; } }
private void applyExternalTransaction( long transactionId, Command...commands ) throws Exception { LockService lockService = mock( LockService.class ); when( lockService.acquireNodeLock( anyLong(), any(LockService.LockType.class) )).thenReturn( LockService.NO_LOCK ); when( lockService.acquireRelationshipLock( anyLong(), any(LockService.LockType.class) )).thenReturn( LockService.NO_LOCK ); NeoStoreBatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, mock( CacheAccessBackDoor.class ), lockService ); TransactionRepresentation tx = new PhysicalTransactionRepresentation( Arrays.asList( commands ) ); CommandHandlerContract.apply( applier, txApplier -> { tx.accept( txApplier ); return false; }, new TransactionToApply( tx, transactionId ) ); }
representation.accept( command -> ((Command)command).handle( new CommandVisitor.Adapter()
private PhysicalTransactionRepresentation transactionRepresentationOf( TransactionRecordState writeTransaction ) throws TransactionFailureException { List<StorageCommand> commands = new ArrayList<>(); writeTransaction.extractCommands( commands ); PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( commands ); tx.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return tx; }
@Test public void shouldCallTheVisitorWithTheFoundTransaction() throws IOException { // given when( entryReader.readLogEntry( channel ) ).thenReturn( A_START_ENTRY, A_COMMAND_ENTRY, A_COMMIT_ENTRY ); // when cursor.next(); // then PhysicalTransactionRepresentation txRepresentation = new PhysicalTransactionRepresentation( singletonList( A_COMMAND_ENTRY.getCommand() ) ); assertEquals( new CommittedTransactionRepresentation( A_START_ENTRY, txRepresentation, A_COMMIT_ENTRY ), cursor.get() ); }
transaction.accept( extractor );
private TransactionRepresentation transaction( TransactionRecordState recordState ) throws TransactionFailureException { List<StorageCommand> commands = new ArrayList<>(); recordState.extractCommands( commands ); PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation( commands ); transaction.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return transaction; }
@Test public void shouldSkipCheckPoints() throws IOException { // given when( entryReader.readLogEntry( channel ) ).thenReturn( A_CHECK_POINT_ENTRY, A_START_ENTRY, A_COMMAND_ENTRY, A_COMMIT_ENTRY, A_CHECK_POINT_ENTRY ); // when cursor.next(); // then PhysicalTransactionRepresentation txRepresentation = new PhysicalTransactionRepresentation( singletonList( A_COMMAND_ENTRY.getCommand() ) ); assertEquals( new CommittedTransactionRepresentation( A_START_ENTRY, txRepresentation, A_COMMIT_ENTRY ), cursor.get() ); } }
private static TransactionToApply prepareTransaction() { List<StorageCommand> commands = createCommands(); PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation( commands ); transactionRepresentation.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return new TransactionToApply( transactionRepresentation ); }
new PhysicalTransactionRepresentation( new ArrayList<>() ) ); FakeCommitment commitment = new FakeCommitment( txId, mock( TransactionIdStore.class ) ); commitment.setHasExplicitIndexChanges( true );
public TransactionRepresentation representation( byte[] additionalHeader, int masterId, int authorId, long startTime, long lastCommittedTx, long committedTime ) { prepareForCommit(); PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation( allCommands() ); representation.setHeader( additionalHeader, masterId, authorId, startTime, lastCommittedTx, committedTime, -1 ); return representation; }
private void assertHandlesLogTruncation( Command cmd ) throws IOException { inMemoryChannel.reset(); writer.serialize( new PhysicalTransactionRepresentation( singletonList( cmd ) ) ); int bytesSuccessfullyWritten = inMemoryChannel.writerPosition(); try { LogEntry logEntry = logEntryReader.readLogEntry( inMemoryChannel ); StorageCommand command = ((LogEntryCommand) logEntry).getCommand(); assertEquals( cmd, command ); } catch ( Exception e ) { throw new AssertionError( "Failed to deserialize " + cmd.toString() + ", because: ", e ); } bytesSuccessfullyWritten--; while ( bytesSuccessfullyWritten-- > 0 ) { inMemoryChannel.reset(); writer.serialize( new PhysicalTransactionRepresentation( singletonList( cmd ) ) ); inMemoryChannel.truncateTo( bytesSuccessfullyWritten ); LogEntry deserialized = logEntryReader.readLogEntry( inMemoryChannel ); assertNull( "Deserialization did not detect log truncation!" + "Record: " + cmd + ", deserialized: " + deserialized, deserialized ); } }
private TransactionRepresentation sillyTransaction( int size ) { Collection<StorageCommand> commands = new ArrayList<>( size ); for ( int i = 0; i < size; i++ ) { // The actual data isn't super important commands.add( createNode( i ) ); commands.add( createProperty( i, PropertyType.INT, 0 ) ); } PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( commands ); tx.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return tx; }
private void addCorruptedCommandsToLastLogFile() throws IOException { PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository( logFiles ); LogFiles internalLogFiles = LogFilesBuilder.builder( directory.databaseLayout(), fileSystemRule ) .withLogVersionRepository( versionRepository ) .withTransactionIdStore( new SimpleTransactionIdStore() ).build(); try ( Lifespan lifespan = new Lifespan( internalLogFiles ) ) { LogFile transactionLogFile = internalLogFiles.getLogFile(); FlushablePositionAwareChannel channel = transactionLogFile.getWriter(); TransactionLogWriter writer = new TransactionLogWriter( new CorruptedLogEntryWriter( channel ) ); Collection<StorageCommand> commands = new ArrayList<>(); commands.add( new Command.PropertyCommand( new PropertyRecord( 1 ), new PropertyRecord( 2 ) ) ); commands.add( new Command.NodeCommand( new NodeRecord( 2 ), new NodeRecord( 3 ) ) ); PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation( commands ); writer.append( transaction, 1000 ); } }
protected TransactionToApply tx() { NodeRecord before = new NodeRecord( 0 ); NodeRecord after = new NodeRecord( 0 ); after.setInUse( true ); Command.NodeCommand nodeCommand = new Command.NodeCommand( before, after ); PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( singletonList( nodeCommand ) ); tx.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return new TransactionToApply( tx ); }