Search in sources :

Example 16 with TransactionId

use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.

the class StoreMigrator method updateOrAddNeoStoreFieldsAsPartOfMigration.

private void updateOrAddNeoStoreFieldsAsPartOfMigration(File migrationDir, File storeDir, String versionToMigrateTo) throws IOException {
    final File storeDirNeoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_ID, MetaDataStore.getRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_ID));
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TIME, System.currentTimeMillis());
    // Store the checksum of the transaction id the upgrade is at right now. Store it both as
    // LAST_TRANSACTION_CHECKSUM and UPGRADE_TRANSACTION_CHECKSUM. Initially the last transaction and the
    // upgrade transaction will be the same, but imagine this scenario:
    //  - legacy store is migrated on instance A at transaction T
    //  - upgraded store is copied, via backup or HA or whatever to instance B
    //  - instance A performs a transaction
    //  - instance B would like to communicate with A where B's last transaction checksum
    //    is verified on A. A, at this point not having logs from pre-migration era, will need to
    //    know the checksum of transaction T to accommodate for this request from B. A will be able
    //    to look up checksums for transactions succeeding T by looking at its transaction logs,
    //    but T needs to be stored in neostore to be accessible. Obvioously this scenario is only
    //    problematic as long as we don't migrate and translate old logs.
    TransactionId lastTxInfo = readLastTxInformation(migrationDir);
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_CHECKSUM, lastTxInfo.checksum());
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_CHECKSUM, lastTxInfo.checksum());
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp());
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp());
    // add LAST_CLOSED_TRANSACTION_LOG_VERSION and LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET to the migrated
    // NeoStore
    LogPosition logPosition = readLastTxLogPosition(migrationDir);
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, logPosition.getLogVersion());
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, logPosition.getByteOffset());
    // Upgrade version in NeoStore
    MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.STORE_VERSION, MetaDataStore.versionStringToLong(versionToMigrateTo));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) TransactionId(org.neo4j.kernel.impl.store.TransactionId) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 17 with TransactionId

use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.

the class LegacyLogs method getTransactionInformation.

public Optional<TransactionId> getTransactionInformation(File storeDir, long transactionId) throws IOException {
    List<File> logFiles = Arrays.asList(fs.listFiles(storeDir, versionedLegacyLogFilesFilter));
    logFiles.sort(NEWEST_FIRST);
    for (File file : logFiles) {
        Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(file);
        boolean hadAnyTransactions = false;
        try (IOCursor<LogEntry> cursor = pair.other()) {
            // The log entries will come sorted from this cursor, so no need to keep track of identifiers and such.
            LogEntryStart startEntry = null;
            while (cursor.next()) {
                LogEntry logEntry = cursor.get();
                if (logEntry instanceof LogEntryStart) {
                    startEntry = (LogEntryStart) logEntry;
                } else if (logEntry instanceof LogEntryCommit) {
                    hadAnyTransactions = true;
                    LogEntryCommit commitEntry = logEntry.as();
                    if (commitEntry.getTxId() == transactionId) {
                        return Optional.of(new TransactionId(transactionId, startEntry.checksum(), commitEntry.getTimeWritten()));
                    }
                }
            }
        }
        if (hadAnyTransactions) {
            // No need to go further back than this. We're looking for the last transaction
            break;
        }
    }
    return Optional.empty();
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) IOCursor(org.neo4j.cursor.IOCursor) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) File(java.io.File) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) TransactionId(org.neo4j.kernel.impl.store.TransactionId)

Example 18 with TransactionId

use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.

the class ClusterTest method lastCommittedTxTimestamp.

private static long lastCommittedTxTimestamp(HighlyAvailableGraphDatabase db) {
    DependencyResolver resolver = db.getDependencyResolver();
    MetaDataStore metaDataStore = resolver.resolveDependency(MetaDataStore.class);
    TransactionId txInfo = metaDataStore.getLastCommittedTransaction();
    return txInfo.commitTimestamp();
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) DependencyResolver(org.neo4j.graphdb.DependencyResolver) TransactionId(org.neo4j.kernel.impl.store.TransactionId)

Example 19 with TransactionId

use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.

the class HighlyAvailableEditionModule method assureLastCommitTimestampInitialized.

private static void assureLastCommitTimestampInitialized(DependencyResolver resolver) {
    MetaDataStore metaDataStore = resolver.resolveDependency(MetaDataStore.class);
    LogicalTransactionStore txStore = resolver.resolveDependency(LogicalTransactionStore.class);
    TransactionId txInfo = metaDataStore.getLastCommittedTransaction();
    long lastCommitTimestampFromStore = txInfo.commitTimestamp();
    if (txInfo.transactionId() == TransactionIdStore.BASE_TX_ID) {
        metaDataStore.setLastTransactionCommitTimestamp(TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP);
        return;
    }
    if (lastCommitTimestampFromStore == TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP || lastCommitTimestampFromStore == TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP) {
        long lastCommitTimestampFromLogs;
        try {
            TransactionMetadata metadata = txStore.getMetadataFor(txInfo.transactionId());
            lastCommitTimestampFromLogs = metadata.getTimeWritten();
        } catch (NoSuchTransactionException e) {
            lastCommitTimestampFromLogs = TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP;
        } catch (IOException e) {
            throw new IllegalStateException("Unable to read transaction logs", e);
        }
        metaDataStore.setLastTransactionCommitTimestamp(lastCommitTimestampFromLogs);
    }
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) IOException(java.io.IOException) TransactionId(org.neo4j.kernel.impl.store.TransactionId) TransactionMetadata(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata)

Example 20 with TransactionId

use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.

the class KernelTransactionsTest method newKernelTransactions.

private static KernelTransactions newKernelTransactions(Locks locks, StorageEngine storageEngine, TransactionCommitProcess commitProcess, boolean testKernelTransactions) throws Throwable {
    LifeSupport life = new LifeSupport();
    life.start();
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(0, 0, 0));
    Tracers tracers = new Tracers("null", NullLog.getInstance(), new Monitors(), mock(JobScheduler.class));
    StatementLocksFactory statementLocksFactory = new SimpleStatementLocksFactory(locks);
    StatementOperationContainer statementOperationsContianer = new StatementOperationContainer(null, null);
    KernelTransactions transactions;
    if (testKernelTransactions) {
        transactions = createTestTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    } else {
        transactions = createTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    }
    transactions.start();
    return transactions;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StatementLocksFactory(org.neo4j.kernel.impl.locking.StatementLocksFactory) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TransactionId(org.neo4j.kernel.impl.store.TransactionId) Tracers(org.neo4j.kernel.monitoring.tracing.Tracers)

Aggregations

TransactionId (org.neo4j.kernel.impl.store.TransactionId)23 Test (org.junit.Test)13 File (java.io.File)11 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)9 PageCache (org.neo4j.io.pagecache.PageCache)8 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)8 StoreId (org.neo4j.kernel.impl.store.StoreId)8 URI (java.net.URI)7 Config (org.neo4j.kernel.configuration.Config)7 BranchedDataPolicy (org.neo4j.kernel.ha.BranchedDataPolicy)7 PagedFile (org.neo4j.io.pagecache.PagedFile)6 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)6 NullLogService (org.neo4j.kernel.impl.logging.NullLogService)6 BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)5 IOException (java.io.IOException)4 CancellationRequest (org.neo4j.helpers.CancellationRequest)4 MismatchingStoreIdException (org.neo4j.kernel.impl.store.MismatchingStoreIdException)4 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)4 InetSocketAddress (java.net.InetSocketAddress)3 LogService (org.neo4j.kernel.impl.logging.LogService)3