Search in sources :

Example 1 with DynamicRecordAllocator

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

the class NodeRecordCheckTest method shouldReportOutOfOrderLabels.

@Test
public void shouldReportOutOfOrderLabels() 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[] { 3, 1, 2 }, null, null);
    LabelTokenRecord label1 = inUse(new LabelTokenRecord(1));
    LabelTokenRecord label2 = inUse(new LabelTokenRecord(2));
    LabelTokenRecord label3 = inUse(new LabelTokenRecord(3));
    add(label1);
    add(label2);
    add(label3);
    add(node);
    // when
    ConsistencyReport.NodeConsistencyReport report = check(node);
    // then
    verify(report).labelsOutOfOrder(3, 1);
}
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 2 with DynamicRecordAllocator

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

the class StorePropertyCursorTest method createSinglePropertyValue.

private static PropertyRecord createSinglePropertyValue(PropertyStore store, int keyId, Object value) {
    DynamicRecordAllocator stringAllocator = store.getStringStore();
    DynamicRecordAllocator arrayAllocator = store.getArrayStore();
    PropertyBlock block = new PropertyBlock();
    PropertyStore.encodeValue(block, keyId, value, stringAllocator, arrayAllocator);
    PropertyRecord record = new PropertyRecord(store.nextId());
    record.addPropertyBlock(block);
    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 3 with DynamicRecordAllocator

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

the class SchemaStore35Test method allocateFrom.

public List<DynamicRecord> allocateFrom(SchemaRule rule, CursorContext cursorContext) {
    List<DynamicRecord> records = new ArrayList<>();
    DynamicRecord record = store.getRecord(rule.getId(), store.newRecord(), CHECK, cursorContext);
    DynamicRecordAllocator recordAllocator = new ReusableRecordsCompositeAllocator(singleton(record), store);
    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)

Example 4 with DynamicRecordAllocator

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

the class ReusableRecordsCompositeAllocatorTest method allocateReusableRecordsAndSwitchToDefaultWhenExhausted.

@Test
void allocateReusableRecordsAndSwitchToDefaultWhenExhausted() {
    DynamicRecord dynamicRecord1 = new DynamicRecord(1);
    DynamicRecord dynamicRecord2 = new DynamicRecord(2);
    DynamicRecordAllocator recordAllocator = mock(DynamicRecordAllocator.class);
    Mockito.when(recordAllocator.nextRecord(NULL)).thenReturn(dynamicRecord2);
    ReusableRecordsCompositeAllocator compositeAllocator = new ReusableRecordsCompositeAllocator(singletonList(dynamicRecord1), recordAllocator);
    assertSame(dynamicRecord1, compositeAllocator.nextRecord(NULL), "Same as pre allocated record.");
    assertSame(dynamicRecord2, compositeAllocator.nextRecord(NULL), "Same as expected allocated record.");
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) DynamicRecordAllocator(org.neo4j.kernel.impl.store.DynamicRecordAllocator) Test(org.junit.jupiter.api.Test)

Example 5 with DynamicRecordAllocator

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

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