Search in sources :

Example 1 with ControlRecordType

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

the class SnapshotFileReader method handleControlBatch.

private void handleControlBatch(FileChannelRecordBatch batch) {
    for (Iterator<Record> iter = batch.iterator(); iter.hasNext(); ) {
        Record record = iter.next();
        try {
            short typeId = ControlRecordType.parseTypeId(record.key());
            ControlRecordType type = ControlRecordType.fromTypeId(typeId);
            switch(type) {
                case LEADER_CHANGE:
                    LeaderChangeMessage message = new LeaderChangeMessage();
                    message.read(new ByteBufferAccessor(record.value()), (short) 0);
                    listener.handleLeaderChange(new LeaderAndEpoch(OptionalInt.of(message.leaderId()), batch.partitionLeaderEpoch()));
                    break;
                default:
                    log.error("Ignoring control record with type {} at offset {}", type, record.offset());
            }
        } catch (Throwable e) {
            log.error("unable to read control record at offset {}", record.offset(), e);
        }
    }
}
Also used : LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) Record(org.apache.kafka.common.record.Record) LeaderAndEpoch(org.apache.kafka.raft.LeaderAndEpoch) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) ControlRecordType(org.apache.kafka.common.record.ControlRecordType)

Aggregations

LeaderChangeMessage (org.apache.kafka.common.message.LeaderChangeMessage)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1 ControlRecordType (org.apache.kafka.common.record.ControlRecordType)1 Record (org.apache.kafka.common.record.Record)1 LeaderAndEpoch (org.apache.kafka.raft.LeaderAndEpoch)1