private void PublishAsCommitted(TransactionToApply batch)
 {
     while (batch != null)
     {
         batch.Commitment().publishAsCommitted();
         batch = batch.Next();
     }
 }
예제 #2
0
            internal virtual int Count(TransactionToApply batch)
            {
                int count = 0;

                while (batch != null)
                {
                    count++;
                    batch = batch.Next();
                }
                return(count);
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAppendBatchOfTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAppendBatchOfTransactions()
        {
            // GIVEN
            when(_logFile.Writer).thenReturn(_channel);
            TransactionAppender appender = Life.add(CreateTransactionAppender());

            when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(2L, 3L, 4L);
            TransactionToApply batch = BatchOf(Transaction(SingleCreateNodeCommand(0), new sbyte[0], 0, 0, 0, 1, 0), Transaction(SingleCreateNodeCommand(1), new sbyte[0], 0, 0, 0, 1, 0), Transaction(SingleCreateNodeCommand(2), new sbyte[0], 0, 0, 0, 1, 0));

            // WHEN
            appender.Append(batch, _logAppendEvent);

            // THEN
            TransactionToApply tx = batch;

            assertEquals(2L, tx.TransactionId());
            tx = tx.Next();
            assertEquals(3L, tx.TransactionId());
            tx = tx.Next();
            assertEquals(4L, tx.TransactionId());
            assertNull(tx.Next());
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long append(org.neo4j.kernel.impl.api.TransactionToApply batch, org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent logAppendEvent) throws java.io.IOException
        public override long Append(TransactionToApply batch, LogAppendEvent logAppendEvent)
        {
            // Assigned base tx id just to make compiler happy
            long lastTransactionId = TransactionIdStore_Fields.BASE_TX_ID;

            // Synchronized with logFile to get absolute control over concurrent rotations happening
            lock ( _logFile )
            {
                // Assert that kernel is healthy before making any changes
                _databaseHealth.assertHealthy(typeof(IOException));
                using (SerializeTransactionEvent serialiseEvent = logAppendEvent.BeginSerializeTransaction())
                {
                    // Append all transactions in this batch to the log under the same logFile monitor
                    TransactionToApply tx = batch;
                    while (tx != null)
                    {
                        long transactionId = _transactionIdStore.nextCommittingTransactionId();

                        // If we're in a scenario where we're merely replicating transactions, i.e. transaction
                        // id have already been generated by another entity we simply check that our id
                        // that we generated match that id. If it doesn't we've run into a problem we can't ´
                        // really recover from and would point to a bug somewhere.
                        MatchAgainstExpectedTransactionIdIfAny(transactionId, tx);

                        TransactionCommitment commitment = AppendToLog(tx.TransactionRepresentation(), transactionId);
                        tx.Commitment(commitment, transactionId);
                        tx.LogPosition(commitment.LogPosition());
                        tx = tx.Next();
                        lastTransactionId = transactionId;
                    }
                }
            }

            // At this point we've appended all transactions in this batch, but we can't mark any of them
            // as committed since they haven't been forced to disk yet. So here we force, or potentially
            // piggy-back on another force, but anyway after this call below we can be sure that all our transactions
            // in this batch exist durably on disk.
            if (ForceAfterAppend(logAppendEvent))
            {
                // We got lucky and were the one forcing the log. It's enough if ones of all doing concurrent committers
                // checks the need for log rotation.
                bool logRotated = _logRotation.rotateLogIfNeeded(logAppendEvent);
                logAppendEvent.LogRotated = logRotated;
            }

            // Mark all transactions as committed
            PublishAsCommitted(batch);

            return(lastTransactionId);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyIndex(org.neo4j.kernel.impl.api.TransactionToApply tx) throws Exception
            internal virtual void VerifyIndex(TransactionToApply tx)
            {
                using (IndexReader reader = Index.newReader())
                {
                    NodeVisitor visitor = new NodeVisitor();
                    for (int i = 0; tx != null; i++)
                    {
                        tx.TransactionRepresentation().accept(visitor.Clear());

                        Value propertyValue             = propertyValue(Id, Base + i);
                        IndexQuery.ExactPredicate query = IndexQuery.exact(outerInstance.descriptor.PropertyId, propertyValue);
                        LongIterator hits = reader.Query(query);
                        assertEquals("Index doesn't contain " + visitor.NodeId + " " + propertyValue, visitor.NodeId, hits.next());
                        assertFalse(hits.hasNext());
                        tx = tx.Next();
                    }
                }
            }
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertTransactionsCommitted(long startTxId, long expectedCount) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private void AssertTransactionsCommitted(long startTxId, long expectedCount)
        {
            ArgumentCaptor <TransactionToApply> batchCaptor = ArgumentCaptor.forClass(typeof(TransactionToApply));

            verify(_commitProcess).commit(batchCaptor.capture(), eq(NULL), eq(EXTERNAL));

            TransactionToApply batch = Iterables.single(batchCaptor.AllValues);
            long expectedTxId        = startTxId;
            long count = 0;

            while (batch != null)
            {
                assertEquals(expectedTxId, batch.TransactionId());
                expectedTxId++;
                batch = batch.Next();
                count++;
            }
            assertEquals(expectedCount, count);
        }
예제 #7
0
        private static TransactionToApply ToApply(ICollection <TransactionRepresentation> transactions)
        {
            TransactionToApply first = null;
            TransactionToApply last  = null;

            foreach (TransactionRepresentation transactionRepresentation in transactions)
            {
                TransactionToApply transaction = new TransactionToApply(transactionRepresentation);
                if (first == null)
                {
                    first = last = transaction;
                }
                else
                {
                    last.Next(transaction);
                    last = transaction;
                }
            }
            return(first);
        }
        private TransactionToApply BatchOf(params TransactionRepresentation[] transactions)
        {
            TransactionToApply first = null;
            TransactionToApply last  = null;

            foreach (TransactionRepresentation transaction in transactions)
            {
                TransactionToApply tx = new TransactionToApply(transaction);
                if (first == null)
                {
                    first = last = tx;
                }
                else
                {
                    last.Next(tx);
                    last = tx;
                }
            }
            return(first);
        }