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);
}
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"));
}
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);
}
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);
}
Aggregations