//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void correctLastAppliedToPreviousLogTransactionInHeaderOnLogFileRotation() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CorrectLastAppliedToPreviousLogTransactionInHeaderOnLogFileRotation()
        {
            LogFiles logFiles = GetLogFiles(_logVersionRepository, _transactionIdStore);

            Life.add(logFiles);
            DatabaseHealth databaseHealth = DatabaseHealth;

            LogRotationImpl                  logRotation = new LogRotationImpl(_monitors.newMonitor(typeof(Org.Neo4j.Kernel.impl.transaction.log.rotation.LogRotation_Monitor)), logFiles, databaseHealth);
            TransactionMetadataCache         transactionMetadataCache = new TransactionMetadataCache();
            SynchronizedArrayIdOrderingQueue idOrderingQueue          = new SynchronizedArrayIdOrderingQueue();

            BatchingTransactionAppender transactionAppender = new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, _transactionIdStore, idOrderingQueue, databaseHealth);

            Life.add(transactionAppender);

            LogAppendEvent     logAppendEvent     = new RotationLogAppendEvent(logRotation);
            TransactionToApply transactionToApply = PrepareTransaction();

            transactionAppender.Append(transactionToApply, logAppendEvent);

            assertEquals(1, logFiles.HighestLogVersion);
            File      highestLogFile = logFiles.HighestLogFile;
            LogHeader logHeader      = LogHeaderReader.readLogHeader(FileSystem, highestLogFile);

            assertEquals(2, logHeader.LastCommittedTxId);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyTransaction(TransactionIdStore transactionIdStore, TransactionMetadataCache positionCache, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store) throws java.io.IOException
        private void VerifyTransaction(TransactionIdStore transactionIdStore, TransactionMetadataCache positionCache, sbyte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store)
        {
            TransactionMetadata expectedMetadata;

            using (TransactionCursor cursor = store.GetTransactions(TransactionIdStore_Fields.BASE_TX_ID + 1))
            {
                bool hasNext = cursor.next();
                assertTrue(hasNext);
                CommittedTransactionRepresentation tx          = cursor.get();
                TransactionRepresentation          transaction = tx.TransactionRepresentation;
                assertArrayEquals(additionalHeader, transaction.AdditionalHeader());
                assertEquals(masterId, transaction.MasterId);
                assertEquals(authorId, transaction.AuthorId);
                assertEquals(timeStarted, transaction.TimeStarted);
                assertEquals(timeCommitted, transaction.TimeCommitted);
                assertEquals(latestCommittedTxWhenStarted, transaction.LatestCommittedTxWhenStarted);
                expectedMetadata = new TransactionMetadata(masterId, authorId, tx.StartEntry.StartPosition, tx.StartEntry.checksum(), timeCommitted);
            }

            positionCache.Clear();

            TransactionMetadata actualMetadata = store.GetMetadataFor(transactionIdStore.LastCommittedTransactionId);

            assertEquals(expectedMetadata, actualMetadata);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowNoSuchTransactionExceptionIfMetadataNotFound() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNoSuchTransactionExceptionIfMetadataNotFound()
        {
            // GIVEN
            LogFiles logFiles = mock(typeof(LogFiles));
            TransactionMetadataCache cache = new TransactionMetadataCache();

            LifeSupport life = new LifeSupport();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, cache, new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>(), monitors, true);
            LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, cache, new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), _monitors, true);

            try
            {
                life.Start();
                // WHEN
                try
                {
                    txStore.GetMetadataFor(10);
                    fail("Should have thrown");
                }
                catch (NoSuchTransactionException)
                {                         // THEN Good
                }
            }
            finally
            {
                life.Shutdown();
            }
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOpenCleanStore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldOpenCleanStore()
        {
            // GIVEN
            TransactionIdStore       transactionIdStore = new SimpleTransactionIdStore();
            TransactionMetadataCache positionCache      = new TransactionMetadataCache();

            LifeSupport life = new LifeSupport();
//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.builder(dir.databaseLayout(), fileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(LogVersionRepository.class)).build();
            LogFiles logFiles = LogFilesBuilder.builder(Dir.databaseLayout(), FileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(typeof(LogVersionRepository))).build();

            life.Add(logFiles);

            life.Add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, _databaseHealth));

            try
            {
                // WHEN
                life.Start();
            }
            finally
            {
                life.Shutdown();
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOpenAndRecoverExistingData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldOpenAndRecoverExistingData()
        {
            // GIVEN
            TransactionIdStore       transactionIdStore = new SimpleTransactionIdStore();
            TransactionMetadataCache positionCache      = new TransactionMetadataCache();

//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 = 4545;
            long        timeCommitted                = timeStarted + 10;
            LifeSupport life = new LifeSupport();
//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.builder(dir.databaseLayout(), fileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(LogVersionRepository.class)).build();
            LogFiles logFiles = LogFilesBuilder.builder(Dir.databaseLayout(), FileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(typeof(LogVersionRepository))).build();

            life.Start();
            life.Add(logFiles);
            try
            {
                AddATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
            }
            finally
            {
                life.Shutdown();
            }

            life = new LifeSupport();
            life.Add(logFiles);
//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();
            FakeRecoveryVisitor visitor          = new FakeRecoveryVisitor(additionalHeader, masterId, authorId, timeStarted, timeCommitted, latestCommittedTxWhenStarted);

            LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, positionCache, new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), _monitors, true);

            life.Add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, _databaseHealth));
            CorruptedLogsTruncator logPruner = new CorruptedLogsTruncator(_databaseDirectory, logFiles, FileSystemRule.get());

            life.add(new Recovery(new RecoveryServiceAnonymousInnerClass(this, recoveryRequired, visitor, txStore)
                                  , logPruner, new LifecycleAdapter(), mock(typeof(RecoveryMonitor)), SilentProgressReporter.INSTANCE, false));

            // WHEN
            try
            {
                life.Start();
            }
            finally
            {
                life.Shutdown();
            }

            // THEN
            assertEquals(1, visitor.VisitedTransactions);
            assertTrue(recoveryRequired.get());
        }
//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);
        }
Beispiel #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void addATransactionAndRewind(org.neo4j.kernel.lifecycle.LifeSupport life, org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles, TransactionMetadataCache positionCache, TransactionIdStore transactionIdStore, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted) throws java.io.IOException
        private void AddATransactionAndRewind(LifeSupport life, LogFiles logFiles, TransactionMetadataCache positionCache, TransactionIdStore transactionIdStore, sbyte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted)
        {
            TransactionAppender appender = life.Add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, _databaseHealth));
            PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(SingleCreateNodeCommand());

            transaction.SetHeader(additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1);
            appender.Append(new TransactionToApply(transaction), Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null);
        }
 public PhysicalLogicalTransactionStore(LogFiles logFiles, TransactionMetadataCache transactionMetadataCache, LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader, Monitors monitors, bool failOnCorruptedLogFiles)
 {
     this._logFiles = logFiles;
     this._logFile  = logFiles.LogFile;
     this._transactionMetadataCache = transactionMetadataCache;
     this._logEntryReader           = logEntryReader;
     this._monitors = monitors;
     this._failOnCorruptedLogFiles = failOnCorruptedLogFiles;
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public LogPosition getAndCacheFoundLogPosition(TransactionMetadataCache transactionMetadataCache) throws NoSuchTransactionException
            public virtual LogPosition GetAndCacheFoundLogPosition(TransactionMetadataCache transactionMetadataCache)
            {
                if (StartEntryForFoundTransaction == null)
                {
                    throw new NoSuchTransactionException(StartTransactionId);
                }
                transactionMetadataCache.CacheTransactionMetadata(StartTransactionId, StartEntryForFoundTransaction.StartPosition, StartEntryForFoundTransaction.MasterId, StartEntryForFoundTransaction.LocalId, LogEntryStart.checksum(StartEntryForFoundTransaction), CommitTimestamp);
                return(StartEntryForFoundTransaction.StartPosition);
            }
 public BatchingTransactionAppender(LogFiles logFiles, LogRotation logRotation, TransactionMetadataCache transactionMetadataCache, TransactionIdStore transactionIdStore, IdOrderingQueue explicitIndexTransactionOrdering, DatabaseHealth databaseHealth)
 {
     this._logFile            = logFiles.LogFile;
     this._logRotation        = logRotation;
     this._transactionIdStore = transactionIdStore;
     this._explicitIndexTransactionOrdering = explicitIndexTransactionOrdering;
     this._databaseHealth           = databaseHealth;
     this._transactionMetadataCache = transactionMetadataCache;
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending()
        {
            // GIVEN
            LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
            LogFiles             logFiles             = LogFilesBuilder.builder(_directory.databaseLayout(), _fileSystemRule.get()).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean            end           = new AtomicBoolean();
            AllTheMonitoring         monitoring    = new AllTheMonitoring(end, 100);
            TransactionIdStore       txIdStore     = new SimpleTransactionIdStore();
            TransactionMetadataCache metadataCache = new TransactionMetadataCache();

            monitoring.LogFile = logFiles.LogFile;
            DatabaseHealth health   = new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance);
            LogRotation    rotation = new LogRotationImpl(monitoring, logFiles, health);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));
            TransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, BYPASS, health));

            // WHEN
            Race race = new Race();

            for (int i = 0; i < 10; i++)
            {
                race.AddContestant(() =>
                {
                    while (!end.get())
                    {
                        try
                        {
                            appender.Append(new TransactionToApply(SillyTransaction(1_000)), NULL);
                        }
                        catch (Exception e)
                        {
                            e.printStackTrace(System.out);
                            end.set(true);
                            fail(e.Message);
                        }
                    }
                });
            }
            race.AddContestant(EndAfterMax(10, SECONDS, end));
            race.Go();

            // THEN
            assertTrue(monitoring.NumberOfRotations() > 0);
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExtractMetadataFromExistingTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldExtractMetadataFromExistingTransaction()
        {
            // GIVEN
            TransactionIdStore       transactionIdStore = new SimpleTransactionIdStore();
            TransactionMetadataCache positionCache      = new TransactionMetadataCache();

//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 = 4545;
            long        timeCommitted                = timeStarted + 10;
            LifeSupport life = new LifeSupport();
//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.builder(dir.databaseLayout(), fileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(LogVersionRepository.class)).build();
            LogFiles logFiles = LogFilesBuilder.builder(Dir.databaseLayout(), FileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(typeof(LogVersionRepository))).build();

            life.Start();
            life.Add(logFiles);
            try
            {
                AddATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
            }
            finally
            {
                life.Shutdown();
            }

            life = new LifeSupport();
            life.Add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>(), monitors, true);
            LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), _monitors, true);

            // WHEN
            life.Start();
            try
            {
                VerifyTransaction(transactionIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
            }
            finally
            {
                life.Shutdown();
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCallTransactionClosedOnFailedForceLogToDisk() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCallTransactionClosedOnFailedForceLogToDisk()
        {
            // GIVEN
            long   txId           = 3;
            string failureMessage = "Forces a failure";
            FlushablePositionAwareChannel channel = spy(new InMemoryClosableChannel());
            IOException failure = new IOException(failureMessage);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.Flushable flushable = mock(java.io.Flushable.class);
            Flushable flushable = mock(typeof(Flushable));

            doAnswer(invocation =>
            {
                invocation.callRealMethod();
                return(flushable);
            }).when(channel).prepareForFlush();
            doThrow(failure).when(flushable).flush();
            when(_logFile.Writer).thenReturn(channel);
            TransactionMetadataCache metadataCache      = new TransactionMetadataCache();
            TransactionIdStore       transactionIdStore = mock(typeof(TransactionIdStore));

            when(transactionIdStore.NextCommittingTransactionId()).thenReturn(txId);
            Mockito.reset(_databaseHealth);
            TransactionAppender appender = Life.add(new BatchingTransactionAppender(_logFiles, NO_ROTATION, metadataCache, transactionIdStore, BYPASS, _databaseHealth));

            // WHEN
            TransactionRepresentation transaction = mock(typeof(TransactionRepresentation));

            when(transaction.AdditionalHeader()).thenReturn(new sbyte[0]);
            try
            {
                appender.Append(new TransactionToApply(transaction), _logAppendEvent);
                fail("Expected append to fail. Something is wrong with the test itself");
            }
            catch (IOException e)
            {
                // THEN
                assertSame(failure, e);
                verify(transactionIdStore, times(1)).nextCommittingTransactionId();
                verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong());
                verify(_databaseHealth).panic(failure);
            }
        }
Beispiel #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowNoSuchTransactionExceptionIfLogFileIsMissing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNoSuchTransactionExceptionIfLogFileIsMissing()
        {
            // GIVEN
            LogFile  logFile  = mock(typeof(LogFile));
            LogFiles logFiles = mock(typeof(LogFiles));

            // a missing file
            when(logFiles.LogFile).thenReturn(logFile);
            when(logFile.GetReader(any(typeof(LogPosition)))).thenThrow(new FileNotFoundException());
            // Which is nevertheless in the metadata cache
            TransactionMetadataCache cache = new TransactionMetadataCache();

            cache.CacheTransactionMetadata(10, new LogPosition(2, 130), 1, 1, 100, DateTimeHelper.CurrentUnixTimeMillis());

            LifeSupport life = new LifeSupport();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, cache, new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>(), monitors, true);
            LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, cache, new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), _monitors, true);

            try
            {
                life.Start();

                // WHEN
                // we ask for that transaction and forward
                try
                {
                    txStore.getTransactions(10);
                    fail();
                }
                catch (NoSuchTransactionException)
                {
                    // THEN
                    // We don't get a FileNotFoundException but a NoSuchTransactionException instead
                }
            }
            finally
            {
                life.Shutdown();
            }
        }