Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean visitPropertyRecordChain(long firstPropertyRecordId, org.neo4j.helpers.collection.Visitor<org.neo4j.kernel.impl.store.record.PropertyRecord,RuntimeException> visitor) throws CircularPropertyRecordChainException
        private bool VisitPropertyRecordChain(long firstPropertyRecordId, Visitor <PropertyRecord, Exception> visitor)
        {
            if (Record.NO_NEXT_PROPERTY.@is(firstPropertyRecordId))
            {
                return(false);
            }

            MutableLongSet visitedPropertyRecordIds = new LongHashSet(8);

            visitedPropertyRecordIds.add(firstPropertyRecordId);
            long nextProp = firstPropertyRecordId;

            while (!Record.NO_NEXT_PROPERTY.@is(nextProp))
            {
                PropertyRecord propRecord = _propertyStore.getRecord(nextProp, _propertyStore.newRecord(), FORCE);
                nextProp = propRecord.NextProp;
                if (!Record.NO_NEXT_PROPERTY.@is(nextProp) && !visitedPropertyRecordIds.add(nextProp))
                {
                    throw new CircularPropertyRecordChainException(propRecord);
                }
                if (visitor.Visit(propRecord))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        // TODO analyzer setting must be replicates to all cluster members
        // TODO eventually_consistent setting must be replicated to all cluster members.

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void awaitCatchup() throws InterruptedException
        private void AwaitCatchup()
        {
            MutableLongSet appliedTransactions = new LongHashSet();

            System.Action <ClusterMember> awaitPopulationAndCollectionAppliedTransactionId = member =>
            {
                GraphDatabaseAPI db = member.database();
                try
                {
                    using (Transaction ignore = Db.beginTx())
                    {
                        Db.schema().awaitIndexesOnline(20, TimeUnit.SECONDS);
                        Db.execute(AWAIT_REFRESH).close();
                        DependencyResolver dependencyResolver = Db.DependencyResolver;
                        TransactionIdStore transactionIdStore = dependencyResolver.resolveDependency(typeof(TransactionIdStore));
                        appliedTransactions.add(transactionIdStore.LastClosedTransactionId);
                    }
                }
                catch (Exception e) when(e is QueryExecutionException || e is System.ArgumentException)
                {
                    if (e.Message.Equals("No index was found"))
                    {
                        // Looks like the index creation hasn't been replicated yet, so we force a retry by making sure that
                        // the 'appliedTransactions' set will definitely contain more than one element.
                        appliedTransactions.add(-1L);
                        appliedTransactions.add(-2L);
                    }
                }
                catch (NotFoundException)
                {
                    // This can happen due to a race inside `db.schema().awaitIndexesOnline`, where the list of indexes are provided by the SchemaCache, which is
                    // updated during command application in commit, but the index status is then fetched from the IndexMap, which is updated when the applier is
                    // closed during commit (which comes later in the commit process than command application). So we are told by the SchemaCache that an index
                    // exists, but we are then also told by the IndexMap that the index does not exist, hence this NotFoundException. Normally, these two are
                    // protected by the schema locks that are taken on index create and index status check. However, those locks are 1) incorrectly managed around
                    // index population, and 2) those locks are NOT TAKEN in Causal Cluster command replication!
                    // So we need to anticipate this, and if the race happens, we simply have to try again. But yeah, it needs to be fixed properly at some point.
                    appliedTransactions.add(-1L);
                    appliedTransactions.add(-2L);
                }
            };
            do
            {
                appliedTransactions.clear();
                Thread.Sleep(25);
                ICollection <CoreClusterMember> cores        = _cluster.coreMembers();
                ICollection <ReadReplica>       readReplicas = _cluster.readReplicas();
                cores.forEach(awaitPopulationAndCollectionAppliedTransactionId);
                readReplicas.forEach(awaitPopulationAndCollectionAppliedTransactionId);
            } while (appliedTransactions.size() != 1);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldVisitUnacquiredIds() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldVisitUnacquiredIds()
        {
            // GIVEN a couple of released ids
            MutableLongSet expected = new LongHashSet();

            for (int i = 0; i < 100; i++)
            {
                expected.add(_freelist.acquireNewId(GENERATION_ONE, _generationTwo));
            }
            expected.forEach(id =>
            {
                try
                {
                    _freelist.releaseId(GENERATION_ONE, _generationTwo, id);
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            });
            // and only a few acquired
            for (int i = 0; i < 10; i++)
            {
                long acquiredId = _freelist.acquireNewId(_generationTwo, _generationThree);
                assertTrue(expected.remove(acquiredId));
            }

            // WHEN/THEN
            _freelist.visitFreelist(new IdProvider_IdProviderVisitor_AdaptorAnonymousInnerClass(this, expected));
            assertTrue(expected.Empty);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldPutFreedFreeListPagesIntoFreeListAsWell() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldPutFreedFreeListPagesIntoFreeListAsWell()
        {
            // GIVEN
            long           prevId;
            long           acquiredId     = BASE_ID + 1;
            long           freelistPageId = BASE_ID + 1;
            MutableLongSet released       = new LongHashSet();

            do
            {
                prevId     = acquiredId;
                acquiredId = _freelist.acquireNewId(GENERATION_ONE, _generationTwo);
                _freelist.releaseId(GENERATION_ONE, _generationTwo, acquiredId);
                released.add(acquiredId);
            } while (acquiredId - prevId == 1);

            // WHEN
            while (!released.Empty)
            {
                long reAcquiredId = _freelist.acquireNewId(_generationTwo, _generationThree);
                released.remove(reAcquiredId);
            }

            // THEN
            assertEquals(freelistPageId, _freelist.acquireNewId(_generationThree, _generationFour));
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.eclipse.collections.api.set.primitive.LongSet gatherIdsModifiedInTransactionState(java.util.List<EntityId> simpleTransactionStateIds, org.apache.lucene.search.IndexSearcher fulltextTransactionStateSearcher, org.apache.lucene.search.Query query) throws java.io.IOException
        private LongSet GatherIdsModifiedInTransactionState(IList <EntityId> simpleTransactionStateIds, IndexSearcher fulltextTransactionStateSearcher, Query query)
        {
            // If there's no state them don't bother gathering it
            if (simpleTransactionStateIds.Count == 0 && fulltextTransactionStateSearcher == null)
            {
                return(LongSets.immutable.empty());
            }
            // There's potentially some state
            DocValuesCollector docValuesCollector = null;
            int fulltextSize = 0;

            if (fulltextTransactionStateSearcher != null)
            {
                docValuesCollector = new DocValuesCollector();
                fulltextTransactionStateSearcher.search(query, docValuesCollector);
                fulltextSize = docValuesCollector.TotalHits;
                // Nah, no state
                if (simpleTransactionStateIds.Count == 0 && fulltextSize == 0)
                {
                    return(LongSets.immutable.empty());
                }
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet set = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet(simpleTransactionStateIds.size() + fulltextSize);
            MutableLongSet set = new LongHashSet(simpleTransactionStateIds.Count + fulltextSize);

            // Add from simple tx state
            foreach (EntityId id in simpleTransactionStateIds)
            {
                set.add(id.Id());
            }

            if (docValuesCollector != null)
            {
                // Add from fulltext tx state
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.iterator.LongIterator valuesIterator = docValuesCollector.getValuesIterator(LuceneExplicitIndex.KEY_DOC_ID);
                LongIterator valuesIterator = docValuesCollector.GetValuesIterator(LuceneExplicitIndex.KEY_DOC_ID);
                while (valuesIterator.hasNext())
                {
                    set.add(valuesIterator.next());
                }
            }
            return(set);
        }
        public static MutableLongSet AsSet(LongIterator iterator)
        {
            MutableLongSet set = new LongHashSet();

            while (iterator.hasNext())
            {
                set.add(iterator.next());
            }
            return(set);
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.eclipse.collections.api.set.primitive.LongSet unmarshalIndexIds(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException
            internal virtual LongSet UnmarshalIndexIds(ReadableChannel channel)
            {
                int            numberOfIndexIds = channel.Int;
                MutableLongSet indexIds         = new LongHashSet(numberOfIndexIds);

                for (int i = 0; i < numberOfIndexIds; i++)
                {
                    indexIds.add(channel.Long);
                }
                return(indexIds);
            }
Esempio n. 8
0
        public override void CheckConsistency(RECORD record, CheckerEngine <RECORD, REPORT> engine, RecordAccess records)
        {
            if (!Record.NO_NEXT_PROPERTY.@is(record.NextProp))
            {
                // Check the whole chain here instead of scattered during multiple checks.
                // This type of check obviously favors chains with good locality, performance-wise.
                IEnumerator <PropertyRecord> props = records.RawPropertyChain(record.NextProp);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                PropertyRecord firstProp = props.next();
                if (!Record.NO_PREVIOUS_PROPERTY.@is(firstProp.PrevProp))
                {
                    engine.Report().propertyNotFirstInChain(firstProp);
                }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableIntSet keys = new org.eclipse.collections.impl.set.mutable.primitive.IntHashSet();
                MutableIntSet keys = new IntHashSet();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet propertyRecordIds = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet(8);
                MutableLongSet propertyRecordIds = new LongHashSet(8);
                propertyRecordIds.add(firstProp.Id);
                using (MandatoryProperties.Check <RECORD, REPORT> mandatory = _mandatoryProperties.apply(record))
                {
                    CheckChainItem(firstProp, engine, keys, mandatory);

                    // Check the whole chain here. We also take the opportunity to check mandatory property constraints.
                    PropertyRecord prop = firstProp;
                    while (props.MoveNext())
                    {
                        PropertyRecord nextProp = props.Current;
                        if (!propertyRecordIds.add(nextProp.Id))
                        {
                            engine.Report().propertyChainContainsCircularReference(prop);
                            break;
                        }
                        CheckChainItem(nextProp, engine, keys, mandatory);
                        prop = nextProp;
                    }
                }
            }
        }
        public static MutableLongSet AsSet(ICollection <long> collection)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet set = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet(collection.size());
            MutableLongSet set = new LongHashSet(collection.Count);

            foreach (long?next in collection)
            {
                set.add(next);
            }
            return(set);
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldStayBoundUnderStress() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldStayBoundUnderStress()
        {
            // GIVEN
            MutableLongSet acquired           = new LongHashSet();
            IList <long>   acquiredList       = new List <long>();     // for quickly finding random to remove
            long           stableGeneration   = GenerationSafePointer.MIN_GENERATION;
            long           unstableGeneration = stableGeneration + 1;
            int            iterations         = 100;

            // WHEN
            for (int i = 0; i < iterations; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (_random.nextBoolean())
                    {
                        // acquire
                        int count = _random.intBetween(5, 10);
                        for (int k = 0; k < count; k++)
                        {
                            long acquiredId = _freelist.acquireNewId(stableGeneration, unstableGeneration);
                            assertTrue(acquired.add(acquiredId));
                            acquiredList.Add(acquiredId);
                        }
                    }
                    else
                    {
                        // release
                        int count = _random.intBetween(5, 20);
                        for (int k = 0; k < count && !acquired.Empty; k++)
                        {
                            long id = acquiredList.RemoveAt(_random.Next(acquiredList.Count));
                            assertTrue(acquired.remove(id));
                            _freelist.releaseId(stableGeneration, unstableGeneration, id);
                        }
                    }
                }

                foreach (long id in acquiredList)
                {
                    _freelist.releaseId(stableGeneration, unstableGeneration, id);
                }
                acquiredList.Clear();
                acquired.clear();

                // checkpoint, sort of
                stableGeneration = unstableGeneration;
                unstableGeneration++;
            }

            // THEN
            assertTrue(_freelist.lastId() < 200, _freelist.lastId().ToString());
        }
        private MutableLongSet CreateNodes(GraphDatabaseService db, Label label, params string[] propertyValues)
        {
            MutableLongSet expected = new LongHashSet();

            using (Transaction tx = Db.beginTx())
            {
                foreach (string value in propertyValues)
                {
                    expected.add(CreateNode(db, map(_key, value), label).Id);
                }
                tx.Success();
            }
            return(expected);
        }
        public virtual MutableLongSet CreateNodes(GraphDatabaseService db, Label label, params object[][] propertyValueTuples)
        {
            MutableLongSet expected = new LongHashSet();

            using (Transaction tx = Db.beginTx())
            {
                foreach (object[] valueTuple in propertyValueTuples)
                {
                    expected.add(CreateNode(db, PropertyMap(Keys, valueTuple), label).Id);
                }
                tx.Success();
            }
            return(expected);
        }
Esempio n. 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void scanningRecordsShouldVisitEachInUseRecordOnce() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ScanningRecordsShouldVisitEachInUseRecordOnce()
        {
            // GIVEN we have a NodeStore with data that spans several pages...
            EphemeralFileSystemAbstraction fs = _efs.get();

            _nodeStore = NewNodeStore(fs);

            ThreadLocalRandom rng = ThreadLocalRandom.current();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet nextRelSet = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet();
            MutableLongSet nextRelSet = new LongHashSet();

            for (int i = 0; i < 10_000; i++)
            {
                // Enough records to span several pages
                int nextRelCandidate = rng.Next(0, int.MaxValue);
                if (nextRelSet.add(nextRelCandidate))
                {
                    long       nodeId = _nodeStore.nextId();
                    NodeRecord record = new NodeRecord(nodeId, false, nextRelCandidate, 20, true);
                    _nodeStore.updateRecord(record);
                    if (rng.Next(0, 10) < 3)
                    {
                        nextRelSet.remove(nextRelCandidate);
                        record.InUse = false;
                        _nodeStore.updateRecord(record);
                    }
                }
            }

            // ...WHEN we now have an interesting set of node records, and we
            // visit each and remove that node from our nextRelSet...

            Visitor <NodeRecord, IOException> scanner = record =>
            {
                // ...THEN we should observe that no nextRel is ever removed twice...
                assertTrue(nextRelSet.remove(record.NextRel));
                return(false);
            };

            _nodeStore.scanAllRecords(scanner);

            // ...NOR do we have anything left in the set afterwards.
            assertTrue(nextRelSet.Empty);
        }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldVisitFreelistPageIds() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldVisitFreelistPageIds()
        {
            // GIVEN a couple of released ids
            MutableLongSet expected = new LongHashSet();

            // Add the already allocated free-list page id
            expected.add(BASE_ID + 1);
            _monitor.set(new MonitorAnonymousInnerClass(this, expected));
            for (int i = 0; i < 100; i++)
            {
                long id = _freelist.acquireNewId(GENERATION_ONE, _generationTwo);
                _freelist.releaseId(GENERATION_ONE, _generationTwo, id);
            }
            assertTrue(expected.size() > 0);

            // WHEN/THEN
            _freelist.visitFreelist(new IdProvider_IdProviderVisitor_AdaptorAnonymousInnerClass2(this, expected));
            assertTrue(expected.Empty);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void keysIterator()
        internal virtual void KeysIterator()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.LongSet keys = org.eclipse.collections.impl.factory.primitive.LongSets.immutable.of(0L, 1L, 2L, 42L);
            LongSet keys = LongSets.immutable.of(0L, 1L, 2L, 42L);

            keys.forEach(k => _map.put(k, k * 10));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.iterator.MutableLongIterator iter = map.longIterator();
            MutableLongIterator iter = _map.longIterator();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet found = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet();
            MutableLongSet found = new LongHashSet();

            while (iter.hasNext())
            {
                found.add(iter.next());
            }

            assertEquals(keys, found);
        }
Esempio n. 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void awaitIndexesOnlineMustWorkOnFulltextIndexes()
        public virtual void AwaitIndexesOnlineMustWorkOnFulltextIndexes()
        {
            string           prop1    = "prop1";
            string           prop2    = "prop2";
            string           prop3    = "prop3";
            string           val1     = "foo foo";
            string           val2     = "bar bar";
            string           val3     = "baz baz";
            Label            label1   = Label.label("FirstLabel");
            Label            label2   = Label.label("SecondLabel");
            Label            label3   = Label.label("ThirdLabel");
            RelationshipType relType1 = RelationshipType.withName("FirstRelType");
            RelationshipType relType2 = RelationshipType.withName("SecondRelType");
            RelationshipType relType3 = RelationshipType.withName("ThirdRelType");

            LongHashSet nodes1 = new LongHashSet();
            LongHashSet nodes2 = new LongHashSet();
            LongHashSet nodes3 = new LongHashSet();
            LongHashSet rels1  = new LongHashSet();
            LongHashSet rels2  = new LongHashSet();
            LongHashSet rels3  = new LongHashSet();

            using (Transaction tx = Db.beginTx())
            {
                for (int i = 0; i < 100; i++)
                {
                    Node node1 = Db.createNode(label1);
                    node1.SetProperty(prop1, val1);
                    nodes1.add(node1.Id);
                    Relationship rel1 = node1.CreateRelationshipTo(node1, relType1);
                    rel1.SetProperty(prop1, val1);
                    rels1.add(rel1.Id);

                    Node node2 = Db.createNode(label2);
                    node2.SetProperty(prop2, val2);
                    nodes2.add(node2.Id);
                    Relationship rel2 = node1.CreateRelationshipTo(node2, relType2);
                    rel2.SetProperty(prop2, val2);
                    rels2.add(rel2.Id);

                    Node node3 = Db.createNode(label3);
                    node3.SetProperty(prop3, val3);
                    nodes3.add(node3.Id);
                    Relationship rel3 = node1.CreateRelationshipTo(node3, relType3);
                    rel3.SetProperty(prop3, val3);
                    rels3.add(rel3.Id);
                }
                tx.Success();
            }

            // Test that multi-token node indexes can be waited for.
            using (Transaction tx = Db.beginTx())
            {
                Db.execute(format(NODE_CREATE, "nodeIndex", array(label1.Name(), label2.Name(), label3.Name()), array(prop1, prop2, prop3))).close();
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                assertQueryFindsIds(Db, true, "nodeIndex", "foo", nodes1);
                assertQueryFindsIds(Db, true, "nodeIndex", "bar", nodes2);
                assertQueryFindsIds(Db, true, "nodeIndex", "baz", nodes3);
                tx.Success();
            }

            // Test that multi-token relationship indexes can be waited for.
            using (Transaction tx = Db.beginTx())
            {
                Db.execute(format(RELATIONSHIP_CREATE, "relIndex", array(relType1.Name(), relType2.Name(), relType3.Name()), array(prop1, prop2, prop3))).close();
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                assertQueryFindsIds(Db, false, "relIndex", "foo", rels1);
                assertQueryFindsIds(Db, false, "relIndex", "bar", rels2);
                assertQueryFindsIds(Db, false, "relIndex", "baz", rels3);
                tx.Success();
            }
        }