/** * Offers a transaction id. Will be accepted if this is higher than the current highest. * This method is thread-safe. * * @param transactionId transaction id to compare for highest. * @param checksum checksum of the transaction. * @param commitTimestamp commit time for transaction with {@code transactionId}. * @return {@code true} if the given transaction id was higher than the current highest, * {@code false}. */ public boolean offer( long transactionId, long checksum, long commitTimestamp ) { TransactionId high = highest.get(); if ( transactionId < high.transactionId() ) { // a higher id has already been offered return false; } TransactionId update = new TransactionId( transactionId, checksum, commitTimestamp ); while ( !highest.compareAndSet( high, update ) ) { high = highest.get(); if ( high.transactionId() >= transactionId ) { // apparently someone else set a higher id while we were trying to set this id return false; } } // we set our id as the highest return true; }
@Override public long getLastCommittedTransactionId() { return committedTransactionId.get().transactionId(); }
@Override public long getLastCommittedTransactionId() { assertNotClosed(); checkInitialized( lastCommittingTxField.get() ); return highestCommittedTransaction.get().transactionId(); }
@Override public synchronized void transactionCommitted( long transactionId, long checksum, long commitTimestamp ) { TransactionId current = committedTransactionId.get(); if ( current == null || transactionId > current.transactionId() ) { committedTransactionId.set( new TransactionId( transactionId, checksum, commitTimestamp ) ); } }
private static Function<TransactionId,Boolean> txInfoAcceptanceOnIdAndTimestamp( long id, long timestamp ) { return txInfo -> txInfo.transactionId() == id && txInfo.commitTimestamp() == timestamp; } }
public void setLastTransactionCommitTimestamp( long timestamp ) { // Preventing race with transactionCommitted() and assure record is consistent with highestCommittedTransaction synchronized ( transactionCommittedLock ) { setRecord( Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, timestamp ); TransactionId transactionId = highestCommittedTransaction.get(); highestCommittedTransaction.set( transactionId.transactionId(), transactionId.checksum(), timestamp ); } }
void writeLastTxInformation( DatabaseLayout migrationStructure, TransactionId txInfo ) throws IOException { writeTxLogCounters( fileSystem, lastTxInformationFile( migrationStructure ), txInfo.transactionId(), txInfo.checksum(), txInfo.commitTimestamp() ); }
KernelTransactionImplementation tx = localTxPool.acquire(); StatementLocks statementLocks = statementLocksFactory.newInstance(); tx.initialize( lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, securityContext, timeout, userTransactionIdCounter.incrementAndGet() ); return tx;
private void assertAccepted( HighestTransactionId highest, long txId ) { TransactionId current = highest.get(); assertTrue( highest.offer( txId, -1, -1 ) ); assertTrue( txId > current.transactionId() ); }
@Test public void shouldKeepHighestDuringConcurrentOfferings() throws Throwable { // GIVEN final HighestTransactionId highest = new HighestTransactionId( -1, -1, -1 ); Race race = new Race(); int updaters = max( 2, getRuntime().availableProcessors() ); final AtomicInteger accepted = new AtomicInteger(); for ( int i = 0; i < updaters; i++ ) { final long id = i + 1; race.addContestant( () -> { if ( highest.offer( id, id, id ) ) { accepted.incrementAndGet(); } } ); } // WHEN race.go(); // THEN assertTrue( accepted.get() > 0 ); assertEquals( updaters, highest.get().transactionId() ); }
if ( highestCommittedTransaction.get().transactionId() == transactionId )
@Test public void shouldGenerateTransactionInformationWhenLogsAreEmpty() throws Exception { // given long txId = 1; DatabaseLayout databaseLayout = directory.databaseLayout(); File neoStore = databaseLayout.metadataStore(); neoStore.createNewFile(); Config config = mock( Config.class ); LogService logService = new SimpleLogService( NullLogProvider.getInstance(), NullLogProvider.getInstance() ); // when // ... transaction info not in neo store assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_ID ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_CHECKSUM ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP ) ); // ... and with migrator StoreMigrator migrator = new StoreMigrator( fileSystemRule.get(), pageCache, config, logService, jobScheduler ); TransactionId actual = migrator.extractTransactionIdInformation( neoStore, txId ); // then assertEquals( txId, actual.transactionId() ); assertEquals( TransactionIdStore.BASE_TX_CHECKSUM, actual.checksum() ); assertEquals( TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP, actual.commitTimestamp() ); }
@Test public void shouldGenerateTransactionInformationWhenLogsNotPresent() throws Exception { // given long txId = 42; DatabaseLayout databaseLayout = directory.databaseLayout(); File neoStore = databaseLayout.metadataStore(); neoStore.createNewFile(); Config config = mock( Config.class ); LogService logService = new SimpleLogService( NullLogProvider.getInstance(), NullLogProvider.getInstance() ); // when // ... transaction info not in neo store assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_ID ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_CHECKSUM ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP ) ); // ... and with migrator StoreMigrator migrator = new StoreMigrator( fileSystemRule.get(), pageCache, config, logService, jobScheduler ); TransactionId actual = migrator.extractTransactionIdInformation( neoStore, txId ); // then assertEquals( txId, actual.transactionId() ); assertEquals( TransactionIdStore.UNKNOWN_TX_CHECKSUM, actual.checksum() ); assertEquals( TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP, actual.commitTimestamp() ); }
/** * Offers a transaction id. Will be accepted if this is higher than the current highest. * This method is thread-safe. * * @param transactionId transaction id to compare for highest. * @param checksum checksum of the transaction. * @param commitTimestamp commit time for transaction with {@code transactionId}. * @return {@code true} if the given transaction id was higher than the current highest, * {@code false}. */ public boolean offer( long transactionId, long checksum, long commitTimestamp ) { TransactionId high = highest.get(); if ( transactionId < high.transactionId() ) { // a higher id has already been offered return false; } TransactionId update = new TransactionId( transactionId, checksum, commitTimestamp ); while ( !highest.compareAndSet( high, update ) ) { high = highest.get(); if ( high.transactionId() >= transactionId ) { // apparently someone else set a higher id while we were trying to set this id return false; } } // we set our id as the highest return true; }
@Override public long getLastCommittedTransactionId() { assertNotClosed(); checkInitialized( lastCommittingTxField.get() ); return highestCommittedTransaction.get().transactionId(); }
void writeLastTxInformation( DatabaseLayout migrationStructure, TransactionId txInfo ) throws IOException { writeTxLogCounters( fileSystem, lastTxInformationFile( migrationStructure ), txInfo.transactionId(), txInfo.checksum(), txInfo.commitTimestamp() ); }
public void setLastTransactionCommitTimestamp( long timestamp ) { // Preventing race with transactionCommitted() and assure record is consistent with highestCommittedTransaction synchronized ( transactionCommittedLock ) { setRecord( Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, timestamp ); TransactionId transactionId = highestCommittedTransaction.get(); highestCommittedTransaction.set( transactionId.transactionId(), transactionId.checksum(), timestamp ); } }
KernelTransactionImplementation tx = localTxPool.acquire(); StatementLocks statementLocks = statementLocksFactory.newInstance(); tx.initialize( lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, securityContext, timeout, userTransactionIdCounter.incrementAndGet() ); return tx;
if ( highestCommittedTransaction.get().transactionId() == transactionId )