Search in sources :

Example 1 with FileRecords

use of org.apache.kafka.common.record.FileRecords in project kafka by apache.

the class RecordsIterator method nextBatches.

private Iterator<MutableRecordBatch> nextBatches() {
    int recordSize = records.sizeInBytes();
    if (bytesRead < recordSize) {
        final MemoryRecords memoryRecords;
        if (records instanceof MemoryRecords) {
            bytesRead = recordSize;
            memoryRecords = (MemoryRecords) records;
        } else if (records instanceof FileRecords) {
            memoryRecords = createMemoryRecords((FileRecords) records);
        } else {
            throw new IllegalStateException(String.format("Unexpected Records type %s", records.getClass()));
        }
        return memoryRecords.batchIterator();
    }
    return Collections.emptyIterator();
}
Also used : FileRecords(org.apache.kafka.common.record.FileRecords) MemoryRecords(org.apache.kafka.common.record.MemoryRecords)

Example 2 with FileRecords

use of org.apache.kafka.common.record.FileRecords in project kafka by apache.

the class FileRawSnapshotReader method open.

/**
 * Opens a snapshot for reading.
 *
 * @param logDir the directory for the topic partition
 * @param snapshotId the end offset and epoch for the snapshotId
 */
public static FileRawSnapshotReader open(Path logDir, OffsetAndEpoch snapshotId) {
    FileRecords fileRecords;
    Path filePath = Snapshots.snapshotPath(logDir, snapshotId);
    try {
        fileRecords = FileRecords.open(filePath.toFile(), // mutable
        false, // fileAlreadyExists
        true, // initFileSize
        0, // preallocate
        false);
    } catch (IOException e) {
        throw new UncheckedIOException(String.format("Unable to Opens a snapshot file %s", filePath.toAbsolutePath()), e);
    }
    return new FileRawSnapshotReader(fileRecords, snapshotId);
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) FileRecords(org.apache.kafka.common.record.FileRecords) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 3 with FileRecords

use of org.apache.kafka.common.record.FileRecords in project kafka by apache.

the class RecordsBatchReaderTest method testReadFromFileRecords.

@ParameterizedTest
@EnumSource(CompressionType.class)
public void testReadFromFileRecords(CompressionType compressionType) throws Exception {
    long baseOffset = 57;
    List<TestBatch<String>> batches = RecordsIteratorTest.createBatches(baseOffset);
    MemoryRecords memRecords = RecordsIteratorTest.buildRecords(compressionType, batches);
    FileRecords fileRecords = FileRecords.open(tempFile());
    fileRecords.append(memRecords);
    testBatchReader(baseOffset, fileRecords, batches);
}
Also used : TestBatch(org.apache.kafka.raft.internals.RecordsIteratorTest.TestBatch) FileRecords(org.apache.kafka.common.record.FileRecords) MemoryRecords(org.apache.kafka.common.record.MemoryRecords) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with FileRecords

use of org.apache.kafka.common.record.FileRecords in project kafka by apache.

the class RecordsIteratorTest method testFileRecords.

@Property
public void testFileRecords(@ForAll CompressionType compressionType, @ForAll long seed) throws IOException {
    List<TestBatch<String>> batches = createBatches(seed);
    MemoryRecords memRecords = buildRecords(compressionType, batches);
    FileRecords fileRecords = FileRecords.open(TestUtils.tempFile());
    fileRecords.append(memRecords);
    testIterator(batches, fileRecords);
}
Also used : FileRecords(org.apache.kafka.common.record.FileRecords) MemoryRecords(org.apache.kafka.common.record.MemoryRecords) Property(net.jqwik.api.Property)

Aggregations

FileRecords (org.apache.kafka.common.record.FileRecords)4 MemoryRecords (org.apache.kafka.common.record.MemoryRecords)3 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 Property (net.jqwik.api.Property)1 TestBatch (org.apache.kafka.raft.internals.RecordsIteratorTest.TestBatch)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1