Search in sources :

Example 11 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class LabelScanStoreTest method shouldFindDecentAmountOfNodesForALabel.

@Test
public void shouldFindDecentAmountOfNodesForALabel() throws Exception {
    // GIVEN
    // 16 is the magic number of the page iterator
    // 32 is the number of nodes in each lucene document
    final int labelId = 1, nodeCount = 32 * 16 + 10;
    start();
    write(new PrefetchingIterator<NodeLabelUpdate>() {

        private int i = -1;

        @Override
        protected NodeLabelUpdate fetchNextOrNull() {
            return ++i < nodeCount ? labelChanges(i, NO_LABELS, new long[] { labelId }) : null;
        }
    });
    // WHEN
    Set<Long> nodeSet = new TreeSet<>();
    LabelScanReader reader = store.newReader();
    PrimitiveLongIterator nodes = reader.nodesWithLabel(labelId);
    while (nodes.hasNext()) {
        nodeSet.add(nodes.next());
    }
    reader.close();
    // THEN
    assertEquals("Found gaps in node id range: " + gaps(nodeSet, nodeCount), nodeCount, nodeSet.size());
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) TreeSet(java.util.TreeSet) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) Test(org.junit.Test)

Example 12 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class IndexAccessorCompatibility method metaGet.

private List<Long> metaGet(ReaderInteraction interaction) throws Exception {
    try (IndexReader reader = accessor.newReader()) {
        List<Long> list = new LinkedList<>();
        for (PrimitiveLongIterator iterator = interaction.results(reader); iterator.hasNext(); ) {
            list.add(iterator.next());
        }
        Collections.sort(list);
        return list;
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) LinkedList(java.util.LinkedList)

Example 13 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class PropertyAndNodeIndexedCheck method verifyNodeCorrectlyIndexedUniquely.

private void verifyNodeCorrectlyIndexedUniquely(long nodeId, int propertyKeyId, Object propertyValue, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, IndexRule indexRule, IndexReader reader) {
    PrimitiveLongIterator indexedNodeIds = null;
    try {
        indexedNodeIds = reader.query(IndexQuery.exact(propertyKeyId, propertyValue));
    } catch (IndexNotApplicableKernelException e) {
        indexedNodeIds = PrimitiveLongCollections.emptyIterator();
    }
    // For verifying node indexed uniquely in offline CC, if one match found in the first stage match,
    // then there is no need to filter the result. The result is a exact match.
    // If multiple matches found, we need to filter the result to get exact matches.
    indexedNodeIds = filterIfMultipleValuesFound(indexedNodeIds, propertyKeyId, propertyValue);
    boolean found = false;
    while (indexedNodeIds.hasNext()) {
        long indexedNodeId = indexedNodeIds.next();
        if (nodeId == indexedNodeId) {
            found = true;
        } else {
            engine.report().uniqueIndexNotUnique(indexRule, propertyValue, indexedNodeId);
        }
    }
    if (!found) {
        engine.report().notIndexed(indexRule, propertyValue);
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException)

Example 14 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class TwoPhaseNodeForRelationshipLocking method unlockAllNodes.

private void unlockAllNodes(KernelStatement state) {
    PrimitiveLongIterator iterator = nodeIds.iterator();
    while (iterator.hasNext()) {
        state.locks().optimistic().releaseExclusive(ResourceTypes.NODE, iterator.next());
    }
    nodeIds.clear();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator)

Example 15 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class LongDiffSetsTest method shouldContainSourceForEmptyDiffSets.

// TODO empty diffset EMPTY
// TODO null/isEmpty elements
@Test
public void shouldContainSourceForEmptyDiffSets() throws Exception {
    // given
    DiffSets<Long> diffSets = new DiffSets<>();
    Iterator<Long> expected = diffSets.apply(iteratorSource(1L, 2L));
    // when
    PrimitiveLongIterator actual = diffSets.augment(iterator(1L, 2L));
    // then
    assertThat(expected, hasSamePrimitiveItems(actual));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) Test(org.junit.Test)

Aggregations

PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)68 Test (org.junit.Test)47 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)15 Transaction (org.neo4j.graphdb.Transaction)10 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)10 ReadOperations (org.neo4j.kernel.api.ReadOperations)8 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)8 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)8 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)8 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)8 IOException (java.io.IOException)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Node (org.neo4j.graphdb.Node)4 Statement (org.neo4j.kernel.api.Statement)4 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 ArrayList (java.util.ArrayList)3 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2