public void append( TransactionRepresentation transaction, long transactionId ) throws IOException { writer.writeStartEntry( transaction.getMasterId(), transaction.getAuthorId(), transaction.getTimeStarted(), transaction.getLatestCommittedTxWhenStarted(), transaction.additionalHeader() ); // Write all the commands to the log channel writer.serialize( transaction ); // Write commit record writer.writeCommitEntry( transactionId, transaction.getTimeCommitted() ); }
@Override public String toString() { TransactionRepresentation tr = this.transactionRepresentation; return "Transaction #" + transactionId + (logPosition != null ? " at log position " + logPosition : " (no log position)") + " {started " + date( tr.getTimeStarted() ) + ", committed " + date( tr.getTimeCommitted() ) + ", with " + countCommands() + " commands in this transaction" + ", authored by " + tr.getAuthorId() + ", with master id " + tr.getMasterId() + ", lock session " + tr.getLockSessionId() + ", latest committed transaction id when started was " + tr.getLatestCommittedTxWhenStarted() + ", additional header bytes: " + HexPrinter.hex( tr.additionalHeader(), Integer.MAX_VALUE, "" ) + "}"; }
assertEquals( startingTime, commitProcess.transaction.getTimeStarted() ); assertEquals( startingTime + 5, commitProcess.transaction.getTimeCommitted() );
@Test public void shouldAppendSingleTransaction() throws Exception { // GIVEN when( logFile.getWriter() ).thenReturn( channel ); long txId = 15; when( transactionIdStore.nextCommittingTransactionId() ).thenReturn( txId ); TransactionAppender appender = life.add( createTransactionAppender() ); // WHEN TransactionRepresentation transaction = transaction( singleCreateNodeCommand( 0 ), new byte[]{1, 2, 5}, 2, 1, 12345, 4545, 12345 + 10 ); appender.append( new TransactionToApply( transaction ), logAppendEvent ); // THEN final LogEntryReader<ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader<>(); try ( PhysicalTransactionCursor<ReadableLogChannel> reader = new PhysicalTransactionCursor<>( channel, logEntryReader ) ) { reader.next(); TransactionRepresentation tx = reader.get().getTransactionRepresentation(); assertArrayEquals( transaction.additionalHeader(), tx.additionalHeader() ); assertEquals( transaction.getMasterId(), tx.getMasterId() ); assertEquals( transaction.getAuthorId(), tx.getAuthorId() ); assertEquals( transaction.getTimeStarted(), tx.getTimeStarted() ); assertEquals( transaction.getTimeCommitted(), tx.getTimeCommitted() ); assertEquals( transaction.getLatestCommittedTxWhenStarted(), tx.getLatestCommittedTxWhenStarted() ); } }
@Override public boolean visit( CommittedTransactionRepresentation tx ) { TransactionRepresentation transaction = tx.getTransactionRepresentation(); assertArrayEquals( additionalHeader, transaction.additionalHeader() ); assertEquals( masterId, transaction.getMasterId() ); assertEquals( authorId, transaction.getAuthorId() ); assertEquals( timeStarted, transaction.getTimeStarted() ); assertEquals( timeCommitted, transaction.getTimeCommitted() ); assertEquals( latestCommittedTxWhenStarted, transaction.getLatestCommittedTxWhenStarted() ); visitedTransactions++; return false; }
assertEquals( masterId, result.getMasterId() ); assertEquals( authorId, result.getAuthorId() ); assertEquals( timeStarted, result.getTimeStarted() ); assertEquals( timeCommitted, result.getTimeCommitted() ); assertEquals( latestCommittedTxWhenStarted, result.getLatestCommittedTxWhenStarted() );
private void verifyTransaction( TransactionIdStore transactionIdStore, TransactionMetadataCache positionCache, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store ) throws IOException { TransactionMetadata expectedMetadata; try ( TransactionCursor cursor = store.getTransactions( TransactionIdStore.BASE_TX_ID + 1 ) ) { boolean hasNext = cursor.next(); assertTrue( hasNext ); CommittedTransactionRepresentation tx = cursor.get(); TransactionRepresentation transaction = tx.getTransactionRepresentation(); assertArrayEquals( additionalHeader, transaction.additionalHeader() ); assertEquals( masterId, transaction.getMasterId() ); assertEquals( authorId, transaction.getAuthorId() ); assertEquals( timeStarted, transaction.getTimeStarted() ); assertEquals( timeCommitted, transaction.getTimeCommitted() ); assertEquals( latestCommittedTxWhenStarted, transaction.getLatestCommittedTxWhenStarted() ); expectedMetadata = new TransactionMetadata( masterId, authorId, tx.getStartEntry().getStartPosition(), tx.getStartEntry().checksum(), timeCommitted ); } positionCache.clear(); TransactionMetadata actualMetadata = store.getMetadataFor( transactionIdStore.getLastCommittedTransactionId() ); assertEquals( expectedMetadata, actualMetadata ); }
public void append( TransactionRepresentation transaction, long transactionId ) throws IOException { writer.writeStartEntry( transaction.getMasterId(), transaction.getAuthorId(), transaction.getTimeStarted(), transaction.getLatestCommittedTxWhenStarted(), transaction.additionalHeader() ); // Write all the commands to the log channel writer.serialize( transaction ); // Write commit record writer.writeCommitEntry( transactionId, transaction.getTimeCommitted() ); }
@Override public String toString() { TransactionRepresentation tr = this.transactionRepresentation; return "Transaction #" + transactionId + (logPosition != null ? " at log position " + logPosition : " (no log position)") + " {started " + date( tr.getTimeStarted() ) + ", committed " + date( tr.getTimeCommitted() ) + ", with " + countCommands() + " commands in this transaction" + ", authored by " + tr.getAuthorId() + ", with master id " + tr.getMasterId() + ", lock session " + tr.getLockSessionId() + ", latest committed transaction id when started was " + tr.getLatestCommittedTxWhenStarted() + ", additional header bytes: " + HexPrinter.hex( tr.additionalHeader(), Integer.MAX_VALUE, "" ) + "}"; }
@Override public void write( ChannelBuffer buffer ) throws IOException { NetworkFlushableChannel channel = new NetworkFlushableChannel( buffer ); writeString( buffer, NeoStoreDataSource.DEFAULT_DATA_SOURCE_NAME ); channel.putInt( tx.getAuthorId() ); channel.putInt( tx.getMasterId() ); channel.putLong( tx.getLatestCommittedTxWhenStarted() ); channel.putLong( tx.getTimeStarted() ); channel.putLong( tx.getTimeCommitted() ); channel.putInt( tx.additionalHeader().length ); channel.put( tx.additionalHeader(), tx.additionalHeader().length ); new LogEntryWriter( channel ).serialize( tx ); } }
public static void write( TransactionRepresentation tx, NetworkFlushableChannelNetty4 channel ) throws IOException { channel.putInt( tx.getAuthorId() ); channel.putInt( tx.getMasterId() ); channel.putLong( tx.getLatestCommittedTxWhenStarted() ); channel.putLong( tx.getTimeStarted() ); channel.putLong( tx.getTimeCommitted() ); channel.putInt( tx.getLockSessionId() ); byte[] additionalHeader = tx.additionalHeader(); if ( additionalHeader != null ) { channel.putInt( additionalHeader.length ); channel.put( additionalHeader, additionalHeader.length ); } else { channel.putInt( 0 ); } new LogEntryWriter( channel ).serialize( tx ); } }
public static void write( TransactionRepresentation tx, NetworkFlushableChannelNetty4 channel ) throws IOException { channel.putInt( tx.getAuthorId() ); channel.putInt( tx.getMasterId() ); channel.putLong( tx.getLatestCommittedTxWhenStarted() ); channel.putLong( tx.getTimeStarted() ); channel.putLong( tx.getTimeCommitted() ); channel.putInt( tx.getLockSessionId() ); byte[] additionalHeader = tx.additionalHeader(); if ( additionalHeader != null ) { channel.putInt( additionalHeader.length ); channel.put( additionalHeader, additionalHeader.length ); } else { channel.putInt( 0 ); } new LogEntryWriter( channel ).serialize( tx ); } }