Esempio n. 1
0
        public override void AssertMatch(long txId, long checksum)
        {
            if (txId == 0)
            {
                return;
            }
            long readChecksum;

            try
            {
                readChecksum = _txChecksumLookup.lookup(txId);
            }
            catch (NoSuchTransactionException)
            {
                // This can happen if it's the first commit from a slave in a cluster where all instances
                // just restored from backup (i.e. no previous tx logs exist), OR if a reporting instance
                // is so far behind that logs have been pruned to the point where the slave cannot catch up anymore.
                // In the first case it's fine (slave had to do checksum match to join cluster), and the second case
                // it's an operational issue solved by making sure enough logs are retained.

                return;                         // Ok!
            }
            catch (IOException e)
            {
                _log.error("Couldn't verify checksum for " + Stringify(txId, checksum), e);
                throw new BranchedDataException("Unable to perform a mandatory sanity check due to an IO error.", e);
            }

            if (checksum != readChecksum)
            {
                throw new BranchedDataException("The cluster contains two logically different versions of the database. " + "This will be automatically resolved. Details: " + Stringify(txId, checksum) + " does not match " + readChecksum);
            }
        }
 public override void FileDeleted(string fileName)
 {
     if (!_fileNameFilter.test(fileName))
     {
         _internalLog.error(format("'%s' which belongs to the store was deleted while database was running.", fileName));
     }
 }
Esempio n. 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public T readState() throws java.io.IOException
        public override T ReadState()
        {
            try
            {
                using (ReadableClosableChannel channel = new ReadAheadChannel <>(_fileSystem.open(_file, OpenMode.READ)))
                {
                    return(_marshal.unmarshal(channel));
                }
            }
            catch (EndOfStreamException e)
            {
                _log.error("End of stream reached: " + _file);
                throw new IOException(e);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Writes logs about database errors.
        /// Short one-line message is written to both user and internal log.
        /// Large message with stacktrace (if available) is written to internal log.
        /// </summary>
        /// <param name="error"> the error to log. </param>
        /// <seealso cref= StoreLogService </seealso>
        /// <seealso cref= DuplicatingLogProvider </seealso>
        public virtual void Report(Neo4jError error)
        {
            if (error.Status().code().classification() == DatabaseError)
            {
                string message = format("Client triggered an unexpected error [%s]: %s, reference %s.", error.Status().code().serialize(), error.Message(), error.Reference());

                // Writing to user log gets duplicated to the internal log
                _userLog.error(message);

                // If cause/stacktrace is available write it to the internal log
                if (error.Cause() != null)
                {
                    _debugLog.error(message, error.Cause());
                }
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, final TxPullRequest msg) throws Exception
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        protected internal override void ChannelRead0(ChannelHandlerContext ctx, TxPullRequest msg)
        {
            _monitor.increment();

            if (msg.PreviousTxId() <= 0)
            {
                _log.error("Illegal tx pull request");
                EndInteraction(ctx, E_INVALID_REQUEST, -1);
                return;
            }

            StoreId localStoreId    = _storeIdSupplier.get();
            StoreId expectedStoreId = msg.ExpectedStoreId();

            long firstTxId = msg.PreviousTxId() + 1;

            /*
             * This is the minimum transaction id we must send to consider our streaming operation successful. The kernel can
             * concurrently prune even future transactions while iterating and the cursor will silently fail on iteration, so
             * we need to add our own protection for this reason and also as a generally important sanity check for the fulfillment
             * of the consistent recovery contract which requires us to stream transactions at least as far as the time when the
             * file copy operation completed.
             */
            long txIdPromise = _transactionIdStore.LastCommittedTransactionId;
            IOCursor <CommittedTransactionRepresentation> txCursor = GetCursor(txIdPromise, ctx, firstTxId, localStoreId, expectedStoreId);

            if (txCursor != null)
            {
                ChunkedTransactionStream txStream = new ChunkedTransactionStream(_log, localStoreId, firstTxId, txIdPromise, txCursor, _protocol);
                // chunked transaction stream ends the interaction internally and closes the cursor
                ctx.writeAndFlush(txStream).addListener(f =>
                {
                    if (_log.DebugEnabled || !f.Success)
                    {
                        string message = format("Streamed transactions [%d--%d] to %s", firstTxId, txStream.LastTxId(), ctx.channel().remoteAddress());
                        if (f.Success)
                        {
                            _log.debug(message);
                        }
                        else
                        {
                            _log.warn(message, f.cause());
                        }
                    }
                });
            }
        }
Esempio n. 6
0
 public override void Init()
 {
     if (_pullIntervalMillis > 0)
     {
         _intervalJobHandle = _scheduler.scheduleRecurring(Group.PULL_UPDATES, () =>
         {
             try
             {
                 _updatePuller.pullUpdates();
             }
             catch (InterruptedException e)
             {
                 _log.error("Pull updates failed", e);
             }
         }, _pullIntervalMillis, _pullIntervalMillis, TimeUnit.MILLISECONDS);
     }
 }
Esempio n. 7
0
        public virtual bool Run()
        {
            if (_tasks == null || _tasks.Length < 1)
            {
                return(true);
            }

            foreach (PreflightTask r in _tasks)
            {
                if (!r.Run())
                {
                    _log.error(r.FailureMessage);
                    _failedTask = r;
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 8
0
        private void SendRange(long startIndex, long endIndex, LeaderContext leaderContext)
        {
            if (startIndex > endIndex)
            {
                return;
            }

            _lastSentIndex = endIndex;

            try
            {
                int            batchSize = ( int )(endIndex - startIndex + 1);
                RaftLogEntry[] entries   = new RaftLogEntry[batchSize];

                long prevLogIndex = startIndex - 1;
                long prevLogTerm  = _raftLog.readEntryTerm(prevLogIndex);

                if (prevLogTerm > leaderContext.Term)
                {
                    _log.warn("%s aborting send. Not leader anymore? %s, prevLogTerm=%d", StatusAsString(), leaderContext, prevLogTerm);
                    return;
                }

                bool entryMissing = false;
                using (InFlightLogEntryReader logEntrySupplier = new InFlightLogEntryReader(_raftLog, _inFlightCache, false))
                {
                    for (int offset = 0; offset < batchSize; offset++)
                    {
                        entries[offset] = logEntrySupplier.Get(startIndex + offset);
                        if (entries[offset] == null)
                        {
                            entryMissing = true;
                            break;
                        }
                        if (entries[offset].Term() > leaderContext.Term)
                        {
                            _log.warn("%s aborting send. Not leader anymore? %s, entryTerm=%d", StatusAsString(), leaderContext, entries[offset].Term());
                            return;
                        }
                    }
                }

                if (entryMissing || DoesNotExistInLog(prevLogIndex, prevLogTerm))
                {
                    if (_raftLog.prevIndex() >= prevLogIndex)
                    {
                        SendLogCompactionInfo(leaderContext);
                    }
                    else
                    {
                        _log.error("%s: Could not send compaction info and entries were missing, but log is not behind.", StatusAsString());
                    }
                }
                else
                {
                    Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request appendRequest = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(_leader, leaderContext.Term, prevLogIndex, prevLogTerm, entries, leaderContext.CommitIndex);

                    _outbound.send(_follower, appendRequest);
                }
            }
            catch (IOException e)
            {
                _log.warn(StatusAsString() + " exception during batch send", e);
            }
        }