Search in sources :

Example 11 with ReusableRecordsAllocator

use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.

the class NodeRecordCheckTest method shouldReportDynamicLabelsNotInUse.

@Test
public void shouldReportDynamicLabelsNotInUse() throws Exception {
    // given
    long[] labelIds = createLabels(100);
    LabelTokenRecord labelRecordNotInUse = notInUse(new LabelTokenRecord(labelIds.length));
    add(labelRecordNotInUse);
    NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
    add(node);
    DynamicRecord labelsRecord1 = inUse(array(new DynamicRecord(1)));
    DynamicRecord labelsRecord2 = inUse(array(new DynamicRecord(2)));
    Collection<DynamicRecord> labelRecords = asList(labelsRecord1, labelsRecord2);
    labelIds[12] = labelIds.length;
    DynamicArrayStore.allocateFromNumbers(new ArrayList<>(), labelIds, new ReusableRecordsAllocator(52, labelRecords));
    assertDynamicRecordChain(labelsRecord1, labelsRecord2);
    node.setLabelField(DynamicNodeLabels.dynamicPointer(labelRecords), labelRecords);
    addNodeDynamicLabels(labelsRecord1);
    addNodeDynamicLabels(labelsRecord2);
    // when
    ConsistencyReport.NodeConsistencyReport report = check(node);
    // then
    verify(report).labelNotInUse(labelRecordNotInUse);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Example 12 with ReusableRecordsAllocator

use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportNodeDynamicLabelContainingDuplicateLabelAsNodeInconsistency.

@Test
public void shouldReportNodeDynamicLabelContainingDuplicateLabelAsNodeInconsistency() throws Exception {
    // given
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            tx.nodeLabel(42, "Label");
            NodeRecord nodeRecord = new NodeRecord(next.node(), false, -1, -1);
            DynamicRecord record = inUse(new DynamicRecord(next.nodeLabel()));
            Collection<DynamicRecord> newRecords = new ArrayList<>();
            allocateFromNumbers(newRecords, prependNodeId(nodeRecord.getId(), new long[] { 42L, 42L }), new ReusableRecordsAllocator(60, record));
            nodeRecord.setLabelField(dynamicPointer(newRecords), newRecords);
            tx.create(nodeRecord);
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.NODE, 1).verify(RecordType.COUNTS, 1).andThatsAllFolks();
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) Collection(java.util.Collection) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 13 with ReusableRecordsAllocator

use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.

the class FullCheckIntegrationTest method chainOfDynamicRecordsWithLabelsForANode.

private Pair<List<DynamicRecord>, List<Integer>> chainOfDynamicRecordsWithLabelsForANode(int labelCount) throws TransactionFailureException {
    // allocate enough labels to need three records
    final long[] labels = new long[labelCount + 1];
    final List<Integer> createdLabels = new ArrayList<>();
    try (Applier applier = fixture.createApplier()) {
        for (int i = 1; /*leave space for the node id*/
        i < labels.length; i++) {
            final int offset = i;
            applier.apply(new GraphStoreFixture.Transaction() {

                // Neo4j can create no more than one label per transaction...
                @Override
                protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
                    Integer label = next.label();
                    tx.nodeLabel((int) (labels[offset] = label), "label:" + offset);
                    createdLabels.add(label);
                }
            });
        }
    }
    final List<DynamicRecord> chain = new ArrayList<>();
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            NodeRecord nodeRecord = new NodeRecord(next.node(), false, -1, -1);
            DynamicRecord record1 = inUse(new DynamicRecord(next.nodeLabel()));
            DynamicRecord record2 = inUse(new DynamicRecord(next.nodeLabel()));
            DynamicRecord record3 = inUse(new DynamicRecord(next.nodeLabel()));
            // the first id should not be a label id, but the id of the node
            labels[0] = nodeRecord.getId();
            ReusableRecordsAllocator allocator = new ReusableRecordsAllocator(60, record1, record2, record3);
            allocateFromNumbers(chain, labels, allocator);
            nodeRecord.setLabelField(dynamicPointer(chain), chain);
            tx.create(nodeRecord);
        }
    });
    return Pair.of(chain, createdLabels);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) Applier(org.neo4j.consistency.checking.GraphStoreFixture.Applier) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture)

Example 14 with ReusableRecordsAllocator

use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.

the class NodeInUseWithCorrectLabelsCheckTest method withDynamicLabels.

private NodeRecord withDynamicLabels(RecordAccessStub recordAccess, NodeRecord nodeRecord, long... labelIds) {
    List<DynamicRecord> preAllocatedRecords = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        preAllocatedRecords.add(inUse(new DynamicRecord(i)));
    }
    Collection<DynamicRecord> dynamicRecords = new ArrayList<>();
    DynamicArrayStore.allocateFromNumbers(dynamicRecords, prependNodeId(nodeRecord.getId(), labelIds), new ReusableRecordsAllocator(4, preAllocatedRecords));
    for (DynamicRecord dynamicRecord : dynamicRecords) {
        recordAccess.addNodeDynamicLabels(dynamicRecord);
    }
    nodeRecord.setLabelField(dynamicPointer(dynamicRecords), dynamicRecords);
    return nodeRecord;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator)

Example 15 with ReusableRecordsAllocator

use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportNodeDynamicLabelContainingUnknownLabelAsNodeInconsistency.

@Test
public void shouldReportNodeDynamicLabelContainingUnknownLabelAsNodeInconsistency() throws Exception {
    // given
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            NodeRecord nodeRecord = new NodeRecord(next.node(), false, -1, -1);
            DynamicRecord record = inUse(new DynamicRecord(next.nodeLabel()));
            Collection<DynamicRecord> newRecords = new ArrayList<>();
            allocateFromNumbers(newRecords, prependNodeId(nodeRecord.getId(), new long[] { 42L }), new ReusableRecordsAllocator(60, record));
            nodeRecord.setLabelField(dynamicPointer(newRecords), newRecords);
            tx.create(nodeRecord);
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.NODE, 1).andThatsAllFolks();
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) Collection(java.util.Collection) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Aggregations

ReusableRecordsAllocator (org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator)16 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)16 Test (org.junit.Test)13 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)10 ArrayList (java.util.ArrayList)4 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)4 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)4 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)4 Collection (java.util.Collection)3 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)3 DynamicLabelConsistencyReport (org.neo4j.consistency.report.ConsistencyReport.DynamicLabelConsistencyReport)3 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)3 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Applier (org.neo4j.consistency.checking.GraphStoreFixture.Applier)1 IdSequence (org.neo4j.kernel.impl.store.id.IdSequence)1 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)1