//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: ReversedSingleFileTransactionCursor(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel channel, org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel> logEntryReader, boolean failOnCorruptedLogFiles, ReversedTransactionCursorMonitor monitor) throws java.io.IOException internal ReversedSingleFileTransactionCursor(ReadAheadLogChannel channel, LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader, bool failOnCorruptedLogFiles, ReversedTransactionCursorMonitor monitor) { this._channel = channel; this._failOnCorruptedLogFiles = failOnCorruptedLogFiles; this._monitor = monitor; // There's an assumption here: that the underlying channel can move in between calls and that the // transaction cursor will just happily read from the new position. this._transactionCursor = new PhysicalTransactionCursor <>(channel, logEntryReader); this._offsets = SketchOutTransactionStartOffsets(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private ReversedSingleFileTransactionCursor txCursor(boolean failOnCorruptedLogFiles) throws java.io.IOException private ReversedSingleFileTransactionCursor TxCursor(bool failOnCorruptedLogFiles) { ReadAheadLogChannel fileReader = ( ReadAheadLogChannel )_logFile.getReader(start(0), NO_MORE_CHANNELS); try { return(new ReversedSingleFileTransactionCursor(fileReader, new VersionAwareLogEntryReader <Org.Neo4j.Kernel.impl.transaction.log.ReadableClosablePositionAwareChannel>(), failOnCorruptedLogFiles, _monitor)); } catch (UnsupportedLogVersionException e) { fileReader.Dispose(); throw e; } }
//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: private int transactionCount() throws java.io.IOException private int TransactionCount() { return(AggregateLogData(version => { int counter = 0; LogVersionBridge bridge = channel => channel; LogVersionedStoreChannel versionedStoreChannel = _files.openForVersion(version); using (ReadableLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, bridge, 1000)) { using (PhysicalTransactionCursor <ReadableLogChannel> physicalTransactionCursor = new PhysicalTransactionCursor <ReadableLogChannel>(channel, new VersionAwareLogEntryReader <>())) { while (physicalTransactionCursor.Next()) { counter++; } } } return counter; })); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyTransactionsInLog(org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles, long fromTxId, long endTxId) throws java.io.IOException private void VerifyTransactionsInLog(LogFiles logFiles, long fromTxId, long endTxId) { long expectedTxId = fromTxId; LogVersionedStoreChannel versionedStoreChannel = logFiles.OpenForVersion(0); using (ReadableLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, Org.Neo4j.Kernel.impl.transaction.log.LogVersionBridge_Fields.NoMoreChannels, 1024)) { using (PhysicalTransactionCursor <ReadableLogChannel> txCursor = new PhysicalTransactionCursor <ReadableLogChannel>(channel, new VersionAwareLogEntryReader <>())) { while (txCursor.Next()) { CommittedTransactionRepresentation tx = txCursor.Get(); long txId = tx.CommitEntry.TxId; assertThat(expectedTxId, lessThanOrEqualTo(endTxId)); assertEquals(expectedTxId, txId); expectedTxId++; } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDetectAndPreventChannelReadingMultipleLogVersions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDetectAndPreventChannelReadingMultipleLogVersions() { // given WriteTransactions(1, 1, 1); _logFile.rotate(); WriteTransactions(1, 1, 1); // when try { using (ReadAheadLogChannel channel = ( ReadAheadLogChannel )_logFile.getReader(start(0))) { new ReversedSingleFileTransactionCursor(channel, new VersionAwareLogEntryReader <Org.Neo4j.Kernel.impl.transaction.log.ReadableClosablePositionAwareChannel>(), false, _monitor); fail("Should've failed"); } } catch (System.ArgumentException e) { // then good assertThat(e.Message, containsString("multiple log versions")); } }
/// <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()); }
//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); }
//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)); }