Search in sources :

Example 86 with PropertyRecord

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

the class DeleteDuplicateNodesStepTest method createNode.

private Ids createNode(DataImporter.Monitor monitor, NeoStores neoStores, int propertyCount, int labelCount) {
    PropertyStore propertyStore = neoStores.getPropertyStore();
    NodeStore nodeStore = neoStores.getNodeStore();
    NodeRecord nodeRecord = nodeStore.newRecord();
    nodeRecord.setId(nodeStore.nextId(NULL));
    nodeRecord.setInUse(true);
    NodeLabelsField.parseLabelsField(nodeRecord).put(labelIds(labelCount), nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE);
    PropertyRecord[] propertyRecords = createPropertyChain(nodeRecord, propertyCount, propertyStore);
    if (propertyRecords.length > 0) {
        nodeRecord.setNextProp(propertyRecords[0].getId());
    }
    nodeStore.updateRecord(nodeRecord, NULL);
    monitor.nodesImported(1);
    monitor.propertiesImported(propertyCount);
    return new Ids(nodeRecord, propertyRecords);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore)

Example 87 with PropertyRecord

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

the class RecordPropertyCursorTest method shouldAbortChainTraversalOnLikelyCycle.

@Test
void shouldAbortChainTraversalOnLikelyCycle() {
    // given
    // many enough to create multiple records in the chain
    Value[] values = createValues(20, 20);
    long firstProp = storeValuesAsPropertyChain(creator, owner, values);
    // and a cycle on the second record
    PropertyStore store = neoStores.getPropertyStore();
    PropertyRecord firstRecord = store.getRecord(firstProp, store.newRecord(), RecordLoad.NORMAL, NULL);
    long secondProp = firstRecord.getNextProp();
    PropertyRecord secondRecord = store.getRecord(secondProp, store.newRecord(), RecordLoad.NORMAL, NULL);
    secondRecord.setNextProp(firstProp);
    store.updateRecord(secondRecord, NULL);
    owner.setId(99);
    // when
    RecordPropertyCursor cursor = createCursor();
    cursor.initNodeProperties(firstProp, owner.getId());
    InconsistentDataReadException e = assertThrows(InconsistentDataReadException.class, () -> {
        while (cursor.next()) {
        // just keep going, it should eventually hit the cycle detection threshold
        }
    });
    // then
    assertEquals(format("Aborting property reading due to detected chain cycle, starting at property record id:%d from owner NODE:%d", firstProp, owner.getId()), e.getMessage());
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Value(org.neo4j.values.storable.Value) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.jupiter.api.Test)

Example 88 with PropertyRecord

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

the class PropertyDeleterTest method shouldHandlePropertyChainDeletionOnUnusedRecord.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldHandlePropertyChainDeletionOnUnusedRecord(boolean log) {
    // given
    startStore(log);
    NodeStore nodeStore = neoStores.getNodeStore();
    NodeRecord node = nodeStore.newRecord();
    node.setId(nodeStore.nextId(NULL));
    List<PropertyBlock> properties = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        properties.add(encodedValue(i, random.nextValue()));
    }
    DirectRecordAccessSet initialChanges = new DirectRecordAccessSet(neoStores, idGeneratorFactory, NULL);
    long firstPropId = propertyCreator.createPropertyChain(node, properties.iterator(), initialChanges.getPropertyRecords());
    node.setNextProp(firstPropId);
    // should update all the changed records directly into the store
    initialChanges.commit();
    // create a cycle in the property chain A -> B
    // ^---v
    List<Value> valuesInTheFirstTwoRecords = new ArrayList<>();
    PropertyRecord firstPropRecord = propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    readValuesFromPropertyRecord(firstPropRecord, valuesInTheFirstTwoRecords);
    long secondPropId = firstPropRecord.getNextProp();
    PropertyRecord secondPropRecord = propertyStore.getRecord(secondPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    readValuesFromPropertyRecord(secondPropRecord, valuesInTheFirstTwoRecords);
    long thirdPropId = secondPropRecord.getNextProp();
    PropertyRecord thirdPropRecord = propertyStore.getRecord(thirdPropId, propertyStore.newRecord(), RecordLoad.NORMAL, NULL);
    thirdPropRecord.setInUse(false);
    propertyStore.updateRecord(thirdPropRecord, NULL);
    // when
    DirectRecordAccessSet changes = new DirectRecordAccessSet(neoStores, idGeneratorFactory, NULL);
    deleter.deletePropertyChain(node, changes.getPropertyRecords());
    changes.commit();
    // then
    assertEquals(Record.NO_NEXT_PROPERTY.longValue(), node.getNextProp());
    assertFalse(propertyStore.getRecord(firstPropId, propertyStore.newRecord(), RecordLoad.CHECK, NULL).inUse());
    assertFalse(propertyStore.getRecord(secondPropId, propertyStore.newRecord(), RecordLoad.CHECK, NULL).inUse());
    assertLogContains("Deleted inconsistent property chain with unused record", log);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with PropertyRecord

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

the class PropertyPhysicalToLogicalConverterTest method shouldConvertInlinedChangedProperty.

@Test
void shouldConvertInlinedChangedProperty() {
    // GIVEN
    int key = 10;
    Value valueBefore = Values.of(12341);
    Value valueAfter = Values.of(738);
    PropertyRecord before = propertyRecord(property(key, valueBefore));
    PropertyRecord after = propertyRecord(property(key, valueAfter));
    // WHEN
    EntityUpdates update = convert(none, none, change(before, after));
    // THEN
    EntityUpdates expected = EntityUpdates.forEntity(0, false).changed(key, valueBefore, valueAfter).build();
    assertEquals(expected, update);
}
Also used : EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Value(org.neo4j.values.storable.Value) Test(org.junit.jupiter.api.Test)

Example 90 with PropertyRecord

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

the class PropertyPhysicalToLogicalConverterTest method shouldConvertInlinedAddedProperty.

@Test
void shouldConvertInlinedAddedProperty() {
    // GIVEN
    int key = 10;
    Value value = Values.of(12345);
    PropertyRecord before = propertyRecord();
    PropertyRecord after = propertyRecord(property(key, value));
    // WHEN
    assertThat(convert(none, none, change(before, after))).isEqualTo(EntityUpdates.forEntity(0, false).added(key, value).build());
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Value(org.neo4j.values.storable.Value) 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