Search in sources :

Example 51 with MutableLongSet

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

the class IndexingService method getIndexIds.

public LongSet getIndexIds() {
    Iterable<IndexProxy> indexProxies = indexMapRef.getAllIndexProxies();
    MutableLongSet indexIds = new LongHashSet();
    for (IndexProxy indexProxy : indexProxies) {
        indexIds.add(indexProxy.getDescriptor().getId());
    }
    return indexIds;
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet)

Example 52 with MutableLongSet

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

the class RollbackIdLeakIT method shouldNotLeakHighIdsOnCreateDeleteInSameTx.

private void shouldNotLeakHighIdsOnCreateDeleteInSameTx(Supplier<DbRestarter> restarterSupplier) throws IOException {
    // given
    MutableLongSet nodeIds = new LongHashSet();
    MutableLongSet relationshipIds = new LongHashSet();
    try (DbRestarter restarter = restarterSupplier.get()) {
        GraphDatabaseService db = restarter.start();
        Node node2;
        Relationship relationship2;
        try (Transaction tx = db.beginTx()) {
            Node node1 = tx.createNode();
            Relationship relationship1 = node1.createRelationshipTo(node1, TEST);
            node2 = tx.createNode();
            relationship2 = node2.createRelationshipTo(node2, TEST);
            nodeIds.add(node2.getId());
            relationshipIds.add(relationship2.getId());
            // Delete first node/relationship, but keep second ones
            node1.delete();
            nodeIds.add(node1.getId());
            relationship1.delete();
            relationshipIds.add(relationship1.getId());
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.getNodeById(node2.getId()).delete();
            tx.getRelationshipById(relationship2.getId()).delete();
            tx.commit();
        }
        assertAllocateIds(restarter.restart(), nodeIds, relationshipIds);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship)

Example 53 with MutableLongSet

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

the class ParallelNodeCursorTransactionStateTestBase method createNodes.

private MutableLongSet createNodes(int size) throws TransactionFailureException, InvalidTransactionTypeKernelException {
    MutableLongSet nodes = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        for (int i = 0; i < size; i++) {
            nodes.add(write.nodeCreate());
        }
        tx.commit();
    }
    return nodes;
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet)

Example 54 with MutableLongSet

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

the class ParallelNodeLabelScanTestBase method createTestGraph.

@Override
public void createTestGraph(GraphDatabaseService graphDb) {
    MutableLongSet fooNodes = LongSets.mutable.empty();
    MutableLongSet barNodes = LongSets.mutable.empty();
    try (KernelTransaction tx = beginTransaction()) {
        TokenWrite tokenWrite = tx.tokenWrite();
        FOO_LABEL = tokenWrite.labelGetOrCreateForName("foo");
        BAR_LABEL = tokenWrite.labelGetOrCreateForName("bar");
        Write write = tx.dataWrite();
        for (int i = 0; i < NUMBER_OF_NODES; i++) {
            long node = write.nodeCreate();
            if (i % 2 == 0) {
                write.nodeAddLabel(node, FOO_LABEL);
                fooNodes.add(node);
            } else {
                write.nodeAddLabel(node, BAR_LABEL);
                barNodes.add(node);
            }
        }
        FOO_NODES = fooNodes;
        BAR_NODES = barNodes;
        tx.commit();
    } catch (KernelException e) {
        throw new AssertionError(e);
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) KernelException(org.neo4j.exceptions.KernelException)

Example 55 with MutableLongSet

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

the class ParallelNodeLabelScanTransactionStateTestBase method scanShouldSeeAddedNodes.

@Test
void scanShouldSeeAddedNodes() throws Exception {
    int size = 64;
    int label = label("L");
    MutableLongSet existing = LongSets.mutable.withAll(createNodesWithLabel(label, size));
    try (KernelTransaction tx = beginTransaction()) {
        MutableLongSet added = LongSets.mutable.withAll(createNodesWithLabel(tx.dataWrite(), label, size));
        try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
            Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
            Set<Long> seen = new HashSet<>();
            while (scan.reserveBatch(cursor, 64)) {
                while (cursor.next()) {
                    long nodeId = cursor.nodeReference();
                    assertTrue(seen.add(nodeId), format("%d was seen multiple times", nodeId));
                    assertTrue(existing.remove(nodeId) || added.remove(nodeId));
                }
            }
            // make sure we have seen all nodes
            assertTrue(existing.isEmpty());
            assertTrue(added.isEmpty());
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

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