@@ -1289,8 +1289,8 @@ private void convertToClassicGroup(
12891289 metadataImage
12901290 );
12911291 } catch (SchemaException e ) {
1292- log .warn ("Cannot downgrade the consumer group " + consumerGroup . groupId () + " : fail to parse " +
1293- "the Consumer Protocol " + ConsumerProtocol .PROTOCOL_TYPE + "." , e );
1292+ log .warn ("Cannot downgrade the consumer group {} : fail to parse the Consumer Protocol {}." ,
1293+ consumerGroup . groupId (), ConsumerProtocol .PROTOCOL_TYPE , e );
12941294
12951295 throw new GroupIdNotFoundException (String .format ("Cannot downgrade the classic group %s: %s." ,
12961296 consumerGroup .groupId (), e .getMessage ()));
@@ -1370,16 +1370,14 @@ ConsumerGroup convertToConsumerGroup(ClassicGroup classicGroup, List<Coordinator
13701370 metadataImage
13711371 );
13721372 } catch (SchemaException e ) {
1373- log .warn ("Cannot upgrade classic group " + classicGroup .groupId () +
1374- " to consumer group because the embedded consumer protocol is malformed: "
1375- + e .getMessage () + "." , e );
1373+ log .warn ("Cannot upgrade classic group {} to consumer group because the embedded consumer protocol is malformed: {}." ,
1374+ classicGroup .groupId (), e .getMessage (), e );
13761375
13771376 throw new GroupIdNotFoundException (
13781377 String .format ("Cannot upgrade classic group %s to consumer group because the embedded consumer protocol is malformed." , classicGroup .groupId ())
13791378 );
13801379 } catch (UnsupportedVersionException e ) {
1381- log .warn ("Cannot upgrade classic group " + classicGroup .groupId () +
1382- " to consumer group: " + e .getMessage () + "." , e );
1380+ log .warn ("Cannot upgrade classic group {} to consumer group: {}." , classicGroup .groupId (), e .getMessage (), e );
13831381
13841382 throw new GroupIdNotFoundException (
13851383 String .format ("Cannot upgrade classic group %s to consumer group because an unsupported custom assignor is in use. " +
@@ -3530,7 +3528,7 @@ private boolean hasStreamsMemberMetadataChanged(
35303528 String memberId = updatedMember .memberId ();
35313529 if (!updatedMember .equals (member )) {
35323530 records .add (newStreamsGroupMemberRecord (groupId , updatedMember ));
3533- log .info ("[GroupId {}][MemberId {}] Member updated its member metdata to {}." ,
3531+ log .info ("[GroupId {}][MemberId {}] Member updated its member metadata to {}." ,
35343532 groupId , memberId , updatedMember );
35353533
35363534 return true ;
@@ -4027,7 +4025,7 @@ private CoordinatorResult<Void, CoordinatorRecord> computeDelayedTargetAssignmen
40274025 throw new IllegalStateException ("Group epoch should be always larger to assignment epoch" );
40284026 }
40294027
4030- if (! group .configuredTopology ().isPresent ()) {
4028+ if (group .configuredTopology ().isEmpty ()) {
40314029 log .warn ("[GroupId {}] Cannot compute delayed target assignment: configured topology is not present" , groupId );
40324030 return EMPTY_RESULT ;
40334031 }
@@ -4350,9 +4348,8 @@ private <T> CoordinatorResult<T, CoordinatorRecord> streamsGroupFenceMember(
43504348 StreamsGroupMember member ,
43514349 T response
43524350 ) {
4353- List <CoordinatorRecord > records = new ArrayList <>();
43544351
4355- records . addAll (removeStreamsMember (group .groupId (), member .memberId ()));
4352+ List < CoordinatorRecord > records = new ArrayList <> (removeStreamsMember (group .groupId (), member .memberId ()));
43564353
43574354 // We bump the group epoch.
43584355 int groupEpoch = group .groupEpoch () + 1 ;
@@ -7287,30 +7284,26 @@ private CoordinatorResult<Void, CoordinatorRecord> expirePendingSync(
72877284 * @return whether the group can accept a joining member.
72887285 */
72897286 private boolean acceptJoiningMember (ClassicGroup group , String memberId ) {
7290- switch (group .currentState ()) {
7291- case EMPTY :
7292- case DEAD :
7287+ return switch (group .currentState ()) {
7288+ case EMPTY , DEAD ->
72937289 // Always accept the request when the group is empty or dead
7294- return true ;
7295- case PREPARING_REBALANCE :
7290+ true ;
7291+ case PREPARING_REBALANCE ->
72967292 // An existing member is accepted if it is already awaiting. New members are accepted
72977293 // up to the max group size. Note that the number of awaiting members is used here
72987294 // for two reasons:
72997295 // 1) the group size is not reliable as it could already be above the max group size
73007296 // if the max group size was reduced.
73017297 // 2) using the number of awaiting members allows to kick out the last rejoining
73027298 // members of the group.
7303- return (group .hasMember (memberId ) && group .member (memberId ).isAwaitingJoin ()) ||
7304- group .numAwaitingJoinResponse () < config .classicGroupMaxSize ();
7305- case COMPLETING_REBALANCE :
7306- case STABLE :
7299+ (group .hasMember (memberId ) && group .member (memberId ).isAwaitingJoin ()) ||
7300+ group .numAwaitingJoinResponse () < config .classicGroupMaxSize ();
7301+ case COMPLETING_REBALANCE , STABLE ->
73077302 // An existing member is accepted. New members are accepted up to the max group size.
73087303 // Note that the group size is used here. When the group transitions to CompletingRebalance,
73097304 // members who haven't rejoined are removed.
7310- return group .hasMember (memberId ) || group .numMembers () < config .classicGroupMaxSize ();
7311- default :
7312- throw new IllegalStateException ("Unknown group state: " + group .stateAsString ());
7313- }
7305+ group .hasMember (memberId ) || group .numMembers () < config .classicGroupMaxSize ();
7306+ };
73147307 }
73157308
73167309 /**
@@ -7645,24 +7638,12 @@ private byte[] prepareAssignment(ConsumerGroupMember member) {
76457638
76467639 // Visible for testing
76477640 static Errors appendGroupMetadataErrorToResponseError (Errors appendError ) {
7648- switch (appendError ) {
7649- case UNKNOWN_TOPIC_OR_PARTITION :
7650- case NOT_ENOUGH_REPLICAS :
7651- case REQUEST_TIMED_OUT :
7652- return COORDINATOR_NOT_AVAILABLE ;
7653-
7654- case NOT_LEADER_OR_FOLLOWER :
7655- case KAFKA_STORAGE_ERROR :
7656- return NOT_COORDINATOR ;
7657-
7658- case MESSAGE_TOO_LARGE :
7659- case RECORD_LIST_TOO_LARGE :
7660- case INVALID_FETCH_SIZE :
7661- return UNKNOWN_SERVER_ERROR ;
7662-
7663- default :
7664- return appendError ;
7665- }
7641+ return switch (appendError ) {
7642+ case UNKNOWN_TOPIC_OR_PARTITION , NOT_ENOUGH_REPLICAS , REQUEST_TIMED_OUT -> COORDINATOR_NOT_AVAILABLE ;
7643+ case NOT_LEADER_OR_FOLLOWER , KAFKA_STORAGE_ERROR -> NOT_COORDINATOR ;
7644+ case MESSAGE_TOO_LARGE , RECORD_LIST_TOO_LARGE , INVALID_FETCH_SIZE -> UNKNOWN_SERVER_ERROR ;
7645+ default -> appendError ;
7646+ };
76667647 }
76677648
76687649 private Optional <Errors > validateSyncGroup (
@@ -7768,35 +7749,31 @@ private CoordinatorResult<HeartbeatResponseData, CoordinatorRecord> classicGroup
77687749 ) {
77697750 validateClassicGroupHeartbeat (group , request .memberId (), request .groupInstanceId (), request .generationId ());
77707751
7771- switch (group .currentState ()) {
7772- case EMPTY :
7773- return new CoordinatorResult <>(
7774- List .of (),
7775- new HeartbeatResponseData ().setErrorCode (Errors .UNKNOWN_MEMBER_ID .code ())
7776- );
7777-
7778- case PREPARING_REBALANCE :
7752+ return switch (group .currentState ()) {
7753+ case EMPTY -> new CoordinatorResult <>(
7754+ List .of (),
7755+ new HeartbeatResponseData ().setErrorCode (Errors .UNKNOWN_MEMBER_ID .code ())
7756+ );
7757+ case PREPARING_REBALANCE -> {
77797758 rescheduleClassicGroupMemberHeartbeat (group , group .member (request .memberId ()));
7780- return new CoordinatorResult <>(
7759+ yield new CoordinatorResult <>(
77817760 List .of (),
77827761 new HeartbeatResponseData ().setErrorCode (Errors .REBALANCE_IN_PROGRESS .code ())
77837762 );
7784-
7785- case COMPLETING_REBALANCE :
7786- case STABLE :
7763+ }
7764+ case COMPLETING_REBALANCE , STABLE -> {
77877765 // Consumers may start sending heartbeats after join-group response, while the group
77887766 // is in CompletingRebalance state. In this case, we should treat them as
77897767 // normal heartbeat requests and reset the timer
77907768 rescheduleClassicGroupMemberHeartbeat (group , group .member (request .memberId ()));
7791- return new CoordinatorResult <>(
7769+ yield new CoordinatorResult <>(
77927770 List .of (),
77937771 new HeartbeatResponseData ()
77947772 );
7795-
7796- default :
7797- throw new IllegalStateException ("Reached unexpected state " +
7773+ }
7774+ default -> throw new IllegalStateException ("Reached unexpected state " +
77987775 group .currentState () + " for group " + group .groupId ());
7799- }
7776+ };
78007777 }
78017778
78027779 /**
@@ -8652,7 +8629,7 @@ private boolean maybeDeleteEmptyStreamsGroup(String groupId, List<CoordinatorRec
86528629 * Checks whether the given protocol type or name in the request is inconsistent with the group's.
86538630 *
86548631 * @param protocolTypeOrName The request's protocol type or name.
8655- * @param groupProtocolTypeOrName The group's protoocl type or name.
8632+ * @param groupProtocolTypeOrName The group's protocol type or name.
86568633 *
86578634 * @return True if protocol is inconsistent, false otherwise.
86588635 */
0 commit comments