예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long doCheckPoint(TriggerInfo triggerInfo) throws java.io.IOException
        private long DoCheckPoint(TriggerInfo triggerInfo)
        {
            try
            {
                using (LogCheckPointEvent @event = _tracer.beginCheckPoint())
                {
                    long[]      lastClosedTransaction   = _transactionIdStore.LastClosedTransaction;
                    long        lastClosedTransactionId = lastClosedTransaction[0];
                    LogPosition logPosition             = new LogPosition(lastClosedTransaction[1], lastClosedTransaction[2]);
                    string      prefix = triggerInfo.Describe(lastClosedTransactionId);

                    /*
                     * Check kernel health before going into waiting for transactions to be closed, to avoid
                     * getting into a scenario where we would await a condition that would potentially never
                     * happen.
                     */
                    _databaseHealth.assertHealthy(typeof(IOException));

                    /*
                     * First we flush the store. If we fail now or during the flush, on recovery we'll find the
                     * earlier check point and replay from there all the log entries. Everything will be ok.
                     */
                    _msgLog.info(prefix + " checkpoint started...");
                    long startTime = currentTimeMillis();
                    _storageEngine.flushAndForce(_ioLimiter);

                    /*
                     * Check kernel health before going to write the next check point.  In case of a panic this check point
                     * will be aborted, which is the safest alternative so that the next recovery will have a chance to
                     * repair the damages.
                     */
                    _databaseHealth.assertHealthy(typeof(IOException));
                    _appender.checkPoint(logPosition, @event);
                    _threshold.checkPointHappened(lastClosedTransactionId);
                    _msgLog.info(prefix + " checkpoint completed in " + duration(currentTimeMillis() - startTime));

                    /*
                     * Prune up to the version pointed from the latest check point,
                     * since it might be an earlier version than the current log version.
                     */
                    _logPruning.pruneLogs(logPosition.LogVersion);
                    _lastCheckPointedTx = lastClosedTransactionId;
                    return(lastClosedTransactionId);
                }
            }
            catch (Exception t)
            {
                // Why only log failure here? It's because check point can potentially be made from various
                // points of execution e.g. background thread triggering check point if needed and during
                // shutdown where it's better to have more control over failure handling.
                _msgLog.error("Checkpoint failed", t);
                throw t;
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long append(org.neo4j.kernel.impl.api.TransactionToApply batch, org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent logAppendEvent) throws java.io.IOException
        public override long Append(TransactionToApply batch, LogAppendEvent logAppendEvent)
        {
            // Assigned base tx id just to make compiler happy
            long lastTransactionId = TransactionIdStore_Fields.BASE_TX_ID;

            // Synchronized with logFile to get absolute control over concurrent rotations happening
            lock ( _logFile )
            {
                // Assert that kernel is healthy before making any changes
                _databaseHealth.assertHealthy(typeof(IOException));
                using (SerializeTransactionEvent serialiseEvent = logAppendEvent.BeginSerializeTransaction())
                {
                    // Append all transactions in this batch to the log under the same logFile monitor
                    TransactionToApply tx = batch;
                    while (tx != null)
                    {
                        long transactionId = _transactionIdStore.nextCommittingTransactionId();

                        // If we're in a scenario where we're merely replicating transactions, i.e. transaction
                        // id have already been generated by another entity we simply check that our id
                        // that we generated match that id. If it doesn't we've run into a problem we can't ´
                        // really recover from and would point to a bug somewhere.
                        MatchAgainstExpectedTransactionIdIfAny(transactionId, tx);

                        TransactionCommitment commitment = AppendToLog(tx.TransactionRepresentation(), transactionId);
                        tx.Commitment(commitment, transactionId);
                        tx.LogPosition(commitment.LogPosition());
                        tx = tx.Next();
                        lastTransactionId = transactionId;
                    }
                }
            }

            // At this point we've appended all transactions in this batch, but we can't mark any of them
            // as committed since they haven't been forced to disk yet. So here we force, or potentially
            // piggy-back on another force, but anyway after this call below we can be sure that all our transactions
            // in this batch exist durably on disk.
            if (ForceAfterAppend(logAppendEvent))
            {
                // We got lucky and were the one forcing the log. It's enough if ones of all doing concurrent committers
                // checks the need for log rotation.
                bool logRotated = _logRotation.rotateLogIfNeeded(logAppendEvent);
                logAppendEvent.LogRotated = logRotated;
            }

            // Mark all transactions as committed
            PublishAsCommitted(batch);

            return(lastTransactionId);
        }
예제 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public <EXCEPTION extends Throwable> void assertHealthy(Class<EXCEPTION> cause) throws EXCEPTION
        public virtual void AssertHealthy <EXCEPTION>(Type cause) where EXCEPTION : Exception
        {
            cause = typeof(EXCEPTION);
            DatabaseHealth.assertHealthy(cause);
        }