//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static java.util.List<org.neo4j.kernel.impl.transaction.TransactionRepresentation> createConstraintCreatingTransactions() throws Exception
        private static IList <TransactionRepresentation> CreateConstraintCreatingTransactions()
        {
            GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newImpermanentDatabase();

            try
            {
                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().constraintFor(LABEL).assertPropertyIsUnique(KEY).create();
                    tx.Success();
                }

                LogicalTransactionStore           txStore = Db.DependencyResolver.resolveDependency(typeof(LogicalTransactionStore));
                IList <TransactionRepresentation> result  = new List <TransactionRepresentation>();
                using (TransactionCursor cursor = txStore.GetTransactions(Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID + 1))
                {
                    while (cursor.next())
                    {
                        result.Add(cursor.get().TransactionRepresentation);
                    }
                }
                return(result);
            }
            finally
            {
                Db.shutdown();
            }
        }
예제 #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);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void closeCurrent() throws java.io.IOException
        private void CloseCurrent()
        {
            if (_currentLogTransactionCursor != null)
            {
                _currentLogTransactionCursor.close();
                _currentLogTransactionCursor = null;
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public EagerlyReversedTransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor cursor) throws java.io.IOException
        public EagerlyReversedTransactionCursor(TransactionCursor cursor)
        {
            this._cursor = cursor;
            while (cursor.next())
            {
                _txs.Add(cursor.get());
            }
            this._indexToReturn = _txs.Count;
        }
예제 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: ReversedSingleFileTransactionCursor(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel channel, org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel> logEntryReader, boolean failOnCorruptedLogFiles, ReversedTransactionCursorMonitor monitor) throws java.io.IOException
        internal ReversedSingleFileTransactionCursor(ReadAheadLogChannel channel, LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader, bool failOnCorruptedLogFiles, ReversedTransactionCursorMonitor monitor)
        {
            this._channel = channel;
            this._failOnCorruptedLogFiles = failOnCorruptedLogFiles;
            this._monitor = monitor;
            // There's an assumption here: that the underlying channel can move in between calls and that the
            // transaction cursor will just happily read from the new position.
            this._transactionCursor = new PhysicalTransactionCursor <>(channel, logEntryReader);
            this._offsets           = SketchOutTransactionStartOffsets();
        }
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation[] exhaust(TransactionCursor cursor) throws java.io.IOException
        public static CommittedTransactionRepresentation[] Exhaust(TransactionCursor cursor)
        {
            IList <CommittedTransactionRepresentation> list = new List <CommittedTransactionRepresentation>();

            while (cursor.next())
            {
                list.Add(cursor.get());
            }
            return(list.ToArray());
        }
예제 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static java.util.List<org.neo4j.kernel.impl.transaction.TransactionRepresentation> extractTransactions(org.neo4j.kernel.internal.GraphDatabaseAPI db) throws java.io.IOException
        private static IList <TransactionRepresentation> ExtractTransactions(GraphDatabaseAPI db)
        {
            LogicalTransactionStore           txStore      = Db.DependencyResolver.resolveDependency(typeof(LogicalTransactionStore));
            IList <TransactionRepresentation> transactions = new List <TransactionRepresentation>();

            using (TransactionCursor cursor = txStore.GetTransactions(Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID + 1))
            {
                cursor.forAll(tx => transactions.Add(tx.TransactionRepresentation));
            }
            return(transactions);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleEmptySource() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleEmptySource()
        {
            // GIVEN
            TransactionCursor source = given();
            EagerlyReversedTransactionCursor cursor = new EagerlyReversedTransactionCursor(source);

            // WHEN
            CommittedTransactionRepresentation[] reversed = exhaust(cursor);

            // THEN
            assertEquals(0, reversed.Length);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReverseTransactionsFromSource() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReverseTransactionsFromSource()
        {
            // GIVEN
            CommittedTransactionRepresentation tx1 = mock(typeof(CommittedTransactionRepresentation));
            CommittedTransactionRepresentation tx2 = mock(typeof(CommittedTransactionRepresentation));
            CommittedTransactionRepresentation tx3 = mock(typeof(CommittedTransactionRepresentation));
            TransactionCursor source = given(tx1, tx2, tx3);
            EagerlyReversedTransactionCursor cursor = new EagerlyReversedTransactionCursor(source);

            // WHEN
            CommittedTransactionRepresentation[] reversed = exhaust(cursor);

            // THEN
            assertArrayEquals(array(tx3, tx2, tx1), reversed);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean next() throws java.io.IOException
        public override bool Next()
        {
            while (_currentLogTransactionCursor == null || !_currentLogTransactionCursor.next())
            {
                // We've run out of transactions in this log version, back up to a previous one
                _currentVersion--;
                if (_currentVersion < _backToPosition.LogVersion)
                {
                    return(false);
                }

                CloseCurrent();
                LogPosition position = _currentVersion > _backToPosition.LogVersion ? start(_currentVersion) : _backToPosition;
                _currentLogTransactionCursor = _cursorFactory.apply(position);
            }
            return(true);
        }
예제 #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static java.util.List<org.neo4j.kernel.impl.transaction.TransactionRepresentation> createTransactionsForCreatingConstraint(System.Action<org.neo4j.kernel.internal.GraphDatabaseAPI> uniqueConstraintCreator) throws Exception
        private static IList <TransactionRepresentation> CreateTransactionsForCreatingConstraint(System.Action <GraphDatabaseAPI> uniqueConstraintCreator)
        {
            // A separate db altogether
            GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestEnterpriseGraphDatabaseFactory()).newImpermanentDatabase();

            try
            {
                CreateConstraint(db, uniqueConstraintCreator);
                LogicalTransactionStore           txStore      = Db.DependencyResolver.resolveDependency(typeof(LogicalTransactionStore));
                IList <TransactionRepresentation> transactions = new List <TransactionRepresentation>();
                using (TransactionCursor cursor = txStore.GetTransactions(Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID + 1))
                {
                    cursor.forAll(tx => transactions.Add(tx.TransactionRepresentation));
                }
                return(transactions);
            }
            finally
            {
                Db.shutdown();
            }
        }
예제 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void init() throws Throwable
        public override void Init()
        {
            RecoveryStartInformation recoveryStartInformation = _recoveryService.RecoveryStartInformation;

            if (!recoveryStartInformation.RecoveryRequired)
            {
                // If there is nothing to recovery, then the schema is initialised immediately.
                _schemaLife.init();
                return;
            }

            LogPosition recoveryPosition = recoveryStartInformation.RecoveryPosition;

            _monitor.recoveryRequired(recoveryPosition);
            _recoveryService.startRecovery();

            LogPosition recoveryToPosition = recoveryPosition;
            CommittedTransactionRepresentation lastTransaction         = null;
            CommittedTransactionRepresentation lastReversedTransaction = null;

            try
            {
                long lowestRecoveredTxId = Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID;
                using (TransactionCursor transactionsToRecover = _recoveryService.getTransactionsInReverseOrder(recoveryPosition), RecoveryApplier recoveryVisitor = _recoveryService.getRecoveryApplier(REVERSE_RECOVERY))
                {
                    while (transactionsToRecover.next())
                    {
                        CommittedTransactionRepresentation transaction = transactionsToRecover.get();
                        if (lastReversedTransaction == null)
                        {
                            lastReversedTransaction = transaction;
                            InitProgressReporter(recoveryStartInformation, lastReversedTransaction);
                        }
                        recoveryVisitor.visit(transaction);
                        lowestRecoveredTxId = transaction.CommitEntry.TxId;
                        ReportProgress();
                    }
                }

                _monitor.reverseStoreRecoveryCompleted(lowestRecoveredTxId);

                // We cannot initialise the schema (tokens, schema cache, indexing service, etc.) until we have returned the store to a consistent state.
                // We need to be able to read the store before we can even figure out what indexes, tokens, etc. we have. Hence we defer the initialisation
                // of the schema life until after we've done the reverse recovery.
                _schemaLife.init();

                using (TransactionCursor transactionsToRecover = _recoveryService.getTransactions(recoveryPosition), RecoveryApplier recoveryVisitor = _recoveryService.getRecoveryApplier(RECOVERY))
                {
                    while (transactionsToRecover.next())
                    {
                        lastTransaction = transactionsToRecover.get();
                        long txId = lastTransaction.CommitEntry.TxId;
                        recoveryVisitor.visit(lastTransaction);
                        _monitor.transactionRecovered(txId);
                        _numberOfRecoveredTransactions++;
                        recoveryToPosition = transactionsToRecover.Position();
                        ReportProgress();
                    }
                    recoveryToPosition = transactionsToRecover.Position();
                }
            }
            catch (Exception e) when(e is Exception || e is ClosedByInterruptException)
            {
                // We do not want to truncate logs based on these exceptions. Since users can influence them with config changes
                // the users are able to workaround this if truncations is really needed.
                throw e;
            }
            catch (Exception t)
            {
                if (_failOnCorruptedLogFiles)
                {
                    ThrowUnableToCleanRecover(t);
                }
                if (lastTransaction != null)
                {
                    LogEntryCommit commitEntry = lastTransaction.CommitEntry;
                    _monitor.failToRecoverTransactionsAfterCommit(t, commitEntry, recoveryToPosition);
                }
                else
                {
                    _monitor.failToRecoverTransactionsAfterPosition(t, recoveryPosition);
                    recoveryToPosition = recoveryPosition;
                }
            }
            _progressReporter.completed();
            _logsTruncator.truncate(recoveryToPosition);

            _recoveryService.transactionsRecovered(lastTransaction, recoveryToPosition);
            _monitor.recoveryCompleted(_numberOfRecoveredTransactions);
        }
예제 #13
0
 public void SetWith(string giveStartBlock, string givenEndBlock, TransactionFullInfoBean[] transactionsFound)
 {
     m_start        = new TransactionCursor(giveStartBlock, "");
     m_end          = new TransactionCursor(givenEndBlock, "");
     m_transactions = transactionsFound;
 }
예제 #14
0
 public void SetWith()
 {
     m_start        = new TransactionCursor("", "");
     m_end          = new TransactionCursor("", "");
     m_transactions = new TransactionFullInfoBean[0];
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static org.neo4j.kernel.impl.transaction.log.TransactionCursor eagerlyReverse(org.neo4j.kernel.impl.transaction.log.TransactionCursor cursor) throws java.io.IOException
        public static TransactionCursor EagerlyReverse(TransactionCursor cursor)
        {
            return(new EagerlyReversedTransactionCursor(cursor));
        }