Search in sources :

Example 6 with NodeLabelUpdate

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

the class PartitionedLuceneLabelScanWriter method updateFields.

private void updateFields(Iterable<NodeLabelUpdate> updates, Map<Long, /*label*/
Bitmap> fields) {
    for (NodeLabelUpdate update : updates) {
        clearLabels(fields, update);
        setLabels(fields, update);
    }
}
Also used : NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate)

Example 7 with NodeLabelUpdate

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

the class LabelScanStoreTest method shouldUpdateAFullRange.

@Test
public void shouldUpdateAFullRange() throws Exception {
    // given
    long label0Id = 0;
    List<NodeLabelUpdate> label0Updates = new ArrayList<>();
    Set<Long> nodes = new HashSet<>();
    for (int i = 0; i < 34; i++) {
        label0Updates.add(NodeLabelUpdate.labelChanges(i, new long[] {}, new long[] { label0Id }));
        nodes.add((long) i);
    }
    start(label0Updates);
    // when
    write(Collections.emptyIterator());
    // then
    LabelScanReader reader = store.newReader();
    Set<Long> nodesWithLabel0 = PrimitiveLongCollections.toSet(reader.nodesWithLabel((int) label0Id));
    assertEquals(nodes, nodesWithLabel0);
}
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 8 with NodeLabelUpdate

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

the class IndexPopulationJobTest method shouldBeAbleToCancelPopulationJob.

@Test
public void shouldBeAbleToCancelPopulationJob() throws Exception {
    // GIVEN
    createNode(map(name, "Mattias"), FIRST);
    IndexPopulator populator = mock(IndexPopulator.class);
    FlippableIndexProxy index = mock(FlippableIndexProxy.class);
    IndexStoreView storeView = mock(IndexStoreView.class);
    ControlledStoreScan storeScan = new ControlledStoreScan();
    when(storeView.visitNodes(any(int[].class), any(IntPredicate.class), Matchers.<Visitor<NodeUpdates, RuntimeException>>any(), Matchers.<Visitor<NodeLabelUpdate, RuntimeException>>any(), anyBoolean())).thenReturn(storeScan);
    final IndexPopulationJob job = newIndexPopulationJob(populator, index, storeView, NullLogProvider.getInstance(), false);
    OtherThreadExecutor<Void> populationJobRunner = cleanup.add(new OtherThreadExecutor<>("Population job test runner", null));
    Future<Void> runFuture = populationJobRunner.executeDontWait(state -> {
        job.run();
        return null;
    });
    storeScan.latch.waitForAllToStart();
    job.cancel().get();
    storeScan.latch.waitForAllToFinish();
    // WHEN
    runFuture.get();
    // THEN
    verify(populator, times(1)).close(false);
    verify(index, times(0)).flip(Matchers.any(), Matchers.any());
}
Also used : IntPredicate(java.util.function.IntPredicate) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Test(org.junit.Test)

Example 9 with NodeLabelUpdate

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

the class NativeLabelScanStoreIT method randomModifications.

private void randomModifications(long[] expected, int count) throws IOException {
    BitSet editedNodes = new BitSet();
    try (LabelScanWriter writer = store.newWriter()) {
        for (int i = 0; i < count; i++) {
            int nodeId = random.nextInt(NODE_COUNT);
            if (editedNodes.get(nodeId)) {
                i--;
                continue;
            }
            int changeSize = random.nextInt(3) + 1;
            long labels = expected[nodeId];
            long[] labelsBefore = getLabels(labels);
            for (int j = 0; j < changeSize; j++) {
                labels = flipRandom(labels, LABEL_COUNT, random.random());
            }
            long[] labelsAfter = getLabels(labels);
            editedNodes.set(nodeId);
            NodeLabelUpdate labelChanges = labelChanges(nodeId, labelsBefore, labelsAfter);
            writer.write(labelChanges);
            expected[nodeId] = labels;
        }
    }
}
Also used : BitSet(java.util.BitSet) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter)

Example 10 with NodeLabelUpdate

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

the class PhysicalToLogicalLabelChangesTest method convertAndAssert.

private void convertAndAssert(long[] before, long[] after, long[] expectedRemoved, long[] expectedAdded) {
    NodeLabelUpdate update = NodeLabelUpdate.labelChanges(0, before, after);
    PhysicalToLogicalLabelChanges.convertToAdditionsAndRemovals(update);
    assertArrayEquals(terminate(update.getLabelsBefore()), expectedRemoved);
    assertArrayEquals(terminate(update.getLabelsAfter()), expectedAdded);
}
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