Search in sources :

Example 1 with TransactionRepresentationCommitProcess

use of org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess in project neo4j by neo4j.

the class ApplyTransactionsCommand method applyTransactions.

private long applyTransactions(File fromPath, GraphDatabaseAPI toDb, long fromTxExclusive, long toTxInclusive, PrintStream out) throws IOException, TransactionFailureException {
    DependencyResolver resolver = toDb.getDependencyResolver();
    TransactionRepresentationCommitProcess commitProcess = new TransactionRepresentationCommitProcess(resolver.resolveDependency(TransactionAppender.class), resolver.resolveDependency(StorageEngine.class));
    LifeSupport life = new LifeSupport();
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
        LogicalTransactionStore source = life.add(new ReadOnlyTransactionStore(pageCache, fileSystem, fromPath, new Monitors()));
        life.start();
        long lastAppliedTx = fromTxExclusive;
        // Some progress if there are more than a couple of transactions to apply
        ProgressListener progress = toTxInclusive - fromTxExclusive >= 100 ? textual(out).singlePart("Application progress", toTxInclusive - fromTxExclusive) : ProgressListener.NONE;
        try (IOCursor<CommittedTransactionRepresentation> cursor = source.getTransactions(fromTxExclusive + 1)) {
            while (cursor.next()) {
                CommittedTransactionRepresentation transaction = cursor.get();
                TransactionRepresentation transactionRepresentation = transaction.getTransactionRepresentation();
                try {
                    commitProcess.commit(new TransactionToApply(transactionRepresentation), NULL, EXTERNAL);
                    progress.add(1);
                } catch (final Throwable e) {
                    System.err.println("ERROR applying transaction " + transaction.getCommitEntry().getTxId());
                    throw e;
                }
                lastAppliedTx = transaction.getCommitEntry().getTxId();
                if (lastAppliedTx == toTxInclusive) {
                    break;
                }
            }
        }
        return lastAppliedTx;
    } finally {
        life.shutdown();
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) StorageEngine(org.neo4j.storageengine.api.StorageEngine) ReadOnlyTransactionStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore) DependencyResolver(org.neo4j.graphdb.DependencyResolver) ProgressListener(org.neo4j.helpers.progress.ProgressListener) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) PageCache(org.neo4j.io.pagecache.PageCache)

Example 2 with TransactionRepresentationCommitProcess

use of org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess in project neo4j by neo4j.

the class CommitProcessSwitcher method getMasterImpl.

@Override
protected TransactionCommitProcess getMasterImpl() {
    TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(dependencyResolver.resolveDependency(TransactionAppender.class), dependencyResolver.resolveDependency(StorageEngine.class));
    IntegrityValidator validator = dependencyResolver.resolveDependency(IntegrityValidator.class);
    return new MasterTransactionCommitProcess(commitProcess, txPropagator, validator, monitor, locks, reacquireSharedSchemaLockOnIncomingTransactions);
}
Also used : IntegrityValidator(org.neo4j.kernel.impl.transaction.state.IntegrityValidator) MasterTransactionCommitProcess(org.neo4j.kernel.ha.MasterTransactionCommitProcess) SlaveTransactionCommitProcess(org.neo4j.kernel.ha.SlaveTransactionCommitProcess) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) MasterTransactionCommitProcess(org.neo4j.kernel.ha.MasterTransactionCommitProcess) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Aggregations

TransactionRepresentationCommitProcess (org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess)2 TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)2 StorageEngine (org.neo4j.storageengine.api.StorageEngine)2 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 ProgressListener (org.neo4j.helpers.progress.ProgressListener)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 PageCache (org.neo4j.io.pagecache.PageCache)1 MasterTransactionCommitProcess (org.neo4j.kernel.ha.MasterTransactionCommitProcess)1 SlaveTransactionCommitProcess (org.neo4j.kernel.ha.SlaveTransactionCommitProcess)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)1 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)1 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)1 ReadOnlyTransactionStore (org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore)1 IntegrityValidator (org.neo4j.kernel.impl.transaction.state.IntegrityValidator)1 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1