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();
}
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);
}
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);
}
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);
}
Aggregations