/** * Find the id of the Newest Encountered Transaction (NET) that could have been seen on this server. * We expect the returned id to be sent back the client and ultimately supplied to * {@link #awaitUpToDate(long, Duration)} on this server, or on a different server in the cluster. * * @return id of the Newest Encountered Transaction (NET). */ public long newestEncounteredTxId() { // return the "last committed" because it is the newest id // "last closed" will return the last gap-free id, pottentially for some old transaction because there might be other committing transactions return transactionIdStore().getLastCommittedTransactionId(); } }
return () -> resolveDependency( TransactionIdStore.class ).getLastCommittedTransactionId();
private static long lastCommittedTxId( GraphDatabaseAPI db ) { TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency( TransactionIdStore.class ); return txIdStore.getLastCommittedTransactionId(); }
@Test public void shouldReturnNewestTransactionId() { when( transactionIdStore.getLastClosedTransactionId() ).thenReturn( 42L ); when( transactionIdStore.getLastCommittedTransactionId() ).thenReturn( 4242L ); assertEquals( 4242L, transactionIdTracker.newestEncounteredTxId() ); } }
private long getLastTxId( @SuppressWarnings( "deprecation" ) GraphDatabaseAPI db ) { return db.getDependencyResolver().resolveDependency( TransactionIdStore.class ).getLastCommittedTransactionId(); }
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 ); }
@Test public void shouldIdentifyTransactionWithNetZeroChangesAsReadOnly() { // GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set // a good way of producing such state is to add a label to an existing node, and then remove it. GraphDatabaseAPI db = dbr.getGraphDatabaseAPI(); TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency( TransactionIdStore.class ); long startTxId = txIdStore.getLastCommittedTransactionId(); Node node = createEmptyNode( db ); try ( Transaction tx = db.beginTx() ) { node.addLabel( TestLabels.LABEL_ONE ); node.removeLabel( TestLabels.LABEL_ONE ); tx.success(); } // WHEN closing that transaction // THEN it should not have been committed assertEquals( "Expected last txId to be what it started at + 2 (1 for the empty node, and one for the label)", startTxId + 2, txIdStore.getLastCommittedTransactionId() ); }
lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
latestCommittedTxWhenStarted, timeCommitted, -1 ); when( transactionIdStore.getLastCommittedTransactionId() ).thenReturn( latestCommittedTxWhenStarted );
@Test public void shouldDetectNoChangesInCommitsAlsoForTheIndexes() { // GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set // a good way of producing such state is to add a label to an existing node, and then remove it. GraphDatabaseAPI db = dbr.getGraphDatabaseAPI(); TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency( TransactionIdStore.class ); long startTxId = txIdStore.getLastCommittedTransactionId(); Node node = createEmptyNode( db ); Index<Node> index = createNodeIndex( db ); try ( Transaction tx = db.beginTx() ) { node.addLabel( TestLabels.LABEL_ONE ); node.removeLabel( TestLabels.LABEL_ONE ); index.add( node, "key", "value" ); index.remove( node, "key", "value" ); tx.success(); } // WHEN closing that transaction // THEN it should not have been committed assertEquals( "Expected last txId to be what it started at + 3 " + "(1 for the empty node, 1 for index, and one for the label)", startTxId + 3, txIdStore.getLastCommittedTransactionId() ); }
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 ); }
void refreshFromNewStore() { assert txQueue == null || txQueue.isEmpty(); lastQueuedTxId = txIdStoreSupplier.get().getLastCommittedTransactionId(); commitProcess = commitProcessSupplier.get(); }
public <T> Response<T> packTransactionObligationResponse( RequestContext context, T response ) { return packTransactionObligationResponse( context, response, transactionIdStore.getLastCommittedTransactionId() ); }
/** * Find the id of the Newest Encountered Transaction (NET) that could have been seen on this server. * We expect the returned id to be sent back the client and ultimately supplied to * {@link #awaitUpToDate(long, Duration)} on this server, or on a different server in the cluster. * * @return id of the Newest Encountered Transaction (NET). */ public long newestEncounteredTxId() { // return the "last committed" because it is the newest id // "last closed" will return the last gap-free id, pottentially for some old transaction because there might be other committing transactions return transactionIdStore().getLastCommittedTransactionId(); } }
void refreshFromNewStore() { assert txQueue.isEmpty(); assert txBatcher == null || txBatcher.isEmpty(); lastQueuedTxId = lastAppliedTxId = txIdStoreSupplier.get().getLastCommittedTransactionId(); commitProcess = commitProcessSupplier.get(); }
@Override public long getLastCommittedTxId() { NeoStoreDataSource neoStoreDataSource = xadsm.getDataSource(); if ( neoStoreDataSource == null ) { return -1; } return neoStoreDataSource.getDependencyResolver().resolveDependency( TransactionIdStore.class ) .getLastCommittedTransactionId(); } }
private RequestContext slaveContextOf( GraphDatabaseAPI graphDb ) { TransactionIdStore transactionIdStore = graphDb.getDependencyResolver().resolveDependency( TransactionIdStore.class ); return anonymous( transactionIdStore.getLastCommittedTransactionId() ); }
@Override public <T> Response<T> packTransactionStreamResponse( RequestContext context, T response ) { final String packerIdentifier = Thread.currentThread().getName(); final long toStartFrom = mandatoryStartTransactionId; final long toEndAt = transactionIdStore.getLastCommittedTransactionId(); TransactionStream transactions = visitor -> { // Check so that it's even worth thinking about extracting any transactions at all if ( toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt ) { monitor.startStreamingTransactions( toStartFrom, packerIdentifier ); extractTransactions( toStartFrom, filterVisitor( visitor, toEndAt ) ); monitor.finishStreamingTransactions( toEndAt, packerIdentifier ); } }; return new TransactionStreamResponse<>( response, storeId.get(), transactions, ResourceReleaser.NO_OP ); }
public <T> Response<T> packTransactionStreamResponse( RequestContext context, T response ) { final long toStartFrom = context.lastAppliedTransaction() + 1; final long toEndAt = transactionIdStore.getLastCommittedTransactionId(); TransactionStream transactions = visitor -> { // Check so that it's even worth thinking about extracting any transactions at all if ( toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt ) { extractTransactions( toStartFrom, filterVisitor( visitor, toEndAt ) ); } }; return new TransactionStreamResponse<>( response, storeId.get(), transactions, ResourceReleaser.NO_OP ); }
@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(); } }