private void close( TransactionToApply batch ) { while ( batch != null ) { if ( batch.commitment().markedAsCommitted() ) { batch.commitment().publishAsClosed(); } batch.close(); batch = batch.next(); } } }
private void publishAsCommitted( TransactionToApply batch ) { while ( batch != null ) { batch.commitment().publishAsCommitted(); batch = batch.next(); } }
private static TransactionToApply newTransactionThatFailsWith( Exception error ) throws IOException { TransactionRepresentation transaction = mock( TransactionRepresentation.class ); when( transaction.additionalHeader() ).thenReturn( new byte[0] ); // allow to build validated index updates but fail on actual tx application doThrow( error ).when( transaction ).accept( any() ); long txId = ThreadLocalRandom.current().nextLong( 0, 1000 ); TransactionToApply txToApply = new TransactionToApply( transaction ); FakeCommitment commitment = new FakeCommitment( txId, mock( TransactionIdStore.class ) ); commitment.setHasExplicitIndexChanges( false ); txToApply.commitment( commitment, txId ); return txToApply; }
@Override public long append( TransactionToApply batch, LogAppendEvent logAppendEvent ) { long txId = TransactionIdStore.BASE_TX_ID; while ( batch != null ) { txId = transactionIdStore.nextCommittingTransactionId(); batch.commitment( new FakeCommitment( txId, transactionIdStore ), txId ); batch.commitment().publishAsCommitted(); batch = batch.next(); } return txId; }
private static TransactionToApply tx( Collection<StorageCommand> commands ) { TransactionToApply tx = new TransactionToApply( transactionRepresentation( commands ) ); tx.commitment( NO_COMMITMENT, 0 ); return tx; }
@Override public boolean visit( CommittedTransactionRepresentation transaction ) throws Exception { TransactionRepresentation txRepresentation = transaction.getTransactionRepresentation(); long txId = transaction.getCommitEntry().getTxId(); TransactionToApply tx = new TransactionToApply( txRepresentation, txId ); tx.commitment( NO_COMMITMENT, txId ); tx.logPosition( transaction.getStartEntry().getStartPosition() ); storageEngine.apply( tx, mode ); return false; }
FakeCommitment commitment = new FakeCommitment( txId, mock( TransactionIdStore.class ) ); commitment.setHasExplicitIndexChanges( true ); txToApply.commitment( commitment, txId ); TransactionApplier txApplier = applier.startTx( txToApply );
@Test public void shouldOnlyCreateOneApplierPerProvider() throws Exception { // GIVEN MutableObjectIntMap<String> names = ObjectIntHashMap.newWithKeysValues( "first", 0, "second", 1 ); MutableObjectIntMap<String> keys = ObjectIntHashMap.newWithKeysValues( "key", 0 ); String applierName = "test-applier"; Commitment commitment = mock( Commitment.class ); when( commitment.hasExplicitIndexChanges() ).thenReturn( true ); IndexConfigStore config = newIndexConfigStore( names, applierName ); ExplicitIndexApplierLookup applierLookup = mock( ExplicitIndexApplierLookup.class ); TransactionApplier transactionApplier = mock( TransactionApplier.class ); when( applierLookup.newApplier( anyString(), anyBoolean() ) ).thenReturn( transactionApplier ); try ( ExplicitBatchIndexApplier applier = new ExplicitBatchIndexApplier( config, applierLookup, BYPASS, INTERNAL ) ) { TransactionToApply tx = new TransactionToApply( null, 2 ); tx.commitment( commitment, 2 ); try ( TransactionApplier txApplier = applier.startTx( tx ) ) { // WHEN IndexDefineCommand definitions = definitions( names, keys ); txApplier.visitIndexDefineCommand( definitions ); txApplier.visitIndexAddNodeCommand( addNodeToIndex( definitions, "first" ) ); txApplier.visitIndexAddNodeCommand( addNodeToIndex( definitions, "second" ) ); txApplier.visitIndexAddRelationshipCommand( addRelationshipToIndex( definitions, "second" ) ); } } // THEN verify( applierLookup, times( 1 ) ).newApplier( eq( applierName ), anyBoolean() ); }
tx.commitment( commitment, transactionId ); tx.logPosition( commitment.logPosition() ); tx = tx.next();
@Override public void commitment( Commitment commitment, long transactionId ) { // TODO Perhaps odd to override this method here just to be able to call txHandler? super.commitment( commitment, transactionId ); txHandler.accept( transactionId ); } } );
private void publishAsCommitted( TransactionToApply batch ) { while ( batch != null ) { batch.commitment().publishAsCommitted(); batch = batch.next(); } }
private void close( TransactionToApply batch ) { while ( batch != null ) { if ( batch.commitment().markedAsCommitted() ) { batch.commitment().publishAsClosed(); } batch.close(); batch = batch.next(); } } }
@Override public boolean visit( CommittedTransactionRepresentation transaction ) throws Exception { TransactionRepresentation txRepresentation = transaction.getTransactionRepresentation(); long txId = transaction.getCommitEntry().getTxId(); TransactionToApply tx = new TransactionToApply( txRepresentation, txId ); tx.commitment( NO_COMMITMENT, txId ); tx.logPosition( transaction.getStartEntry().getStartPosition() ); storageEngine.apply( tx, mode ); return false; }
tx.commitment( commitment, transactionId ); tx.logPosition( commitment.logPosition() ); tx = tx.next();