Search in sources :

Example 1 with JoinGroupResponseMember

use of org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember in project kafka by apache.

the class RequestResponseTest method createJoinGroupResponse.

private JoinGroupResponse createJoinGroupResponse(short version) {
    List<JoinGroupResponseData.JoinGroupResponseMember> members = new ArrayList<>();
    for (int i = 0; i < 2; i++) {
        JoinGroupResponseMember member = new JoinGroupResponseData.JoinGroupResponseMember().setMemberId("consumer" + i).setMetadata(new byte[0]);
        if (version >= 5)
            member.setGroupInstanceId("instance" + i);
        members.add(member);
    }
    JoinGroupResponseData data = new JoinGroupResponseData().setErrorCode(Errors.NONE.code()).setGenerationId(1).setProtocolType(// Added in v7 but ignorable
    "consumer").setProtocolName("range").setLeader("leader").setMemberId("consumer1").setMembers(members);
    // v1 and above could set throttle time
    if (version >= 1)
        data.setThrottleTimeMs(1000);
    return new JoinGroupResponse(data);
}
Also used : JoinGroupResponseData(org.apache.kafka.common.message.JoinGroupResponseData) ArrayList(java.util.ArrayList) JoinGroupResponseMember(org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember) UpdateMetadataEndpoint(org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataEndpoint)

Example 2 with JoinGroupResponseMember

use of org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember in project kafka by apache.

the class MessageTest method testJoinGroupResponseVersions.

@Test
public void testJoinGroupResponseVersions() throws Exception {
    Supplier<JoinGroupResponseData> newResponse = () -> new JoinGroupResponseData().setMemberId(memberId).setLeader(memberId).setGenerationId(1).setMembers(Collections.singletonList(new JoinGroupResponseMember().setMemberId(memberId)));
    testAllMessageRoundTrips(newResponse.get());
    testAllMessageRoundTripsFromVersion((short) 2, newResponse.get().setThrottleTimeMs(1000));
    testAllMessageRoundTrips(newResponse.get().members().get(0).setGroupInstanceId(null));
    testAllMessageRoundTripsFromVersion((short) 5, newResponse.get().members().get(0).setGroupInstanceId("instanceId"));
}
Also used : JoinGroupResponseMember(org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember) Test(org.junit.jupiter.api.Test)

Example 3 with JoinGroupResponseMember

use of org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember in project kafka by apache.

the class EagerAssignor method performAssignment.

@Override
public Map<String, ByteBuffer> performAssignment(String leaderId, String protocol, List<JoinGroupResponseMember> allMemberMetadata, WorkerCoordinator coordinator) {
    log.debug("Performing task assignment");
    Map<String, ExtendedWorkerState> memberConfigs = new HashMap<>();
    for (JoinGroupResponseMember member : allMemberMetadata) memberConfigs.put(member.memberId(), IncrementalCooperativeConnectProtocol.deserializeMetadata(ByteBuffer.wrap(member.metadata())));
    long maxOffset = findMaxMemberConfigOffset(memberConfigs, coordinator);
    Long leaderOffset = ensureLeaderConfig(maxOffset, coordinator);
    if (leaderOffset == null)
        return fillAssignmentsAndSerialize(memberConfigs.keySet(), Assignment.CONFIG_MISMATCH, leaderId, memberConfigs.get(leaderId).url(), maxOffset, new HashMap<>(), new HashMap<>());
    return performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator);
}
Also used : HashMap(java.util.HashMap) JoinGroupResponseMember(org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember)

Example 4 with JoinGroupResponseMember

use of org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember in project kafka by apache.

the class IncrementalCooperativeAssignor method performAssignment.

@Override
public Map<String, ByteBuffer> performAssignment(String leaderId, String protocol, List<JoinGroupResponseMember> allMemberMetadata, WorkerCoordinator coordinator) {
    log.debug("Performing task assignment");
    Map<String, ExtendedWorkerState> memberConfigs = new HashMap<>();
    for (JoinGroupResponseMember member : allMemberMetadata) {
        memberConfigs.put(member.memberId(), IncrementalCooperativeConnectProtocol.deserializeMetadata(ByteBuffer.wrap(member.metadata())));
    }
    log.debug("Member configs: {}", memberConfigs);
    // The new config offset is the maximum seen by any member. We always perform assignment using this offset,
    // even if some members have fallen behind. The config offset used to generate the assignment is included in
    // the response so members that have fallen behind will not use the assignment until they have caught up.
    long maxOffset = memberConfigs.values().stream().map(ExtendedWorkerState::offset).max(Long::compare).get();
    log.debug("Max config offset root: {}, local snapshot config offsets root: {}", maxOffset, coordinator.configSnapshot().offset());
    short protocolVersion = memberConfigs.values().stream().allMatch(state -> state.assignment().version() == CONNECT_PROTOCOL_V2) ? CONNECT_PROTOCOL_V2 : CONNECT_PROTOCOL_V1;
    Long leaderOffset = ensureLeaderConfig(maxOffset, coordinator);
    if (leaderOffset == null) {
        Map<String, ExtendedAssignment> assignments = fillAssignments(memberConfigs.keySet(), Assignment.CONFIG_MISMATCH, leaderId, memberConfigs.get(leaderId).url(), maxOffset, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), 0, protocolVersion);
        return serializeAssignments(assignments);
    }
    return performTaskAssignment(leaderId, leaderOffset, memberConfigs, coordinator, protocolVersion);
}
Also used : IntStream(java.util.stream.IntStream) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) HashMap(java.util.HashMap) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CONNECT_PROTOCOL_V2(org.apache.kafka.connect.runtime.distributed.IncrementalCooperativeConnectProtocol.CONNECT_PROTOCOL_V2) JoinGroupResponseMember(org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember) CONNECT_PROTOCOL_V1(org.apache.kafka.connect.runtime.distributed.IncrementalCooperativeConnectProtocol.CONNECT_PROTOCOL_V1) Assignment(org.apache.kafka.connect.runtime.distributed.ConnectProtocol.Assignment) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) LinkedHashSet(java.util.LinkedHashSet) Logger(org.slf4j.Logger) Time(org.apache.kafka.common.utils.Time) Iterator(java.util.Iterator) LeaderState(org.apache.kafka.connect.runtime.distributed.WorkerCoordinator.LeaderState) Collection(java.util.Collection) Set(java.util.Set) WorkerLoad(org.apache.kafka.connect.runtime.distributed.WorkerCoordinator.WorkerLoad) ConnectorsAndTasks(org.apache.kafka.connect.runtime.distributed.WorkerCoordinator.ConnectorsAndTasks) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Entry(java.util.Map.Entry) Collections(java.util.Collections) HashMap(java.util.HashMap) JoinGroupResponseMember(org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember)

Aggregations

JoinGroupResponseMember (org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 JoinGroupResponseData (org.apache.kafka.common.message.JoinGroupResponseData)1 UpdateMetadataEndpoint (org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataEndpoint)1