use of org.apache.kafka.common.message.SnapshotHeaderRecord in project kafka by apache.
the class SnapshotWriterReaderTest method validateDelimiters.
private int validateDelimiters(RawSnapshotReader snapshot, long lastContainedLogTime) {
assertNotEquals(0, snapshot.sizeInBytes());
int countRecords = 0;
Iterator<RecordBatch> recordBatches = Utils.covariantCast(snapshot.records().batchIterator());
assertTrue(recordBatches.hasNext());
RecordBatch batch = recordBatches.next();
Iterator<Record> records = batch.streamingIterator(new GrowableBufferSupplier());
// Verify existence of the header record
assertTrue(batch.isControlBatch());
assertTrue(records.hasNext());
Record record = records.next();
countRecords += 1;
SnapshotHeaderRecord headerRecord = ControlRecordUtils.deserializedSnapshotHeaderRecord(record);
assertEquals(headerRecord.version(), ControlRecordUtils.SNAPSHOT_HEADER_HIGHEST_VERSION);
assertEquals(headerRecord.lastContainedLogTimestamp(), lastContainedLogTime);
assertFalse(records.hasNext());
// Loop over remaining records
while (recordBatches.hasNext()) {
batch = recordBatches.next();
records = batch.streamingIterator(new GrowableBufferSupplier());
while (records.hasNext()) {
countRecords += 1;
record = records.next();
}
}
// Verify existence of the footer record in the end
assertTrue(batch.isControlBatch());
SnapshotFooterRecord footerRecord = ControlRecordUtils.deserializedSnapshotFooterRecord(record);
assertEquals(footerRecord.version(), ControlRecordUtils.SNAPSHOT_HEADER_HIGHEST_VERSION);
return countRecords;
}
use of org.apache.kafka.common.message.SnapshotHeaderRecord in project kafka by apache.
the class RecordsSnapshotWriter method initializeSnapshotWithHeader.
/**
* Adds a {@link SnapshotHeaderRecord} to snapshot
*
* @throws IllegalStateException if the snapshot is not empty
*/
private void initializeSnapshotWithHeader() {
if (snapshot.sizeInBytes() != 0) {
String message = String.format("Initializing writer with a non-empty snapshot: id = '%s'.", snapshot.snapshotId());
throw new IllegalStateException(message);
}
SnapshotHeaderRecord headerRecord = new SnapshotHeaderRecord().setVersion(ControlRecordUtils.SNAPSHOT_HEADER_HIGHEST_VERSION).setLastContainedLogTimestamp(lastContainedLogTimestamp);
accumulator.appendSnapshotHeaderMessage(headerRecord, time.milliseconds());
accumulator.forceDrain();
}
Aggregations