Search in sources :

Example 6 with DynamicRecordAllocator

use of org.neo4j.kernel.impl.store.DynamicRecordAllocator in project neo4j by neo4j.

the class NodeRecordCheckTest method shouldProperlyReportOutOfOrderLabelsThatAreFarAway.

@Test
public void shouldProperlyReportOutOfOrderLabelsThatAreFarAway() throws Exception {
    // given
    final NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
    // We need to do this override so we can put the labels unsorted, since InlineNodeLabels always sorts on insert
    new InlineNodeLabels(node) {

        @Override
        public Collection<DynamicRecord> put(long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator) {
            return putSorted(node, labelIds, nodeStore, allocator);
        }
    }.put(new long[] { 1, 18, 13, 14, 15, 16, 12 }, null, null);
    LabelTokenRecord label1 = inUse(new LabelTokenRecord(1));
    LabelTokenRecord label12 = inUse(new LabelTokenRecord(12));
    LabelTokenRecord label13 = inUse(new LabelTokenRecord(13));
    LabelTokenRecord label14 = inUse(new LabelTokenRecord(14));
    LabelTokenRecord label15 = inUse(new LabelTokenRecord(15));
    LabelTokenRecord label16 = inUse(new LabelTokenRecord(16));
    LabelTokenRecord label18 = inUse(new LabelTokenRecord(18));
    add(label1);
    add(label12);
    add(label13);
    add(label14);
    add(label15);
    add(label16);
    add(label18);
    add(node);
    // when
    ConsistencyReport.NodeConsistencyReport report = check(node);
    // then
    verify(report).labelsOutOfOrder(18, 13);
    verify(report).labelsOutOfOrder(16, 12);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) InlineNodeLabels(org.neo4j.kernel.impl.store.InlineNodeLabels) DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) NodeStore(org.neo4j.kernel.impl.store.NodeStore) Collection(java.util.Collection) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Example 7 with DynamicRecordAllocator

use of org.neo4j.kernel.impl.store.DynamicRecordAllocator in project neo4j by neo4j.

the class StorePropertyCursorTest method createTwoPropertyValues.

private static PropertyRecord createTwoPropertyValues(PropertyStore store, int keyId1, Object value1, int keyId2, Object value2) {
    DynamicRecordAllocator stringAllocator = store.getStringStore();
    DynamicRecordAllocator arrayAllocator = store.getArrayStore();
    PropertyBlock block1 = new PropertyBlock();
    PropertyStore.encodeValue(block1, keyId1, value1, stringAllocator, arrayAllocator);
    PropertyBlock block2 = new PropertyBlock();
    PropertyStore.encodeValue(block2, keyId2, value2, stringAllocator, arrayAllocator);
    PropertyRecord record = new PropertyRecord(store.nextId());
    record.addPropertyBlock(block1);
    if (block1.getSize() + block2.getSize() <= PropertyRecordFormat.DEFAULT_PAYLOAD_SIZE) {
        record.addPropertyBlock(block2);
    } else {
        PropertyRecord nextRecord = new PropertyRecord(store.nextId());
        record.setNextProp(nextRecord.getId());
        nextRecord.addPropertyBlock(block2);
        nextRecord.setPrevProp(record.getId());
        nextRecord.setInUse(true);
        updateRecord(store, nextRecord);
    }
    record.setInUse(true);
    updateRecord(store, record);
    return record;
}
Also used : DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 8 with DynamicRecordAllocator

use of org.neo4j.kernel.impl.store.DynamicRecordAllocator in project neo4j by neo4j.

the class StorePropertyPayloadCursorTest method asBlocks.

private static long[] asBlocks(Object... values) {
    DynamicRecordAllocator stringAllocator = new StandaloneDynamicRecordAllocator();
    DynamicRecordAllocator arrayAllocator = new StandaloneDynamicRecordAllocator();
    long[] blocks = new long[PropertyType.getPayloadSizeLongs()];
    int cursor = 0;
    for (int i = 0; i < values.length; i++) {
        Object value = values[i];
        PropertyBlock block = new PropertyBlock();
        PropertyStore.encodeValue(block, i, value, stringAllocator, arrayAllocator);
        long[] valueBlocks = block.getValueBlocks();
        System.arraycopy(valueBlocks, 0, blocks, cursor, valueBlocks.length);
        cursor += valueBlocks.length;
    }
    return blocks;
}
Also used : DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) StandaloneDynamicRecordAllocator(org.neo4j.kernel.impl.store.StandaloneDynamicRecordAllocator) StandaloneDynamicRecordAllocator(org.neo4j.kernel.impl.store.StandaloneDynamicRecordAllocator) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 9 with DynamicRecordAllocator

use of org.neo4j.kernel.impl.store.DynamicRecordAllocator in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportArrayPropertyInconsistencies.

@Test
void shouldReportArrayPropertyInconsistencies() throws Exception {
    // given
    int recordDataSize = GraphDatabaseSettings.DEFAULT_BLOCK_SIZE - 12;
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            // A dynamic array property with a broken chain, first dynamic record pointing to an unused second dynamic record
            List<DynamicRecord> allocatedRecords = new ArrayList<>();
            long[] arrayValue = new long[70];
            for (int i = 0; i < arrayValue.length; i++) {
                arrayValue[i] = i * 10_000;
            }
            DynamicArrayStore.allocateRecords(allocatedRecords, arrayValue, new DynamicRecordAllocator() {

                @Override
                public int getRecordDataSize() {
                    return recordDataSize;
                }

                @Override
                public DynamicRecord nextRecord(CursorContext cursorContext) {
                    return StandardDynamicRecordAllocator.allocateRecord(next.arrayProperty());
                }
            }, true, NULL, INSTANCE);
            assertThat(allocatedRecords.size()).isGreaterThan(1);
            DynamicRecord array = allocatedRecords.get(0);
            array.setType(ARRAY.intValue());
            // A property block referencing this dynamic array property
            PropertyBlock block = new PropertyBlock();
            block.setSingleBlock((((long) ARRAY.intValue()) << 24) | (array.getId() << 28));
            block.addValueRecord(array);
            // Set the property key explicitly to one created in the setup (property key 0 can be an internal token)
            block.setKeyIndexId(key1);
            // A property record with this block in it
            PropertyRecord property = new PropertyRecord(next.property());
            property.addPropertyBlock(block);
            // A node referencing this property record
            NodeRecord node = new NodeRecord(next.node());
            node.initialize(true, property.getId(), false, NO_NEXT_RELATIONSHIP.longValue(), NO_LABELS_FIELD.longValue());
            property.setNodeId(node.getId());
            tx.create(property);
            tx.create(node);
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.ARRAY_PROPERTY, 1).andThatsAllFolks();
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) CursorContext(org.neo4j.io.pagecache.context.CursorContext) StandardDynamicRecordAllocator(org.neo4j.kernel.impl.store.StandardDynamicRecordAllocator) DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) 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) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) 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 10 with DynamicRecordAllocator

use of org.neo4j.kernel.impl.store.DynamicRecordAllocator in project neo4j by neo4j.

the class RecordStorageMigratorIT method allocateFrom.

public static List<DynamicRecord> allocateFrom(SchemaStore35 schemaStore35, SchemaRule rule, CursorContext cursorContext) {
    List<DynamicRecord> records = new ArrayList<>();
    DynamicRecord record = schemaStore35.getRecord(rule.getId(), schemaStore35.newRecord(), CHECK, cursorContext);
    DynamicRecordAllocator recordAllocator = new ReusableRecordsCompositeAllocator(singleton(record), schemaStore35);
    allocateRecordsFromBytes(records, SchemaRuleSerialization35.serialize(rule, INSTANCE), recordAllocator, cursorContext, INSTANCE);
    return records;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) ReusableRecordsCompositeAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsCompositeAllocator) ArrayList(java.util.ArrayList)

Aggregations

DynamicRecordAllocator (org.neo4j.kernel.impl.store.DynamicRecordAllocator)10 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)5 ArrayList (java.util.ArrayList)4 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)4 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)4 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 Collection (java.util.Collection)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)2 InlineNodeLabels (org.neo4j.kernel.impl.store.InlineNodeLabels)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 StandardDynamicRecordAllocator (org.neo4j.kernel.impl.store.StandardDynamicRecordAllocator)2 ReusableRecordsCompositeAllocator (org.neo4j.kernel.impl.store.allocator.ReusableRecordsCompositeAllocator)2 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)2 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)1