示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static java.util.List<org.neo4j.kernel.impl.transaction.log.entry.LogEntry> logEntries(org.neo4j.io.fs.FileSystemAbstraction fileSystem, String logPath) throws java.io.IOException
        public static IList <LogEntry> LogEntries(FileSystemAbstraction fileSystem, string logPath)
        {
            File         logFile     = new File(logPath);
            StoreChannel fileChannel = fileSystem.Open(logFile, OpenMode.READ);

            // Always a header
            LogHeader header = readLogHeader(ByteBuffer.allocate(LOG_HEADER_SIZE), fileChannel, true, logFile);

            // Read all log entries
            PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileChannel, header.LogVersion, header.LogFormatVersion);
            ReadableLogChannel logChannel     = new ReadAheadLogChannel(versionedStoreChannel);
            LogEntryCursor     logEntryCursor = new LogEntryCursor(new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), logChannel);

            return(Iterables.asList(new IOCursorAsResourceIterable <>(logEntryCursor)));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.util.List<org.neo4j.kernel.impl.transaction.log.entry.CheckPoint> find(long version) throws java.io.IOException
            public virtual IList <CheckPoint> Find(long version)
            {
                IList <CheckPoint> checkPoints = new List <CheckPoint>();

                for ( ; version >= INITIAL_LOG_VERSION && LogFiles.versionExists(version); version--)
                {
                    LogVersionedStoreChannel             channel = LogFiles.openForVersion(version);
                    ReadableClosablePositionAwareChannel recoveredDataChannel = new ReadAheadLogChannel(channel);

                    using (LogEntryCursor cursor = new LogEntryCursor(LogEntryReader, recoveredDataChannel))
                    {
                        while (cursor.Next())
                        {
                            LogEntry entry = cursor.Get();
                            if (entry is CheckPoint)
                            {
                                checkPoints.Add(entry.As());
                            }
                        }
                    }
                }
                return(checkPoints);
            }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private LogTailInformation findLogTail() throws java.io.IOException
        private LogTailInformation FindLogTail()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long highestLogVersion = logFiles.getHighestLogVersion();
            long            highestLogVersion           = _logFiles.HighestLogVersion;
            long            version                     = highestLogVersion;
            long            versionToSearchForCommits   = highestLogVersion;
            LogEntryStart   latestStartEntry            = null;
            long            oldestStartEntryTransaction = -1;
            long            oldestVersionFound          = -1;
            LogEntryVersion latestLogEntryVersion       = null;
            bool            startRecordAfterCheckpoint  = false;
            bool            corruptedTransactionLogs    = false;

            while (version >= _logFiles.LowestLogVersion && version >= INITIAL_LOG_VERSION)
            {
                oldestVersionFound = version;
                CheckPoint latestCheckPoint = null;
                try
                {
                    using (LogVersionedStoreChannel channel = _logFiles.openForVersion(version), ReadAheadLogChannel readAheadLogChannel = new ReadAheadLogChannel(channel), LogEntryCursor cursor = new LogEntryCursor(_logEntryReader, readAheadLogChannel))
                    {
                        LogEntry entry;
                        long     maxEntryReadPosition = 0;
                        while (cursor.Next())
                        {
                            entry = cursor.Get();

                            // Collect data about latest checkpoint
                            if (entry is CheckPoint)
                            {
                                latestCheckPoint = entry.As();
                            }
                            else if (entry is LogEntryCommit)
                            {
                                if (oldestStartEntryTransaction == NoTransactionId)
                                {
                                    oldestStartEntryTransaction = (( LogEntryCommit )entry).TxId;
                                }
                            }
                            else if (entry is LogEntryStart)
                            {
                                LogEntryStart startEntry = entry.As();
                                if (version == versionToSearchForCommits)
                                {
                                    latestStartEntry = startEntry;
                                }
                                startRecordAfterCheckpoint = true;
                            }

                            // Collect data about latest entry version, only in first log file
                            if (version == versionToSearchForCommits || latestLogEntryVersion == null)
                            {
                                latestLogEntryVersion = entry.Version;
                            }
                            maxEntryReadPosition = readAheadLogChannel.Position();
                        }
                        if (HasUnreadableBytes(channel, maxEntryReadPosition))
                        {
                            corruptedTransactionLogs = true;
                        }
                    }
                }
                catch (Exception e) when(e is Exception || e is ClosedByInterruptException)
                {
                    // These should not be parsing errors
                    throw e;
                }
                catch (Exception t)
                {
                    _monitor.corruptedLogFile(version, t);
                    if (_failOnCorruptedLogFiles)
                    {
                        throwUnableToCleanRecover(t);
                    }
                    corruptedTransactionLogs = true;
                }

                if (latestCheckPoint != null)
                {
                    return(CheckpointTailInformation(highestLogVersion, latestStartEntry, oldestVersionFound, latestLogEntryVersion, latestCheckPoint, corruptedTransactionLogs));
                }

                version--;

                // if we have found no commits in the latest log, keep searching in the next one
                if (latestStartEntry == null)
                {
                    versionToSearchForCommits--;
                }
            }

            return(new LogTailInformation(corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound, highestLogVersion, latestLogEntryVersion));
        }
示例#4
0
        /// <summary>
        /// Extracts txId from first commit entry, when starting reading at the given {@code position}.
        /// If no commit entry found in the version, the reader will continue into next version(s) up till
        /// {@code maxLogVersion} until finding one.
        /// </summary>
        /// <param name="initialPosition"> <seealso cref="LogPosition"/> to start scan from. </param>
        /// <param name="maxLogVersion"> max log version to scan. </param>
        /// <returns> value object that contains first transaction id of closes commit entry to {@code initialPosition},
        /// or <seealso cref="LogTailInformation.NO_TRANSACTION_ID"/> if not found. And failure flag that will be set to true if
        /// there was some exception during transaction log processing. </returns>
        /// <exception cref="IOException"> on channel close I/O error. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected ExtractedTransactionRecord extractFirstTxIdAfterPosition(org.neo4j.kernel.impl.transaction.log.LogPosition initialPosition, long maxLogVersion) throws java.io.IOException
        protected internal virtual ExtractedTransactionRecord ExtractFirstTxIdAfterPosition(LogPosition initialPosition, long maxLogVersion)
        {
            LogPosition currentPosition = initialPosition;

            while (currentPosition.LogVersion <= maxLogVersion)
            {
                LogVersionedStoreChannel storeChannel = TryOpenStoreChannel(currentPosition);
                if (storeChannel != null)
                {
                    try
                    {
                        storeChannel.Position(currentPosition.ByteOffset);
                        using (ReadAheadLogChannel logChannel = new ReadAheadLogChannel(storeChannel), LogEntryCursor cursor = new LogEntryCursor(_logEntryReader, logChannel))
                        {
                            while (cursor.Next())
                            {
                                LogEntry entry = cursor.Get();
                                if (entry is LogEntryCommit)
                                {
                                    return(new ExtractedTransactionRecord((( LogEntryCommit )entry).TxId));
                                }
                            }
                        }
                    }
                    catch (Exception t)
                    {
                        _monitor.corruptedLogFile(currentPosition.LogVersion, t);
                        return(new ExtractedTransactionRecord(true));
                    }
                    finally
                    {
                        storeChannel.close();
                    }
                }

                currentPosition = LogPosition.start(currentPosition.LogVersion + 1);
            }
            return(new ExtractedTransactionRecord());
        }