Search in sources :

Example 1 with BeginQuorumEpochRequestData

use of org.apache.kafka.common.message.BeginQuorumEpochRequestData in project kafka by apache.

the class KafkaRaftClient method handleBeginQuorumEpochRequest.

/**
 * Handle a BeginEpoch request. This API may return the following errors:
 *
 * - {@link Errors#INCONSISTENT_CLUSTER_ID} if the cluster id is presented in request
 *      but different from this node
 * - {@link Errors#BROKER_NOT_AVAILABLE} if this node is currently shutting down
 * - {@link Errors#INCONSISTENT_VOTER_SET} if the request suggests inconsistent voter membership (e.g.
 *      if this node or the sender is not one of the current known voters)
 * - {@link Errors#FENCED_LEADER_EPOCH} if the epoch is smaller than this node's epoch
 */
private BeginQuorumEpochResponseData handleBeginQuorumEpochRequest(RaftRequest.Inbound requestMetadata, long currentTimeMs) {
    BeginQuorumEpochRequestData request = (BeginQuorumEpochRequestData) requestMetadata.data;
    if (!hasValidClusterId(request.clusterId())) {
        return new BeginQuorumEpochResponseData().setErrorCode(Errors.INCONSISTENT_CLUSTER_ID.code());
    }
    if (!hasValidTopicPartition(request, log.topicPartition())) {
        // Until we support multi-raft, we treat topic partition mismatches as invalid requests
        return new BeginQuorumEpochResponseData().setErrorCode(Errors.INVALID_REQUEST.code());
    }
    BeginQuorumEpochRequestData.PartitionData partitionRequest = request.topics().get(0).partitions().get(0);
    int requestLeaderId = partitionRequest.leaderId();
    int requestEpoch = partitionRequest.leaderEpoch();
    Optional<Errors> errorOpt = validateVoterOnlyRequest(requestLeaderId, requestEpoch);
    if (errorOpt.isPresent()) {
        return buildBeginQuorumEpochResponse(errorOpt.get());
    }
    maybeTransition(OptionalInt.of(requestLeaderId), requestEpoch, currentTimeMs);
    return buildBeginQuorumEpochResponse(Errors.NONE);
}
Also used : BeginQuorumEpochRequestData(org.apache.kafka.common.message.BeginQuorumEpochRequestData) Errors(org.apache.kafka.common.protocol.Errors) BeginQuorumEpochResponseData(org.apache.kafka.common.message.BeginQuorumEpochResponseData)

Example 2 with BeginQuorumEpochRequestData

use of org.apache.kafka.common.message.BeginQuorumEpochRequestData in project kafka by apache.

the class RaftClientTestContext method collectBeginEpochRequests.

private List<RaftRequest.Outbound> collectBeginEpochRequests(int epoch) {
    List<RaftRequest.Outbound> requests = new ArrayList<>();
    for (RaftRequest.Outbound raftRequest : channel.drainSentRequests(Optional.of(ApiKeys.BEGIN_QUORUM_EPOCH))) {
        assertTrue(raftRequest.data() instanceof BeginQuorumEpochRequestData);
        BeginQuorumEpochRequestData request = (BeginQuorumEpochRequestData) raftRequest.data();
        BeginQuorumEpochRequestData.PartitionData partitionRequest = request.topics().get(0).partitions().get(0);
        assertEquals(epoch, partitionRequest.leaderEpoch());
        assertEquals(localIdOrThrow(), partitionRequest.leaderId());
        requests.add(raftRequest);
    }
    return requests;
}
Also used : BeginQuorumEpochRequestData(org.apache.kafka.common.message.BeginQuorumEpochRequestData) ArrayList(java.util.ArrayList)

Aggregations

BeginQuorumEpochRequestData (org.apache.kafka.common.message.BeginQuorumEpochRequestData)2 ArrayList (java.util.ArrayList)1 BeginQuorumEpochResponseData (org.apache.kafka.common.message.BeginQuorumEpochResponseData)1 Errors (org.apache.kafka.common.protocol.Errors)1