Search in sources :

Example 1 with InvalidRecordException

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

the class RsdrMain method readStore.

private static void readStore(FileSystemAbstraction fileSystem, RecordStore store, long fromId, long toId, Pattern pattern) throws IOException {
    toId = Math.min(toId, store.getHighId());
    try (StoreChannel channel = fileSystem.open(store.getStorageFileName(), "r")) {
        int recordSize = store.getRecordSize();
        ByteBuffer buf = ByteBuffer.allocate(recordSize);
        for (long i = fromId; i <= toId; i++) {
            buf.clear();
            long offset = recordSize * i;
            int count = channel.read(buf, offset);
            if (count == -1) {
                break;
            }
            byte[] bytes = new byte[count];
            buf.clear();
            buf.get(bytes);
            String hex = DatatypeConverter.printHexBinary(bytes);
            int paddingNeeded = (recordSize * 2 - Math.max(count * 2, 0)) + 1;
            String format = "%s %6s 0x%08X %s%" + paddingNeeded + "s%s%n";
            String str;
            String use;
            try {
                AbstractBaseRecord record = RecordStore.getRecord(store, i, CHECK);
                use = record.inUse() ? "+" : "-";
                str = record.toString();
            } catch (InvalidRecordException e) {
                str = new String(bytes, 0, count, "ASCII");
                use = "?";
            }
            if (pattern == null || pattern.matcher(str).find()) {
                console.printf(format, use, i, offset, hex, " ", str);
            }
        }
    }
}
Also used : AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ByteBuffer(java.nio.ByteBuffer) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException)

Example 2 with InvalidRecordException

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

the class RelationshipCreator method connect.

private void connect(long nodeId, long firstRelId, RelationshipRecord rel, RecordAccess<Long, RelationshipRecord, Void> relRecords, ResourceLocker locks) {
    long newCount = 1;
    if (firstRelId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        locks.acquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, firstRelId);
        RelationshipRecord firstRel = relRecords.getOrLoad(firstRelId, null).forChangingLinkage();
        boolean changed = false;
        if (firstRel.getFirstNode() == nodeId) {
            newCount = firstRel.getFirstPrevRel() + 1;
            firstRel.setFirstPrevRel(rel.getId());
            firstRel.setFirstInFirstChain(false);
            changed = true;
        }
        if (firstRel.getSecondNode() == nodeId) {
            newCount = firstRel.getSecondPrevRel() + 1;
            firstRel.setSecondPrevRel(rel.getId());
            firstRel.setFirstInSecondChain(false);
            changed = true;
        }
        if (!changed) {
            throw new InvalidRecordException(nodeId + " doesn't match " + firstRel);
        }
    }
    // Set the relationship count
    if (rel.getFirstNode() == nodeId) {
        rel.setFirstPrevRel(newCount);
        rel.setFirstInFirstChain(true);
    }
    if (rel.getSecondNode() == nodeId) {
        rel.setSecondPrevRel(newCount);
        rel.setFirstInSecondChain(true);
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException)

Example 3 with InvalidRecordException

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

the class PropertyDeleter method deletePropertyChain.

public void deletePropertyChain(PrimitiveRecord primitive, RecordAccess<PropertyRecord, PrimitiveRecord> propertyRecords) {
    long nextProp = primitive.getNextProp();
    MutableLongSet seenPropertyIds = null;
    int count = 0;
    try {
        while (nextProp != Record.NO_NEXT_PROPERTY.longValue()) {
            RecordProxy<PropertyRecord, PrimitiveRecord> propertyChange = propertyRecords.getOrLoad(nextProp, primitive, cursorContext);
            PropertyRecord propRecord = propertyChange.forChangingData();
            deletePropertyRecordIncludingValueRecords(propRecord);
            if (++count >= CYCLE_DETECTION_THRESHOLD) {
                if (seenPropertyIds == null) {
                    seenPropertyIds = LongSets.mutable.empty();
                }
                if (!seenPropertyIds.add(nextProp)) {
                    throw new InconsistentDataReadException("Cycle detected in property chain for %s", primitive);
                }
            }
            nextProp = propRecord.getNextProp();
            propRecord.setChanged(primitive);
        }
    } catch (InvalidRecordException e) {
        // This property chain, or a dynamic value record chain contains a record which is not in use, so it's somewhat broken.
        // Abort reading the chain, but don't fail the deletion of this property record chain.
        logInconsistentPropertyChain(primitive, "unused record", e);
    } catch (InconsistentDataReadException e) {
        // This property chain, or a dynamic value record chain contains a cycle.
        // Abort reading the chain, but don't fail the deletion of this property record chain.
        logInconsistentPropertyChain(primitive, "cycle", e);
    }
    primitive.setNextProp(Record.NO_NEXT_PROPERTY.intValue());
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord)

Example 4 with InvalidRecordException

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

the class RelationshipDeleter method disconnect.

private void disconnect(RelationshipRecord rel, RelationshipConnection pointer, RecordAccess<RelationshipRecord, Void> relChanges) {
    long otherRelId = pointer.otherSide().get(rel);
    if (isNull(otherRelId)) {
        return;
    }
    RelationshipRecord otherRel = relChanges.getOrLoad(otherRelId, null, cursorContext).forChangingLinkage();
    boolean changed = false;
    long newId = pointer.get(rel);
    boolean newIsFirst = pointer.isFirstInChain(rel);
    if (otherRel.getFirstNode() == pointer.compareNode(rel)) {
        pointer.start().set(otherRel, newId, newIsFirst);
        changed = true;
    }
    if (otherRel.getSecondNode() == pointer.compareNode(rel)) {
        pointer.end().set(otherRel, newId, newIsFirst);
        changed = true;
    }
    if (!changed) {
        throw new InvalidRecordException(otherRel + " don't match " + rel);
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException)

Example 5 with InvalidRecordException

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

the class RelationshipDeleter method disconnect.

private void disconnect(RelationshipRecord rel, RelationshipConnection pointer, RecordAccess<Long, RelationshipRecord, Void> relChanges, ResourceLocker locks) {
    long otherRelId = pointer.otherSide().get(rel);
    if (otherRelId == Record.NO_NEXT_RELATIONSHIP.intValue()) {
        return;
    }
    locks.acquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, otherRelId);
    RelationshipRecord otherRel = relChanges.getOrLoad(otherRelId, null).forChangingLinkage();
    boolean changed = false;
    long newId = pointer.get(rel);
    boolean newIsFirst = pointer.isFirstInChain(rel);
    if (otherRel.getFirstNode() == pointer.compareNode(rel)) {
        pointer.start().set(otherRel, newId, newIsFirst);
        changed = true;
    }
    if (otherRel.getSecondNode() == pointer.compareNode(rel)) {
        pointer.end().set(otherRel, newId, newIsFirst);
        changed = true;
    }
    if (!changed) {
        throw new InvalidRecordException(otherRel + " don't match " + rel);
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException)

Aggregations

InvalidRecordException (org.neo4j.kernel.impl.store.InvalidRecordException)7 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)4 ByteBuffer (java.nio.ByteBuffer)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 PrefetchingIterator (org.neo4j.internal.helpers.collection.PrefetchingIterator)1 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 SchemaRule (org.neo4j.internal.schema.SchemaRule)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 AbstractBaseRecord (org.neo4j.kernel.impl.store.record.AbstractBaseRecord)1 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)1 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)1 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)1 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)1