Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void apply(org.neo4j.storageengine.api.CommandsToApply batch, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws Exception
        public override void Apply(CommandsToApply batch, TransactionApplicationMode mode)
        {
            // Have these command appliers as separate try-with-resource to have better control over
            // point between closing this and the locks above
            try
            {
                using (IndexActivator indexActivator = new IndexActivator(_indexingService), LockGroup locks = new LockGroup(), BatchTransactionApplier batchApplier = Applier(mode, indexActivator))
                {
                    while (batch != null)
                    {
                        using (TransactionApplier txApplier = batchApplier.StartTx(batch, locks))
                        {
                            batch.Accept(txApplier);
                        }
                        batch = batch.Next();
                    }
                }
            }
            catch (Exception cause)
            {
                TransactionApplyKernelException kernelException = new TransactionApplyKernelException(cause, "Failed to apply transaction: %s", batch);
                _databaseHealth.panic(kernelException);
                throw kernelException;
            }
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionApplier startTx(org.neo4j.storageengine.api.CommandsToApply transaction) throws java.io.IOException
        public override TransactionApplier StartTx(CommandsToApply transaction)
        {
            long activeTransactionId = transaction.TransactionId();

            try
            {
                // Cache transactionApplier because it has some expensive lookups
                if (_txApplier == null)
                {
                    _txApplier = new ExplicitIndexTransactionApplier(_applierLookup, _indexConfigStore, _mode, _transactionOrdering);
                }

                if (transaction.RequiresApplicationOrdering())
                {
                    // Index operations must preserve order so wait for previous tx to finish
                    _transactionOrdering.waitFor(activeTransactionId);
                    // And set current tx so we can notify the next transaction when we are finished
                    if (transaction.Next() != null)
                    {
                        // Let each transaction notify the next
                        _txApplier.TransactionId = activeTransactionId;
                    }
                    else
                    {
                        // except the last transaction, which notifies that it is done after appliers have been closed
                        _lastTransactionId = activeTransactionId;
                    }
                }

                return(_txApplier);
            }
            catch (InterruptedException e)
            {
                Thread.CurrentThread.Interrupt();
                throw new IOException("Interrupted while waiting for applying tx:" + activeTransactionId + " explicit index updates", e);
            }
        }