@ -2551,7 +2551,7 @@ public class KafkaAdminClient extends AdminClient {
@@ -2551,7 +2551,7 @@ public class KafkaAdminClient extends AdminClient {
void handleResponse ( AbstractResponse abstractResponse ) {
final FindCoordinatorResponse fcResponse = ( FindCoordinatorResponse ) abstractResponse ;
if ( handleFindCoordinator Error ( fcResponse , futures . get ( groupId ) ) )
if ( handleGroupRequest Error ( fcResponse . error ( ) , futures . get ( groupId ) ) )
return ;
final long nowDescribeConsumerGroups = time . milliseconds ( ) ;
@ -2577,38 +2577,37 @@ public class KafkaAdminClient extends AdminClient {
@@ -2577,38 +2577,37 @@ public class KafkaAdminClient extends AdminClient {
. findFirst ( ) . get ( ) ;
final Errors groupError = Errors . forCode ( describedGroup . errorCode ( ) ) ;
if ( groupError ! = Errors . NONE ) {
// TODO: KAFKA-6789, we can retry based on the error code
future . completeExceptionally ( groupError . exception ( ) ) ;
} else {
final String protocolType = describedGroup . protocolType ( ) ;
if ( protocolType . equals ( ConsumerProtocol . PROTOCOL_TYPE ) | | protocolType . isEmpty ( ) ) {
final List < DescribedGroupMember > members = describedGroup . members ( ) ;
final List < MemberDescription > memberDescriptions = new ArrayList < > ( members . size ( ) ) ;
final Set < AclOperation > authorizedOperations = validAclOperations ( describedGroup . authorizedOperations ( ) ) ;
for ( DescribedGroupMember groupMember : members ) {
Set < TopicPartition > partitions = Collections . emptySet ( ) ;
if ( groupMember . memberAssignment ( ) . length > 0 ) {
final PartitionAssignor . Assignment assignment = ConsumerProtocol .
deserializeAssignment ( ByteBuffer . wrap ( groupMember . memberAssignment ( ) ) ) ;
partitions = new HashSet < > ( assignment . partitions ( ) ) ;
}
final MemberDescription memberDescription =
new MemberDescription ( groupMember . memberId ( ) ,
groupMember . clientId ( ) ,
groupMember . clientHost ( ) ,
new MemberAssignment ( partitions ) ) ;
memberDescriptions . add ( memberDescription ) ;
if ( handleGroupRequestError ( groupError , future ) )
return ;
final String protocolType = describedGroup . protocolType ( ) ;
if ( protocolType . equals ( ConsumerProtocol . PROTOCOL_TYPE ) | | protocolType . isEmpty ( ) ) {
final List < DescribedGroupMember > members = describedGroup . members ( ) ;
final List < MemberDescription > memberDescriptions = new ArrayList < > ( members . size ( ) ) ;
final Set < AclOperation > authorizedOperations = validAclOperations ( describedGroup . authorizedOperations ( ) ) ;
for ( DescribedGroupMember groupMember : members ) {
Set < TopicPartition > partitions = Collections . emptySet ( ) ;
if ( groupMember . memberAssignment ( ) . length > 0 ) {
final PartitionAssignor . Assignment assignment = ConsumerProtocol .
deserializeAssignment ( ByteBuffer . wrap ( groupMember . memberAssignment ( ) ) ) ;
partitions = new HashSet < > ( assignment . partitions ( ) ) ;
}
final ConsumerGroupDescription consumerGroupDescription =
new ConsumerGroupDescription ( groupId , protocolType . isEmpty ( ) ,
memberDescriptions ,
describedGroup . protocolData ( ) ,
ConsumerGroupState . parse ( describedGroup . groupState ( ) ) ,
fcResponse . node ( ) ,
authorizedOperations ) ;
future . complete ( consumerGroupDescription ) ;
final MemberDescription memberDescription =
new MemberDescription ( groupMember . memberId ( ) ,
groupMember . clientId ( ) ,
groupMember . clientHost ( ) ,
new MemberAssignment ( partitions ) ) ;
memberDescriptions . add ( memberDescription ) ;
}
final ConsumerGroupDescription consumerGroupDescription =
new ConsumerGroupDescription ( groupId , protocolType . isEmpty ( ) ,
memberDescriptions ,
describedGroup . protocolData ( ) ,
ConsumerGroupState . parse ( describedGroup . groupState ( ) ) ,
fcResponse . node ( ) ,
authorizedOperations ) ;
future . complete ( consumerGroupDescription ) ;
}
}
@ -2641,11 +2640,10 @@ public class KafkaAdminClient extends AdminClient {
@@ -2641,11 +2640,10 @@ public class KafkaAdminClient extends AdminClient {
. collect ( Collectors . toSet ( ) ) ;
}
private boolean handleFindCoordinatorError ( FindCoordinatorResponse response , KafkaFutureImpl < ? > future ) {
Errors error = response . error ( ) ;
if ( error . exception ( ) instanceof RetriableException ) {
private boolean handleGroupRequestError ( Errors error , KafkaFutureImpl < ? > future ) {
if ( error = = Errors . COORDINATOR_LOAD_IN_PROGRESS | | error = = Errors . COORDINATOR_NOT_AVAILABLE ) {
throw error . exception ( ) ;
} else if ( response . hasError ( ) ) {
} else if ( error ! = Errors . NONE ) {
future . completeExceptionally ( error . exception ( ) ) ;
return true ;
}
@ -2797,7 +2795,7 @@ public class KafkaAdminClient extends AdminClient {
@@ -2797,7 +2795,7 @@ public class KafkaAdminClient extends AdminClient {
void handleResponse ( AbstractResponse abstractResponse ) {
final FindCoordinatorResponse response = ( FindCoordinatorResponse ) abstractResponse ;
if ( handleFindCoordinator Error ( response , groupOffsetListingFuture ) )
if ( handleGroupRequest Error ( response . error ( ) , groupOffsetListingFuture ) )
return ;
final long nowListConsumerGroupOffsets = time . milliseconds ( ) ;
@ -2815,26 +2813,25 @@ public class KafkaAdminClient extends AdminClient {
@@ -2815,26 +2813,25 @@ public class KafkaAdminClient extends AdminClient {
final OffsetFetchResponse response = ( OffsetFetchResponse ) abstractResponse ;
final Map < TopicPartition , OffsetAndMetadata > groupOffsetsListing = new HashMap < > ( ) ;
if ( response . hasError ( ) ) {
groupOffsetListingFuture . completeExceptionally ( response . error ( ) . exception ( ) ) ;
} else {
for ( Map . Entry < TopicPartition , OffsetFetchResponse . PartitionData > entry :
response . responseData ( ) . entrySet ( ) ) {
final TopicPartition topicPartition = entry . getKey ( ) ;
OffsetFetchResponse . PartitionData partitionData = entry . getValue ( ) ;
final Errors error = partitionData . error ;
if ( error = = Errors . NONE ) {
final Long offset = partitionData . offset ;
final String metadata = partitionData . metadata ;
final Optional < Integer > leaderEpoch = partitionData . leaderEpoch ;
groupOffsetsListing . put ( topicPartition , new OffsetAndMetadata ( offset , leaderEpoch , metadata ) ) ;
} else {
log . warn ( "Skipping return offset for {} due to error {}." , topicPartition , error ) ;
}
if ( handleGroupRequestError ( response . error ( ) , groupOffsetListingFuture ) )
return ;
for ( Map . Entry < TopicPartition , OffsetFetchResponse . PartitionData > entry :
response . responseData ( ) . entrySet ( ) ) {
final TopicPartition topicPartition = entry . getKey ( ) ;
OffsetFetchResponse . PartitionData partitionData = entry . getValue ( ) ;
final Errors error = partitionData . error ;
if ( error = = Errors . NONE ) {
final Long offset = partitionData . offset ;
final String metadata = partitionData . metadata ;
final Optional < Integer > leaderEpoch = partitionData . leaderEpoch ;
groupOffsetsListing . put ( topicPartition , new OffsetAndMetadata ( offset , leaderEpoch , metadata ) ) ;
} else {
log . warn ( "Skipping return offset for {} due to error {}." , topicPartition , error ) ;
}
groupOffsetListingFuture . complete ( groupOffsetsListing ) ;
}
groupOffsetListingFuture . complete ( groupOffsetsListing ) ;
}
@Override
@ -2891,7 +2888,7 @@ public class KafkaAdminClient extends AdminClient {
@@ -2891,7 +2888,7 @@ public class KafkaAdminClient extends AdminClient {
void handleResponse ( AbstractResponse abstractResponse ) {
final FindCoordinatorResponse response = ( FindCoordinatorResponse ) abstractResponse ;
if ( handleFindCoordinator Error ( response , futures . get ( groupId ) ) )
if ( handleGroupRequest Error ( response . error ( ) , futures . get ( groupId ) ) )
return ;
final long nowDeleteConsumerGroups = time . milliseconds ( ) ;
@ -2912,11 +2909,10 @@ public class KafkaAdminClient extends AdminClient {
@@ -2912,11 +2909,10 @@ public class KafkaAdminClient extends AdminClient {
KafkaFutureImpl < Void > future = futures . get ( groupId ) ;
final Errors groupError = response . get ( groupId ) ;
if ( groupError ! = Errors . NONE ) {
future . completeExceptionally ( groupError . exception ( ) ) ;
} else {
future . complete ( null ) ;
}
if ( handleGroupRequestError ( groupError , future ) )
return ;
future . complete ( null ) ;
}
@Override