Search in sources :

Example 71 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens.

@Test
void shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens() throws Exception {
    // given
    StubStorageCursors data = new StubStorageCursors();
    int numNodes = 10;
    MutableLongSet relevantNodeIds = LongSets.mutable.empty();
    for (int i = 0; i < numNodes; i++) {
        int labelId = i % 2 == 0 ? LABEL : OTHER_LABEL;
        data.withNode(i).labels(labelId).properties(KEY, stringValue("name_" + i));
        if (labelId == LABEL) {
            relevantNodeIds.add(i);
        }
    }
    TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), false, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    GeneratedIndexUpdates updates = sender.batches.get(0);
    updates.completeBatch();
    for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
        assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
    }
    assertThat(relevantNodeIds.isEmpty()).isTrue();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class GBPTreeGenericCountsStore method readTxIdInformation.

private TxIdInformation readTxIdInformation(long highestGapFreeTxId, CursorContext cursorContext) throws IOException {
    MutableLongSet strayTxIds = new LongHashSet();
    visitStrayTxIdsInTree(strayTxIds::add, cursorContext);
    return new TxIdInformation(highestGapFreeTxId, strayTxIds);
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet)

Example 73 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldCreateEqualEntityPropertyUpdatesOnRecoveryOfCreatedEntities.

@Test
void shouldCreateEqualEntityPropertyUpdatesOnRecoveryOfCreatedEntities() throws Exception {
    neoStores = createStores();
    /* There was an issue where recovering a tx where a node with a label and a property
         * was created resulted in two exact copies of NodePropertyUpdates. */
    // GIVEN
    long nodeId = 0;
    long relId = 1;
    int labelId = 5;
    int relTypeId = 4;
    int propertyKeyId = 7;
    // -- indexes
    long nodeRuleId = 0;
    TransactionRecordState recordState = newTransactionRecordState();
    SchemaRule nodeRule = IndexPrototype.forSchema(forLabel(labelId, propertyKeyId)).withName("index_" + nodeRuleId).materialise(nodeRuleId);
    recordState.schemaRuleCreate(nodeRuleId, false, nodeRule);
    long relRuleId = 1;
    SchemaRule relRule = IndexPrototype.forSchema(forRelType(relTypeId, propertyKeyId)).withName("index_" + relRuleId).materialise(relRuleId);
    recordState.schemaRuleCreate(relRuleId, false, relRule);
    apply(recordState);
    // -- and a tx creating a node and a rel for those indexes
    recordState = newTransactionRecordState();
    recordState.nodeCreate(nodeId);
    recordState.addLabelToNode(labelId, nodeId);
    recordState.nodeAddProperty(nodeId, propertyKeyId, Values.of("Neo"));
    recordState.relModify(singleCreate(relId, relTypeId, nodeId, nodeId));
    recordState.relAddProperty(relId, propertyKeyId, Values.of("Oen"));
    // WHEN
    CommandsToApply transaction = transaction(recordState);
    IndexUpdatesExtractor extractor = new IndexUpdatesExtractor();
    transaction.accept(extractor);
    // THEN
    // -- later recovering that tx, there should be only one update for each type
    assertTrue(extractor.containsAnyEntityOrPropertyUpdate());
    MutableLongSet recoveredNodeIds = new LongHashSet();
    recoveredNodeIds.addAll(entityIds(extractor.getNodeCommands()));
    assertEquals(1, recoveredNodeIds.size());
    assertEquals(nodeId, recoveredNodeIds.longIterator().next());
    MutableLongSet recoveredRelIds = new LongHashSet();
    recoveredRelIds.addAll(entityIds(extractor.getRelationshipCommands()));
    assertEquals(1, recoveredRelIds.size());
    assertEquals(relId, recoveredRelIds.longIterator().next());
}
Also used : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) SchemaRule(org.neo4j.internal.schema.SchemaRule) Test(org.junit.jupiter.api.Test)

Example 74 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class RelationshipLockHelperTest method avoidTakingDuplicateLocks.

@Test
void avoidTakingDuplicateLocks() {
    MutableLongObjectMap<RecordAccess.RecordProxy<RelationshipRecord, Void>> proxies = LongObjectMaps.mutable.empty();
    MutableLongSet idsToDelete = LongSets.mutable.empty();
    MutableLongBag expectedLocks = LongBags.mutable.empty();
    idsToDelete.add(1);
    RelationshipRecord record = new RelationshipRecord(1);
    record.initialize(true, 1, 2, 3, 4, 5, 7, 7, 5, false, false);
    var proxy = mock(RecordAccess.RecordProxy.class);
    when(proxy.forReadingLinkage()).thenAnswer(invocation -> record);
    proxies.put(1, proxy);
    RecordAccess<RelationshipRecord, Void> relRecords = mock(RecordAccess.class);
    when(relRecords.getOrLoad(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> proxies.get(invocation.getArgument(0)));
    TrackingResourceLocker locks = new TrackingResourceLocker(random, NO_MONITOR).withStrictAssertionsOn(ResourceTypes.RELATIONSHIP);
    RelationshipLockHelper.lockRelationshipsInOrder(idsAsBatch(idsToDelete), 2, relRecords, locks, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
    List<ActiveLock> activeLocks = locks.activeLocks().collect(Collectors.toList());
    assertThat(activeLocks).hasSize(4).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 1)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 2)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 5)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 7));
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ActiveLock(org.neo4j.lock.ActiveLock) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 75 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class RelationshipLockHelperTest method shouldTakeAllRelevantLocksForDeletion.

@ParameterizedTest
@ValueSource(ints = { 1, 10, 100, 1000 })
void shouldTakeAllRelevantLocksForDeletion(int numNodes) {
    // Given
    MutableLongObjectMap<RecordAccess.RecordProxy<RelationshipRecord, Void>> proxies = LongObjectMaps.mutable.empty();
    MutableLongBag expectedLocks = LongBags.mutable.empty();
    MutableLongSet idsToDelete = LongSets.mutable.empty();
    int maxId = numNodes * 10;
    for (int i = 0; i < numNodes; i++) {
        long id = random.nextInt(maxId);
        if (idsToDelete.add(id)) {
            VolatileRelationshipRecord record = new VolatileRelationshipRecord(id, expectedLocks, maxId);
            var proxy = mock(RecordAccess.RecordProxy.class);
            when(proxy.forReadingLinkage()).thenAnswer(invocation -> new RelationshipRecord(record.maybeChange()));
            proxies.put(id, proxy);
        }
    }
    RecordAccess<RelationshipRecord, Void> relRecords = mock(RecordAccess.class);
    when(relRecords.getOrLoad(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> proxies.get(invocation.getArgument(0)));
    TrackingResourceLocker locks = new TrackingResourceLocker(random, NO_MONITOR).withStrictAssertionsOn(ResourceTypes.RELATIONSHIP);
    // When
    RelationshipLockHelper.lockRelationshipsInOrder(idsAsBatch(idsToDelete), NULL_REFERENCE.longValue(), relRecords, locks, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
    // Then
    assertThat(locks.getExclusiveLocks(ResourceTypes.RELATIONSHIP).toSortedArray()).containsExactly(expectedLocks.toSet().toSortedArray());
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)153 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)57 Test (org.junit.jupiter.api.Test)54 Test (org.junit.Test)49 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)17 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 ArrayList (java.util.ArrayList)13 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)12 LongIterator (org.eclipse.collections.api.iterator.LongIterator)10 LongSet (org.eclipse.collections.api.set.primitive.LongSet)9 Value (org.neo4j.values.storable.Value)8 Map (java.util.Map)7 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)7 Transaction (org.neo4j.graphdb.Transaction)7 Write (org.neo4j.internal.kernel.api.Write)7 NavigableMap (java.util.NavigableMap)6 UnmodifiableMap (org.eclipse.collections.impl.UnmodifiableMap)6 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)6