Search in sources :

Example 81 with PropertyRecord

use of org.neo4j.kernel.impl.store.record.PropertyRecord in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportPropertyInconsistencies.

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

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            NodeRecord node = new NodeRecord(next.node());
            PropertyRecord property = new PropertyRecord(next.property());
            node.setNextProp(property.getId());
            // Mess up the prev/next pointers a bit
            property.setNextProp(1_000);
            PropertyBlock block = new PropertyBlock();
            block.setSingleBlock(next.propertyKey() | (((long) PropertyType.INT.intValue()) << 24) | (666L << 28));
            property.addPropertyBlock(block);
            tx.create(node);
            tx.create(property);
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.PROPERTY, 2).verify(RecordType.NODE, 1).andThatsAllFolks();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 82 with PropertyRecord

use of org.neo4j.kernel.impl.store.record.PropertyRecord in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportCircularPropertyRecordChain.

private void shouldReportCircularPropertyRecordChain(RecordType expectedInconsistentRecordType, EntityCreator entityCreator) throws Exception {
    // Given
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(TransactionDataBuilder tx, IdGenerator next) {
            // Create property chain A --> B --> C --> D
            // ↑           │
            // └───────────┘
            long a = next.property();
            long b = next.property();
            long c = next.property();
            long d = next.property();
            tx.create(propertyRecordWithSingleIntProperty(a, next.propertyKey(), -1, b));
            tx.create(propertyRecordWithSingleIntProperty(b, next.propertyKey(), a, c));
            tx.create(propertyRecordWithSingleIntProperty(c, next.propertyKey(), b, d));
            tx.create(propertyRecordWithSingleIntProperty(d, next.propertyKey(), c, b));
            entityCreator.create(tx, next, a);
        }

        private PropertyRecord propertyRecordWithSingleIntProperty(long id, int propertyKeyId, long prev, long next) {
            PropertyRecord record = new PropertyRecord(id).initialize(true, prev, next);
            PropertyBlock block = new PropertyBlock();
            PropertyStore.encodeValue(block, propertyKeyId, Values.intValue(10), null, null, false, NULL, INSTANCE);
            record.addPropertyBlock(block);
            return record;
        }
    });
    // When
    ConsistencySummaryStatistics stats = check();
    // Then report will be filed on Node inconsistent with the Property completing the circle
    on(stats).verify(expectedInconsistentRecordType, 1);
}
Also used : TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics)

Example 83 with PropertyRecord

use of org.neo4j.kernel.impl.store.record.PropertyRecord in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldDetectInvalidUseOfInternalPropertyKeyTokens.

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

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            int propertyKey = next.propertyKey();
            tx.propertyKey(propertyKey, "FOO", true);
            long nextProp = next.property();
            PropertyRecord property = new PropertyRecord(nextProp).initialize(true, NO_PREVIOUS_PROPERTY.longValue(), NO_NEXT_PROPERTY.longValue());
            PropertyBlock block = new PropertyBlock();
            block.setSingleBlock(propertyKey | (((long) PropertyType.INT.intValue()) << 24) | (666L << 28));
            property.addPropertyBlock(block);
            tx.create(property);
            tx.create(new NodeRecord(next.node()).initialize(true, nextProp, false, NO_NEXT_RELATIONSHIP.longValue(), NO_LABELS_FIELD.longValue()));
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    assertFalse(stats.isConsistent());
    on(stats).verify(RecordType.PROPERTY, 1).andThatsAllFolks();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 84 with PropertyRecord

use of org.neo4j.kernel.impl.store.record.PropertyRecord in project neo4j by neo4j.

the class DeleteDuplicateNodesStepTest method shouldDeleteEverythingAboutTheDuplicatedNodes.

@RepeatedTest(10)
void shouldDeleteEverythingAboutTheDuplicatedNodes() throws Exception {
    // given
    Ids[] ids = new Ids[9];
    DataImporter.Monitor monitor = new DataImporter.Monitor();
    // node with many properties and many labels
    ids[0] = createNode(monitor, neoStores, 10, 10);
    // node with many properties and few labels
    ids[1] = createNode(monitor, neoStores, 10, 1);
    // node with many properties and no labels
    ids[2] = createNode(monitor, neoStores, 10, 0);
    // node with few properties and many labels
    ids[3] = createNode(monitor, neoStores, 1, 10);
    // node with few properties and few labels
    ids[4] = createNode(monitor, neoStores, 1, 1);
    // node with few properties and no labels
    ids[5] = createNode(monitor, neoStores, 1, 0);
    // node with no properties and many labels
    ids[6] = createNode(monitor, neoStores, 0, 10);
    // node with no properties and few labels
    ids[7] = createNode(monitor, neoStores, 0, 1);
    // node with no properties and no labels
    ids[8] = createNode(monitor, neoStores, 0, 0);
    // when
    long[] duplicateNodeIds = randomNodes(ids);
    SimpleStageControl control = new SimpleStageControl();
    try (DeleteDuplicateNodesStep step = new DeleteDuplicateNodesStep(control, Configuration.DEFAULT, iterator(duplicateNodeIds), neoStores.getNodeStore(), neoStores.getPropertyStore(), monitor, PageCacheTracer.NULL)) {
        control.steps(step);
        startAndAwaitCompletionOf(step);
    }
    control.assertHealthy();
    // then
    int expectedNodes = 0;
    int expectedProperties = 0;
    for (Ids entity : ids) {
        boolean expectedToBeInUse = !ArrayUtils.contains(duplicateNodeIds, entity.node.getId());
        int stride = expectedToBeInUse ? 1 : 0;
        expectedNodes += stride;
        // Verify node record
        assertEquals(expectedToBeInUse, neoStores.getNodeStore().isInUse(entity.node.getId(), NULL));
        // Verify label records
        for (DynamicRecord labelRecord : entity.node.getDynamicLabelRecords()) {
            assertEquals(expectedToBeInUse, neoStores.getNodeStore().getDynamicLabelStore().isInUse(labelRecord.getId(), NULL));
        }
        // Verify property records
        for (PropertyRecord propertyRecord : entity.properties) {
            assertEquals(expectedToBeInUse, neoStores.getPropertyStore().isInUse(propertyRecord.getId(), NULL));
            for (PropertyBlock property : propertyRecord) {
                // Verify property dynamic value records
                for (DynamicRecord valueRecord : property.getValueRecords()) {
                    AbstractDynamicStore valueStore;
                    switch(property.getType()) {
                        case STRING:
                            valueStore = neoStores.getPropertyStore().getStringStore();
                            break;
                        case ARRAY:
                            valueStore = neoStores.getPropertyStore().getArrayStore();
                            break;
                        default:
                            throw new IllegalArgumentException(propertyRecord + " " + property);
                    }
                    assertEquals(expectedToBeInUse, valueStore.isInUse(valueRecord.getId(), NULL));
                }
                expectedProperties += stride;
            }
        }
    }
    assertEquals(expectedNodes, monitor.nodesImported());
    assertEquals(expectedProperties, monitor.propertiesImported());
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) AbstractDynamicStore(org.neo4j.kernel.impl.store.AbstractDynamicStore) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 85 with PropertyRecord

use of org.neo4j.kernel.impl.store.record.PropertyRecord in project neo4j by neo4j.

the class DeleteDuplicateNodesStepTest method createPropertyChain.

// A slight duplication of PropertyCreator logic, please try and remove in favor of that utility later on
private PropertyRecord[] createPropertyChain(NodeRecord nodeRecord, int numberOfProperties, PropertyStore propertyStore) {
    List<PropertyRecord> records = new ArrayList<>();
    PropertyRecord current = null;
    int space = PropertyType.getPayloadSizeLongs();
    for (int i = 0; i < numberOfProperties; i++) {
        PropertyBlock block = new PropertyBlock();
        propertyStore.encodeValue(block, i, random.nextValue(), NULL, INSTANCE);
        if (current == null || block.getValueBlocks().length > space) {
            PropertyRecord next = propertyStore.newRecord();
            nodeRecord.setIdTo(next);
            next.setId(propertyStore.nextId(NULL));
            if (current != null) {
                next.setPrevProp(current.getId());
                current.setNextProp(next.getId());
            }
            next.setInUse(true);
            current = next;
            space = PropertyType.getPayloadSizeLongs();
            records.add(current);
        }
        current.addPropertyBlock(block);
        space -= block.getValueBlocks().length;
    }
    records.forEach(record -> propertyStore.updateRecord(record, NULL));
    return records.toArray(new PropertyRecord[0]);
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) ArrayList(java.util.ArrayList) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Aggregations

PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)230 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)86 Test (org.junit.Test)75 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)37 Test (org.junit.jupiter.api.Test)36 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)35 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)28 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)19 ArrayList (java.util.ArrayList)17 Value (org.neo4j.values.storable.Value)17 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)14 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)14 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 Pair (org.neo4j.helpers.collection.Pair)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 NodeStore (org.neo4j.kernel.impl.store.NodeStore)8