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; }
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 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 ); }
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 ); }
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; }
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 ); }
transaction.setHeader( startEntry.getAdditionalHeader(), startEntry.getMasterId(), startEntry.getLocalId(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), commitEntry.getTimeWritten(), -1 );
PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation( singleCreateNodeCommand( 0 ) ); transactionRepresentation.setHeader( additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1 );
TransactionHeaderInformation headerInformation = headerInformationFactory.create(); long timeCommitted = clocks.systemClock().millis(); transactionRepresentation.setHeader( headerInformation.getAdditionalHeader(), headerInformation.getMasterId(), headerInformation.getAuthorId(),
PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation( singleCreateNodeCommand( 0 ) ); transactionRepresentation.setHeader( additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1 );
public TransactionRepresentation representation( byte[] additionalHeader, int masterId, int authorId, long startTime, long lastCommittedTx, long committedTime ) { PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation( commands ); representation.setHeader( additionalHeader, masterId, authorId, startTime, lastCommittedTx, committedTime, -1 ); return representation; }
private void applyToStore( Collection<StorageCommand> commands, long logIndex ) { PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation( commands ); representation.setHeader( encodeLogIndexAsTxHeader( logIndex ), 0, 0, 0, 0L, 0L, 0 ); try ( LockGroup ignored = new LockGroup() ) { commitProcess.commit( new TransactionToApply( representation, versionContext ), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL ); } catch ( TransactionFailureException e ) { throw new RuntimeException( e ); } }
private int applyToStore( Collection<StorageCommand> commands, long logIndex ) throws NoSuchEntryException { int tokenId = extractTokenId( commands ); PhysicalTransactionRepresentation representation = new PhysicalTransactionRepresentation( commands ); representation.setHeader( encodeLogIndexAsTxHeader( logIndex ), 0, 0, 0, 0L, 0L, 0 ); try ( LockGroup ignored = new LockGroup() ) { commitProcess.commit( new TransactionToApply( representation ), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL ); } catch ( TransactionFailureException e ) { throw new RuntimeException( e ); } return tokenId; }
private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws IOException { PhysicalLogFiles logFiles = new PhysicalLogFiles( storeDir, fs ); ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository( pageCache, storeDir ); ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore( pageCache, storeDir ); PhysicalLogFile logFile = new PhysicalLogFile( fs, logFiles, Long.MAX_VALUE /*don't rotate*/, () -> readOnlyTransactionIdStore.getLastClosedTransactionId() - 1, logVersionRepository, new Monitors().newMonitor( PhysicalLogFile.Monitor.class ), new LogHeaderCache( 10 ) ); long dummyTransactionId; try ( Lifespan lifespan = new Lifespan( logFile ) ) { FlushableChannel channel = logFile.getWriter(); TransactionLogWriter writer = new TransactionLogWriter( new LogEntryWriter( channel ) ); long lastCommittedTransactionId = readOnlyTransactionIdStore.getLastCommittedTransactionId(); PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation( Collections.emptyList() ); byte[] txHeaderBytes = LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader( -1 ); tx.setHeader( txHeaderBytes, -1, -1, -1, lastCommittedTransactionId, -1, -1 ); dummyTransactionId = lastCommittedTransactionId + 1; writer.append( tx, dummyTransactionId ); channel.prepareForFlush().flush(); } File neoStoreFile = new File( storeDir, MetaDataStore.DEFAULT_NAME ); MetaDataStore.setRecord( pageCache, neoStoreFile, LAST_TRANSACTION_ID, dummyTransactionId ); }