Esempio n. 1
0
//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());
        }
Esempio n. 2
0
//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();
            }
        }
Esempio n. 3
0
//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]);
        }
Esempio n. 4
0
//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());
        }
Esempio n. 5
0
//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();
            }
        }
Esempio n. 6
0
        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);
                }
            });
        }