Search in sources :

Example 76 with DynamicRecord

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

the class NodeLabelReader method getListOfLabels.

public static long[] getListOfLabels(NodeRecord nodeRecord, RecordStore<DynamicRecord> labels) {
    long field = nodeRecord.getLabelField();
    if (NodeLabelsField.fieldPointsToDynamicRecordOfLabels(field)) {
        List<DynamicRecord> recordList = new ArrayList<>();
        PrimitiveLongSet alreadySeen = Primitive.longSet(16);
        long id = NodeLabelsField.firstDynamicLabelRecordId(field);
        while (!Record.NULL_REFERENCE.is(id)) {
            DynamicRecord record = labels.getRecord(id, labels.newRecord(), FORCE);
            if (!record.inUse() || !alreadySeen.add(id)) {
                return PrimitiveLongCollections.EMPTY_LONG_ARRAY;
            }
            recordList.add(record);
        }
        return LabelChainWalker.labelIds(recordList);
    }
    return InlineNodeLabels.get(nodeRecord);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) ArrayList(java.util.ArrayList)

Example 77 with DynamicRecord

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

the class StorePropertyPayloadCursor method readFromStore.

private void readFromStore(RecordCursor<DynamicRecord> cursor) {
    buffer.clear();
    long startBlockId = PropertyBlock.fetchLong(currentHeader());
    cursor.placeAt(startBlockId, FORCE);
    while (true) {
        cursor.next();
        DynamicRecord dynamicRecord = cursor.get();
        byte[] data = dynamicRecord.getData();
        if (buffer.remaining() < data.length) {
            buffer.flip();
            ByteBuffer newBuffer = newBiggerBuffer(data.length);
            newBuffer.put(buffer);
            buffer = newBuffer;
        }
        buffer.put(data, 0, data.length);
        if (Record.NULL_REFERENCE.is(dynamicRecord.getNextBlock())) {
            break;
        }
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ByteBuffer(java.nio.ByteBuffer)

Example 78 with DynamicRecord

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

the class AbstractDynamicStore method readFullByteArrayFromHeavyRecords.

/**
     * @return Pair&lt; header-in-first-record , all-other-bytes &gt;
     */
public static Pair<byte[], byte[]> readFullByteArrayFromHeavyRecords(Iterable<DynamicRecord> records, PropertyType propertyType) {
    byte[] header = null;
    List<byte[]> byteList = new ArrayList<>();
    int totalSize = 0, i = 0;
    for (DynamicRecord record : records) {
        int offset = 0;
        if (i++ == 0) {
            // This is the first one, read out the header separately
            header = propertyType.readDynamicRecordHeader(record.getData());
            offset = header.length;
        }
        byteList.add(record.getData());
        totalSize += record.getData().length - offset;
    }
    byte[] bArray = new byte[totalSize];
    assert header != null : "header should be non-null since records should not be empty: " + Iterables.toString(records, ", ");
    int sourceOffset = header.length;
    int offset = 0;
    for (byte[] currentArray : byteList) {
        System.arraycopy(currentArray, sourceOffset, bArray, offset, currentArray.length - sourceOffset);
        offset += currentArray.length - sourceOffset;
        sourceOffset = 0;
    }
    return Pair.of(header, bArray);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList)

Example 79 with DynamicRecord

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

the class DynamicNodeLabels method putSorted.

public static Collection<DynamicRecord> putSorted(NodeRecord node, long[] labelIds, NodeStore nodeStore, DynamicRecordAllocator allocator) {
    long existingLabelsField = node.getLabelField();
    long existingLabelsBits = parseLabelsBody(existingLabelsField);
    Collection<DynamicRecord> changedDynamicRecords = node.getDynamicLabelRecords();
    long labelField = node.getLabelField();
    if (fieldPointsToDynamicRecordOfLabels(labelField)) {
        // There are existing dynamic label records, get them
        nodeStore.ensureHeavy(node, existingLabelsBits);
        changedDynamicRecords = node.getDynamicLabelRecords();
        setNotInUse(changedDynamicRecords);
    }
    if (!InlineNodeLabels.tryInlineInNodeRecord(node, labelIds, changedDynamicRecords)) {
        Iterator<DynamicRecord> recycledRecords = changedDynamicRecords.iterator();
        Collection<DynamicRecord> allocatedRecords = allocateRecordsForDynamicLabels(node.getId(), labelIds, new ReusableRecordsCompositeAllocator(recycledRecords, allocator));
        // Set the rest of the previously set dynamic records as !inUse
        while (recycledRecords.hasNext()) {
            DynamicRecord removedRecord = recycledRecords.next();
            removedRecord.setInUse(false);
            allocatedRecords.add(removedRecord);
        }
        node.setLabelField(dynamicPointer(allocatedRecords), allocatedRecords);
        changedDynamicRecords = allocatedRecords;
    }
    return changedDynamicRecords;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ReusableRecordsCompositeAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsCompositeAllocator)

Example 80 with DynamicRecord

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

the class AbstractDynamicStoreTest method newTestableDynamicStore.

private AbstractDynamicStore newTestableDynamicStore() {
    DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
    AbstractDynamicStore store = new AbstractDynamicStore(fileName, Config.empty(), IdType.ARRAY_BLOCK, idGeneratorFactory, pageCache, NullLogProvider.getInstance(), "test", BLOCK_SIZE, formats.dynamic(), formats.storeVersion()) {

        @Override
        public void accept(Processor processor, DynamicRecord record) {
        // Ignore
        }

        @Override
        public String getTypeDescriptor() {
            return "TestDynamicStore";
        }
    };
    store.initialise(true);
    return store;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)

Aggregations

DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)225 Test (org.junit.Test)117 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)51 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)38 ArrayList (java.util.ArrayList)32 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)28 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)23 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)21 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)21 IOException (java.io.IOException)20 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)16 ReusableRecordsAllocator (org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator)16 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)16 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)16 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)15 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)15 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)15 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)15 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)14 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)14