use of org.apache.kafka.common.message.SnapshotFooterRecord 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.SnapshotFooterRecord in project kafka by apache.
the class RecordsSnapshotWriter method finalizeSnapshotWithFooter.
/**
* Adds a {@link SnapshotFooterRecord} to the snapshot
*
* No more records should be appended to the snapshot after calling this method
*/
private void finalizeSnapshotWithFooter() {
SnapshotFooterRecord footerRecord = new SnapshotFooterRecord().setVersion(ControlRecordUtils.SNAPSHOT_FOOTER_HIGHEST_VERSION);
accumulator.appendSnapshotFooterMessage(footerRecord, time.milliseconds());
accumulator.forceDrain();
}
Aggregations