//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void assertWholeTransactionsIn(org.neo4j.kernel.impl.transaction.log.files.LogFile logFile, long logVersion) throws java.io.IOException
        private static void AssertWholeTransactionsIn(LogFile logFile, long logVersion)
        {
            using (ReadableLogChannel reader = logFile.GetReader(new LogPosition(logVersion, LOG_HEADER_SIZE)))
            {
                VersionAwareLogEntryReader <ReadableLogChannel> entryReader = new VersionAwareLogEntryReader <ReadableLogChannel>();
                LogEntry entry;
                bool     inTx         = false;
                int      transactions = 0;
                while ((entry = entryReader.ReadLogEntry(reader)) != null)
                {
                    if (!inTx)                                // Expects start entry
                    {
                        assertTrue(entry is LogEntryStart);
                        inTx = true;
                    }
                    else                              // Expects command/commit entry
                    {
                        assertTrue(entry is LogEntryCommand || entry is LogEntryCommit);
                        if (entry is LogEntryCommit)
                        {
                            inTx = false;
                            transactions++;
                        }
                    }
                }
                assertFalse(inTx);
                assertTrue(transactions > 0);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public TransactionCursor getTransactions(final long transactionIdToStartFrom) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public override TransactionCursor GetTransactions(long transactionIdToStartFrom)
        {
            // look up in position cache
            try
            {
                TransactionMetadataCache.TransactionMetadata transactionMetadata = _transactionMetadataCache.getTransactionMetadata(transactionIdToStartFrom);
                if (transactionMetadata != null)
                {
                    // we're good
                    ReadableLogChannel channel = _logFile.getReader(transactionMetadata.StartPosition);
                    return(new PhysicalTransactionCursor <>(channel, _logEntryReader));
                }

                // ask logFiles about the version it may be in
                LogVersionLocator headerVisitor = new LogVersionLocator(transactionIdToStartFrom);
                _logFiles.accept(headerVisitor);

                // ask LogFile
                TransactionPositionLocator transactionPositionLocator = new TransactionPositionLocator(transactionIdToStartFrom, _logEntryReader);
                _logFile.accept(transactionPositionLocator, headerVisitor.LogPosition);
                LogPosition position = transactionPositionLocator.GetAndCacheFoundLogPosition(_transactionMetadataCache);
                return(new PhysicalTransactionCursor <>(_logFile.getReader(position), _logEntryReader));
            }
            catch (FileNotFoundException e)
            {
                throw new NoSuchTransactionException(transactionIdToStartFrom, "Log position acquired, but couldn't find the log file itself. Perhaps it just recently was " + "deleted? [" + e.Message + "]", e);
            }
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void removeLastCheckpointRecordFromLastLogFile() throws java.io.IOException
        private void RemoveLastCheckpointRecordFromLastLogFile()
        {
            LogPosition checkpointPosition = null;

            LogFile transactionLogFile = _logFiles.LogFile;
            VersionAwareLogEntryReader <ReadableLogChannel> entryReader = new VersionAwareLogEntryReader <ReadableLogChannel>();
            LogPosition startPosition = LogPosition.start(_logFiles.HighestLogVersion);

            using (ReadableLogChannel reader = transactionLogFile.GetReader(startPosition))
            {
                LogEntry logEntry;
                do
                {
                    logEntry = entryReader.ReadLogEntry(reader);
                    if (logEntry is CheckPoint)
                    {
                        checkpointPosition = (( CheckPoint )logEntry).LogPosition;
                    }
                } while (logEntry != null);
            }
            if (checkpointPosition != null)
            {
                using (StoreChannel storeChannel = _fileSystemRule.open(_logFiles.HighestLogFile, OpenMode.READ_WRITE))
                {
                    storeChannel.Truncate(checkpointPosition.ByteOffset);
                }
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void accept(LogFile_LogFileVisitor visitor, org.neo4j.kernel.impl.transaction.log.LogPosition startingFromPosition) throws java.io.IOException
        public override void Accept(LogFile_LogFileVisitor visitor, LogPosition startingFromPosition)
        {
            using (ReadableLogChannel reader = GetReader(startingFromPosition))
            {
                visitor.Visit(reader);
            }
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long getTimestampForVersion(long version) throws java.io.IOException
            internal virtual long GetTimestampForVersion(long version)
            {
                LogPosition position = LogPosition.start(version);

                using (ReadableLogChannel channel = LogFiles.LogFile.getReader(position))
                {
                    LogEntry entry;
                    while ((entry = LogEntryReader.readLogEntry(channel)) != null)
                    {
                        if (entry is LogEntryStart)
                        {
                            return(entry.As <LogEntryStart>().TimeWritten);
                        }
                    }
                }
                return(-1);
            }
 private void Deplete(ReadableLogChannel reader)
 {
     sbyte[] dataChunk = new sbyte[100];
     try
     {
         while (true)
         {
             reader.Get(dataChunk, dataChunk.Length);
         }
     }
     catch (ReadPastEndException)
     {
         // This is OK, it means we've reached the end
     }
     catch (IOException e)
     {
         throw new Exception(e);
     }
 }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static boolean checkPointInTxLog(org.neo4j.graphdb.GraphDatabaseService db) throws java.io.IOException
        private static bool CheckPointInTxLog(GraphDatabaseService db)
        {
            LogFiles logFiles = (( GraphDatabaseAPI )db).DependencyResolver.resolveDependency(typeof(LogFiles));
            LogFile  logFile  = logFiles.LogFile;

            using (ReadableLogChannel reader = logFile.GetReader(new LogPosition(0, LOG_HEADER_SIZE)))
            {
                LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
                LogEntry entry;
                while ((entry = logEntryReader.ReadLogEntry(reader)) != null)
                {
                    if (entry is CheckPoint)
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
        /// <summary>
        /// Utility method for creating a <seealso cref="ReversedMultiFileTransactionCursor"/> with a <seealso cref="LogFile"/> as the source of
        /// <seealso cref="TransactionCursor"/> for each log version.
        /// </summary>
        /// <param name="logFile"> <seealso cref="LogFile"/> to supply log entries forming transactions. </param>
        /// <param name="backToPosition"> <seealso cref="LogPosition"/> to read backwards to. </param>
        /// <param name="failOnCorruptedLogFiles"> fail reading from log files as soon as first error is encountered </param>
        /// <param name="monitor"> reverse transaction cursor monitor </param>
        /// <returns> a <seealso cref="TransactionCursor"/> which returns transactions from the end of the log stream and backwards to
        /// and including transaction starting at <seealso cref="LogPosition"/>. </returns>
        /// <exception cref="IOException"> on I/O error. </exception>
        public static TransactionCursor FromLogFile(LogFiles logFiles, LogFile logFile, LogPosition backToPosition, bool failOnCorruptedLogFiles, ReversedTransactionCursorMonitor monitor)
        {
            long highestVersion = logFiles.HighestLogVersion;
            LogEntryReader <ReadableClosablePositionAwareChannel>          logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
            ThrowingFunction <LogPosition, TransactionCursor, IOException> factory        = position =>
            {
                ReadableLogChannel channel = logFile.GetReader(position, NO_MORE_CHANNELS);
                if (channel is ReadAheadLogChannel)
                {
                    // This is a channel which can be positioned explicitly and is the typical case for such channels
                    // Let's take advantage of this fact and use a bit smarter reverse implementation
                    return(new ReversedSingleFileTransactionCursor(( ReadAheadLogChannel )channel, logEntryReader, failOnCorruptedLogFiles, monitor));
                }

                // Fall back to simply eagerly reading each single log file and reversing in memory
                return(eagerlyReverse(new PhysicalTransactionCursor <>(channel, logEntryReader)));
            };

            return(new ReversedMultiFileTransactionCursor(factory, highestVersion, backToPosition));
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.eclipse.collections.api.map.primitive.ObjectLongMap<Class> getLogEntriesDistribution(org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles) throws java.io.IOException
        private static ObjectLongMap <Type> GetLogEntriesDistribution(LogFiles logFiles)
        {
            LogFile transactionLogFile = logFiles.LogFile;

            LogPosition fileStartPosition = new LogPosition(0, LogHeader.LOG_HEADER_SIZE);
            VersionAwareLogEntryReader <ReadableLogChannel> entryReader = new VersionAwareLogEntryReader <ReadableLogChannel>();

            MutableObjectLongMap <Type> multiset = new ObjectLongHashMap <Type>();

            using (ReadableLogChannel fileReader = transactionLogFile.GetReader(fileStartPosition))
            {
                LogEntry logEntry = entryReader.ReadLogEntry(fileReader);
                while (logEntry != null)
                {
                    multiset.addToValue(logEntry.GetType(), 1);
                    logEntry = entryReader.ReadLogEntry(fileReader);
                }
            }
            return(multiset);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotSeeEmptyLogFileWhenReadingTransactionStream() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotSeeEmptyLogFileWhenReadingTransactionStream()
        {
            // GIVEN
            LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
            LogFiles             logFiles             = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule.get()).withLogVersionRepository(logVersionRepository).withTransactionIdStore(new SimpleTransactionIdStore()).build();

            _life.add(logFiles);
            LogFile logFile = logFiles.LogFile;
            FlushablePositionAwareChannel writer        = logFile.Writer;
            LogPositionMarker             startPosition = new LogPositionMarker();

            writer.GetCurrentPosition(startPosition);

            // WHEN
            AtomicBoolean end = new AtomicBoolean();

            sbyte[] dataChunk = new sbyte[100];
            // one thread constantly writing to and rotating the channel
            AtomicInteger rotations = new AtomicInteger();

            System.Threading.CountdownEvent startSignal = new System.Threading.CountdownEvent(1);
            Future <Void> writeFuture = _t2.execute(ignored =>
            {
                ThreadLocalRandom random = ThreadLocalRandom.current();
                startSignal.Signal();
                while (!end.get())
                {
                    writer.Put(dataChunk, random.Next(1, dataChunk.Length));
                    if (logFile.RotationNeeded())
                    {
                        logFile.Rotate();
                        // Let's just close the gap to the reader so that it gets closer to the "hot zone"
                        // where the rotation happens.
                        writer.GetCurrentPosition(startPosition);
                        rotations.incrementAndGet();
                    }
                }
                return(null);
            });

            assertTrue(startSignal.await(10, SECONDS));
            // one thread reading through the channel
            long maxEndTime = currentTimeMillis() + _limitTime;
            int  reads      = 0;

            try
            {
                for ( ; currentTimeMillis() < maxEndTime && reads < LIMIT_READS && rotations.get() < LIMIT_ROTATIONS; reads++)
                {
                    using (ReadableLogChannel reader = logFile.GetReader(startPosition.NewPosition()))
                    {
                        Deplete(reader);
                    }
                }
            }
            finally
            {
                end.set(true);
                writeFuture.get();
            }

            // THEN simply getting here means this was successful
        }