Search in sources :

Example 66 with PropertyRecord

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

the class PropertyTraverser method assertPropertyChain.

public boolean assertPropertyChain(PrimitiveRecord primitive, RecordAccess<PropertyRecord, PrimitiveRecord> propertyRecords) {
    List<PropertyRecord> toCheck = new LinkedList<>();
    long nextIdToFetch = primitive.getNextProp();
    while (nextIdToFetch != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = propertyRecords.getOrLoad(nextIdToFetch, primitive, cursorContext).forReadingLinkage();
        toCheck.add(propRecord);
        assert propRecord.inUse() : primitive + "->" + Arrays.toString(toCheck.toArray());
        assert propRecord.size() <= PropertyType.getPayloadSize() : propRecord + " size " + propRecord.size();
        nextIdToFetch = propRecord.getNextProp();
    }
    if (toCheck.isEmpty()) {
        assert primitive.getNextProp() == Record.NO_NEXT_PROPERTY.intValue() : primitive;
        return true;
    }
    PropertyRecord first = toCheck.get(0);
    PropertyRecord last = toCheck.get(toCheck.size() - 1);
    assert first.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue() : primitive + "->" + Arrays.toString(toCheck.toArray());
    assert last.getNextProp() == Record.NO_NEXT_PROPERTY.intValue() : primitive + "->" + Arrays.toString(toCheck.toArray());
    PropertyRecord current;
    PropertyRecord previous = first;
    for (int i = 1; i < toCheck.size(); i++) {
        current = toCheck.get(i);
        assert current.getPrevProp() == previous.getId() : primitive + "->" + Arrays.toString(toCheck.toArray());
        assert previous.getNextProp() == current.getId() : primitive + "->" + Arrays.toString(toCheck.toArray());
        previous = current;
    }
    return true;
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) LinkedList(java.util.LinkedList)

Example 67 with PropertyRecord

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

the class FulltextIndexConsistencyCheckIT method mustDiscoverRelationshipInIndexMissingFromStore.

@Disabled("Turns out that this is not something that the consistency checker actually looks for, currently. " + "The test is disabled until the consistency checker is extended with checks that will discover this sort of inconsistency.")
@Test
void mustDiscoverRelationshipInIndexMissingFromStore() throws Exception {
    GraphDatabaseService db = createDatabase();
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(RELATIONSHIP_CREATE, "rels", asStrList("REL"), asStrList("prop"))).close();
        tx.commit();
    }
    long relId;
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        Node node = tx.createNode();
        Relationship rel = node.createRelationshipTo(node, RelationshipType.withName("REL"));
        relId = rel.getId();
        rel.setProperty("prop", "value");
        tx.commit();
    }
    NeoStores stores = getNeoStores(db);
    RelationshipRecord record = stores.getRelationshipStore().newRecord();
    record = stores.getRelationshipStore().getRecord(relId, record, RecordLoad.NORMAL, NULL);
    long propId = record.getNextProp();
    record.setNextProp(AbstractBaseRecord.NO_ID);
    stores.getRelationshipStore().updateRecord(record, NULL);
    PropertyRecord propRecord = stores.getPropertyStore().getRecord(propId, stores.getPropertyStore().newRecord(), RecordLoad.NORMAL, NULL);
    propRecord.setInUse(false);
    stores.getPropertyStore().updateRecord(propRecord, NULL);
    managementService.shutdown();
    ConsistencyCheckService.Result result = checkConsistency();
    assertFalse(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 68 with PropertyRecord

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

the class SafePropertyChainReader method read.

<PRIMITIVE extends PrimitiveRecord> boolean read(MutableIntObjectMap<Value> intoValues, PRIMITIVE entity, Function<PRIMITIVE, ConsistencyReport.PrimitiveConsistencyReport> primitiveReporter, CursorContext cursorContext) {
    lightClear(seenRecords);
    long propertyRecordId = entity.getNextProp();
    long previousRecordId = NULL_REFERENCE.longValue();
    boolean chainIsOk = true;
    while (!NULL_REFERENCE.is(propertyRecordId) && !context.isCancelled()) {
        if (!seenRecords.add(propertyRecordId)) {
            primitiveReporter.apply(entity).propertyChainContainsCircularReference(propertyReader.record());
            chainIsOk = false;
            break;
        }
        PropertyRecord propertyRecord = propertyReader.read(propertyRecordId);
        if (!propertyRecord.inUse()) {
            primitiveReporter.apply(entity).propertyNotInUse(propertyRecord);
            reporter.forProperty(context.recordLoader.property(previousRecordId, cursorContext)).nextNotInUse(propertyRecord);
            chainIsOk = false;
        } else {
            if (propertyRecord.getPrevProp() != previousRecordId) {
                if (NULL_REFERENCE.is(previousRecordId)) {
                    primitiveReporter.apply(entity).propertyNotFirstInChain(propertyRecord);
                } else {
                    reporter.forProperty(context.recordLoader.property(previousRecordId, cursorContext)).nextDoesNotReferenceBack(propertyRecord);
                // prevDoesNotReferenceBack is not reported, unnecessary double report (same inconsistency from different directions)
                }
                chainIsOk = false;
            }
            for (PropertyBlock block : propertyRecord) {
                int propertyKeyId = block.getKeyIndexId();
                if (!checkValidToken(propertyRecord, propertyKeyId, context.tokenHolders.propertyKeyTokens(), neoStores.getPropertyKeyTokenStore(), (property, token) -> reporter.forProperty(property).invalidPropertyKey(block), (property, token) -> reporter.forProperty(property).keyNotInUse(block, token), cursorContext)) {
                    chainIsOk = false;
                }
                PropertyType type = block.forceGetType();
                Value value = Values.NO_VALUE;
                if (type == null) {
                    reporter.forProperty(propertyRecord).invalidPropertyType(block);
                } else {
                    try {
                        switch(type) {
                            case STRING:
                                dynamicRecords.clear();
                                if (safeLoadDynamicRecordChain(record -> dynamicRecords.add(record.copy()), stringReader, seenDynamicRecordIds, block.getSingleValueLong(), stringStoreBlockSize, NO_DYNAMIC_HANDLER, (id, record) -> reporter.forProperty(propertyRecord).stringNotInUse(block, record), (id, record) -> reporter.forDynamicBlock(RecordType.STRING_PROPERTY, stringReader.record()).nextNotInUse(record), (id, record) -> reporter.forProperty(propertyRecord).stringEmpty(block, record), record -> reporter.forDynamicBlock(RecordType.STRING_PROPERTY, record).recordNotFullReferencesNext(), record -> reporter.forDynamicBlock(RecordType.STRING_PROPERTY, record).invalidLength())) {
                                    value = propertyStore.getTextValueFor(dynamicRecords, cursorContext);
                                }
                                break;
                            case ARRAY:
                                dynamicRecords.clear();
                                if (safeLoadDynamicRecordChain(record -> dynamicRecords.add(record.copy()), arrayReader, seenDynamicRecordIds, block.getSingleValueLong(), arrayStoreBlockSize, NO_DYNAMIC_HANDLER, (id, record) -> reporter.forProperty(propertyRecord).arrayNotInUse(block, record), (id, record) -> reporter.forDynamicBlock(RecordType.ARRAY_PROPERTY, arrayReader.record()).nextNotInUse(record), (id, record) -> reporter.forProperty(propertyRecord).arrayEmpty(block, record), record -> reporter.forDynamicBlock(RecordType.ARRAY_PROPERTY, record).recordNotFullReferencesNext(), record -> reporter.forDynamicBlock(RecordType.ARRAY_PROPERTY, record).invalidLength())) {
                                    value = propertyStore.getArrayFor(dynamicRecords, cursorContext);
                                }
                                break;
                            default:
                                value = type.value(block, null, cursorContext);
                                break;
                        }
                    } catch (Exception e) {
                        reporter.forProperty(propertyRecord).invalidPropertyValue(propertyRecord.getId(), block.getKeyIndexId());
                    }
                }
                if (value == Values.NO_VALUE) {
                    chainIsOk = false;
                } else if (propertyKeyId >= 0 && intoValues.put(propertyKeyId, value) != null) {
                    primitiveReporter.apply(entity).propertyKeyNotUniqueInChain();
                    chainIsOk = false;
                }
            }
        }
        previousRecordId = propertyRecordId;
        propertyRecordId = propertyRecord.getNextProp();
    }
    return chainIsOk;
}
Also used : PropertyType(org.neo4j.kernel.impl.store.PropertyType) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IOUtils.closeAllUnchecked(org.neo4j.io.IOUtils.closeAllUnchecked) NULL_REFERENCE(org.neo4j.kernel.impl.store.record.Record.NULL_REFERENCE) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NO_DYNAMIC_HANDLER(org.neo4j.consistency.checker.RecordLoading.NO_DYNAMIC_HANDLER) RecordLoading.checkValidToken(org.neo4j.consistency.checker.RecordLoading.checkValidToken) MutableIntObjectMap(org.eclipse.collections.api.map.primitive.MutableIntObjectMap) RecordType(org.neo4j.consistency.RecordType) Value(org.neo4j.values.storable.Value) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) Values(org.neo4j.values.storable.Values) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) List(java.util.List) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) RecordLoading.lightClear(org.neo4j.consistency.checker.RecordLoading.lightClear) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RecordLoading.safeLoadDynamicRecordChain(org.neo4j.consistency.checker.RecordLoading.safeLoadDynamicRecordChain) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) Value(org.neo4j.values.storable.Value) PropertyType(org.neo4j.kernel.impl.store.PropertyType)

Example 69 with PropertyRecord

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

the class BatchingNeoStoresTest method createRecordIn.

private static <RECORD extends AbstractBaseRecord> void createRecordIn(RecordStore<RECORD> store) {
    RECORD record = store.newRecord();
    record.setId(store.nextId(NULL));
    record.setInUse(true);
    if (record instanceof PropertyRecord) {
        // Special hack for property store, since it's not enough to simply set a record as in use there
        PropertyBlock block = new PropertyBlock();
        ((PropertyStore) store).encodeValue(block, 0, Values.of(10), NULL, INSTANCE);
        ((PropertyRecord) record).addPropertyBlock(block);
    }
    store.updateRecord(record, NULL);
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore)

Example 70 with PropertyRecord

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

the class LogCommandSerializationV4_0Test method readPropertyCommandWithFixedReferenceFormat.

@Test
void readPropertyCommandWithFixedReferenceFormat() throws IOException {
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    PropertyRecord before = new PropertyRecord(1);
    PropertyRecord after = new PropertyRecord(1);
    before.setUseFixedReferences(true);
    after.setUseFixedReferences(true);
    new Command.PropertyCommand(writer(), before, after).serialize(channel);
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.PropertyCommand);
    Command.PropertyCommand propertyCommand = (Command.PropertyCommand) command;
    // Then
    assertBeforeAndAfterEquals(propertyCommand, before, after);
    assertTrue(propertyCommand.getBefore().isUseFixedReferences());
    assertTrue(propertyCommand.getAfter().isUseFixedReferences());
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

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