Search in sources :

Example 1 with SnapshotFooterRecord

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;
}
Also used : SnapshotHeaderRecord(org.apache.kafka.common.message.SnapshotHeaderRecord) GrowableBufferSupplier(org.apache.kafka.common.utils.BufferSupplier.GrowableBufferSupplier) RecordBatch(org.apache.kafka.common.record.RecordBatch) SnapshotFooterRecord(org.apache.kafka.common.message.SnapshotFooterRecord) Record(org.apache.kafka.common.record.Record) SnapshotHeaderRecord(org.apache.kafka.common.message.SnapshotHeaderRecord) SnapshotFooterRecord(org.apache.kafka.common.message.SnapshotFooterRecord)

Example 2 with SnapshotFooterRecord

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();
}
Also used : SnapshotFooterRecord(org.apache.kafka.common.message.SnapshotFooterRecord)

Aggregations

SnapshotFooterRecord (org.apache.kafka.common.message.SnapshotFooterRecord)2 SnapshotHeaderRecord (org.apache.kafka.common.message.SnapshotHeaderRecord)1 Record (org.apache.kafka.common.record.Record)1 RecordBatch (org.apache.kafka.common.record.RecordBatch)1 GrowableBufferSupplier (org.apache.kafka.common.utils.BufferSupplier.GrowableBufferSupplier)1