private void matchAgainstExpectedTransactionIdIfAny( long transactionId, TransactionToApply tx ) { long expectedTransactionId = tx.transactionId(); if ( expectedTransactionId != TRANSACTION_ID_NOT_SPECIFIED ) { if ( transactionId != expectedTransactionId ) { IllegalStateException ex = new IllegalStateException( "Received " + tx.transactionRepresentation() + " with txId:" + expectedTransactionId + " to be applied, but appending it ended up generating an unexpected txId:" + transactionId ); databaseHealth.panic( ex ); throw ex; } } }
@Override public long commit( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) { assert transaction == null : "Designed to only allow one transaction"; assert batch.next() == null : "Designed to only allow one transaction"; transaction = batch.transactionRepresentation(); return ++txId; } }
private static TransactionCommitProcess newRememberingCommitProcess( final TransactionRepresentation[] slot ) throws TransactionFailureException { TransactionCommitProcess commitProcess = mock( TransactionCommitProcess.class ); when( commitProcess.commit( any( TransactionToApply.class ), any( CommitEvent.class ), any( TransactionApplicationMode.class ) ) ) .then( invocation -> { slot[0] = ((TransactionToApply) invocation.getArgument( 0 )).transactionRepresentation(); return 1L; } ); return commitProcess; }
/** * Simply calls through to the {@link TransactionRepresentation#accept(Visitor)} method for each {@link * TransactionToApply} given. This assumes that the {@link BatchTransactionApplier} will return {@link * TransactionApplier}s which actually do the work and that the transaction has all the relevant data. * * @param applier to use * @param transactions to apply */ public static void apply( BatchTransactionApplier applier, TransactionToApply... transactions ) throws Exception { for ( TransactionToApply tx : transactions ) { try ( TransactionApplier txApplier = applier.startTx( tx, new LockGroup() ) ) { tx.transactionRepresentation().accept( txApplier ); } } applier.close(); }
TransactionCommitment commitment = appendToLog( tx.transactionRepresentation(), transactionId ); tx.commitment( commitment, transactionId ); tx.logPosition( commitment.logPosition() );
private void verifyIndex( TransactionToApply tx ) throws Exception { try ( IndexReader reader = index.newReader() ) { NodeVisitor visitor = new NodeVisitor(); for ( int i = 0; tx != null; i++ ) { tx.transactionRepresentation().accept( visitor.clear() ); Value propertyValue = propertyValue( id, base + i ); IndexQuery.ExactPredicate query = IndexQuery.exact( descriptor.getPropertyId(), propertyValue ); LongIterator hits = reader.query( query ); assertEquals( "Index doesn't contain " + visitor.nodeId + " " + propertyValue, visitor.nodeId, hits.next() ); assertFalse( hits.hasNext() ); tx = tx.next(); } } } }
private boolean batchSizeExceedsSafeZone( TransactionToApply first, TransactionToApply last ) { long lastAppliedTimestamp = last.transactionRepresentation().getTimeCommitted(); long firstAppliedTimestamp = first.transactionRepresentation().getTimeCommitted(); long chunkLength = lastAppliedTimestamp - firstAppliedTimestamp; return chunkLength > idReuseSafeZoneTime; }
private void matchAgainstExpectedTransactionIdIfAny( long transactionId, TransactionToApply tx ) { long expectedTransactionId = tx.transactionId(); if ( expectedTransactionId != TRANSACTION_ID_NOT_SPECIFIED ) { if ( transactionId != expectedTransactionId ) { IllegalStateException ex = new IllegalStateException( "Received " + tx.transactionRepresentation() + " with txId:" + expectedTransactionId + " to be applied, but appending it ended up generating an unexpected txId:" + transactionId ); databaseHealth.panic( ex ); throw ex; } } }
TransactionApplicationMode mode ) throws TransactionFailureException ReplicatedTransaction transaction = createImmutableReplicatedTransaction( tx.transactionRepresentation() ); Future<Object> futureTxId; try
TransactionApplicationMode mode ) throws TransactionFailureException ReplicatedTransaction transaction = createImmutableReplicatedTransaction( tx.transactionRepresentation() ); Future<Object> futureTxId; try
private void markUnsafeTransactionsForTermination( TransactionToApply first, TransactionToApply last ) long firstCommittedTimestamp = first.transactionRepresentation().getTimeCommitted(); long lastCommittedTimestamp = last.transactionRepresentation().getTimeCommitted(); long earliestSafeTimestamp = lastCommittedTimestamp - idReuseSafeZoneTime;
TransactionCommitment commitment = appendToLog( tx.transactionRepresentation(), transactionId ); tx.commitment( commitment, transactionId ); tx.logPosition( commitment.logPosition() );