Search in sources :

Example 26 with DynamicRecord

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

the class AbstractDynamicStore method readFullByteArrayFromHeavyRecords.

/**
     * @return Pair< header-in-first-record , all-other-bytes >
     */
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 27 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 28 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)

Example 29 with DynamicRecord

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

the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.

@Test
public void shouldCreateConsistentUniquenessConstraint() throws Exception {
    // given
    BatchInserter inserter = newBatchInserter();
    // when
    inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
    // then
    GraphDatabaseAPI graphdb = (GraphDatabaseAPI) switchToEmbeddedGraphDatabaseService(inserter);
    try {
        NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
        SchemaStore store = neoStores.getSchemaStore();
        SchemaStorage storage = new SchemaStorage(store);
        List<Long> inUse = new ArrayList<>();
        DynamicRecord record = store.nextRecord();
        for (long i = 1, high = store.getHighestPossibleIdInUse(); i <= high; i++) {
            store.getRecord(i, record, RecordLoad.FORCE);
            if (record.inUse() && record.isStartRecord()) {
                inUse.add(i);
            }
        }
        assertEquals("records in use", 2, inUse.size());
        SchemaRule rule0 = storage.loadSingleSchemaRule(inUse.get(0));
        SchemaRule rule1 = storage.loadSingleSchemaRule(inUse.get(1));
        IndexRule indexRule;
        ConstraintRule constraintRule;
        if (rule0 instanceof IndexRule) {
            indexRule = (IndexRule) rule0;
            constraintRule = (ConstraintRule) rule1;
        } else {
            constraintRule = (ConstraintRule) rule0;
            indexRule = (IndexRule) rule1;
        }
        assertEquals("index should reference constraint", constraintRule.getId(), indexRule.getOwningConstraint().longValue());
        assertEquals("constraint should reference index", indexRule.getId(), constraintRule.getOwnedIndex());
    } finally {
        graphdb.shutdown();
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Matchers.anyLong(org.mockito.Matchers.anyLong) Test(org.junit.Test)

Example 30 with DynamicRecord

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

the class SchemaStorage method loadAllSchemaRules.

<ReturnType extends SchemaRule> Iterator<ReturnType> loadAllSchemaRules(final Predicate<ReturnType> predicate, final Class<ReturnType> returnType, final boolean ignoreMalformed) {
    return new PrefetchingIterator<ReturnType>() {

        private final long highestId = schemaStore.getHighestPossibleIdInUse();

        private long currentId = 1;

        /*record 0 contains the block size*/
        private final byte[] scratchData = newRecordBuffer();

        private final DynamicRecord record = schemaStore.newRecord();

        @Override
        protected ReturnType fetchNextOrNull() {
            while (currentId <= highestId) {
                long id = currentId++;
                schemaStore.getRecord(id, record, RecordLoad.FORCE);
                if (record.inUse() && record.isStartRecord()) {
                    try {
                        SchemaRule schemaRule = loadSingleSchemaRuleViaBuffer(id, scratchData);
                        if (returnType.isInstance(schemaRule)) {
                            ReturnType returnRule = returnType.cast(schemaRule);
                            if (predicate.test(returnRule)) {
                                return returnRule;
                            }
                        }
                    } catch (MalformedSchemaRuleException e) {
                        if (!ignoreMalformed) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            return null;
        }
    };
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PrefetchingIterator(org.neo4j.helpers.collection.PrefetchingIterator) MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule)

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