Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void reportProgressOnRecovery() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReportProgressOnRecovery()
        {
            RecoveryService                    recoveryService           = mock(typeof(RecoveryService), Answers.RETURNS_MOCKS);
            CorruptedLogsTruncator             logsTruncator             = mock(typeof(CorruptedLogsTruncator));
            RecoveryMonitor                    recoveryMonitor           = mock(typeof(RecoveryMonitor));
            TransactionCursor                  reverseTransactionCursor  = mock(typeof(TransactionCursor));
            TransactionCursor                  transactionCursor         = mock(typeof(TransactionCursor));
            CommittedTransactionRepresentation transactionRepresentation = mock(typeof(CommittedTransactionRepresentation));

            int         transactionsToRecover         = 5;
            int         expectedMax                   = transactionsToRecover * 2;
            int         lastCommittedTransactionId    = 14;
            LogPosition recoveryStartPosition         = LogPosition.start(0);
            int         firstTxIdAfterLastCheckPoint  = 10;
            RecoveryStartInformation startInformation = new RecoveryStartInformation(recoveryStartPosition, firstTxIdAfterLastCheckPoint);

            when(reverseTransactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
            when(transactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
            when(reverseTransactionCursor.get()).thenReturn(transactionRepresentation);
            when(transactionCursor.get()).thenReturn(transactionRepresentation);
            when(transactionRepresentation.CommitEntry).thenReturn(new LogEntryCommit(lastCommittedTransactionId, 1L));

            when(recoveryService.RecoveryStartInformation).thenReturn(startInformation);
            when(recoveryService.GetTransactionsInReverseOrder(recoveryStartPosition)).thenReturn(reverseTransactionCursor);
            when(recoveryService.GetTransactions(recoveryStartPosition)).thenReturn(transactionCursor);

            AssertableProgressReporter progressReporter = new AssertableProgressReporter(expectedMax);
            Recovery recovery = new Recovery(recoveryService, logsTruncator, new LifecycleAdapter(), recoveryMonitor, progressReporter, true);

            Recovery.init();

            progressReporter.Verify();
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.Optional<long> getLatestTransactionLogIndex(long startTxId, org.neo4j.io.layout.DatabaseLayout databaseLayout) throws java.io.IOException
        private long?GetLatestTransactionLogIndex(long startTxId, DatabaseLayout databaseLayout)
        {
            if (!HasTxLogs(databaseLayout))
            {
                return(null);
            }

            // this is not really a read-only store, because it will create an empty transaction log if there is none
            ReadOnlyTransactionStore txStore = new ReadOnlyTransactionStore(_pageCache, _fs, databaseLayout, _config, new Monitors());

            long lastTxId = BASE_TX_ID;

            try
            {
                using (Lifespan ignored = new Lifespan(txStore), TransactionCursor cursor = txStore.GetTransactions(startTxId))
                {
                    while (cursor.next())
                    {
                        CommittedTransactionRepresentation tx = cursor.get();
                        lastTxId = tx.CommitEntry.TxId;
                    }

                    return(lastTxId);
                }
            }
            catch (NoSuchTransactionException)
            {
                return(null);
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropIndexOnRecovery() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDropIndexOnRecovery()
        {
            // given a transaction stream ending in an INDEX DROP command.
            CommittedTransactionRepresentation dropTransaction = PrepareDropTransaction();
            File storeDir           = Directory.databaseDir();
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(storeDir);

            CreateIndex(db);
            Db.shutdown();
            AppendDropTransactionToTransactionLog(Directory.databaseDir(), dropTransaction);

            // when recovering this (the drop transaction with the index file intact)
            Monitors monitors = new Monitors();
            AssertRecoveryIsPerformed recoveryMonitor = new AssertRecoveryIsPerformed();

            monitors.AddMonitorListener(recoveryMonitor);
            db = (new TestGraphDatabaseFactory()).setMonitors(monitors).newEmbeddedDatabase(storeDir);
            try
            {
                assertTrue(recoveryMonitor.RecoveryWasPerformed);

                // then
                using (Transaction tx = Db.beginTx())
                {
                    assertEquals(0, count(Db.schema().Indexes));
                    tx.Success();
                }
            }
            finally
            {
                // and the ability to shut down w/o failing on still open files
                Db.shutdown();
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean visit(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation transaction) throws Exception
            public override bool Visit(CommittedTransactionRepresentation transaction)
            {
                TransactionRepresentation txRepresentation = transaction.TransactionRepresentation;
                long txId             = transaction.CommitEntry.TxId;
                TransactionToApply tx = new TransactionToApply(txRepresentation, txId);

                tx.Commitment(NO_COMMITMENT, txId);
                tx.LogPosition(transaction.StartEntry.StartPosition);
                StorageEngine.apply(tx, Mode);
                return(false);
            }
Exemple #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void appendDropTransactionToTransactionLog(java.io.File databaseDirectory, org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation dropTransaction) throws java.io.IOException
        private void AppendDropTransactionToTransactionLog(File databaseDirectory, CommittedTransactionRepresentation dropTransaction)
        {
            LogFiles     logFiles          = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseDirectory, Fs).build();
            File         logFile           = logFiles.GetLogFileForVersion(logFiles.HighestLogVersion);
            StoreChannel writeStoreChannel = Fs.open(logFile, OpenMode.READ_WRITE);

            writeStoreChannel.Position(writeStoreChannel.size());
            using (PhysicalFlushableChannel writeChannel = new PhysicalFlushableChannel(writeStoreChannel))
            {
                (new LogEntryWriter(writeChannel)).serialize(dropTransaction);
            }
        }
        public override void TransactionsRecovered(CommittedTransactionRepresentation lastRecoveredTransaction, LogPosition positionAfterLastRecoveredTransaction)
        {
            long recoveredTransactionLogVersion = positionAfterLastRecoveredTransaction.LogVersion;
            long recoveredTransactionOffset     = positionAfterLastRecoveredTransaction.ByteOffset;

            if (lastRecoveredTransaction != null)
            {
                LogEntryCommit commitEntry = lastRecoveredTransaction.CommitEntry;
                _transactionIdStore.setLastCommittedAndClosedTransactionId(commitEntry.TxId, LogEntryStart.checksum(lastRecoveredTransaction.StartEntry), commitEntry.TimeWritten, recoveredTransactionOffset, recoveredTransactionLogVersion);
            }
            _logVersionRepository.CurrentLogVersion = recoveredTransactionLogVersion;
        }
Exemple #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation extractLastTransaction(org.neo4j.kernel.internal.GraphDatabaseAPI db) throws java.io.IOException
        private static CommittedTransactionRepresentation ExtractLastTransaction(GraphDatabaseAPI db)
        {
            LogicalTransactionStore            txStore     = Db.DependencyResolver.resolveDependency(typeof(LogicalTransactionStore));
            CommittedTransactionRepresentation transaction = null;

            using (TransactionCursor cursor = txStore.GetTransactions(Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID + 1))
            {
                while (cursor.next())
                {
                    transaction = cursor.get();
                }
            }
            return(transaction);
        }
Exemple #8
0
 public TxPullResponse(StoreId storeId, CommittedTransactionRepresentation tx)
 {
     this._storeId = storeId;
     this._tx      = tx;
 }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void appendToLogAndApplyToStore(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation tx) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        public virtual void AppendToLogAndApplyToStore(CommittedTransactionRepresentation tx)
        {
            _commitProcess.commit(new TransactionToApply(tx.TransactionRepresentation, tx.CommitEntry.TxId, _versionContextSupplier.VersionContext), NULL, EXTERNAL);
        }