private bool Recover(File storeDir, LogFiles logFiles) { LifeSupport life = new LifeSupport(); RecoveryMonitor monitor = mock(typeof(RecoveryMonitor)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean recoveryRequired = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean recoveryRequired = new AtomicBoolean(); try { StorageEngine storageEngine = mock(typeof(StorageEngine)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel> reader = new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>(); LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogTailScanner tailScanner = GetTailScanner(logFiles, reader); TransactionMetadataCache metadataCache = new TransactionMetadataCache(); LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, metadataCache, reader, _monitors, false); CorruptedLogsTruncator logPruner = new CorruptedLogsTruncator(storeDir, logFiles, FileSystemRule.get()); life.add(new Recovery(new DefaultRecoveryServiceAnonymousInnerClass3(this, storageEngine, tailScanner, _transactionIdStore, txStore, _versionRepository, NO_MONITOR, recoveryRequired) , logPruner, _schemaLife, monitor, SilentProgressReporter.INSTANCE, false)); life.Start(); } finally { life.Shutdown(); } return(recoveryRequired.get()); }
//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); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAppendSingleTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAppendSingleTransaction() { // GIVEN when(_logFile.Writer).thenReturn(_channel); long txId = 15; when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(txId); TransactionAppender appender = Life.add(CreateTransactionAppender()); // WHEN TransactionRepresentation transaction = transaction(SingleCreateNodeCommand(0), new sbyte[] { 1, 2, 5 }, 2, 1, 12345, 4545, 12345 + 10); appender.Append(new TransactionToApply(transaction), _logAppendEvent); // THEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<ReadableLogChannel> logEntryReader = new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>(); LogEntryReader <ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableLogChannel>(); using (PhysicalTransactionCursor <ReadableLogChannel> reader = new PhysicalTransactionCursor <ReadableLogChannel>(_channel, logEntryReader)) { reader.Next(); TransactionRepresentation tx = reader.Get().TransactionRepresentation; assertArrayEquals(transaction.AdditionalHeader(), tx.AdditionalHeader()); assertEquals(transaction.MasterId, tx.MasterId); assertEquals(transaction.AuthorId, tx.AuthorId); assertEquals(transaction.TimeStarted, tx.TimeStarted); assertEquals(transaction.TimeCommitted, tx.TimeCommitted); assertEquals(transaction.LatestCommittedTxWhenStarted, tx.LatestCommittedTxWhenStarted); } }
//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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSupportConcurrentConsumptionOfSlaves() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSupportConcurrentConsumptionOfSlaves() { // Given LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); HighAvailabilitySlaves haSlaves = new HighAvailabilitySlaves(ClusterMembersOfSize(1000), mock(typeof(Cluster)), new DefaultSlaveFactory(NullLogProvider.Instance, new Monitors(), 42, Suppliers.singleton(logEntryReader)), new HostnamePort(null, 0)); // When ExecutorService executor = Executors.newFixedThreadPool(5); for (int i = 0; i < 5; i++) { executor.submit(SlavesConsumingRunnable(haSlaves)); } executor.shutdown(); executor.awaitTermination(30, SECONDS); // Then int slavesCount = 0; LifeSupport life = ReflectionUtil.getPrivateField(haSlaves, "life", typeof(LifeSupport)); foreach (Lifecycle lifecycle in life.LifecycleInstances) { if (lifecycle is Slave) { slavesCount++; } } assertEquals("Unexpected number of slaves", 1000 - 1, slavesCount); // One instance is master }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSerializeAndDeserializeTransactionRepresentation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSerializeAndDeserializeTransactionRepresentation() { // GIVEN PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(JustOneNode()); sbyte[] additionalHeader = "extra".GetBytes(); int masterId = 1; int authorId = 2; long timeStarted = 12345; long lastTxWhenStarted = 12; long timeCommitted = timeStarted + 10; transaction.SetHeader(additionalHeader, masterId, authorId, timeStarted, lastTxWhenStarted, timeCommitted, -1); Protocol.TransactionSerializer serializer = new Protocol.TransactionSerializer(transaction); ChannelBuffer buffer = new ChannelBufferWrapper(new InMemoryClosableChannel()); // WHEN serializing the transaction serializer.Write(buffer); // THEN deserializing the same transaction should yield the same data. // ... remember that this deserializer doesn't read the data source name string. Read it manually here assertEquals(NeoStoreDataSource.DEFAULT_DATA_SOURCE_NAME, Protocol.ReadString(buffer)); VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); TransactionRepresentation readTransaction = (new Protocol.TransactionRepresentationDeserializer(reader)).Read(buffer, ByteBuffer.allocate(1000)); assertArrayEquals(additionalHeader, readTransaction.AdditionalHeader()); assertEquals(masterId, readTransaction.MasterId); assertEquals(authorId, readTransaction.AuthorId); assertEquals(timeStarted, readTransaction.TimeStarted); assertEquals(lastTxWhenStarted, readTransaction.LatestCommittedTxWhenStarted); assertEquals(timeCommitted, readTransaction.TimeCommitted); }
internal static ICollection <StorageCommand> ExtractCommands(sbyte[] commandBytes) { ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes); NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer); LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), InvalidLogEntryHandler.STRICT); LogEntryCommand entryRead; IList <StorageCommand> commands = new LinkedList <StorageCommand>(); try { while ((entryRead = ( LogEntryCommand )reader.ReadLogEntry(channel)) != null) { commands.Add(entryRead.Command); } } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); // TODO: Handle or throw. } return(commands); }
/// <summary> /// Opens a <seealso cref="LogEntryCursor"/> for requested file /// </summary> /// <param name="fileSystem"> to find {@code file} in. </param> /// <param name="file"> file to open </param> /// <param name="readerLogVersionBridge"> log version bridge to use </param> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static org.neo4j.kernel.impl.transaction.log.LogEntryCursor openLogEntryCursor(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file, org.neo4j.kernel.impl.transaction.log.LogVersionBridge readerLogVersionBridge) throws java.io.IOException public static LogEntryCursor OpenLogEntryCursor(FileSystemAbstraction fileSystem, File file, LogVersionBridge readerLogVersionBridge) { LogVersionedStoreChannel channel = OpenVersionedChannel(fileSystem, file); ReadableLogChannel logChannel = new ReadAheadLogChannel(channel, readerLogVersionBridge); LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); return(new LogEntryCursor(logEntryReader, logChannel)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public ReadOnlyTransactionStore(org.neo4j.io.pagecache.PageCache pageCache, org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.layout.DatabaseLayout fromDatabaseLayout, org.neo4j.kernel.configuration.Config config, org.neo4j.kernel.monitoring.Monitors monitors) throws java.io.IOException public ReadOnlyTransactionStore(PageCache pageCache, FileSystemAbstraction fs, DatabaseLayout fromDatabaseLayout, Config config, Monitors monitors) { TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(); LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(fromDatabaseLayout, fs, pageCache).withLogEntryReader(logEntryReader).withConfig(config).build(); _physicalStore = new PhysicalLogicalTransactionStore(logFiles, transactionMetadataCache, logEntryReader, monitors, true); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.kernel.impl.storemigration.UpgradableDatabase getUpgradableDatabase(org.neo4j.kernel.impl.storemigration.StoreVersionCheck check) throws java.io.IOException private UpgradableDatabase GetUpgradableDatabase(StoreVersionCheck check) { VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(_workingDatabaseLayout.databaseDirectory(), _fs).build(); LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); return(new UpgradableDatabase(check, Standard.LATEST_RECORD_FORMATS, tailScanner)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private UpgradableDatabase getUpgradableDatabase(org.neo4j.io.pagecache.PageCache pageCache) throws java.io.IOException private UpgradableDatabase GetUpgradableDatabase(PageCache pageCache) { VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(_databaseLayout.databaseDirectory(), _fileSystem).withLogEntryReader(entryReader).build(); LogTailScanner tailScanner = new LogTailScanner(logFiles, entryReader, new Monitors()); return(new UpgradableDatabase(new StoreVersionCheck(pageCache), RecordFormats, tailScanner)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Setup() { FileSystem = FileSystemRule.get(); DatabaseLayout = TestDirectory.databaseLayout(); MigrationTestUtils.FindFormatStoreDirectoryForVersion(Version, DatabaseLayout.databaseDirectory()); VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(DatabaseLayout.databaseDirectory(), FileSystem).build(); TailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); }
/// <summary> /// Analyzes transactions found in log file(s) specified by {@code storeDirOrLogFile} calling methods on the supplied /// <seealso cref="Monitor"/> for each encountered data item. /// </summary> /// <param name="fileSystem"> <seealso cref="FileSystemAbstraction"/> to find the files on. </param> /// <param name="storeDirOrLogFile"> <seealso cref="File"/> pointing either to a directory containing transaction log files, or directly /// pointing to a single transaction log file to analyze. </param> /// <param name="invalidLogEntryHandler"> <seealso cref="InvalidLogEntryHandler"/> to pass in to the internal <seealso cref="LogEntryReader"/>. </param> /// <param name="monitor"> <seealso cref="Monitor"/> receiving call-backs for all <seealso cref="Monitor.transaction(LogEntry[]) transactions"/>, /// <seealso cref="Monitor.checkpoint(CheckPoint, LogPosition) checkpoints"/> and <seealso cref="Monitor.logFile(File, long) log file transitions"/> /// encountered during the analysis. </param> /// <exception cref="IOException"> on I/O error. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void analyze(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File storeDirOrLogFile, org.neo4j.kernel.impl.transaction.log.entry.InvalidLogEntryHandler invalidLogEntryHandler, Monitor monitor) throws java.io.IOException public static void Analyze(FileSystemAbstraction fileSystem, File storeDirOrLogFile, InvalidLogEntryHandler invalidLogEntryHandler, Monitor monitor) { File firstFile; LogVersionBridge bridge; ReadAheadLogChannel channel; LogEntryReader <ReadableClosablePositionAwareChannel> entryReader; LogPositionMarker positionMarker; if (storeDirOrLogFile.Directory) { // Use natural log version bridging if a directory is supplied //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build(); bridge = new ReaderLogVersionBridgeAnonymousInnerClass(logFiles, monitor, channel); long lowestLogVersion = logFiles.LowestLogVersion; if (lowestLogVersion < 0) { throw new System.InvalidOperationException(format("Transaction logs at '%s' not found.", storeDirOrLogFile)); } firstFile = logFiles.GetLogFileForVersion(lowestLogVersion); monitor.LogFile(firstFile, lowestLogVersion); } else { // Use no bridging, simply reading this single log file if a file is supplied firstFile = storeDirOrLogFile; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDirOrLogFile, fileSystem).build(); monitor.LogFile(firstFile, logFiles.GetLogVersion(firstFile)); bridge = NO_MORE_CHANNELS; } channel = new ReadAheadLogChannel(openVersionedChannel(fileSystem, firstFile), bridge); entryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), invalidLogEntryHandler); positionMarker = new LogPositionMarker(); using (TransactionLogEntryCursor cursor = new TransactionLogEntryCursor(new LogEntryCursor(entryReader, channel))) { channel.GetCurrentPosition(positionMarker); while (cursor.Next()) { LogEntry[] tx = cursor.Get(); if (tx.Length == 1 && tx[0].Type == CHECK_POINT) { monitor.Checkpoint(tx[0].As(), positionMarker.NewPosition()); } else { monitor.Transaction(tx); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCleanExistentLockSessionOnFinishOffChannel() public virtual void ShouldCleanExistentLockSessionOnFinishOffChannel() { Master master = mock(typeof(Master)); ConversationManager conversationManager = mock(typeof(ConversationManager)); LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); MasterServer masterServer = new MasterServer(master, mock(typeof(LogProvider)), mock(typeof(Server.Configuration)), mock(typeof(TxChecksumVerifier)), mock(typeof(ByteCounterMonitor)), mock(typeof(RequestMonitor)), conversationManager, logEntryReader); RequestContext requestContext = new RequestContext(1L, 1, 1, 0, 0L); masterServer.StopConversation(requestContext); Mockito.verify(conversationManager).stop(requestContext); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public boolean isRecoveryRequiredAt(org.neo4j.io.layout.DatabaseLayout databaseLayout) throws java.io.IOException public virtual bool IsRecoveryRequiredAt(DatabaseLayout databaseLayout) { // We need config to determine where the logical log files are if (!NeoStores.isStorePresent(_pageCache, databaseLayout)) { return(false); } LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(databaseLayout, _fs, _pageCache).withConfig(_config).withLogEntryReader(reader).build(); LogTailScanner tailScanner = new LogTailScanner(logFiles, reader, _monitors); return((new RecoveryStartInformationProvider(tailScanner, NO_MONITOR)).get().RecoveryRequired); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, java.util.List<Object> out) throws Exception protected internal override void Decode(ChannelHandlerContext ctx, ByteBuf msg, IList <object> @out) { NetworkReadableClosableChannelNetty4 logChannel = new NetworkReadableClosableChannelNetty4(msg); StoreId storeId = StoreIdMarshal.INSTANCE.unmarshal(logChannel); LogEntryReader <NetworkReadableClosableChannelNetty4> reader = new VersionAwareLogEntryReader <NetworkReadableClosableChannelNetty4>(new RecordStorageCommandReaderFactory(), InvalidLogEntryHandler.STRICT); PhysicalTransactionCursor <NetworkReadableClosableChannelNetty4> transactionCursor = new PhysicalTransactionCursor <NetworkReadableClosableChannelNetty4>(logChannel, reader); transactionCursor.Next(); CommittedTransactionRepresentation tx = transactionCursor.Get(); if (tx != null) { @out.Add(new TxPullResponse(storeId, tx)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSeeThatACleanDatabaseShouldNotRequireRecovery() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSeeThatACleanDatabaseShouldNotRequireRecovery() { File file = _logFiles.getLogFileForVersion(_logVersion); WriteSomeData(file, pair => { LogEntryWriter writer = pair.first(); Consumer <LogPositionMarker> consumer = pair.other(); LogPositionMarker marker = new LogPositionMarker(); // last committed tx consumer.accept(marker); writer.writeStartEntry(0, 1, 2L, 3L, new sbyte[0]); writer.writeCommitEntry(4L, 5L); // check point consumer.accept(marker); writer.writeCheckPointEntry(marker.newPosition()); return(true); }); LifeSupport life = new LifeSupport(); RecoveryMonitor monitor = mock(typeof(RecoveryMonitor)); try { StorageEngine storageEngine = mock(typeof(StorageEngine)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel> reader = new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>(); LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogTailScanner tailScanner = GetTailScanner(_logFiles, reader); TransactionMetadataCache metadataCache = new TransactionMetadataCache(); LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(_logFiles, metadataCache, reader, _monitors, false); CorruptedLogsTruncator logPruner = new CorruptedLogsTruncator(_storeDir, _logFiles, FileSystemRule.get()); life.add(new Recovery(new DefaultRecoveryServiceAnonymousInnerClass2(this, storageEngine, tailScanner, _transactionIdStore, txStore, _versionRepository, NO_MONITOR) , logPruner, _schemaLife, monitor, SilentProgressReporter.INSTANCE, false)); life.Start(); verifyZeroInteractions(monitor); } finally { life.Shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Setup() { FileSystem = FileSystemRule.get(); DatabaseLayout = TestDirectory.databaseLayout(); // doesn't matter which version we pick we are changing it to the wrong one... MigrationTestUtils.FindFormatStoreDirectoryForVersion(StandardV2_3.STORE_VERSION, DatabaseLayout.databaseDirectory()); changeVersionNumber(FileSystem, DatabaseLayout.file(NEOSTORE_FILENAME), Version); File metadataStore = DatabaseLayout.metadataStore(); PageCache pageCache = PageCacheRule.getPageCache(FileSystem); MetaDataStore.setRecord(pageCache, metadataStore, STORE_VERSION, MetaDataStore.versionStringToLong(Version)); VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(DatabaseLayout.databaseDirectory(), FileSystem).build(); TailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static void filterTransactionLogFile(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file, final LogHook<org.neo4j.kernel.impl.transaction.log.entry.LogEntry> filter) 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: internal static void FilterTransactionLogFile(FileSystemAbstraction fileSystem, File file, LogHook <LogEntry> filter) { filter.File(file); using (StoreChannel @in = fileSystem.Open(file, OpenMode.READ)) { LogHeader logHeader = readLogHeader(ByteBuffer.allocate(LOG_HEADER_SIZE), @in, true, file); PhysicalLogVersionedStoreChannel inChannel = new PhysicalLogVersionedStoreChannel(@in, logHeader.LogVersion, logHeader.LogFormatVersion); ReadableLogChannel inBuffer = new ReadAheadLogChannel(inChannel); LogEntryReader <ReadableLogChannel> entryReader = new VersionAwareLogEntryReader <ReadableLogChannel>(); LogEntry entry; while ((entry = entryReader.ReadLogEntry(inBuffer)) != null) { filter.test(entry); } } }
internal virtual TransactionRepresentation Read(NetworkReadableClosableChannelNetty4 channel) { try { LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), InvalidLogEntryHandler.STRICT); int authorId = channel.Int; int masterId = channel.Int; long latestCommittedTxWhenStarted = channel.Long; long timeStarted = channel.Long; long timeCommitted = channel.Long; int lockSessionId = channel.Int; int headerLength = channel.Int; sbyte[] header; if (headerLength == 0) { header = ExtraHeader; } else { header = new sbyte[headerLength]; } channel.Get(header, headerLength); LogEntryCommand entryRead; IList <StorageCommand> commands = new LinkedList <StorageCommand>(); while ((entryRead = ( LogEntryCommand )reader.ReadLogEntry(channel)) != null) { commands.Add(entryRead.Command); } PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands); tx.SetHeader(header, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, lockSessionId); return(tx); } catch (IOException e) { throw new Exception(e); } }
//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); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAppendCommittedTransactions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAppendCommittedTransactions() { // GIVEN when(_logFile.Writer).thenReturn(_channel); long nextTxId = 15; when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId); TransactionAppender appender = Life.add(new BatchingTransactionAppender(_logFiles, NO_ROTATION, _positionCache, _transactionIdStore, BYPASS, _databaseHealth)); // WHEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final byte[] additionalHeader = new byte[]{1, 2, 5}; sbyte[] additionalHeader = new sbyte[] { 1, 2, 5 }; const int masterId = 2; int authorId = 1; const long timeStarted = 12345; long latestCommittedTxWhenStarted = nextTxId - 5; long timeCommitted = timeStarted + 10; PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(SingleCreateNodeCommand(0)); transactionRepresentation.SetHeader(additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1); LogEntryStart start = new LogEntryStart(0, 0, 0L, latestCommittedTxWhenStarted, null, LogPosition.UNSPECIFIED); LogEntryCommit commit = new LogEntryCommit(nextTxId, 0L); CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit); appender.Append(new TransactionToApply(transactionRepresentation, transaction.CommitEntry.TxId), _logAppendEvent); // THEN LogEntryReader <ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableLogChannel>(); using (PhysicalTransactionCursor <ReadableLogChannel> reader = new PhysicalTransactionCursor <ReadableLogChannel>(_channel, logEntryReader)) { reader.Next(); TransactionRepresentation result = reader.Get().TransactionRepresentation; assertArrayEquals(additionalHeader, result.AdditionalHeader()); assertEquals(masterId, result.MasterId); assertEquals(authorId, result.AuthorId); assertEquals(timeStarted, result.TimeStarted); assertEquals(timeCommitted, result.TimeCommitted); assertEquals(latestCommittedTxWhenStarted, result.LatestCommittedTxWhenStarted); } }
private void VerifyCheckpointInLog(LogFiles logFiles, bool shouldExist) { LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), InvalidLogEntryHandler.STRICT); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.recovery.LogTailScanner logTailScanner = new org.neo4j.kernel.recovery.LogTailScanner(logFiles, logEntryReader, new org.neo4j.kernel.monitoring.Monitors()); LogTailScanner logTailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); LogTailScanner.LogTailInformation tailInformation = logTailScanner.TailInformation; if (!shouldExist) { assertNull(tailInformation.LastCheckPoint); return; } assertNotNull(tailInformation.LastCheckPoint); assertEquals(0, tailInformation.LastCheckPoint.LogPosition.LogVersion); assertEquals(LOG_HEADER_SIZE, tailInformation.LastCheckPoint.LogPosition.ByteOffset); assertTrue(tailInformation.CommitsAfterLastCheckpoint()); }
/// <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)); }
//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 WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void appendCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryVersion logVersion) throws java.io.IOException private void AppendCheckpoint(LogEntryVersion logVersion) { PageCache pageCache = _pageCacheRule.getPageCache(_fs); VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(_storeDirectory.databaseLayout(), _fs, pageCache).withLogEntryReader(logEntryReader).build(); LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); LogTailScanner.LogTailInformation tailInformation = tailScanner.TailInformation; using (Lifespan lifespan = new Lifespan(logFiles)) { FlushablePositionAwareChannel channel = logFiles.LogFile.Writer; LogPosition logPosition = tailInformation.LastCheckPoint.LogPosition; // Fake record channel.Put(logVersion.byteCode()).put(CHECK_POINT).putLong(logPosition.LogVersion).putLong(logPosition.ByteOffset); channel.PrepareForFlush().flush(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Parameterized.Parameters(name = "Migrate: {0}->{1}") public static Iterable<Object[]> data() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public static IEnumerable <object[]> Data() { FileSystemAbstraction fs = _fileSystemRule.get(); PageCache pageCache = _pageCacheRule.getPageCache(fs); TestDirectory testDirectory = TestDirectory.testDirectory(); testDirectory.PrepareDirectory(typeof(StoreMigrationIT), "migration"); DatabaseLayout databaseLayout = testDirectory.DatabaseLayout(); StoreVersionCheck storeVersionCheck = new StoreVersionCheck(pageCache); VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.DatabaseDirectory(), fs).withLogEntryReader(logEntryReader).build(); LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); IList <object[]> data = new List <object[]>(); List <RecordFormats> recordFormats = new List <RecordFormats>(); RecordFormatSelector.allFormats().forEach(f => addIfNotThere(f, recordFormats)); foreach (RecordFormats toFormat in recordFormats) { UpgradableDatabase upgradableDatabase = new UpgradableDatabase(storeVersionCheck, toFormat, tailScanner); foreach (RecordFormats fromFormat in recordFormats) { try { CreateDb(fromFormat, databaseLayout.DatabaseDirectory()); if (!upgradableDatabase.HasCurrentVersion(databaseLayout)) { upgradableDatabase.CheckUpgradable(databaseLayout); data.Add(new object[] { fromFormat, toFormat }); } } catch (Exception) { //This means that the combination is not migratable. } fs.DeleteRecursively(databaseLayout.DatabaseDirectory()); } } return(data); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void removeCheckPointFromTxLog(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File databaseDirectory) throws java.io.IOException public static void RemoveCheckPointFromTxLog(FileSystemAbstraction fileSystem, File databaseDirectory) { LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseDirectory, fileSystem).build(); LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); LogTailScanner.LogTailInformation logTailInformation = tailScanner.TailInformation; if (logTailInformation.CommitsAfterLastCheckpoint()) { // done already return; } // let's assume there is at least a checkpoint assertNotNull(logTailInformation.LastCheckPoint); LogPosition logPosition = logTailInformation.LastCheckPoint.LogPosition; File logFile = logFiles.GetLogFileForVersion(logPosition.LogVersion); fileSystem.Truncate(logFile, logPosition.ByteOffset); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldResolveMasterClientFactory() public virtual void ShouldResolveMasterClientFactory() { // Given LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); MasterClientResolver resolver = new MasterClientResolver(NullLogProvider.Instance, Org.Neo4j.com.storecopy.ResponseUnpacker_Fields.NoOpResponseUnpacker, mock(typeof(InvalidEpochExceptionHandler)), 1, 1, 1, 1024, Suppliers.singleton(logEntryReader)); LifeSupport life = new LifeSupport(); try { life.Start(); MasterClient masterClient1 = resolver.Instantiate("cluster://localhost", 44, null, new Monitors(), StoreId.DEFAULT, life); assertThat(masterClient1, instanceOf(typeof(MasterClient320))); } finally { life.Shutdown(); } IllegalProtocolVersionException illegalProtocolVersionException = new IllegalProtocolVersionException(MasterClient214.PROTOCOL_VERSION.ApplicationProtocol, MasterClient310.PROTOCOL_VERSION.ApplicationProtocol, "Protocol is too modern"); // When resolver.Handle(illegalProtocolVersionException); // Then life = new LifeSupport(); try { life.Start(); MasterClient masterClient2 = resolver.Instantiate("cluster://localhost", 55, null, new Monitors(), StoreId.DEFAULT, life); assertThat(masterClient2, instanceOf(typeof(MasterClient214))); } finally { life.Shutdown(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long parseAllTxLogs() throws java.io.IOException public virtual long ParseAllTxLogs() { // Initialize this txId to the BASE_TX_ID because if we don't find any tx log that means that // no transactions have been appended in this test and that getLastCommittedTransactionId() // will also return this constant. Why this is, is another question - but thread scheduling and // I/O spikes on some build machines can be all over the place and also the test duration is // configurable. long txId = Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID; using (FileSystemAbstraction fs = new DefaultFileSystemAbstraction(), ReadableLogChannel channel = OpenLogFile(fs, 0)) { LogEntryReader <ReadableLogChannel> reader = new VersionAwareLogEntryReader <ReadableLogChannel>(); LogEntry logEntry = reader.ReadLogEntry(channel); for ( ; logEntry != null; logEntry = reader.ReadLogEntry(channel)) { if (logEntry.Type == LogEntryByteCodes.TX_COMMIT) { txId = logEntry.As <LogEntryCommit>().TxId; } } } return(txId); }