コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static Exception executeFailingTransaction(RecordStorageEngine engine) throws java.io.IOException
        private static Exception ExecuteFailingTransaction(RecordStorageEngine engine)
        {
            Exception          applicationError = new UnderlyingStorageException("No space left on device");
            TransactionToApply txToApply        = NewTransactionThatFailsWith(applicationError);

            try
            {
                engine.Apply(txToApply, TransactionApplicationMode.INTERNAL);
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertSame(applicationError, Exceptions.rootCause(e));
            }
            return(applicationError);
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.neo4j.kernel.impl.api.TransactionToApply newTransactionThatFailsWith(Exception error) throws java.io.IOException
        private static TransactionToApply NewTransactionThatFailsWith(Exception error)
        {
            TransactionRepresentation transaction = mock(typeof(TransactionRepresentation));

            when(transaction.AdditionalHeader()).thenReturn(new sbyte[0]);
            // allow to build validated index updates but fail on actual tx application
            doThrow(error).when(transaction).accept(any());

            long txId = ThreadLocalRandom.current().nextLong(0, 1000);
            TransactionToApply txToApply  = new TransactionToApply(transaction);
            FakeCommitment     commitment = new FakeCommitment(txId, mock(typeof(TransactionIdStore)));

            commitment.HasExplicitIndexChanges = false;
            txToApply.Commitment(commitment, txId);
            return(txToApply);
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void queue(TransactionToApply transaction) throws Exception
        public virtual void Queue(TransactionToApply transaction)
        {
            if (Empty)
            {
                _first = _last = transaction;
            }
            else
            {
                _last.next(transaction);
                _last = transaction;
            }
            if (++_size == _maxSize)
            {
                Empty();
            }
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRegisterIndexesToActivateIntoTheActivator() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRegisterIndexesToActivateIntoTheActivator()
        {
            // given
            IndexingService indexing = mock(typeof(IndexingService));
            LabelScanWriter writer   = new OrderVerifyingLabelScanWriter(10, 15, 20);
            WorkSync <System.Func <LabelScanWriter>, LabelUpdateWork> labelScanSync    = spy(new WorkSync <System.Func <LabelScanWriter>, LabelUpdateWork>(SingletonProvider(writer)));
            WorkSync <IndexingUpdateService, IndexUpdatesWork>        indexUpdatesSync = new WorkSync <IndexingUpdateService, IndexUpdatesWork>(indexing);
            PropertyStore      propertyStore  = mock(typeof(PropertyStore));
            TransactionToApply tx             = mock(typeof(TransactionToApply));
            IndexActivator     indexActivator = new IndexActivator(indexing);
            long indexId1      = 1;
            long indexId2      = 2;
            long indexId3      = 3;
            long constraintId1 = 10;
            long constraintId2 = 11;
            long constraintId3 = 12;
            IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("index-key", "v1");
            StoreIndexDescriptor    rule1 = uniqueForSchema(forLabel(1, 1), providerDescriptor).withIds(indexId1, constraintId1);
            StoreIndexDescriptor    rule2 = uniqueForSchema(forLabel(2, 1), providerDescriptor).withIds(indexId2, constraintId2);
            StoreIndexDescriptor    rule3 = uniqueForSchema(forLabel(3, 1), providerDescriptor).withIds(indexId3, constraintId3);

            using (IndexBatchTransactionApplier applier = new IndexBatchTransactionApplier(indexing, labelScanSync, indexUpdatesSync, mock(typeof(NodeStore)), mock(typeof(RelationshipStore)), propertyStore, indexActivator))
            {
                using (TransactionApplier txApplier = applier.StartTx(tx))
                {
                    // WHEN
                    // activate index 1
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(Collections.emptyList(), AsRecords(rule1, true), rule1));

                    // activate index 2
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(Collections.emptyList(), AsRecords(rule2, true), rule2));

                    // activate index 3
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(Collections.emptyList(), AsRecords(rule3, true), rule3));

                    // drop index 2
                    txApplier.VisitSchemaRuleCommand(new Command.SchemaRuleCommand(AsRecords(rule2, true), AsRecords(rule2, false), rule2));
                }
            }

            verify(indexing).dropIndex(rule2);
            indexActivator.Close();
            verify(indexing).activateIndex(indexId1);
            verify(indexing).activateIndex(indexId3);
            verifyNoMoreInteractions(indexing);
        }
コード例 #5
0
        public override void ApplyCommand(ReplicatedTransaction replicatedTx, long commandIndex, System.Action <Result> callback)
        {
            lock (this)
            {
                if (commandIndex <= _lastCommittedIndex)
                {
                    _log.debug("Ignoring transaction at log index %d since already committed up to %d", commandIndex, _lastCommittedIndex);
                    return;
                }

                TransactionRepresentation tx;

                sbyte[] extraHeader = encodeLogIndexAsTxHeader(commandIndex);
                tx = ReplicatedTransactionFactory.ExtractTransactionRepresentation(replicatedTx, extraHeader);

                int currentTokenId  = _lockTokenStateMachine.currentToken().id();
                int txLockSessionId = tx.LockSessionId;

                if (currentTokenId != txLockSessionId && txLockSessionId != Org.Neo4j.Kernel.impl.locking.Locks_Client_Fields.NO_LOCK_SESSION_ID)
                {
                    callback(Result.of(new TransactionFailureException(LockSessionExpired, "The lock session in the cluster has changed: [current lock session id:%d, tx lock session id:%d]", currentTokenId, txLockSessionId)));
                }
                else
                {
                    try
                    {
                        TransactionToApply transaction = new TransactionToApply(tx, _versionContextSupplier.VersionContext);
                        transaction.OnClose(txId =>
                        {
                            if (tx.LatestCommittedTxWhenStarted >= txId)
                            {
                                throw new System.InvalidOperationException(format("Out of order transaction. Expected that %d < %d", tx.LatestCommittedTxWhenStarted, txId));
                            }

                            callback(Result.of(txId));
                            _commandIndexTracker.AppliedCommandIndex = commandIndex;
                        });
                        _queue.queue(transaction);
                    }
                    catch (Exception e)
                    {
                        throw PanicException(e);
                    }
                }
            }
        }
コード例 #6
0
        public override void Run()
        {
            long latestTxId = Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID;

            while (_condition.AsBoolean)
            {
                TransactionToApply transaction = _factory.nextTransaction(latestTxId);
                try
                {
                    latestTxId = _transactionAppender.append(transaction, Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null);
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            }
        }
コード例 #7
0
//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();
                    }
                }
            }
コード例 #8
0
        private void MarkUnsafeTransactionsForTermination(TransactionToApply first, TransactionToApply last)
        {
            long firstCommittedTimestamp = first.TransactionRepresentation().TimeCommitted;
            long lastCommittedTimestamp  = last.TransactionRepresentation().TimeCommitted;
            long earliestSafeTimestamp   = lastCommittedTimestamp - _idReuseSafeZoneTime;

            foreach (KernelTransactionHandle txHandle in _kernelTransactions.activeTransactions())
            {
                long commitTimestamp = txHandle.LastTransactionTimestampWhenStarted();

                if (commitTimestamp != Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_COMMIT_TIMESTAMP && commitTimestamp < earliestSafeTimestamp)
                {
                    if (txHandle.MarkForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Outdated))
                    {
                        _log.info("Marking transaction for termination, " + "invalidated due to an upcoming batch of changes being applied:" + "\n" + "  Batch: firstCommittedTxId:" + first.TransactionId() + ", firstCommittedTimestamp:" + InformativeTimestamp(firstCommittedTimestamp) + ", lastCommittedTxId:" + last.TransactionId() + ", lastCommittedTimestamp:" + InformativeTimestamp(lastCommittedTimestamp) + ", batchTimeRange:" + InformativeDuration(lastCommittedTimestamp - firstCommittedTimestamp) + ", earliestSafeTimestamp:" + InformativeTimestamp(earliestSafeTimestamp) + ", safeZoneDuration:" + InformativeDuration(_idReuseSafeZoneTime) + "\n" + "  Transaction: lastCommittedTimestamp:" + InformativeTimestamp(txHandle.LastTransactionTimestampWhenStarted()) + ", lastCommittedTxId:" + txHandle.LastTransactionIdWhenStarted() + ", localStartTimestamp:" + InformativeTimestamp(txHandle.StartTime()));
                    }
                }
            }
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKernelPanicIfTransactionIdsMismatch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKernelPanicIfTransactionIdsMismatch()
        {
            // Given
            BatchingTransactionAppender appender = Life.add(CreateTransactionAppender());

            when(_transactionIdStore.nextCommittingTransactionId()).thenReturn(42L);
            TransactionToApply batch = new TransactionToApply(mock(typeof(TransactionRepresentation)), 43L);

            // When
            try
            {
                appender.Append(batch, Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null);
                fail("should have thrown ");
            }
            catch (System.InvalidOperationException ex)
            {
                // Then
                verify(_databaseHealth, times(1)).panic(ex);
            }
        }
コード例 #13
0
//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());
        }
コード例 #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long commit(org.neo4j.kernel.impl.api.TransactionToApply first) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private long Commit(TransactionToApply first)
        {
            return(_commitProcess.commit(first, CommitEvent.NULL, EXTERNAL));
        }
コード例 #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long commit(org.neo4j.kernel.impl.api.TransactionToApply batch, org.neo4j.kernel.impl.transaction.tracing.CommitEvent commitEvent, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws org.neo4j.graphdb.TransactionFailureException
            public override long Commit(TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode)
            {
                TransactionsToApply.Add(batch.TransactionRepresentation());
                return(-1);
            }