use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method shouldInlineOneLabelWithHighId.
@Test
public void shouldInlineOneLabelWithHighId() throws Exception {
// GIVEN
long labelId = 10000;
NodeRecord node = nodeRecordWithInlinedLabels();
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
nodeLabels.add(labelId, null, null);
// THEN
assertEquals(inlinedLabelsLongRepresentation(labelId), node.getLabelField());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelReader method getListOfLabels.
public static <RECORD extends AbstractBaseRecord, REPORT extends ConsistencyReport> Set<Long> getListOfLabels(NodeRecord nodeRecord, RecordAccess records, CheckerEngine<RECORD, REPORT> engine) {
final Set<Long> labels = new HashSet<>();
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(nodeRecord);
if (nodeLabels instanceof DynamicNodeLabels) {
DynamicNodeLabels dynamicNodeLabels = (DynamicNodeLabels) nodeLabels;
long firstRecordId = dynamicNodeLabels.getFirstDynamicRecordId();
RecordReference<DynamicRecord> firstRecordReference = records.nodeLabels(firstRecordId);
engine.comparativeCheck(firstRecordReference, new LabelChainWalker<>(new LabelChainWalker.Validator<RECORD, REPORT>() {
@Override
public void onRecordNotInUse(DynamicRecord dynamicRecord, CheckerEngine<RECORD, REPORT> engine) {
}
@Override
public void onRecordChainCycle(DynamicRecord record, CheckerEngine<RECORD, REPORT> engine) {
}
@Override
public void onWellFormedChain(long[] labelIds, CheckerEngine<RECORD, REPORT> engine, RecordAccess records) {
copyToSet(labelIds, labels);
}
}));
} else {
copyToSet(nodeLabels.get(null), labels);
}
return labels;
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method oneDynamicRecordShouldExtendIntoAnAdditionalIfTooManyLabels.
@Test
public void oneDynamicRecordShouldExtendIntoAnAdditionalIfTooManyLabels() throws Exception {
// GIVEN
// will occupy 60B of data, i.e. one dynamic record
NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, oneByteLongs(56));
Collection<DynamicRecord> initialRecords = node.getDynamicLabelRecords();
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
Set<DynamicRecord> changedDynamicRecords = Iterables.asSet(nodeLabels.add(1, nodeStore, nodeStore.getDynamicLabelStore()));
// THEN
assertTrue(changedDynamicRecords.containsAll(initialRecords));
assertEquals(initialRecords.size() + 1, changedDynamicRecords.size());
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeLabelsFieldTest method shouldSpillOverToDynamicRecordIfExceedsInlinedSpace.
@Test
public void shouldSpillOverToDynamicRecordIfExceedsInlinedSpace() throws Exception {
// GIVEN -- the upper limit for a label ID for 3 labels would be 36b/3 - 1 = 12b - 1 = 4095
long labelId1 = 10, labelId2 = 30, labelId3 = 4096;
NodeRecord node = nodeRecordWithInlinedLabels(labelId1, labelId2);
NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
// WHEN
Collection<DynamicRecord> changedDynamicRecords = nodeLabels.add(labelId3, nodeStore, nodeStore.getDynamicLabelStore());
// THEN
assertEquals(1, Iterables.count(changedDynamicRecords));
assertEquals(dynamicLabelsLongRepresentation(changedDynamicRecords), node.getLabelField());
assertTrue(Arrays.equals(new long[] { labelId1, labelId2, labelId3 }, DynamicNodeLabels.getDynamicLabelsArray(changedDynamicRecords, nodeStore.getDynamicLabelStore())));
}
use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.
the class NodeCommandTest method shouldSerializeInlineLabels.
@Test
public void shouldSerializeInlineLabels() throws Exception {
// Given
NodeRecord before = new NodeRecord(12, false, 1, 2);
before.setInUse(true);
NodeRecord after = new NodeRecord(12, false, 2, 1);
after.setInUse(true);
NodeLabels nodeLabels = parseLabelsField(after);
nodeLabels.add(1337, nodeStore, nodeStore.getDynamicLabelStore());
// When
assertSerializationWorksFor(new Command.NodeCommand(before, after));
}
Aggregations