@Override public TransactionCommitProcess create( TransactionAppender appender, StorageEngine storageEngine, Config config ) { if ( config.get( GraphDatabaseSettings.read_only ) ) { return new ReadOnlyTransactionCommitProcess(); } return new TransactionRepresentationCommitProcess( appender, storageEngine ); } }
public void apply( Transaction transaction ) throws TransactionFailureException { TransactionRepresentation representation = transaction.representation( idGenerator(), masterId(), myId(), transactionIdStore.getLastCommittedTransactionId(), neoStores ); commitProcess.commit( new TransactionToApply( representation ), CommitEvent.NULL, TransactionApplicationMode.EXTERNAL ); }
@Override public long commit( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) throws TransactionFailureException { long lastTxId = appendToLog( batch, commitEvent ); try { applyToStore( batch, commitEvent, mode ); return lastTxId; } finally { close( batch ); } }
@SuppressWarnings("deprecation") protected void applyTransaction( Transaction transaction ) throws TransactionFailureException { // TODO you know... we could have just appended the transaction representation to the log // and the next startup of the store would do recovery where the transaction would have been // applied and all would have been well. GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( directory ); GraphDatabaseAPI database = (GraphDatabaseAPI) builder.newGraphDatabase(); try ( LockGroup locks = new LockGroup() ) { DependencyResolver dependencyResolver = database.getDependencyResolver(); TransactionRepresentationCommitProcess commitProcess = new TransactionRepresentationCommitProcess( dependencyResolver.resolveDependency( TransactionAppender.class ), dependencyResolver.resolveDependency( TransactionRepresentationStoreApplier.class ), dependencyResolver.resolveDependency( IndexUpdatesValidator.class ) ); TransactionIdStore transactionIdStore = database.getDependencyResolver().resolveDependency( TransactionIdStore.class ); NodeStore nodes = database.getDependencyResolver().resolveDependency( NeoStores.class ).getNodeStore(); commitProcess.commit( transaction.representation( idGenerator(), masterId(), myId(), transactionIdStore.getLastCommittedTransactionId(), nodes ), locks, CommitEvent.NULL, TransactionApplicationMode.EXTERNAL ); } finally { database.shutdown(); } }
@Test public void shouldFailWithProperMessageOnAppendException() throws Exception { // GIVEN TransactionAppender appender = mock( TransactionAppender.class ); IOException rootCause = new IOException( "Mock exception" ); doThrow( new IOException( rootCause ) ).when( appender ).append( any( TransactionToApply.class ), any( LogAppendEvent.class ) ); StorageEngine storageEngine = mock( StorageEngine.class ); TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess( appender, storageEngine ); // WHEN try { commitProcess.commit( mockedTransaction(), commitEvent, INTERNAL ); fail( "Should have failed, something is wrong with the mocking in this test" ); } catch ( TransactionFailureException e ) { assertThat( e.getMessage(), containsString( "Could not append transaction representation to log" ) ); assertTrue( contains( e, rootCause.getMessage(), rootCause.getClass() ) ); } }
public void appendToLogAndApplyToStore( CommittedTransactionRepresentation tx ) throws TransactionFailureException { commitProcess.commit( new TransactionToApply( tx.getTransactionRepresentation(), tx.getCommitEntry().getTxId() ), NULL, EXTERNAL ); } }
@Override public long commit( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) throws TransactionFailureException { long lastTxId = appendToLog( batch, commitEvent ); try { applyToStore( batch, commitEvent, mode ); return lastTxId; } finally { close( batch ); } }
@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 ); }
public void appendToLogAndApplyToStore( CommittedTransactionRepresentation tx ) throws TransactionFailureException { commitProcess.commit( new TransactionToApply( tx.getTransactionRepresentation(), tx.getCommitEntry().getTxId(), versionContextSupplier.getVersionContext() ), NULL, EXTERNAL ); } }
@Test public void shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly() throws Exception { // GIVEN TransactionIdStore transactionIdStore = mock( TransactionIdStore.class ); TransactionAppender appender = new TestableTransactionAppender( transactionIdStore ); long txId = 11; when( transactionIdStore.nextCommittingTransactionId() ).thenReturn( txId ); IOException rootCause = new IOException( "Mock exception" ); StorageEngine storageEngine = mock( StorageEngine.class ); doThrow( new IOException( rootCause ) ).when( storageEngine ).apply( any( TransactionToApply.class ), any( TransactionApplicationMode.class ) ); TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess( appender, storageEngine ); TransactionToApply transaction = mockedTransaction(); // WHEN try { commitProcess.commit( transaction, commitEvent, INTERNAL ); } catch ( TransactionFailureException e ) { assertThat( e.getMessage(), containsString( "Could not apply the transaction to the store" ) ); assertTrue( contains( e, rootCause.getMessage(), rootCause.getClass() ) ); } // THEN // we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked verify( transactionIdStore, times( 1 ) ).transactionClosed( eq( txId ), anyLong(), anyLong() ); }
Applier() { database = (GraphDatabaseAPI) new TestGraphDatabaseFactory() .newEmbeddedDatabaseBuilder( directory.databaseDir() ) .setConfig( "dbms.backup.enabled", "false" ) .newGraphDatabase(); DependencyResolver dependencyResolver = database.getDependencyResolver(); commitProcess = new TransactionRepresentationCommitProcess( dependencyResolver.resolveDependency( TransactionAppender.class ), dependencyResolver.resolveDependency( StorageEngine.class ) ); transactionIdStore = database.getDependencyResolver().resolveDependency( TransactionIdStore.class ); neoStores = database.getDependencyResolver().resolveDependency( RecordStorageEngine.class ) .testAccessNeoStores(); }
/** * Called by the DataSourceManager during start. */ public void registerCommitProcessDependencies( TransactionAppender appender, StorageEngine applier ) { localCommit = new TransactionRepresentationCommitProcess( appender, applier ); }
@Override public TransactionCommitProcess create( TransactionAppender appender, StorageEngine storageEngine, Config config ) { if ( config.get( GraphDatabaseSettings.read_only ) ) { return new ReadOnlyTransactionCommitProcess(); } return new TransactionRepresentationCommitProcess( appender, storageEngine ); } }
@Override public TransactionCommitProcess commitProcess() { // We simply can't resolve the commit process here, since the commit process of a slave // is one that sends transactions to the master. We here, however would like to actually // commit transactions in this db. return new TransactionRepresentationCommitProcess( resolver.resolveDependency( TransactionAppender.class ), resolver.resolveDependency( StorageEngine.class ) ); }
public TransactionApplier( DependencyResolver resolver ) { commitProcess = new TransactionRepresentationCommitProcess( resolver.resolveDependency( TransactionAppender.class ), resolver.resolveDependency( StorageEngine.class ) ); }
public TransactionApplier( DependencyResolver resolver ) { commitProcess = new TransactionRepresentationCommitProcess( resolver.resolveDependency( TransactionAppender.class ), resolver.resolveDependency( StorageEngine.class ) ); versionContextSupplier = resolver.resolveDependency( VersionContextSupplier.class ); }
() -> new TransactionRepresentationCommitProcess( dependencies.resolveDependency( TransactionAppender.class ), dependencies.resolveDependency( StorageEngine.class ) );
new TransactionRepresentationCommitProcess( appender, applier );
Supplier<TransactionCommitProcess> writableCommitProcess = () -> new TransactionRepresentationCommitProcess( dependencies.resolveDependency( TransactionAppender.class ), dependencies.resolveDependency( StorageEngine.class ) );