Search in sources :

Example 6 with ApiMessage

use of org.apache.kafka.common.protocol.ApiMessage in project kafka by apache.

the class KafkaRaftClient method maybeSendFetchOrFetchSnapshot.

private long maybeSendFetchOrFetchSnapshot(FollowerState state, long currentTimeMs) {
    final Supplier<ApiMessage> requestSupplier;
    if (state.fetchingSnapshot().isPresent()) {
        RawSnapshotWriter snapshot = state.fetchingSnapshot().get();
        long snapshotSize = snapshot.sizeInBytes();
        requestSupplier = () -> buildFetchSnapshotRequest(snapshot.snapshotId(), snapshotSize);
    } else {
        requestSupplier = this::buildFetchRequest;
    }
    return maybeSendRequest(currentTimeMs, state.leaderId(), requestSupplier);
}
Also used : RawSnapshotWriter(org.apache.kafka.snapshot.RawSnapshotWriter) ApiMessage(org.apache.kafka.common.protocol.ApiMessage)

Example 7 with ApiMessage

use of org.apache.kafka.common.protocol.ApiMessage in project kafka by apache.

the class RecordTestUtils method replayAll.

/**
 * Replay a list of records to the metadata delta.
 *
 * @param delta the metadata delta on which to replay the records
 * @param highestOffset highest offset from the list of records
 * @param highestEpoch highest epoch from the list of records
 * @param recordsAndVersions list of records
 */
public static void replayAll(MetadataDelta delta, long highestOffset, int highestEpoch, List<ApiMessageAndVersion> recordsAndVersions) {
    for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
        ApiMessage record = recordAndVersion.message();
        delta.replay(highestOffset, highestEpoch, record);
    }
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ApiMessage(org.apache.kafka.common.protocol.ApiMessage)

Example 8 with ApiMessage

use of org.apache.kafka.common.protocol.ApiMessage in project kafka by apache.

the class RecordTestUtils method replayAll.

/**
 * Replay a list of records.
 *
 * @param target                The object to invoke the replay function on.
 * @param recordsAndVersions    A list of records.
 */
public static void replayAll(Object target, List<ApiMessageAndVersion> recordsAndVersions) {
    for (ApiMessageAndVersion recordAndVersion : recordsAndVersions) {
        ApiMessage record = recordAndVersion.message();
        try {
            Method method = target.getClass().getMethod("replay", record.getClass());
            method.invoke(target, record);
        } catch (NoSuchMethodException e) {
            try {
                Method method = target.getClass().getMethod("replay", record.getClass(), Optional.class);
                method.invoke(target, record, Optional.empty());
            } catch (NoSuchMethodException t) {
            // ignore
            } catch (InvocationTargetException t) {
                throw new RuntimeException(t);
            } catch (IllegalAccessException t) {
                throw new RuntimeException(t);
            }
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Optional(java.util.Optional) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ApiMessage(org.apache.kafka.common.protocol.ApiMessage) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ApiMessage (org.apache.kafka.common.protocol.ApiMessage)8 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)5 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Optional (java.util.Optional)1 Errors (org.apache.kafka.common.protocol.Errors)1 ConnectionState (org.apache.kafka.raft.RequestManager.ConnectionState)1 RawSnapshotWriter (org.apache.kafka.snapshot.RawSnapshotWriter)1