@Override public TransactionId getLastCommittedTransaction() { return new TransactionId( transactionId, transactionChecksum, BASE_TX_COMMIT_TIMESTAMP ); }
void writeLastTxInformation( DatabaseLayout migrationStructure, TransactionId txInfo ) throws IOException { writeTxLogCounters( fileSystem, lastTxInformationFile( migrationStructure ), txInfo.transactionId(), txInfo.checksum(), txInfo.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; }
private static Function<TransactionId,Boolean> txInfoAcceptanceOnIdAndTimestamp( long id, long timestamp ) { return txInfo -> txInfo.transactionId() == id && txInfo.commitTimestamp() == timestamp; } }
lastTxInfo.checksum() ); MetaDataStore.setRecord( pageCache, migrationDirNeoStore, Position.UPGRADE_TRANSACTION_CHECKSUM, lastTxInfo.checksum() ); MetaDataStore.setRecord( pageCache, migrationDirNeoStore, Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp() ); MetaDataStore.setRecord( pageCache, migrationDirNeoStore, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.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 ); } }
@Override public long getLastCommittedTransactionId() { return committedTransactionId.get().transactionId(); }
lastTxId, lastTxInfo.checksum(), lastTxLogPosition.getLogVersion(), lastTxLogPosition.getByteOffset(), progressReporter, oldFormat, newFormat );
@Test public void lastTxCommitTimestampShouldBeBaseInNewStore() { try ( MetaDataStore metaDataStore = newMetaDataStore() ) { long timestamp = metaDataStore.getLastCommittedTransaction().commitTimestamp(); assertThat( timestamp, equalTo( TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP ) ); } }
@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 ) ); } }
KernelTransactionImplementation tx = localTxPool.acquire(); StatementLocks statementLocks = statementLocksFactory.newInstance(); tx.initialize( lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, securityContext, timeout, userTransactionIdCounter.incrementAndGet() ); return tx;
assertEquals( transactionId, lastClosedTransaction[0] ); assertEquals( LogEntryStart.checksum( additionalHeaderData, masterId, authorId ), transactionIdStore.getLastCommittedTransaction().checksum() ); assertEquals( commitTimestamp, transactionIdStore.getLastCommittedTransaction().commitTimestamp() ); assertEquals( logVersion, lastClosedTransaction[1] ); assertEquals( marker.getByteOffset(), lastClosedTransaction[2] );
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 ); } }
@Override public long getLastCommittedTransactionId() { assertNotClosed(); checkInitialized( lastCommittingTxField.get() ); return highestCommittedTransaction.get().transactionId(); }
lastTxId, lastTxInfo.checksum(), lastTxLogPosition.getLogVersion(), lastTxLogPosition.getByteOffset(), progressReporter, oldFormat, newFormat );
@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() ); }
/** * In case if we can't find information about transaction in logs we will create new transaction * information record. * Those should be used <b>only</b> in case if we do not have any transaction logs available during * migration. * * Logs can be absent in two possible scenarios: * <ol> * <li>We do not have any logs since there were not transaction.</li> * <li>Logs are missing.</li> * </ol> * For both of those cases specific informational records will be produced. * * @param lastTransactionId last committed transaction id * @return supplier of custom id records. */ private static TransactionId specificTransactionInformationSupplier( long lastTransactionId ) { return lastTransactionId == TransactionIdStore.BASE_TX_ID ? new TransactionId( lastTransactionId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP ) : new TransactionId( lastTransactionId, UNKNOWN_TX_CHECKSUM, UNKNOWN_TX_COMMIT_TIMESTAMP ); }
/** * 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; }
KernelTransactionImplementation tx = localTxPool.acquire(); StatementLocks statementLocks = statementLocksFactory.newInstance(); tx.initialize( lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, securityContext, timeout, userTransactionIdCounter.incrementAndGet() ); return tx;
lastTxInfo.checksum() ); MetaDataStore.setRecord( pageCache, migrationDirNeoStore, Position.UPGRADE_TRANSACTION_CHECKSUM, lastTxInfo.checksum() ); MetaDataStore.setRecord( pageCache, migrationDirNeoStore, Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp() ); MetaDataStore.setRecord( pageCache, migrationDirNeoStore, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp() );