Search in sources :

Example 11 with NodeLabels

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());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 12 with NodeLabels

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;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) RecordAccess(org.neo4j.consistency.store.RecordAccess) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) CheckerEngine(org.neo4j.consistency.checking.CheckerEngine) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) InlineNodeLabels(org.neo4j.kernel.impl.store.InlineNodeLabels) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) HashSet(java.util.HashSet)

Example 13 with NodeLabels

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());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 14 with NodeLabels

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())));
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 15 with NodeLabels

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));
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Command(org.neo4j.kernel.impl.transaction.command.Command) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.Test)

Aggregations

NodeLabels (org.neo4j.kernel.impl.store.NodeLabels)26 Test (org.junit.Test)23 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)23 DynamicNodeLabels (org.neo4j.kernel.impl.store.DynamicNodeLabels)21 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)10 HashSet (java.util.HashSet)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 Command (org.neo4j.kernel.impl.transaction.command.Command)2 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)2 CheckerEngine (org.neo4j.consistency.checking.CheckerEngine)1 LabelChainWalker (org.neo4j.consistency.checking.LabelChainWalker)1 RecordAccess (org.neo4j.consistency.store.RecordAccess)1 InlineNodeLabels (org.neo4j.kernel.impl.store.InlineNodeLabels)1