Search in sources :

Example 1 with PhysicalFlushableChecksumChannel

use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.

the class RecoverIndexDropIT method appendDropTransactionToTransactionLog.

private void appendDropTransactionToTransactionLog(Path transactionLogsDirectory, CommittedTransactionRepresentation dropTransaction, StorageEngineFactory storageEngineFactory) throws IOException {
    LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(transactionLogsDirectory, fs).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build();
    LogFile logFile = logFiles.getLogFile();
    try (ReadableLogChannel reader = logFile.getReader(logFile.extractHeader(0).getStartPosition())) {
        LogEntryReader logEntryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
        while (logEntryReader.readLogEntry(reader) != null) {
        }
        LogPosition position = logEntryReader.lastPosition();
        StoreChannel storeChannel = fs.write(logFile.getLogFileForVersion(logFile.getHighestLogVersion()));
        storeChannel.position(position.getByteOffset());
        try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, new HeapScopedBuffer(100, INSTANCE))) {
            new LogEntryWriter<>(writeChannel, KernelVersion.LATEST).serialize(dropTransaction);
        }
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) PhysicalFlushableChecksumChannel(org.neo4j.io.fs.PhysicalFlushableChecksumChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 2 with PhysicalFlushableChecksumChannel

use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.

the class DetachedCheckpointLogEntryWriterTest method longCheckpointReasonIsTrimmedToFit.

@Test
void longCheckpointReasonIsTrimmedToFit() throws IOException {
    try (var buffer = new HeapScopedBuffer((int) kibiBytes(1), INSTANCE)) {
        StoreChannel storeChannel = fs.write(directory.createFile("b"));
        try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, buffer)) {
            var checkpointLogEntryWriter = new DetachedCheckpointLogEntryWriter(writeChannel);
            long initialPosition = writeChannel.position();
            writeCheckpoint(checkpointLogEntryWriter, StringUtils.repeat("b", 1024));
            long recordLength = writeChannel.position() - initialPosition;
            assertThat(recordLength).isEqualTo(RECORD_LENGTH_BYTES);
        }
    }
}
Also used : HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) PhysicalFlushableChecksumChannel(org.neo4j.io.fs.PhysicalFlushableChecksumChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 3 with PhysicalFlushableChecksumChannel

use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.

the class DetachedCheckpointLogEntryWriterTest method detachedCheckpointEntryHasSpecificLength.

@Test
void detachedCheckpointEntryHasSpecificLength() throws IOException {
    try (var buffer = new HeapScopedBuffer((int) kibiBytes(1), INSTANCE)) {
        StoreChannel storeChannel = fs.write(directory.createFile("a"));
        try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, buffer)) {
            var checkpointLogEntryWriter = new DetachedCheckpointLogEntryWriter(writeChannel);
            long initialPosition = writeChannel.position();
            writeCheckpoint(checkpointLogEntryWriter, "checkpoint reason");
            assertThat(writeChannel.position() - initialPosition).isEqualTo(RECORD_LENGTH_BYTES);
        }
    }
}
Also used : HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) PhysicalFlushableChecksumChannel(org.neo4j.io.fs.PhysicalFlushableChecksumChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 4 with PhysicalFlushableChecksumChannel

use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.

the class DetachedCheckpointLogEntryWriterTest method anyCheckpointEntryHaveTheSameSize.

@Test
void anyCheckpointEntryHaveTheSameSize() throws IOException {
    try (var buffer = new HeapScopedBuffer((int) kibiBytes(1), INSTANCE)) {
        StoreChannel storeChannel = fs.write(directory.createFile("b"));
        try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, buffer)) {
            var checkpointLogEntryWriter = new DetachedCheckpointLogEntryWriter(writeChannel);
            for (int i = 0; i < 100; i++) {
                long initialPosition = writeChannel.position();
                writeCheckpoint(checkpointLogEntryWriter, randomAlphabetic(10, 512));
                long recordLength = writeChannel.position() - initialPosition;
                assertThat(recordLength).isEqualTo(RECORD_LENGTH_BYTES);
            }
        }
    }
}
Also used : HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) PhysicalFlushableChecksumChannel(org.neo4j.io.fs.PhysicalFlushableChecksumChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) Test(org.junit.jupiter.api.Test)

Example 5 with PhysicalFlushableChecksumChannel

use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.

the class PhysicalFlushableChecksumChannelTest method beginCehcksumShouldResetCalculations.

@Test
void beginCehcksumShouldResetCalculations() throws IOException {
    final Path firstFile = directory.homePath().resolve("file1");
    StoreChannel storeChannel = fileSystem.write(firstFile);
    int channelChecksum;
    try (PhysicalFlushableChecksumChannel channel = new PhysicalFlushableChecksumChannel(storeChannel, new HeapScopedBuffer(100, INSTANCE))) {
        channel.put((byte) 5);
        channel.beginChecksum();
        channel.put((byte) 10);
        channelChecksum = channel.putChecksum();
    }
    int fileSize = (int) fileSystem.getFileSize(firstFile);
    assertEquals(Byte.BYTES + Byte.BYTES + Integer.BYTES, fileSize);
    byte[] writtenBytes = new byte[fileSize];
    try (InputStream in = Files.newInputStream(firstFile)) {
        in.read(writtenBytes);
    }
    ByteBuffer buffer = ByteBuffer.wrap(writtenBytes);
    Checksum checksum = CHECKSUM_FACTORY.get();
    checksum.update(10);
    assertEquals(checksum.getValue(), channelChecksum);
    assertEquals(5, buffer.get());
    assertEquals(10, buffer.get());
    assertEquals(checksum.getValue(), buffer.getInt());
}
Also used : Path(java.nio.file.Path) HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) PhysicalFlushableChecksumChannel(org.neo4j.io.fs.PhysicalFlushableChecksumChannel) InputStream(java.io.InputStream) Checksum(java.util.zip.Checksum) StoreChannel(org.neo4j.io.fs.StoreChannel) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

PhysicalFlushableChecksumChannel (org.neo4j.io.fs.PhysicalFlushableChecksumChannel)6 StoreChannel (org.neo4j.io.fs.StoreChannel)6 HeapScopedBuffer (org.neo4j.io.memory.HeapScopedBuffer)6 Test (org.junit.jupiter.api.Test)5 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 Path (java.nio.file.Path)2 Checksum (java.util.zip.Checksum)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)1 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)1 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)1 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)1 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)1 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)1