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 ); } }
private PhysicalTransactionRepresentation transactionRepresentationOf( TransactionRecordState tx ) throws TransactionFailureException { List<StorageCommand> commands = new ArrayList<>(); tx.extractCommands( commands ); return new PhysicalTransactionRepresentation( commands ); }
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 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; }
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; }
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 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 ) ); }
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 ); }
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; }
@Test public void shouldSuccessfullyCommitTransactionWithNoCommands() throws Exception { // GIVEN long txId = 11; long commitTimestamp = System.currentTimeMillis(); TransactionIdStore transactionIdStore = mock( TransactionIdStore.class ); TransactionAppender appender = new TestableTransactionAppender( transactionIdStore ); when( transactionIdStore.nextCommittingTransactionId() ).thenReturn( txId ); StorageEngine storageEngine = mock( StorageEngine.class ); TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess( appender, storageEngine ); PhysicalTransactionRepresentation noCommandTx = new PhysicalTransactionRepresentation( Collections.emptyList() ); noCommandTx.setHeader( new byte[0], -1, -1, -1, -1, -1, -1 ); // WHEN commitProcess.commit( new TransactionToApply( noCommandTx ), commitEvent, INTERNAL ); verify( transactionIdStore ).transactionCommitted( txId, FakeCommitment.CHECKSUM, FakeCommitment.TIMESTAMP ); }
@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() ); }
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 ); }
@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 TransactionRepresentation tx( int size ) { Collection<StorageCommand> commands = new ArrayList<>(); for ( int i = 0; i < size; i++ ) { // The type of command doesn't matter here commands.add( new Command.NodeCommand( new NodeRecord( i ), new NodeRecord( i ).initialize( true, i, false, i, NO_LABELS_FIELD.longValue() ) ) ); } PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( commands ); tx.setHeader( new byte[0], 0, 0, 0, 0, 0, 0 ); return tx; }
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 ); } }
TransactionToApply nextTransaction( long txId ) { PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation( createRandomCommands() ); TransactionHeaderInformation headerInfo = DEFAULT.create(); representation.setHeader( headerInfo.getAdditionalHeader(), headerInfo.getMasterId(), headerInfo.getAuthorId(), headerInfo.getAuthorId(), txId, currentTimeMillis(), 42 ); return new TransactionToApply( representation ); }
private void addATransactionAndRewind( LifeSupport life, LogFiles logFiles, TransactionMetadataCache positionCache, TransactionIdStore transactionIdStore, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted ) throws IOException { TransactionAppender appender = life.add( new BatchingTransactionAppender( logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, DATABASE_HEALTH ) ); PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation( singleCreateNodeCommand() ); transaction.setHeader( additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1 ); appender.append( new TransactionToApply( transaction ), LogAppendEvent.NULL ); }
long latestCommittedTxWhenStarted = 4545; long timeCommitted = timeStarted + 10; PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation( singleCreateNodeCommand( 0 ) ); transactionRepresentation.setHeader( additionalHeader, masterId, authorId, timeStarted,
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 ); } }