//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToRepeatedlyReadWrittenValues() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToRepeatedlyReadWrittenValues() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given segment.Write(0, _entry1); segment.Write(1, _entry2); segment.Write(2, _entry3); segment.Flush(); for (int i = 0; i < 3; i++) { // when IOCursor <EntryRecord> cursor = segment.GetCursor(0); // then assertTrue(cursor.next()); assertEquals(_entry1, cursor.get().logEntry()); assertTrue(cursor.next()); assertEquals(_entry2, cursor.get().logEntry()); assertTrue(cursor.next()); assertEquals(_entry3, cursor.get().logEntry()); assertFalse(cursor.next()); cursor.close(); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata getMetadataFor(long transactionId) throws java.io.IOException public override TransactionMetadata GetMetadataFor(long transactionId) { if (transactionId <= BASE_TX_ID) { return(_metadataForEmptyStore); } TransactionMetadata transactionMetadata = _transactionMetadataCache.getTransactionMetadata(transactionId); if (transactionMetadata == null) { using (IOCursor <CommittedTransactionRepresentation> cursor = GetTransactions(transactionId)) { while (cursor.next()) { CommittedTransactionRepresentation tx = cursor.get(); LogEntryCommit commitEntry = tx.CommitEntry; long committedTxId = commitEntry.TxId; long timeWritten = commitEntry.TimeWritten; TransactionMetadata metadata = _transactionMetadataCache.cacheTransactionMetadata(committedTxId, tx.StartEntry.StartPosition, tx.StartEntry.MasterId, tx.StartEntry.LocalId, LogEntryStart.checksum(tx.StartEntry), timeWritten); if (committedTxId == transactionId) { transactionMetadata = metadata; } } } if (transactionMetadata == null) { throw new NoSuchTransactionException(transactionId); } } return(transactionMetadata); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void extractTransactions(long startingAtTransactionId, org.neo4j.helpers.collection.Visitor<org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation,Exception> visitor) throws Exception protected internal virtual void ExtractTransactions(long startingAtTransactionId, Visitor <CommittedTransactionRepresentation, Exception> visitor) { using (IOCursor <CommittedTransactionRepresentation> cursor = TransactionStore.getTransactions(startingAtTransactionId)) { while (cursor.next() && !visitor.Visit(cursor.get())) { } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public Object readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception public override object ReadChunk(ByteBufAllocator allocator) { Debug.Assert(!_endOfInput); if (_pending != null) { if (_noMoreTransactions) { _endOfInput = true; } return(ConsumePending()); } else if (_noMoreTransactions) { /* finalization should always have a last ending message */ throw new System.InvalidOperationException(); } else if (_txCursor.next()) { Debug.Assert(_pending == null); CommittedTransactionRepresentation tx = _txCursor.get(); _lastTxId = tx.CommitEntry.TxId; if (_lastTxId != _expectedTxId) { string msg = format("Transaction cursor out of order. Expected %d but was %d", _expectedTxId, _lastTxId); throw new System.InvalidOperationException(msg); } _expectedTxId++; _pending = new TxPullResponse(_storeId, tx); return(ResponseMessageType.TX); } else { Debug.Assert(_pending == null); _noMoreTransactions = true; _protocol.expect(CatchupServerProtocol.State.MESSAGE_TYPE); CatchupResult result; if (_lastTxId >= _txIdPromise) { result = SUCCESS_END_OF_STREAM; } else { result = E_TRANSACTION_PRUNED; _log.warn("Transaction cursor fell short. Expected at least %d but only got to %d.", _txIdPromise, _lastTxId); } _pending = new TxStreamFinishedResponse(result, _lastTxId); return(ResponseMessageType.TX_STREAM_FINISHED); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public boolean next() throws java.io.IOException public override bool Next() { _transaction.Clear(); LogEntry entry; while ( @delegate.next() ) { entry = @delegate.get(); _transaction.Add( entry ); if ( IsBreakPoint( entry ) ) { return true; } } return _transaction.Count > 0; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public boolean next() throws java.io.IOException public override bool Next() { bool hasNext = _inner.next(); if (hasNext) { _current.set(_inner.get().logEntry()); _index++; } else { _current.invalidate(); } return(hasNext); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private long applyTransactions(java.io.File fromPath, org.neo4j.kernel.internal.GraphDatabaseAPI toDb, org.neo4j.kernel.configuration.Config toConfig, long fromTxExclusive, long toTxInclusive, java.io.PrintStream out) throws Exception private long ApplyTransactions( File fromPath, GraphDatabaseAPI toDb, Config toConfig, long fromTxExclusive, long toTxInclusive, PrintStream @out ) { DependencyResolver resolver = toDb.DependencyResolver; TransactionRepresentationCommitProcess commitProcess = new TransactionRepresentationCommitProcess( resolver.ResolveDependency( typeof( TransactionAppender ) ), resolver.ResolveDependency( typeof( StorageEngine ) ) ); LifeSupport life = new LifeSupport(); try { using ( DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = createInitialisedScheduler(), PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem, jobScheduler) ) { LogicalTransactionStore source = life.Add( new ReadOnlyTransactionStore( pageCache, fileSystem, DatabaseLayout.of( fromPath ), Config.defaults(), new Monitors() ) ); life.Start(); long lastAppliedTx = fromTxExclusive; // Some progress if there are more than a couple of transactions to apply ProgressListener progress = toTxInclusive - fromTxExclusive >= 100 ? textual( @out ).singlePart( "Application progress", toTxInclusive - fromTxExclusive ) : Org.Neo4j.Helpers.progress.ProgressListener_Fields.None; using ( IOCursor<CommittedTransactionRepresentation> cursor = source.GetTransactions( fromTxExclusive + 1 ) ) { while ( cursor.next() ) { CommittedTransactionRepresentation transaction = cursor.get(); TransactionRepresentation transactionRepresentation = transaction.TransactionRepresentation; try { commitProcess.Commit( new TransactionToApply( transactionRepresentation ), NULL, EXTERNAL ); progress.Add( 1 ); } //JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#: //ORIGINAL LINE: catch (final Throwable e) catch ( Exception e ) { Console.Error.WriteLine( "ERROR applying transaction " + transaction.CommitEntry.TxId ); throw e; } lastAppliedTx = transaction.CommitEntry.TxId; if ( lastAppliedTx == toTxInclusive ) { break; } } } return lastAppliedTx; } } finally { life.Shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToWriteAndRead() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToWriteAndRead() { using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _segmentHeader)) { // given segment.Write(0, _entry1); segment.Flush(); // when IOCursor <EntryRecord> cursor = segment.GetCursor(0); // then assertTrue(cursor.next()); assertEquals(_entry1, cursor.get().logEntry()); cursor.close(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public boolean next() throws java.io.IOException public override bool Next() { _currentIndex++; if (_segmentRange == null || _currentIndex >= _limit) { if (!NextSegment()) { return(false); } } if (_cursor.next()) { _currentRecord.set(_cursor.get()); return(true); } _currentRecord.invalidate(); return(false); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private int dump(String filenameOrDirectory, java.io.PrintStream out) throws java.io.IOException, DamagedLogStorageException, DisposedException private int Dump(string filenameOrDirectory, PrintStream @out) { LogProvider logProvider = NullLogProvider.Instance; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] logsFound = {0}; int[] logsFound = new int[] { 0 }; FileNames fileNames = new FileNames(new File(filenameOrDirectory)); ReaderPool readerPool = new ReaderPool(0, logProvider, fileNames, _fileSystem, Clocks.systemClock()); RecoveryProtocol recoveryProtocol = new RecoveryProtocol(_fileSystem, fileNames, readerPool, _marshal, logProvider); Segments segments = recoveryProtocol.Run().Segments; segments.Visit(segment => { logsFound[0]++; @out.println("=== " + segment.Filename + " ==="); SegmentHeader header = segment.header(); @out.println(header.ToString()); try { using (IOCursor <EntryRecord> cursor = segment.getCursor(header.PrevIndex() + 1)) { while (cursor.next()) { @out.println(cursor.get().ToString()); } } } catch (Exception e) when(e is DisposedException || e is IOException) { e.printStackTrace(); Environment.Exit(-1); return(true); } return(false); }); return(logsFound[0]); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("SameParameterValue") private void testTransactionStream(int firstTxId, int lastTxId, int txIdPromise, org.neo4j.causalclustering.catchup.CatchupResult expectedResult) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: private void TestTransactionStream(int firstTxId, int lastTxId, int txIdPromise, CatchupResult expectedResult) { ChunkedTransactionStream txStream = new ChunkedTransactionStream(NullLog.Instance, _storeId, firstTxId, txIdPromise, _cursor, _protocol); IList <bool> more = new List <bool>(); IList <CommittedTransactionRepresentation> txs = new List <CommittedTransactionRepresentation>(); for (int txId = firstTxId; txId <= lastTxId; txId++) { more.Add(true); txs.Add(Tx(txId)); } txs.Add(null); more.Add(false); when(_cursor.next()).thenAnswer(returnsElementsOf(more)); when(_cursor.get()).thenAnswer(returnsElementsOf(txs)); // when/then assertFalse(txStream.EndOfInput); for (int txId = firstTxId; txId <= lastTxId; txId++) { assertEquals(ResponseMessageType.TX, txStream.ReadChunk(_allocator)); assertEquals(new TxPullResponse(_storeId, txs[txId - firstTxId]), txStream.ReadChunk(_allocator)); } assertEquals(ResponseMessageType.TX_STREAM_FINISHED, txStream.ReadChunk(_allocator)); assertEquals(new TxStreamFinishedResponse(expectedResult, lastTxId), txStream.ReadChunk(_allocator)); assertTrue(txStream.EndOfInput); // when txStream.Close(); // then verify(_cursor).close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void readLog(org.neo4j.cursor.IOCursor<org.neo4j.kernel.impl.transaction.log.entry.LogEntry> cursor, final long fromLine, final long toLine, final java.util.regex.Pattern pattern) 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: private static void ReadLog(IOCursor <LogEntry> cursor, long fromLine, long toLine, Pattern pattern) { TimeZone timeZone = TimeZone.Default; long lineCount = -1; while (cursor.next()) { LogEntry logEntry = cursor.get(); lineCount++; if (lineCount > toLine) { return; } if (lineCount < fromLine) { continue; } string str = logEntry.ToString(timeZone); if (pattern == null || pattern.matcher(str).find()) { _console.printf("%s%n", str); } } }
public override T Get() { return(@delegate.get()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: State run() throws java.io.IOException, DamagedLogStorageException, DisposedException internal virtual State Run() { State state = new State(); SortedDictionary <long, File> files = _fileNames.getAllFiles(_fileSystem, _log); if (Files.SetOfKeyValuePairs().Empty) { state.Segments = new Segments(_fileSystem, _fileNames, _readerPool, emptyList(), _contentMarshal, _logProvider, -1); state.Segments.rotate(-1, -1, -1); state.Terms = new Terms(-1, -1); return(state); } IList <SegmentFile> segmentFiles = new List <SegmentFile>(); SegmentFile segment = null; long expectedVersion = Files.firstKey(); bool mustRecoverLastHeader = false; bool skip = true; // the first file is treated the same as a skip foreach (KeyValuePair <long, File> entry in Files.SetOfKeyValuePairs()) { long fileNameVersion = entry.Key; File file = entry.Value; SegmentHeader header; CheckVersionSequence(fileNameVersion, expectedVersion); try { header = LoadHeader(_fileSystem, file); CheckVersionMatches(header.Version(), fileNameVersion); } catch (EndOfStreamException e) { if (Files.lastKey() != fileNameVersion) { throw new DamagedLogStorageException(e, "Intermediate file with incomplete or no header found: %s", file); } else if (Files.Count == 1) { throw new DamagedLogStorageException(e, "Single file with incomplete or no header found: %s", file); } /* Last file header must be recovered by scanning next-to-last file and writing a new header based on that. */ mustRecoverLastHeader = true; break; } segment = new SegmentFile(_fileSystem, file, _readerPool, fileNameVersion, _contentMarshal, _logProvider, header); segmentFiles.Add(segment); if (segment.Header().prevIndex() != segment.Header().prevFileLastIndex()) { _log.info(format("Skipping from index %d to %d.", segment.Header().prevFileLastIndex(), segment.Header().prevIndex() + 1)); skip = true; } if (skip) { state.PrevIndex = segment.Header().prevIndex(); state.PrevTerm = segment.Header().prevTerm(); skip = false; } expectedVersion++; } Debug.Assert(segment != null); state.AppendIndex = segment.Header().prevIndex(); state.Terms = new Terms(segment.Header().prevIndex(), segment.Header().prevTerm()); using (IOCursor <EntryRecord> cursor = segment.GetCursor(segment.Header().prevIndex() + 1)) { while (cursor.next()) { EntryRecord entry = cursor.get(); state.AppendIndex = entry.LogIndex(); state.Terms.append(state.AppendIndex, entry.LogEntry().term()); } } if (mustRecoverLastHeader) { SegmentHeader header = new SegmentHeader(state.AppendIndex, expectedVersion, state.AppendIndex, state.Terms.latest()); _log.warn("Recovering last file based on next-to-last file. " + header); File file = _fileNames.getForVersion(expectedVersion); WriteHeader(_fileSystem, file, header); segment = new SegmentFile(_fileSystem, file, _readerPool, expectedVersion, _contentMarshal, _logProvider, header); segmentFiles.Add(segment); } state.Segments = new Segments(_fileSystem, _fileNames, _readerPool, segmentFiles, _contentMarshal, _logProvider, segment.Header().version()); return(state); }