Esempio n. 1
0
 private void SetCount(RelationshipGroupCache cache, int nodeId, int count)
 {
     for (int i = 0; i < count; i++)
     {
         cache.IncrementGroupCount(nodeId);
     }
 }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleGroupCountBeyondSignedShortRange()
        public virtual void ShouldHandleGroupCountBeyondSignedShortRange()
        {
            // GIVEN
            long nodeId = 0;
            int  limit  = short.MaxValue + 10;
            RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(100), nodeId + 1);

            // WHEN first counting all groups per node
            for (int type = 0; type < limit; type++)
            {
                cache.IncrementGroupCount(nodeId);
            }
            // and WHEN later putting group records into the cache
            RelationshipGroupRecord group = new RelationshipGroupRecord(-1);

            group.OwningNode = nodeId;
            for (int type = 0; type < limit; type++)
            {
                group.Id       = type;
                group.FirstOut = type;                         // just some relationship
                group.Type     = type;
                cache.Put(group);
            }
            long prepared = cache.Prepare(nodeId);

            // THEN that should work, because it used to fail inside prepare, but we can also ask
            // the groupCount method to be sure
            assertEquals(nodeId, prepared);
            assertEquals(limit, cache.GroupCount(nodeId));
        }
Esempio n. 3
0
            public PrefetchingIteratorAnonymousInnerClass(RelationshipGroupCache outerInstance)
            {
                this.outerInstance   = outerInstance;
                nodeId               = outerInstance.fromNodeId;
                countLeftForThisNode = outerInstance.GroupCount(nodeId);

                findNextNodeWithGroupsIfNeeded();
            }
Esempio n. 4
0
        public WriteGroupsStage(Configuration config, RelationshipGroupCache cache, RecordStore <RelationshipGroupRecord> store) : base(NAME, null, config, 0)
        {
            Add(new ReadGroupsFromCacheStep(Control(), config, cache.GetEnumerator(), GROUP_ENTRY_SIZE));
            Add(new EncodeGroupsStep(Control(), config, store));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: add(new UpdateRecordsStep<>(control(), config, store, new org.neo4j.unsafe.impl.batchimport.store.StorePrepareIdSequence()));
            Add(new UpdateRecordsStep <object>(Control(), config, store, new StorePrepareIdSequence()));
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSortOutOfOrderTypes()
        public virtual void ShouldSortOutOfOrderTypes()
        {
            // GIVEN
            int nodeCount = 100;
            RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(40), nodeCount);

            int[] counts     = new int[nodeCount];
            int   groupCount = 0;

            for (int nodeId = 0; nodeId < Counts.Length; nodeId++)
            {
                counts[nodeId] = Random.Next(10);
                SetCount(cache, nodeId, counts[nodeId]);
                groupCount += counts[nodeId];
            }
            assertEquals(nodeCount, cache.Prepare(0));
            bool thereAreMoreGroups = true;
            int  cachedCount        = 0;

            int[] types = ScrambledTypes(10);
            for (int i = 0; thereAreMoreGroups; i++)
            {
                int typeId = types[i];
                thereAreMoreGroups = false;
                for (int nodeId = 0; nodeId < nodeCount; nodeId++)
                {
                    if (counts[nodeId] > 0)
                    {
                        thereAreMoreGroups = true;
                        if (cache.Put((new RelationshipGroupRecord(nodeId)).initialize(true, typeId, -1, -1, -1, nodeId, -1)))
                        {
                            cachedCount++;
                            counts[nodeId]--;
                        }
                    }
                }
            }
            assertEquals(groupCount, cachedCount);

            // WHEN/THEN
            long currentNodeId = -1;
            int  currentTypeId = -1;
            int  readCount     = 0;

            foreach (RelationshipGroupRecord group in cache)
            {
                assertTrue(group.OwningNode >= currentNodeId);
                if (group.OwningNode > currentNodeId)
                {
                    currentNodeId = group.OwningNode;
                    currentTypeId = -1;
                }
                assertTrue(group.Type > currentTypeId);
                readCount++;
            }
            assertEquals(cachedCount, readCount);
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPutGroupsOnlyWithinPreparedRange()
        public virtual void ShouldPutGroupsOnlyWithinPreparedRange()
        {
            // GIVEN
            int nodeCount = 1000;
            RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(4), nodeCount);

            int[] counts = new int[nodeCount];
            for (int nodeId = 0; nodeId < Counts.Length; nodeId++)
            {
                counts[nodeId] = Random.Next(10);
                SetCount(cache, nodeId, counts[nodeId]);
            }

            long toNodeId = cache.Prepare(0);

            assertTrue(toNodeId < nodeCount);

            // WHEN
            bool thereAreMoreGroups = true;
            int  cachedCount        = 0;

            while (thereAreMoreGroups)
            {
                thereAreMoreGroups = false;
                for (int nodeId = 0; nodeId < nodeCount; nodeId++)
                {
                    if (counts[nodeId] > 0)
                    {
                        thereAreMoreGroups = true;
                        int typeId = counts[nodeId]--;
                        if (cache.Put((new RelationshipGroupRecord(nodeId)).initialize(true, typeId, -1, -1, -1, nodeId, -1)))
                        {
                            cachedCount++;
                        }
                    }
                }
            }
            assertTrue(cachedCount >= toNodeId);

            // THEN the relationship groups we get back are only for those we prepared for
            int readCount = 0;

            foreach (RelationshipGroupRecord cachedGroup in cache)
            {
                assertTrue(cachedGroup.OwningNode >= 0 && cachedGroup.OwningNode < toNodeId);
                readCount++;
            }
            assertEquals(cachedCount, readCount);
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFindSpaceToPutMoreGroupsThanSpecifiedForANode()
        public virtual void ShouldNotFindSpaceToPutMoreGroupsThanSpecifiedForANode()
        {
            // GIVEN
            int nodeCount = 10;
            RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(4), nodeCount);

            SetCount(cache, 1, 7);
            assertEquals(nodeCount, cache.Prepare(0));

            // WHEN
            for (int i = 0; i < 7; i++)
            {
                cache.Put((new RelationshipGroupRecord(i + 1)).initialize(true, i, -1, -1, -1, 1, -1));
            }
            try
            {
                cache.Put((new RelationshipGroupRecord(8)).initialize(true, 8, -1, -1, -1, 1, -1));
                fail("Should have failed");
            }
            catch (System.InvalidOperationException)
            {               // Good
            }
        }
        public virtual void Run(long memoryWeCanHoldForCertain, BatchingNeoStores neoStore, long highNodeId)
        {
            using (RelationshipGroupCache groupCache = new RelationshipGroupCache(_numberArrayFactory, memoryWeCanHoldForCertain, highNodeId))
            {
                // Read from the temporary relationship group store...
                RecordStore <RelationshipGroupRecord> fromStore = neoStore.TemporaryRelationshipGroupStore;
                // and write into the main relationship group store
                RecordStore <RelationshipGroupRecord> toStore = neoStore.RelationshipGroupStore;

                // Count all nodes, how many groups each node has each
                Configuration groupConfig = withBatchSize(_config, neoStore.RelationshipGroupStore.RecordsPerPage);
                StatsProvider memoryUsage = new MemoryUsageStatsProvider(neoStore, groupCache);
                ExecuteStage(new CountGroupsStage(groupConfig, fromStore, groupCache, memoryUsage));
                long fromNodeId = 0;
                long toNodeId   = 0;
                while (fromNodeId < highNodeId)
                {
                    // See how many nodes' groups we can fit into the cache this iteration of the loop.
                    // Groups that doesn't fit in this round will be included in consecutive rounds.
                    toNodeId = groupCache.Prepare(fromNodeId);
                    _monitor.defragmentingNodeRange(fromNodeId, toNodeId);
                    // Cache those groups
                    ExecuteStage(new ScanAndCacheGroupsStage(groupConfig, fromStore, groupCache, memoryUsage));
                    // And write them in sequential order in the store
                    ExecuteStage(new WriteGroupsStage(groupConfig, groupCache, toStore));

                    // Make adjustments for the next iteration
                    fromNodeId = toNodeId;
                }

                // Now update nodes to point to the new groups
                ByteArray groupCountCache = groupCache.GroupCountCache;
                groupCountCache.clear();
                Configuration nodeConfig = withBatchSize(_config, neoStore.NodeStore.RecordsPerPage);
                ExecuteStage(new NodeFirstGroupStage(nodeConfig, toStore, neoStore.NodeStore, groupCountCache));
            }
        }
Esempio n. 9
0
        public ScanAndCacheGroupsStage(Configuration config, RecordStore <RelationshipGroupRecord> store, RelationshipGroupCache cache, params StatsProvider[] additionalStatsProviders) : base(NAME, null, config, RECYCLE_BATCHES)
        {
            Add(new BatchFeedStep(Control(), config, allInReversed(store, config), store.RecordSize));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: add(new org.neo4j.unsafe.impl.batchimport.staging.ReadRecordsStep<>(control(), config, false, store));
            Add(new ReadRecordsStep <object>(Control(), config, false, store));
            Add(new CacheGroupsStep(Control(), config, cache, additionalStatsProviders));
        }
Esempio n. 10
0
 public CacheGroupsStep(StageControl control, Configuration config, RelationshipGroupCache cache, params StatsProvider[] additionalStatsProviders) : base(control, "CACHE", config, 1, additionalStatsProviders)
 {
     this._cache = cache;
 }