Search in sources :

Example 1 with AbstractBaseRecord

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

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

the class DumpStoreTest method dumpStoreShouldPrintBufferWithContent.

@Test
public void dumpStoreShouldPrintBufferWithContent() throws Exception {
    // Given
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(outStream);
    DumpStore dumpStore = new DumpStore(out);
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    for (byte i = 0; i < 10; i++) {
        buffer.put(i);
    }
    buffer.flip();
    AbstractBaseRecord record = Mockito.mock(AbstractBaseRecord.class);
    // When
    //when( record.inUse() ).thenReturn( true );
    dumpStore.dumpHex(record, buffer, 2, 4);
    // Then
    Assert.assertEquals(String.format("@ 0x00000008: 00 01 02 03  04 05 06 07  08 09%n"), outStream.toString());
}
Also used : PrintStream(java.io.PrintStream) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with AbstractBaseRecord

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

the class DumpStoreTest method dumpStoreShouldPrintShorterMessageForAllZeroBuffer.

@Test
public void dumpStoreShouldPrintShorterMessageForAllZeroBuffer() throws Exception {
    // Given
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(outStream);
    DumpStore dumpStore = new DumpStore(out);
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    AbstractBaseRecord record = Mockito.mock(AbstractBaseRecord.class);
    // When
    //when( record.inUse() ).thenReturn( true );
    dumpStore.dumpHex(record, buffer, 2, 4);
    // Then
    Assert.assertEquals(String.format(": all zeros @ 0x8 - 0xc%n"), outStream.toString());
}
Also used : PrintStream(java.io.PrintStream) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with AbstractBaseRecord

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

the class IdGeneratorTest method makeSureIdCapacityCannotBeExceeded.

@Test
public void makeSureIdCapacityCannotBeExceeded() throws Exception {
    RecordFormats formats = Standard.LATEST_RECORD_FORMATS;
    List<RecordFormat<? extends AbstractBaseRecord>> recordFormats = Arrays.asList(formats.node(), formats.dynamic(), formats.labelToken(), formats.property(), formats.propertyKeyToken(), formats.relationship(), formats.relationshipGroup(), formats.relationshipTypeToken());
    for (RecordFormat format : recordFormats) {
        makeSureIdCapacityCannotBeExceeded(format);
    }
}
Also used : AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) RecordFormat(org.neo4j.kernel.impl.store.format.RecordFormat) PropertyKeyTokenRecordFormat(org.neo4j.kernel.impl.store.format.standard.PropertyKeyTokenRecordFormat) RelationshipRecordFormat(org.neo4j.kernel.impl.store.format.standard.RelationshipRecordFormat) NodeRecordFormat(org.neo4j.kernel.impl.store.format.standard.NodeRecordFormat) PropertyRecordFormat(org.neo4j.kernel.impl.store.format.standard.PropertyRecordFormat) Test(org.junit.Test)

Example 5 with AbstractBaseRecord

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

the class RecordStorageEngine method listStorageFiles.

@Override
public Collection<StoreFileMetadata> listStorageFiles() {
    List<StoreFileMetadata> files = new ArrayList<>();
    for (StoreType type : StoreType.values()) {
        if (type.equals(StoreType.COUNTS)) {
            addCountStoreFiles(files);
        } else {
            final RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore(type);
            StoreFileMetadata metadata = new StoreFileMetadata(recordStore.getStorageFileName(), Optional.of(type), recordStore.getRecordSize());
            files.add(metadata);
        }
    }
    return files;
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) ArrayList(java.util.ArrayList) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata)

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