コード例 #1
0
ファイル: EncodeGroupsStep.cs プロジェクト: Neo4Net/Neo4Net
        protected internal override void Process(RelationshipGroupRecord[] batch, BatchSender sender)
        {
            int groupStartIndex = 0;

            for (int i = 0; i < batch.Length; i++)
            {
                RelationshipGroupRecord group = batch[i];

                // The iterator over the groups will not produce real next pointers, they are instead
                // a count meaning how many groups come after it. This encoder will set the real group ids.
                long count       = group.Next;
                bool lastInChain = count == 0;

                group.Id = _nextId == -1 ? _nextId = _store.nextId() : _nextId;
                if (!lastInChain)
                {
                    group.Next = _nextId = _store.nextId();
                }
                else
                {
                    group.Next = _nextId = -1;

                    // OK so this group is the last in this chain, which means all the groups in this chain
                    // are now fully populated. We can now prepare these groups so that their potential
                    // secondary units ends up very close by.
                    for (int j = groupStartIndex; j <= i; j++)
                    {
                        _store.prepareForCommit(batch[j]);
                    }

                    groupStartIndex = i + 1;
                }
            }
            Debug.Assert(groupStartIndex == batch.Length);

            sender.Send(batch);
        }
コード例 #2
0
        private void CreateRecordIn <RECORD>(RecordStore <RECORD> store) where RECORD : Org.Neo4j.Kernel.impl.store.record.AbstractBaseRecord
        {
            RECORD record = store.NewRecord();

            record.Id    = store.nextId();
            record.InUse = true;
            if (record is PropertyRecord)
            {
                // Special hack for property store, since it's not enough to simply set a record as in use there
                PropertyBlock block = new PropertyBlock();
                (( PropertyStore )store).encodeValue(block, 0, Values.of(10));
                (( PropertyRecord )record).addPropertyBlock(block);
            }
            store.UpdateRecord(record);
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDefragmentRelationshipGroupsWhenSomeDense()
        public virtual void ShouldDefragmentRelationshipGroupsWhenSomeDense()
        {
            // GIVEN some nodes which has their groups scattered
            int nodeCount             = 100;
            int relationshipTypeCount = 50;
            RecordStore <RelationshipGroupRecord> groupStore = _stores.TemporaryRelationshipGroupStore;
            RelationshipGroupRecord  groupRecord             = groupStore.NewRecord();
            RecordStore <NodeRecord> nodeStore = _stores.NodeStore;
            NodeRecord nodeRecord       = nodeStore.NewRecord();
            long       cursor           = 0;
            BitArray   initializedNodes = new BitArray();

            for (int typeId = relationshipTypeCount - 1; typeId >= 0; typeId--)
            {
                for (int nodeId = 0; nodeId < nodeCount; nodeId++, cursor++)
                {
                    // Reasoning behind this thing is that we want to have roughly 10% of the nodes dense
                    // right from the beginning and then some stray dense nodes coming into this in the
                    // middle of the type range somewhere
                    double comparison = typeId == 0 || initializedNodes.Get(nodeId) ? 0.1 : 0.001;

                    if (_random.NextDouble() < comparison)
                    {
                        // next doesn't matter at all, as we're rewriting it anyway
                        // firstOut/In/Loop we could use in verification phase later
                        groupRecord.Initialize(true, typeId, cursor, cursor + 1, cursor + 2, nodeId, 4);
                        groupRecord.Id = groupStore.nextId();
                        groupStore.UpdateRecord(groupRecord);

                        if (!initializedNodes.Get(nodeId))
                        {
                            nodeRecord.Initialize(true, -1, true, groupRecord.Id, 0);
                            nodeRecord.Id = nodeId;
                            nodeStore.UpdateRecord(nodeRecord);
                            nodeStore.HighestPossibleIdInUse = nodeId;
                            initializedNodes.Set(nodeId, true);
                        }
                    }
                }
            }

            // WHEN
            Defrag(nodeCount, groupStore);

            // THEN all groups should sit sequentially in the store
            VerifyGroupsAreSequentiallyOrderedByNode();
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldEncodeGroupChains() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldEncodeGroupChains()
        {
            // GIVEN
            StageControl control = mock(typeof(StageControl));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicLong nextId = new java.util.concurrent.atomic.AtomicLong();
            AtomicLong nextId = new AtomicLong();
            RecordStore <RelationshipGroupRecord> store = mock(typeof(RecordStore));

            when(store.nextId()).thenAnswer(invocation => nextId.incrementAndGet());
            doAnswer(invocation =>
            {
                // our own way of marking that this has record been prepared (firstOut=1)
                invocation.getArgument <RelationshipGroupRecord>(0).FirstOut = 1;
                return(null);
            }).when(store).prepareForCommit(any(typeof(RelationshipGroupRecord)));
            Configuration    config  = Configuration.withBatchSize(DEFAULT, 10);
            EncodeGroupsStep encoder = new EncodeGroupsStep(control, config, store);

            // WHEN
            encoder.Start([email protected]_Fields.ORDER_SEND_DOWNSTREAM);
            Catcher catcher = new Catcher();

            encoder.Process(Batch(new Group(1, 3), new Group(2, 3), new Group(3, 4)), catcher);
            encoder.Process(Batch(new Group(4, 2), new Group(5, 10)), catcher);
            encoder.Process(Batch(new Group(6, 35)), catcher);
            encoder.Process(Batch(new Group(7, 2)), catcher);
            encoder.endOfUpstream();
            encoder.awaitCompleted();
            encoder.Close();

            // THEN
            assertEquals(4, catcher.Batches.Count);
            long lastOwningNodeLastBatch = -1;

            foreach (RelationshipGroupRecord[] batch in catcher.Batches)
            {
                AssertBatch(batch, lastOwningNodeLastBatch);
                lastOwningNodeLastBatch = batch[batch.Length - 1].OwningNode;
            }
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDefragmentRelationshipGroupsWhenAllDense()
        public virtual void ShouldDefragmentRelationshipGroupsWhenAllDense()
        {
            // GIVEN some nodes which has their groups scattered
            int nodeCount             = 100;
            int relationshipTypeCount = 50;
            RecordStore <RelationshipGroupRecord> groupStore = _stores.TemporaryRelationshipGroupStore;
            RelationshipGroupRecord  groupRecord             = groupStore.NewRecord();
            RecordStore <NodeRecord> nodeStore = _stores.NodeStore;
            NodeRecord nodeRecord = nodeStore.NewRecord();
            long       cursor     = 0;

            for (int typeId = relationshipTypeCount - 1; typeId >= 0; typeId--)
            {
                for (long nodeId = 0; nodeId < nodeCount; nodeId++, cursor++)
                {
                    // next doesn't matter at all, as we're rewriting it anyway
                    // firstOut/In/Loop we could use in verification phase later
                    groupRecord.Initialize(true, typeId, cursor, cursor + 1, cursor + 2, nodeId, 4);
                    groupRecord.Id = groupStore.nextId();
                    groupStore.UpdateRecord(groupRecord);

                    if (typeId == 0)
                    {
                        // first round also create the nodes
                        nodeRecord.Initialize(true, -1, true, groupRecord.Id, 0);
                        nodeRecord.Id = nodeId;
                        nodeStore.UpdateRecord(nodeRecord);
                        nodeStore.HighestPossibleIdInUse = nodeId;
                    }
                }
            }

            // WHEN
            Defrag(nodeCount, groupStore);

            // THEN all groups should sit sequentially in the store
            VerifyGroupsAreSequentiallyOrderedByNode();
        }
コード例 #6
0
 public virtual long NewRuleId()
 {
     return(_schemaStore.nextId());
 }
コード例 #7
0
 public override long NextId()
 {
     return(Actual.nextId());
 }