Search in sources :

Example 41 with PropertyBlock

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

the class PropertyStoreConsistentReadTest method assertRecordsEqual.

@Override
protected void assertRecordsEqual(PropertyRecord actualRecord, PropertyRecord expectedRecord) {
    assertNotNull(actualRecord, "actualRecord");
    assertNotNull(expectedRecord, "expectedRecord");
    assertThat(actualRecord.getDeletedRecords()).as("getDeletedRecords").isEqualTo(expectedRecord.getDeletedRecords());
    assertThat(actualRecord.getNextProp()).as("getNextProp").isEqualTo(expectedRecord.getNextProp());
    assertThat(actualRecord.getNodeId()).as("getEntityId").isEqualTo(expectedRecord.getNodeId());
    assertThat(actualRecord.getPrevProp()).as("getPrevProp").isEqualTo(expectedRecord.getPrevProp());
    assertThat(actualRecord.getRelId()).as("getRelId").isEqualTo(expectedRecord.getRelId());
    assertThat(actualRecord.getId()).as("getId").isEqualTo(expectedRecord.getId());
    assertThat(actualRecord.getId()).as("getLongId").isEqualTo(expectedRecord.getId());
    List<PropertyBlock> actualBlocks = Iterables.asList(actualRecord);
    List<PropertyBlock> expectedBlocks = Iterables.asList(expectedRecord);
    assertThat(actualBlocks.size()).as("getPropertyBlocks().size").isEqualTo(expectedBlocks.size());
    for (int i = 0; i < actualBlocks.size(); i++) {
        PropertyBlock actualBlock = actualBlocks.get(i);
        PropertyBlock expectedBlock = expectedBlocks.get(i);
        assertPropertyBlocksEqual(i, actualBlock, expectedBlock);
    }
}
Also used : PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 42 with PropertyBlock

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

the class FullCheckIntegrationTest method serializeRule.

private void serializeRule(SchemaRule rule, SchemaRecord schemaRecord, TransactionDataBuilder tx, IdGenerator next) throws KernelException {
    IntObjectMap<Value> protoProperties = SchemaStore.convertSchemaRuleToMap(rule, tx.tokenHolders());
    Collection<PropertyBlock> blocks = new ArrayList<>();
    DynamicRecordAllocator stringAllocator = null;
    DynamicRecordAllocator arrayAllocator = null;
    protoProperties.forEachKeyValue((keyId, value) -> {
        PropertyBlock block = new PropertyBlock();
        PropertyStore.encodeValue(block, keyId, value, stringAllocator, arrayAllocator, true, NULL, INSTANCE);
        blocks.add(block);
    });
    long nextPropId = Record.NO_NEXT_PROPERTY.longValue();
    PropertyRecord currRecord = newInitialisedPropertyRecord(next, rule);
    for (PropertyBlock block : blocks) {
        if (!currRecord.hasSpaceFor(block)) {
            PropertyRecord nextRecord = newInitialisedPropertyRecord(next, rule);
            linkAndWritePropertyRecord(currRecord, nextRecord.getId(), nextPropId, tx);
            nextPropId = currRecord.getId();
            currRecord = nextRecord;
        }
        currRecord.addPropertyBlock(block);
    }
    linkAndWritePropertyRecord(currRecord, Record.NO_PREVIOUS_PROPERTY.longValue(), nextPropId, tx);
    nextPropId = currRecord.getId();
    schemaRecord.initialize(true, nextPropId);
    schemaRecord.setId(rule.getId());
}
Also used : StandardDynamicRecordAllocator(org.neo4j.kernel.impl.store.StandardDynamicRecordAllocator) DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Value(org.neo4j.values.storable.Value) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayList(java.util.ArrayList)

Example 43 with PropertyBlock

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

the class DetectRandomSabotageIT method shouldDetectIndexConfigCorruption.

/* Failures/bugs found by the random sabotage are fixed and tested below, if they don't fit into any other FullCheck IT*/
// From Seed 1608234007554L
@Test
void shouldDetectIndexConfigCorruption() throws Exception {
    // Given
    SchemaStore schemaStore = neoStores.getSchemaStore();
    long indexId = resolver.resolveDependency(IndexingService.class).getIndexIds().longIterator().next();
    SchemaRecord schemaRecord = schemaStore.getRecord(indexId, schemaStore.newRecord(), RecordLoad.FORCE, NULL);
    PropertyStore propertyStore = schemaStore.propertyStore();
    PropertyRecord indexConfigPropertyRecord = propertyStore.getRecord(schemaRecord.getNextProp(), propertyStore.newRecord(), RecordLoad.FORCE, NULL);
    propertyStore.ensureHeavy(indexConfigPropertyRecord, NULL);
    // When
    int[] tokenId = new int[1];
    resolver.resolveDependency(TokenHolders.class).propertyKeyTokens().getOrCreateInternalIds(new String[] { "foo" }, tokenId);
    PropertyBlock block = indexConfigPropertyRecord.iterator().next();
    indexConfigPropertyRecord.removePropertyBlock(block.getKeyIndexId());
    PropertyBlock newBlock = new PropertyBlock();
    propertyStore.encodeValue(newBlock, tokenId[0], intValue(11), NULL, INSTANCE);
    indexConfigPropertyRecord.addPropertyBlock(newBlock);
    propertyStore.updateRecord(indexConfigPropertyRecord, NULL);
    // then
    ConsistencyCheckService.Result result = shutDownAndRunConsistencyChecker();
    boolean hasSomeErrorOrWarning = result.summary().getTotalInconsistencyCount() > 0 || result.summary().getTotalWarningCount() > 0;
    assertTrue(hasSomeErrorOrWarning);
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.jupiter.api.Test)

Example 44 with PropertyBlock

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

the class SafePropertyChainReaderTest method testPropertyValueInconsistency.

private <T extends ConsistencyReport> void testPropertyValueInconsistency(Value consistentValue, Consumer<PropertyBlock> vandal, Class<T> expectedReportClass, Consumer<T> report) throws Exception {
    // given
    long nodeId;
    try (AutoCloseable ignored = tx()) {
        // (N)--->(P)---> (vandalized dynamic value chain)
        long propId = propertyStore.nextId(CursorContext.NULL);
        nodeId = node(nodeStore.nextId(CursorContext.NULL), propId, NULL);
        PropertyBlock dynamicBlock = propertyValue(propertyKey1, consistentValue);
        property(propId, NULL, NULL, dynamicBlock);
        vandal.accept(dynamicBlock);
        property(propId, NULL, NULL, dynamicBlock);
    }
    // when
    checkNode(nodeId);
    // then
    expect(expectedReportClass, report);
}
Also used : PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 45 with PropertyBlock

use of org.neo4j.kernel.impl.store.record.PropertyBlock 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)

Aggregations

PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)139 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)86 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)25 Test (org.junit.jupiter.api.Test)16 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)14 Value (org.neo4j.values.storable.Value)13 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)10 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 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)8 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)7 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)7 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)7 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)7