//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTruncateLogAfterLastCompleteTransactionAfterSuccessfulRecovery() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTruncateLogAfterLastCompleteTransactionAfterSuccessfulRecovery() { // GIVEN File file = _logFiles.getLogFileForVersion(_logVersion); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.LogPositionMarker marker = new org.neo4j.kernel.impl.transaction.log.LogPositionMarker(); LogPositionMarker marker = new LogPositionMarker(); WriteSomeData(file, pair => { LogEntryWriter writer = pair.first(); Consumer <LogPositionMarker> consumer = pair.other(); // last committed tx writer.writeStartEntry(0, 1, 2L, 3L, new sbyte[0]); writer.writeCommitEntry(4L, 5L); // incomplete tx consumer.accept(marker); // <-- marker has the last good position writer.writeStartEntry(0, 1, 5L, 4L, new sbyte[0]); return(true); }); // WHEN bool recoveryRequired = Recover(_storeDir, _logFiles); // THEN assertTrue(recoveryRequired); assertEquals(marker.ByteOffset, file.length()); }
//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(); } }
private void InitializeInstanceFields() { _writer = new LogEntryWriter(_inMemoryChannel); NeoStoreRecord after = new NeoStoreRecord(); after.NextProp = 42; _permutations[typeof(Command.NeoStoreCommand)] = new Command[] { new Command.NeoStoreCommand(new NeoStoreRecord(), after) }; _permutations[typeof(Command.NodeCommand)] = new Command[] { new Command.NodeCommand(new NodeRecord(12L, false, 13L, 13L), new NodeRecord(0, false, 0, 0)) }; _permutations[typeof(Command.RelationshipCommand)] = new Command[] { new Command.RelationshipCommand(new RelationshipRecord(1L), new RelationshipRecord(1L, 2L, 3L, 4)) }; _permutations[typeof(Command.PropertyCommand)] = new Command[] { new Command.PropertyCommand(new PropertyRecord(1, new NodeRecord(12L, false, 13L, 13)), new PropertyRecord(1, new NodeRecord(12L, false, 13L, 13))) }; _permutations[typeof(Command.RelationshipGroupCommand)] = new Command[] { new Command.LabelTokenCommand(new LabelTokenRecord(1), CreateLabelTokenRecord(1)) }; _permutations[typeof(Command.SchemaRuleCommand)] = new Command[] { new Command.SchemaRuleCommand(singletonList(dynamicRecord(1L, false, true, -1L, 1, "hello".GetBytes())), singletonList(dynamicRecord(1L, true, true, -1L, 1, "hello".GetBytes())), TestIndexDescriptorFactory.forLabel(3, 4).withId(1)) }; _permutations[typeof(Command.RelationshipTypeTokenCommand)] = new Command[] { new Command.RelationshipTypeTokenCommand(new RelationshipTypeTokenRecord(1), CreateRelationshipTypeTokenRecord(1)) }; _permutations[typeof(Command.PropertyKeyTokenCommand)] = new Command[] { new Command.PropertyKeyTokenCommand(new PropertyKeyTokenRecord(1), CreatePropertyKeyTokenRecord(1)) }; _permutations[typeof(Command.LabelTokenCommand)] = new Command[] { new Command.LabelTokenCommand(new LabelTokenRecord(1), CreateLabelTokenRecord(1)) }; // Index commands IndexCommand.AddRelationshipCommand addRelationshipCommand = new IndexCommand.AddRelationshipCommand(); addRelationshipCommand.Init(1, 1L, 12345, "some value", 1, 1); _permutations[typeof(IndexCommand.AddRelationshipCommand)] = new Command[] { addRelationshipCommand }; IndexCommand.CreateCommand createCommand = new IndexCommand.CreateCommand(); createCommand.Init(1, IndexEntityType.Relationship.id(), MapUtil.stringMap("string1", "string 2")); _permutations[typeof(IndexCommand.CreateCommand)] = new Command[] { createCommand }; IndexCommand.AddNodeCommand addCommand = new IndexCommand.AddNodeCommand(); addCommand.Init(1234, 122L, 2, "value"); _permutations[typeof(IndexCommand.AddNodeCommand)] = new Command[] { addCommand }; IndexCommand.DeleteCommand deleteCommand = new IndexCommand.DeleteCommand(); deleteCommand.Init(1, IndexEntityType.Relationship.id()); _permutations[typeof(IndexCommand.DeleteCommand)] = new Command[] { deleteCommand }; IndexCommand.RemoveCommand removeCommand = new IndexCommand.RemoveCommand(); removeCommand.Init(1, IndexEntityType.Node.id(), 126, (sbyte)3, "the value"); _permutations[typeof(IndexCommand.RemoveCommand)] = new Command[] { removeCommand }; IndexDefineCommand indexDefineCommand = new IndexDefineCommand(); indexDefineCommand.Init(ObjectIntHashMap.newWithKeysValues("string1", 45, "key1", 2), ObjectIntHashMap.newWithKeysValues("string", 2)); _permutations[typeof(IndexDefineCommand)] = new Command[] { indexDefineCommand }; // Counts commands _permutations[typeof(Command.NodeCountsCommand)] = new Command[] { new Command.NodeCountsCommand(42, 11) }; _permutations[typeof(Command.RelationshipCountsCommand)] = new Command[] { new Command.RelationshipCountsCommand(17, 2, 13, -2) }; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTellTransactionIdStoreAfterSuccessfulRecovery() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTellTransactionIdStoreAfterSuccessfulRecovery() { // GIVEN File file = _logFiles.getLogFileForVersion(_logVersion); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.LogPositionMarker marker = new org.neo4j.kernel.impl.transaction.log.LogPositionMarker(); LogPositionMarker marker = new LogPositionMarker(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final byte[] additionalHeaderData = new byte[0]; sbyte[] additionalHeaderData = new sbyte[0]; const int masterId = 0; const int authorId = 1; const long transactionId = 4; const long commitTimestamp = 5; WriteSomeData(file, pair => { LogEntryWriter writer = pair.first(); Consumer <LogPositionMarker> consumer = pair.other(); // last committed tx writer.writeStartEntry(masterId, authorId, 2L, 3L, additionalHeaderData); writer.writeCommitEntry(transactionId, commitTimestamp); consumer.accept(marker); return(true); }); // WHEN bool recoveryRequired = Recover(_storeDir, _logFiles); // THEN assertTrue(recoveryRequired); long[] lastClosedTransaction = _transactionIdStore.LastClosedTransaction; assertEquals(transactionId, lastClosedTransaction[0]); assertEquals(LogEntryStart.checksum(additionalHeaderData, masterId, authorId), _transactionIdStore.LastCommittedTransaction.checksum()); assertEquals(commitTimestamp, _transactionIdStore.LastCommittedTransaction.commitTimestamp()); assertEquals(_logVersion, lastClosedTransaction[1]); assertEquals(marker.ByteOffset, lastClosedTransaction[2]); }
//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)); } }
/// <summary>Dequeues all log info instances from the queue, prepares the text line, and writes to the sink.</summary> private void FlushLogEntryQueue() { if (m_LogEntryQueue.Count == 0) { return; } FileInfo fileinfo = new FileInfo(m_FilePath); if (fileinfo.Length > 1_048_576 * LoggerOptions.MaxFileSizeInMB) { InitializeSink(); fileinfo = new FileInfo(m_FilePath); } using var fs = fileinfo.Open(FileMode.Append, FileAccess.Write, FileShare.ReadWrite); using var sw = new StreamWriter(fs); while (m_LogEntryQueue.TryDequeue(out LogEntry Info)) { var line = LogEntryWriter.GenerateLogEntryLine(Info); sw.Write(line.ToString()); } sw.Flush(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void doNotTruncateCheckpointsAfterLastTransaction() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void DoNotTruncateCheckpointsAfterLastTransaction() { File file = _logFiles.getLogFileForVersion(_logVersion); LogPositionMarker marker = new LogPositionMarker(); WriteSomeData(file, pair => { LogEntryWriter writer = pair.first(); writer.writeStartEntry(1, 1, 1L, 1L, ArrayUtils.EMPTY_BYTE_ARRAY); writer.writeCommitEntry(1L, 2L); writer.writeCheckPointEntry(new LogPosition(_logVersion, LogHeader.LOG_HEADER_SIZE)); writer.writeCheckPointEntry(new LogPosition(_logVersion, LogHeader.LOG_HEADER_SIZE)); writer.writeCheckPointEntry(new LogPosition(_logVersion, LogHeader.LOG_HEADER_SIZE)); writer.writeCheckPointEntry(new LogPosition(_logVersion, LogHeader.LOG_HEADER_SIZE)); Consumer <LogPositionMarker> other = pair.other(); other.accept(marker); return(true); }); assertTrue(Recover(_storeDir, _logFiles)); assertEquals(marker.ByteOffset, file.length()); }
public CommittedTransactionSerializer(FlushableChannel networkFlushableChannel) { this._writer = new LogEntryWriter(networkFlushableChannel); }
/// <summary>For file based loggers that include a header row this method writes the first line to the sink</summary> private void WriteLogHeader() { File.WriteAllText(m_FilePath, LogEntryWriter.GenerateLogHeaderLine().ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRecoverExistingData() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRecoverExistingData() { 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); LogPosition lastCommittedTxPosition = marker.newPosition(); writer.writeStartEntry(0, 1, 2L, 3L, new sbyte[0]); _lastCommittedTxStartEntry = new LogEntryStart(0, 1, 2L, 3L, new sbyte[0], lastCommittedTxPosition); writer.writeCommitEntry(4L, 5L); _lastCommittedTxCommitEntry = new LogEntryCommit(4L, 5L); // check point pointing to the previously committed transaction writer.writeCheckPointEntry(lastCommittedTxPosition); _expectedCheckPointEntry = new CheckPoint(lastCommittedTxPosition); // tx committed after checkpoint consumer.accept(marker); writer.writeStartEntry(0, 1, 6L, 4L, new sbyte[0]); _expectedStartEntry = new LogEntryStart(0, 1, 6L, 4L, new sbyte[0], marker.newPosition()); writer.writeCommitEntry(5L, 7L); _expectedCommitEntry = new LogEntryCommit(5L, 7L); return(true); }); 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 DefaultRecoveryServiceAnonymousInnerClass(this, storageEngine, tailScanner, _transactionIdStore, txStore, _versionRepository, NO_MONITOR, recoveryRequired) , logPruner, _schemaLife, monitor, SilentProgressReporter.INSTANCE, false)); life.Start(); InOrder order = inOrder(monitor); order.verify(monitor, times(1)).recoveryRequired(any(typeof(LogPosition))); order.verify(monitor, times(1)).recoveryCompleted(2); assertTrue(recoveryRequired.get()); } finally { life.Shutdown(); } }
private LogCreator LogFile(params Entry[] entries) { return((logVersion, positions) => { try { AtomicLong lastTxId = new AtomicLong(); _logVersionRepository.CurrentLogVersion = logVersion; LifeSupport logFileLife = new LifeSupport(); logFileLife.start(); logFileLife.add(_logFiles); LogFile logFile = _logFiles.LogFile; try { FlushablePositionAwareChannel writeChannel = logFile.Writer; LogPositionMarker positionMarker = new LogPositionMarker(); LogEntryWriter writer = new LogEntryWriter(writeChannel); foreach (Entry entry in entries) { LogPosition currentPosition = writeChannel.getCurrentPosition(positionMarker).newPosition(); positions.put(entry, currentPosition); if (entry is StartEntry) { writer.writeStartEntry(0, 0, 0, 0, new sbyte[0]); } else if (entry is CommitEntry) { CommitEntry commitEntry = ( CommitEntry )entry; writer.writeCommitEntry(commitEntry.TxId, 0); lastTxId.set(commitEntry.TxId); } else if (entry is CheckPointEntry) { CheckPointEntry checkPointEntry = ( CheckPointEntry )entry; Entry target = checkPointEntry.WithPositionOfEntry; LogPosition logPosition = target != null?positions.get(target) : currentPosition; Debug.Assert(logPosition != null, "No registered log position for " + target); writer.writeCheckPointEntry(logPosition); } else if (entry is PositionEntry) { // Don't write anything, this entry is just for registering a position so that // another CheckPointEntry can refer to it } else { throw new System.ArgumentException("Unknown entry " + entry); } } } finally { logFileLife.shutdown(); } } catch (IOException e) { throw new UncheckedIOException(e); } }); }