//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.kernel.impl.transaction.log.ReadableLogChannel getReader(org.neo4j.kernel.impl.transaction.log.LogPosition position, org.neo4j.kernel.impl.transaction.log.LogVersionBridge logVersionBridge) throws java.io.IOException public override ReadableLogChannel GetReader(LogPosition position, LogVersionBridge logVersionBridge) { PhysicalLogVersionedStoreChannel logChannel = _logFiles.openForVersion(position.LogVersion); logChannel.Position(position.ByteOffset); return(new ReadAheadLogChannel(logChannel, logVersionBridge)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.kernel.impl.transaction.log.ReadableLogChannel openLogFile(org.neo4j.io.fs.FileSystemAbstraction fs, int version) throws java.io.IOException internal virtual ReadableLogChannel OpenLogFile(FileSystemAbstraction fs, int version) { LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(WorkingDirectory, fs).build(); PhysicalLogVersionedStoreChannel channel = logFiles.OpenForVersion(version); return(new ReadAheadLogChannel(channel, new ReaderLogVersionBridge(logFiles))); }
/// <summary> /// Rotates the current log file, continuing into next (version) log file. /// This method must be recovery safe, which means a crash at any point should be recoverable. /// Concurrent readers must also be able to parry for concurrent rotation. /// Concurrent writes will not be an issue since rotation and writing contends on the same monitor. /// /// Steps during rotation are: /// <ol> /// <li>1: Increment log version, <seealso cref="LogVersionRepository.incrementAndGetVersion()"/> (also flushes the store)</li> /// <li>2: Flush current log</li> /// <li>3: Create new log file</li> /// <li>4: Write header</li> /// </ol> /// /// Recovery: what happens if crash between: /// <ol> /// <li>1-2: New log version has been set, starting the writer will create the new log file idempotently. /// At this point there may have been half-written transactions in the previous log version, /// although they haven't been considered committed and so they will be truncated from log during recovery</li> /// <li>2-3: New log version has been set, starting the writer will create the new log file idempotently. /// At this point there may be complete transactions in the previous log version which may not have been /// acknowledged to be committed back to the user, but will be considered committed anyway.</li> /// <li>3-4: New log version has been set, starting the writer will see that the new file exists and /// will be forgiving when trying to read the header of it, so that if it isn't complete a fresh /// header will be set.</li> /// </ol> /// /// Reading: what happens when rotation is between: /// <ol> /// <li>1-2: Reader bridge will see that there's a new version (when asking <seealso cref="LogVersionRepository"/> /// and try to open it. The log file doesn't exist yet though. The bridge can parry for this by catching /// <seealso cref="FileNotFoundException"/> and tell the reader that the stream has ended</li> /// <li>2-3: Same as (1-2)</li> /// <li>3-4: Here the new log file exists, but the header may not be fully written yet. /// the reader will fail when trying to read the header since it's reading it strictly and bridge /// catches that exception, treating it the same as if the file didn't exist.</li> /// </ol> /// </summary> /// <param name="currentLog"> current <seealso cref="LogVersionedStoreChannel channel"/> to flush and close. </param> /// <returns> the channel of the newly opened/created log file. </returns> /// <exception cref="IOException"> if an error regarding closing or opening log files occur. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel rotate(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel currentLog) throws java.io.IOException private PhysicalLogVersionedStoreChannel Rotate(LogVersionedStoreChannel currentLog) { /* * The store is now flushed. If we fail now the recovery code will open the * current log file and replay everything. That's unnecessary but totally ok. */ long newLogVersion = _logVersionRepository.incrementAndGetVersion(); /* * Rotation can happen at any point, although not concurrently with an append, * although an append may have (most likely actually) left at least some bytes left * in the buffer for future flushing. Flushing that buffer now makes the last appended * transaction complete in the log we're rotating away. Awesome. */ _writer.prepareForFlush().flush(); /* * The log version is now in the store, flushed and persistent. If we crash * now, on recovery we'll attempt to open the version we're about to create * (but haven't yet), discover it's not there. That will lead to creating * the file, setting the header and continuing. * We using committing transaction id as a source of last transaction id here since * we can have transactions that are not yet published as committed but were already stored * into transaction log that was just rotated. */ PhysicalLogVersionedStoreChannel newLog = _logFiles.createLogChannelForVersion(newLogVersion, OpenMode.READ_WRITE, _context.committingTransactionId); currentLog.close(); return(newLog); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public synchronized void rotate() throws java.io.IOException public override void Rotate() { lock (this) { _channel = Rotate(_channel); _writer.Channel = _channel; } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void init() throws java.io.IOException public override void Init() { _logVersionRepository = _context.LogVersionRepository; // Make sure at least a bare bones log file is available before recovery long lastLogVersionUsed = this._logVersionRepository.CurrentLogVersion; _channel = _logFiles.createLogChannelForVersion(lastLogVersionUsed, OpenMode.READ_WRITE, _context.getLastCommittedTransactionId); _channel.close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void start() throws java.io.IOException public override void Start() { // Recovery has taken place before this, so the log file has been truncated to last known good tx // Just read header and move to the end long lastLogVersionUsed = _logVersionRepository.CurrentLogVersion; _channel = _logFiles.createLogChannelForVersion(lastLogVersionUsed, OpenMode.READ_WRITE, _context.getLastCommittedTransactionId); // Move to the end _channel.position(_channel.size()); _writer = new PositionAwarePhysicalFlushableChannel(_channel); }
//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 void verifyTransactionLogs(java.io.File txDirectory, java.io.File storeDir) throws java.io.IOException private void VerifyTransactionLogs(File txDirectory, File storeDir) { FileSystemAbstraction fileSystem = FileSystemRule.get(); LogFiles storeDirLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDir, fileSystem).build(); assertFalse(storeDirLogs.VersionExists(0)); LogFiles txDirectoryLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(txDirectory, fileSystem).build(); assertTrue(txDirectoryLogs.VersionExists(0)); using (PhysicalLogVersionedStoreChannel physicalLogVersionedStoreChannel = txDirectoryLogs.OpenForVersion(0)) { assertThat(physicalLogVersionedStoreChannel.Size(), greaterThan(0L)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void writeSomeData(java.io.File file, org.neo4j.helpers.collection.Visitor<org.neo4j.helpers.collection.Pair<org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter,System.Action<org.neo4j.kernel.impl.transaction.log.LogPositionMarker>>,java.io.IOException> visitor) throws java.io.IOException private void WriteSomeData(File file, Visitor <Pair <LogEntryWriter, System.Action <LogPositionMarker> >, IOException> visitor) { using (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(FileSystemRule.get().open(file, OpenMode.READ_WRITE), _logVersion, CURRENT_LOG_VERSION), PositionAwarePhysicalFlushableChannel writableLogChannel = new PositionAwarePhysicalFlushableChannel(versionedStoreChannel)) { writeLogHeader(writableLogChannel, _logVersion, 2L); System.Action <LogPositionMarker> consumer = marker => { try { writableLogChannel.GetCurrentPosition(marker); } catch (IOException e) { throw new Exception(e); } }; LogEntryWriter first = new LogEntryWriter(writableLogChannel); visitor.Visit(Pair.of(first, consumer)); } }