Search in sources :

Example 1 with NodeLabelUpdate

use of org.neo4j.kernel.api.labelscan.NodeLabelUpdate in project neo4j by neo4j.

the class NativeLabelScanWriterTest method shouldAddLabels.

@Test
public void shouldAddLabels() throws Exception {
    // GIVEN
    ControlledInserter inserter = new ControlledInserter();
    long[] expected = new long[NODE_COUNT];
    try (NativeLabelScanWriter writer = new NativeLabelScanWriter(max(5, NODE_COUNT / 100))) {
        writer.initialize(inserter);
        // WHEN
        for (int i = 0; i < NODE_COUNT * 3; i++) {
            NodeLabelUpdate update = randomUpdate(expected);
            writer.write(update);
        }
    }
    // THEN
    for (int i = 0; i < LABEL_COUNT; i++) {
        long[] expectedNodeIds = nodesWithLabel(expected, i);
        long[] actualNodeIds = asArray(new LabelScanValueIterator(inserter.nodesFor(i)));
        assertArrayEquals("For label " + i, expectedNodeIds, actualNodeIds);
    }
}
Also used : NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) Test(org.junit.Test)

Example 2 with NodeLabelUpdate

use of org.neo4j.kernel.api.labelscan.NodeLabelUpdate 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 3 with NodeLabelUpdate

use of org.neo4j.kernel.api.labelscan.NodeLabelUpdate in project neo4j by neo4j.

the class LabelScanStoreTest method shouldWorkWithAFullRange.

@Test
public void shouldWorkWithAFullRange() throws Exception {
    // given
    long labelId = 0;
    List<NodeLabelUpdate> updates = new ArrayList<>();
    Set<Long> nodes = new HashSet<>();
    for (int i = 0; i < 34; i++) {
        updates.add(NodeLabelUpdate.labelChanges(i, new long[] {}, new long[] { labelId }));
        nodes.add((long) i);
    }
    start(updates);
    // when
    LabelScanReader reader = store.newReader();
    Set<Long> nodesWithLabel = PrimitiveLongCollections.toSet(reader.nodesWithLabel((int) labelId));
    // then
    assertEquals(nodes, nodesWithLabel);
}
Also used : LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) ArrayList(java.util.ArrayList) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with NodeLabelUpdate

use of org.neo4j.kernel.api.labelscan.NodeLabelUpdate in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportLabelScanStoreInconsistencies.

@Test
public void shouldReportLabelScanStoreInconsistencies() throws Exception {
    // given
    GraphStoreFixture.IdGenerator idGenerator = fixture.idGenerator();
    long nodeId1 = idGenerator.node();
    long labelId = idGenerator.label() - 1;
    LabelScanStore labelScanStore = fixture.directStoreAccess().labelScanStore();
    Iterable<NodeLabelUpdate> nodeLabelUpdates = asIterable(labelChanges(nodeId1, new long[] {}, new long[] { labelId }));
    write(labelScanStore, nodeLabelUpdates);
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.LABEL_SCAN_DOCUMENT, 1).andThatsAllFolks();
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 5 with NodeLabelUpdate

use of org.neo4j.kernel.api.labelscan.NodeLabelUpdate in project neo4j by neo4j.

the class NativeLabelScanWriter method flushPendingChanges.

private void flushPendingChanges() throws IOException {
    Arrays.sort(pendingUpdates, 0, pendingUpdatesCursor, UPDATE_SORTER);
    long currentLabelId = lowestLabelId;
    value.clear();
    key.clear();
    while (currentLabelId != Long.MAX_VALUE) {
        long nextLabelId = Long.MAX_VALUE;
        for (int i = 0; i < pendingUpdatesCursor; i++) {
            NodeLabelUpdate update = pendingUpdates[i];
            long nodeId = update.getNodeId();
            nextLabelId = extractChange(update.getLabelsAfter(), currentLabelId, nodeId, nextLabelId, true);
            nextLabelId = extractChange(update.getLabelsBefore(), currentLabelId, nodeId, nextLabelId, false);
        }
        currentLabelId = nextLabelId;
    }
    flushPendingRange();
    pendingUpdatesCursor = 0;
}
Also used : NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate)

Aggregations

NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)10 Test (org.junit.Test)6 LabelScanReader (org.neo4j.storageengine.api.schema.LabelScanReader)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BitSet (java.util.BitSet)1 TreeSet (java.util.TreeSet)1 IntPredicate (java.util.function.IntPredicate)1 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)1 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)1 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)1 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)1 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)1 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)1 LabelScanStore (org.neo4j.kernel.api.labelscan.LabelScanStore)1 LabelScanWriter (org.neo4j.kernel.api.labelscan.LabelScanWriter)1