Search in sources :

Example 1 with RelationshipData

use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.

the class DegreesRebuildFromStoreTest method generateData.

private void generateData(RecordStorageEngine storageEngine, int denseThreshold, int[] relationshipTypes) throws Exception {
    int numNodes = 100;
    long[] nodes = new long[numNodes];
    applyLogicalChanges(storageEngine, (state, tx) -> {
        NodeStore nodeStore = storageEngine.testAccessNeoStores().getNodeStore();
        for (int i = 0; i < numNodes; i++) {
            nodes[i] = nodeStore.nextId(NULL);
            tx.visitCreatedNode(nodes[i]);
        }
    });
    RelationshipStore relationshipStore = storageEngine.testAccessNeoStores().getRelationshipStore();
    List<RelationshipData> relationships = new ArrayList<>();
    int numRelationships = numNodes * denseThreshold;
    for (int i = 0; i < numRelationships; i++) {
        relationships.add(new RelationshipData(relationshipStore.nextId(NULL), random.among(relationshipTypes), random.among(nodes), random.among(nodes)));
    }
    applyLogicalChanges(storageEngine, (state, tx) -> {
        NodeState nodeState = mock(NodeState.class);
        when(nodeState.labelDiffSets()).thenReturn(LongDiffSets.EMPTY);
        when(state.getNodeState(anyLong())).thenReturn(nodeState);
        tx.visitRelationshipModifications(new FlatRelationshipModifications(relationships.toArray(new RelationshipData[0])));
    });
}
Also used : RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeState(org.neo4j.storageengine.api.txstate.NodeState) FlatRelationshipModifications(org.neo4j.internal.recordstorage.FlatRelationshipModifications) ArrayList(java.util.ArrayList) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore)

Example 2 with RelationshipData

use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.

the class TransactionRecordStateTest method movingBilaterallyOfTheDenseNodeThresholdIsConsistent.

@Test
void movingBilaterallyOfTheDenseNodeThresholdIsConsistent() throws Exception {
    neoStores = createStores(Config.defaults(dense_node_threshold, 10));
    TransactionRecordState tx = newTransactionRecordState();
    long nodeId = neoStores.getNodeStore().nextId(NULL);
    tx.nodeCreate(nodeId);
    int typeA = (int) neoStores.getRelationshipTypeTokenStore().nextId(NULL);
    tx.createRelationshipTypeToken("A", typeA, false);
    createRelationships(neoStores, tx, nodeId, typeA, INCOMING, 20);
    TransactionApplierFactory applier = buildApplier(LockService.NO_LOCK_SERVICE);
    apply(applier, transaction(tx));
    tx = newTransactionRecordState();
    int typeB = 1;
    tx.createRelationshipTypeToken("B", typeB, false);
    // WHEN
    // i remove enough relationships to become dense and remove enough to become not dense
    RelationshipData[] relationshipsOfTypeB = createRelationships(neoStores, tx, nodeId, typeB, OUTGOING, 5);
    tx.relModify(new FlatRelationshipModifications(relationships(), relationshipsOfTypeB));
    CommandsToApply ptx = transaction(tx);
    apply(applier, ptx);
    // THEN
    // The dynamic label record in before should be the same id as in after, and should be in use
    final AtomicBoolean foundRelationshipGroupInUse = new AtomicBoolean();
    ptx.accept(command -> ((Command) command).handle(new CommandVisitor.Adapter() {

        @Override
        public boolean visitRelationshipGroupCommand(Command.RelationshipGroupCommand command) {
            if (command.getAfter().inUse()) {
                if (!foundRelationshipGroupInUse.get()) {
                    foundRelationshipGroupInUse.set(true);
                } else {
                    fail();
                }
            }
            return false;
        }
    }));
    assertTrue(foundRelationshipGroupInUse.get(), "Did not create relationship group command");
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RelationshipGroupCommand(org.neo4j.internal.recordstorage.Command.RelationshipGroupCommand) Test(org.junit.jupiter.api.Test)

Example 3 with RelationshipData

use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.

the class RelationshipModifierTest method sparseDelete.

@Test
void sparseDelete() {
    // given
    long node1 = createEmptyNode();
    long node2 = createEmptyNode();
    RelationshipData relationship = relationship(99, 1, node1, node2);
    createRelationships(singletonList(relationship));
    // when
    modify(singleDelete(relationship));
    // then
    locks.assertHasLock(NODE, EXCLUSIVE, node1);
    locks.assertNoLock(RELATIONSHIP_GROUP, EXCLUSIVE, node1);
    locks.assertHasLock(NODE, EXCLUSIVE, node2);
    locks.assertNoLock(RELATIONSHIP_GROUP, EXCLUSIVE, node2);
}
Also used : RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 4 with RelationshipData

use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.

the class RelationshipModifierTest method readRelationshipsFromStore.

private static Set<RelationshipData> readRelationshipsFromStore(long node, MapRecordStore store) {
    Set<RelationshipData> relationships = new HashSet<>();
    store.relationshipChainVisitor().visit(node, relationshipCollector(r -> relationships.add(new RelationshipData(r.getId(), r.getType(), r.getFirstNode(), r.getSecondNode()))));
    return relationships;
}
Also used : RelationshipModifications(org.neo4j.storageengine.api.txstate.RelationshipModifications) BeforeEach(org.junit.jupiter.api.BeforeEach) Record.isNull(org.neo4j.kernel.impl.store.record.Record.isNull) RepeatedTest(org.junit.jupiter.api.RepeatedTest) MutableInt(org.apache.commons.lang3.mutable.MutableInt) ArrayUtil.indexOf(org.neo4j.internal.helpers.ArrayUtil.indexOf) LongSupplier(java.util.function.LongSupplier) RandomExtension(org.neo4j.test.extension.RandomExtension) OUTGOING(org.neo4j.storageengine.api.RelationshipDirection.OUTGOING) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) LockType(org.neo4j.lock.LockType) GroupDegreeCommand.combinedKeyOnGroupAndDirection(org.neo4j.internal.recordstorage.Command.GroupDegreeCommand.combinedKeyOnGroupAndDirection) NullLogProvider(org.neo4j.logging.NullLogProvider) IdSequence(org.neo4j.internal.id.IdSequence) Collections.singletonList(java.util.Collections.singletonList) NO_LABELS_FIELD(org.neo4j.kernel.impl.store.record.Record.NO_LABELS_FIELD) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Monitors(org.neo4j.monitoring.Monitors) RandomRule(org.neo4j.test.rule.RandomRule) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Map(java.util.Map) RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) FlatRelationshipModifications.relationship(org.neo4j.internal.recordstorage.FlatRelationshipModifications.relationship) EXCLUSIVE(org.neo4j.lock.LockType.EXCLUSIVE) Exceptions(org.neo4j.internal.helpers.Exceptions) RELATIONSHIP_GROUP(org.neo4j.lock.ResourceTypes.RELATIONSHIP_GROUP) Record(org.neo4j.kernel.impl.store.record.Record) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) FlatRelationshipModifications.creations(org.neo4j.internal.recordstorage.FlatRelationshipModifications.creations) LOOP(org.neo4j.storageengine.api.RelationshipDirection.LOOP) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) FlatRelationshipModifications.modifications(org.neo4j.internal.recordstorage.FlatRelationshipModifications.modifications) RELATIONSHIP_DELETE(org.neo4j.lock.ResourceTypes.RELATIONSHIP_DELETE) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) FlatRelationshipModifications.relationships(org.neo4j.internal.recordstorage.FlatRelationshipModifications.relationships) NODE(org.neo4j.lock.ResourceTypes.NODE) EMPTY_LONG_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_LONG_ARRAY) Mockito.mock(org.mockito.Mockito.mock) FlatRelationshipModifications.singleCreate(org.neo4j.internal.recordstorage.FlatRelationshipModifications.singleCreate) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) EmptyMemoryTracker(org.neo4j.memory.EmptyMemoryTracker) Supplier(java.util.function.Supplier) ResourceType(org.neo4j.lock.ResourceType) RelationshipDirection(org.neo4j.storageengine.api.RelationshipDirection) ArrayList(java.util.ArrayList) Iterables.asSet(org.neo4j.internal.helpers.collection.Iterables.asSet) LongObjectMaps(org.eclipse.collections.impl.factory.primitive.LongObjectMaps) HashSet(java.util.HashSet) Inject(org.neo4j.test.extension.Inject) RelationshipChainVisitor.relationshipCollector(org.neo4j.internal.recordstorage.RelationshipChainVisitor.relationshipCollector) IntSupplier(java.util.function.IntSupplier) INCOMING(org.neo4j.storageengine.api.RelationshipDirection.INCOMING) Integer.min(java.lang.Integer.min) RELATIONSHIP(org.neo4j.lock.ResourceTypes.RELATIONSHIP) NONE(org.neo4j.lock.LockTracer.NONE) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) FlatRelationshipModifications.deletions(org.neo4j.internal.recordstorage.FlatRelationshipModifications.deletions) IGNORE(org.neo4j.lock.ResourceLocker.IGNORE) ResourceLocker(org.neo4j.lock.ResourceLocker) FlatRelationshipModifications.singleDelete(org.neo4j.internal.recordstorage.FlatRelationshipModifications.singleDelete) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) NULL_MONITOR(org.neo4j.internal.recordstorage.RecordAccess.LoadMonitor.NULL_MONITOR) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) HashSet(java.util.HashSet)

Example 5 with RelationshipData

use of org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData in project neo4j by neo4j.

the class RelationshipModifierTest method generateRelationshipData.

private List<RelationshipData> generateRelationshipData(int count, long node, IntSupplier typeStrategy, LongSupplier otherNodeStrategy, Supplier<RelationshipDirection> directionStrategy) {
    List<RelationshipData> relationships = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        long otherNode = otherNodeStrategy.getAsLong();
        RelationshipDirection direction = directionStrategy.get();
        long start = direction == OUTGOING || direction == LOOP ? node : otherNode;
        long end = direction == INCOMING || direction == LOOP ? node : otherNode;
        relationships.add(new RelationshipData(nextRelationshipId(), typeStrategy.getAsInt(), start, end));
    }
    return relationships;
}
Also used : RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) RelationshipDirection(org.neo4j.storageengine.api.RelationshipDirection) ArrayList(java.util.ArrayList)

Aggregations

RelationshipData (org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData)6 ArrayList (java.util.ArrayList)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 Test (org.junit.jupiter.api.Test)3 RelationshipDirection (org.neo4j.storageengine.api.RelationshipDirection)3 IntSupplier (java.util.function.IntSupplier)2 LongSupplier (java.util.function.LongSupplier)2 RelationshipModifications (org.neo4j.storageengine.api.txstate.RelationshipModifications)2 Integer.min (java.lang.Integer.min)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Consumer (java.util.function.Consumer)1