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);
}
}
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());
}
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);
}
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();
}
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;
}
Aggregations