Search in sources :

Example 6 with AbstractBaseRecord

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

the class RecordStorageEngine method listStorageFiles.

@Override
public void listStorageFiles(Collection<StoreFileMetadata> atomic, Collection<StoreFileMetadata> replayable) {
    atomic.add(new StoreFileMetadata(databaseLayout.countStore(), RecordFormat.NO_RECORD_SIZE));
    atomic.add(new StoreFileMetadata(databaseLayout.relationshipGroupDegreesStore(), RecordFormat.NO_RECORD_SIZE));
    for (StoreType type : StoreType.values()) {
        final RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore(type);
        StoreFileMetadata metadata = new StoreFileMetadata(recordStore.getStorageFile(), recordStore.getRecordSize());
        replayable.add(metadata);
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata)

Example 7 with AbstractBaseRecord

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

the class SchemaStorage method streamAllSchemaRules.

@VisibleForTesting
Stream<SchemaRule> streamAllSchemaRules(boolean ignoreMalformed, CursorContext cursorContext) {
    long startId = schemaStore.getNumberOfReservedLowIds();
    long endId = schemaStore.getHighId();
    Stream<IndexDescriptor> nli = Stream.empty();
    KernelVersion currentVersion;
    try {
        currentVersion = versionSupplier.kernelVersion();
    } catch (IllegalStateException ignored) {
        // If KernelVersion is missing we are an older store.
        currentVersion = KernelVersion.V4_2;
    }
    if (currentVersion.isLessThan(KernelVersion.VERSION_IN_WHICH_TOKEN_INDEXES_ARE_INTRODUCED)) {
        nli = Stream.of(IndexDescriptor.INJECTED_NLI);
    }
    return Stream.concat(LongStream.range(startId, endId).mapToObj(id -> schemaStore.getRecord(id, schemaStore.newRecord(), RecordLoad.LENIENT_ALWAYS, cursorContext)).filter(AbstractBaseRecord::inUse).flatMap(record -> readSchemaRuleThrowingRuntimeException(record, ignoreMalformed, cursorContext)), nli);
}
Also used : KernelVersion(org.neo4j.kernel.KernelVersion) SchemaRule(org.neo4j.internal.schema.SchemaRule) CursorContext(org.neo4j.io.pagecache.context.CursorContext) KernelVersion(org.neo4j.kernel.KernelVersion) Value(org.neo4j.values.storable.Value) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) IntObjectMap(org.eclipse.collections.api.map.primitive.IntObjectMap) KernelVersionRepository(org.neo4j.storageengine.api.KernelVersionRepository) IntObjectProcedure(org.eclipse.collections.api.block.procedure.primitive.IntObjectProcedure) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) VisibleForTesting(org.neo4j.util.VisibleForTesting) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRuleNotFoundException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaRuleNotFoundException) MemoryTracker(org.neo4j.memory.MemoryTracker) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Record(org.neo4j.kernel.impl.store.record.Record) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) Collection(java.util.Collection) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) DuplicateSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.DuplicateSchemaRuleException) Stream(java.util.stream.Stream) KernelException(org.neo4j.exceptions.KernelException) TokenHolders(org.neo4j.token.TokenHolders) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) SchemaDescriptorSupplier(org.neo4j.internal.schema.SchemaDescriptorSupplier) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) IndexRef(org.neo4j.internal.schema.IndexRef) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) VisibleForTesting(org.neo4j.util.VisibleForTesting)

Example 8 with AbstractBaseRecord

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

the class RecordAssert method containsRecords.

// Build a contains matcher that matches all records of a single given type
// NOTE: This is a bit brittle, if you like it'd be easy to make it a general purpose
// list-of-records-of-any-type matcher. As-is, if you use it to match mixed-type records,
// behavior is undefined.
// NOTE: This nests diff functions for individual records; if you want a matcher for
// a single record, just refactor those out and have this delegate to them, see how
// the containsChanges delegates here for an example.
public DiffAssert<Iterable<? extends AbstractBaseRecord>> containsRecords(String recordPlural, Stream<? extends AbstractBaseRecord> expected) {
    Map<Long, AbstractBaseRecord> expectedById = expected.collect(toMap(AbstractBaseRecord::getId, identity()));
    return new DiffAssert<>() {

        @Override
        String diff(Iterable<? extends AbstractBaseRecord> actual) {
            Set<Long> seen = new HashSet<>(expectedById.keySet());
            for (AbstractBaseRecord record : actual) {
                seen.remove(record.getId());
                if (!expectedById.containsKey(record.getId())) {
                    return String.format("This record was not expected: %s", record);
                }
                String diff = diff(expectedById.get(record.getId()), record);
                if (diff != null) {
                    return diff;
                }
            }
            return null;
        }

        private String diff(AbstractBaseRecord expected, AbstractBaseRecord actual) {
            if (expected instanceof NodeRecord) {
                return diff((NodeRecord) expected, (NodeRecord) actual);
            }
            if (expected instanceof RelationshipRecord) {
                return diff((RelationshipRecord) expected, (RelationshipRecord) actual);
            }
            if (expected instanceof RelationshipGroupRecord) {
                return diff((RelationshipGroupRecord) expected, (RelationshipGroupRecord) actual);
            }
            throw new UnsupportedOperationException(String.format("No diff implementation (just add one, its easy) for: %s", expected));
        }

        private String diff(NodeRecord expected, NodeRecord actual) {
            if (actual.getId() == expected.getId() && actual.getNextRel() == expected.getNextRel() && actual.getLabelField() == expected.getLabelField() && actual.getNextProp() == expected.getNextProp() && actual.isDense() == expected.isDense() && actual.isLight() == expected.isLight()) {
                return null;
            }
            return describeDiff(expected.toString(), actual.toString());
        }

        private String diff(RelationshipGroupRecord expected, RelationshipGroupRecord actual) {
            if (actual.getId() == expected.getId() && actual.getType() == expected.getType() && actual.getNext() == expected.getNext() && actual.getFirstOut() == expected.getFirstOut() && actual.getFirstIn() == expected.getFirstIn() && actual.getFirstLoop() == expected.getFirstLoop() && actual.getOwningNode() == expected.getOwningNode()) {
                return null;
            }
            return describeDiff(expected.toString(), actual.toString());
        }

        private String diff(RelationshipRecord expected, RelationshipRecord actual) {
            if (actual.getId() == expected.getId() && actual.getFirstNode() == expected.getFirstNode() && actual.getSecondNode() == expected.getSecondNode() && actual.getType() == expected.getType() && actual.getFirstPrevRel() == expected.getFirstPrevRel() && actual.getFirstNextRel() == expected.getFirstNextRel() && actual.getSecondPrevRel() == expected.getSecondPrevRel() && actual.getSecondNextRel() == expected.getSecondNextRel() && actual.isFirstInFirstChain() == expected.isFirstInFirstChain() && actual.isFirstInSecondChain() == expected.isFirstInSecondChain()) {
                return null;
            }
            return describeDiff(expected.toString(), actual.toString());
        }

        private String describeDiff(String expected, String actual) {
            StringBuilder arrow = new StringBuilder();
            char[] expectedChars = expected.toCharArray();
            char[] actualChars = actual.toCharArray();
            for (int i = 0; i < Math.min(expectedChars.length, actualChars.length); i++) {
                if (expectedChars[i] != actualChars[i]) {
                    break;
                }
                arrow.append('-');
            }
            return String.format("Record fields don't match.\n" + "Expected: %s\n" + "Actual:   %s\n" + "          %s", expected, actual, arrow.append('^').toString());
        }
    };
}
Also used : AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) HashSet(java.util.HashSet)

Aggregations

AbstractBaseRecord (org.neo4j.kernel.impl.store.record.AbstractBaseRecord)8 ByteBuffer (java.nio.ByteBuffer)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 StoreType (org.neo4j.kernel.impl.store.StoreType)2 StoreFileMetadata (org.neo4j.storageengine.api.StoreFileMetadata)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LongStream (java.util.stream.LongStream)1 Stream (java.util.stream.Stream)1 IntObjectProcedure (org.eclipse.collections.api.block.procedure.primitive.IntObjectProcedure)1 IntObjectMap (org.eclipse.collections.api.map.primitive.IntObjectMap)1 KernelException (org.neo4j.exceptions.KernelException)1 DuplicateSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.DuplicateSchemaRuleException)1 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 SchemaRuleNotFoundException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaRuleNotFoundException)1 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)1