Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyTransactionsInLog(org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles, long fromTxId, long endTxId) throws java.io.IOException
        private void VerifyTransactionsInLog(LogFiles logFiles, long fromTxId, long endTxId)
        {
            long expectedTxId = fromTxId;
            LogVersionedStoreChannel versionedStoreChannel = logFiles.OpenForVersion(0);

            using (ReadableLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, Org.Neo4j.Kernel.impl.transaction.log.LogVersionBridge_Fields.NoMoreChannels, 1024))
            {
                using (PhysicalTransactionCursor <ReadableLogChannel> txCursor = new PhysicalTransactionCursor <ReadableLogChannel>(channel, new VersionAwareLogEntryReader <>()))
                {
                    while (txCursor.Next())
                    {
                        CommittedTransactionRepresentation tx = txCursor.Get();
                        long txId = tx.CommitEntry.TxId;

                        assertThat(expectedTxId, lessThanOrEqualTo(endTxId));
                        assertEquals(expectedTxId, txId);
                        expectedTxId++;
                    }
                }
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyTransactionLogs(java.io.File txDirectory, java.io.File storeDir) throws java.io.IOException
        private void VerifyTransactionLogs(File txDirectory, File storeDir)
        {
            FileSystemAbstraction fileSystem = FileSystemRule.get();
            LogFiles storeDirLogs            = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDir, fileSystem).build();

            assertFalse(storeDirLogs.VersionExists(0));

            LogFiles txDirectoryLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(txDirectory, fileSystem).build();

            assertTrue(txDirectoryLogs.VersionExists(0));
            using (PhysicalLogVersionedStoreChannel physicalLogVersionedStoreChannel = txDirectoryLogs.OpenForVersion(0))
            {
                assertThat(physicalLogVersionedStoreChannel.Size(), greaterThan(0L));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void databasePanicShouldHandleOutOfMemoryErrors() throws java.io.IOException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DatabasePanicShouldHandleOutOfMemoryErrors()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch panicLatch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent panicLatch = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch adversaryLatch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent adversaryLatch = new System.Threading.CountdownEvent(1);
            OutOfMemoryAwareFileSystem      fs             = new OutOfMemoryAwareFileSystem();

            _life.add(new FileSystemLifecycleAdapter(fs));
            DatabaseHealth slowPanicDatabaseHealth = new SlowPanickingDatabaseHealth(panicLatch, adversaryLatch);
            LogFiles       logFiles = LogFilesBuilder.builder(_testDirectory.databaseLayout(), fs).withLogVersionRepository(_logVersionRepository).withTransactionIdStore(_transactionIdStore).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final BatchingTransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, explicitIndexTransactionOrdering, slowPanicDatabaseHealth));
            BatchingTransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, _logRotation, _transactionMetadataCache, _transactionIdStore, _explicitIndexTransactionOrdering, slowPanicDatabaseHealth));

            _life.start();

            // Commit initial transaction
            appender.Append(Tx(), Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null);

            // Try to commit one transaction, will fail during flush with OOM, but not actually panic
            fs.ShouldOOM = true;
            Future <long> failingTransaction = _executor.submit(() => appender.Append(Tx(), Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null));

            panicLatch.await();

            // Try to commit one additional transaction, should fail since database has already panicked
            fs.ShouldOOM = false;
            try
            {
                appender.Append(Tx(), new LogAppendEvent_EmptyAnonymousInnerClass2(this, adversaryLatch));
                fail("Should have failed since database should have panicked");
            }
            catch (IOException e)
            {
                assertTrue(e.Message.contains("The database has encountered a critical error"));
            }

            // Check that we actually got an OutOfMemoryError
            try
            {
                failingTransaction.get();
                fail("Should have failed with OutOfMemoryError error");
            }
            catch (ExecutionException e)
            {
                assertTrue(e.InnerException is System.OutOfMemoryException);
            }

            // Check number of transactions, should only have one
            LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();

            assertEquals(logFiles.LowestLogVersion, logFiles.HighestLogVersion);
            long version = logFiles.HighestLogVersion;

            using (LogVersionedStoreChannel channel = logFiles.OpenForVersion(version), ReadAheadLogChannel readAheadLogChannel = new ReadAheadLogChannel(channel), LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadLogChannel))
            {
                LogEntry entry;
                long     numberOfTransactions = 0;
                while (cursor.Next())
                {
                    entry = cursor.Get();
                    if (entry is LogEntryCommit)
                    {
                        numberOfTransactions++;
                    }
                }
                assertEquals(1, numberOfTransactions);
            }
        }