@@ -2984,7 +2984,7 @@ private void addInitializingTopicsRecords(String groupId, List<CoordinatorRecord
2984
2984
groupId ,
2985
2985
attachTopicName (finalInitializingMap ),
2986
2986
attachTopicName (currentMap .initializedTopics ()),
2987
- Map . of ( )
2987
+ attachTopicName ( currentMap . deletingTopics () )
2988
2988
)
2989
2989
);
2990
2990
}
@@ -4979,7 +4979,7 @@ public CoordinatorResult<Void, CoordinatorRecord> initializeShareGroupState(
4979
4979
group .groupId (),
4980
4980
attachTopicName (finalInitializingMap ),
4981
4981
attachTopicName (finalInitializedMap ),
4982
- Map . of ( )
4982
+ attachTopicName ( currentMap . deletingTopics () )
4983
4983
)),
4984
4984
null
4985
4985
);
@@ -5025,7 +5025,7 @@ public CoordinatorResult<Void, CoordinatorRecord> uninitializeShareGroupState(
5025
5025
groupId ,
5026
5026
attachTopicName (finalInitializingTopics ),
5027
5027
attachTopicName (info .initializedTopics ()),
5028
- Map . of ( )
5028
+ attachTopicName ( info . deletingTopics () )
5029
5029
)
5030
5030
),
5031
5031
null
@@ -5057,6 +5057,13 @@ public List<InitializeShareGroupStateParameters> reconcileShareGroupStateInitial
5057
5057
return requests ;
5058
5058
}
5059
5059
5060
+ private Map <Uuid , String > attachTopicName (Set <Uuid > topicIds ) {
5061
+ TopicsImage topicsImage = metadataImage .topics ();
5062
+ return topicIds .stream ()
5063
+ .map (topicId -> Map .entry (topicId , topicsImage .getTopic (topicId ).name ()))
5064
+ .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
5065
+ }
5066
+
5060
5067
private Map <Uuid , Map .Entry <String , Set <Integer >>> attachTopicName (Map <Uuid , Set <Integer >> initMap ) {
5061
5068
TopicsImage topicsImage = metadataImage .topics ();
5062
5069
Map <Uuid , Map .Entry <String , Set <Integer >>> finalMap = new HashMap <>();
@@ -8142,39 +8149,49 @@ public void createGroupTombstoneRecords(
8142
8149
/**
8143
8150
* Returns an optional of delete share group request object to be used with the persister.
8144
8151
* Empty if no subscribed topics or if the share group is empty.
8145
- * @param shareGroup - A share group
8152
+ * @param shareGroupId Share group id
8153
+ * @param records List of coordinator records to append to
8146
8154
* @return Optional of object representing the share group state delete request.
8147
8155
*/
8148
- public Optional <DeleteShareGroupStateParameters > shareGroupBuildPartitionDeleteRequest (ShareGroup shareGroup ) {
8149
- TopicsImage topicsImage = metadataImage .topics ();
8150
- Set <String > subscribedTopics = shareGroup .subscribedTopicNames ().keySet ();
8151
- List <TopicData <PartitionIdData >> topicDataList = new ArrayList <>(subscribedTopics .size ());
8152
-
8153
- for (String topic : subscribedTopics ) {
8154
- TopicImage topicImage = topicsImage .getTopic (topic );
8155
- topicDataList .add (
8156
- new TopicData <>(
8157
- topicImage .id (),
8158
- topicImage .partitions ().keySet ().stream ()
8159
- .map (PartitionFactory ::newPartitionIdData )
8160
- .toList ()
8161
- )
8162
- );
8156
+ public Optional <DeleteShareGroupStateParameters > shareGroupBuildPartitionDeleteRequest (String shareGroupId , List <CoordinatorRecord > records ) {
8157
+ if (!shareGroupPartitionMetadata .containsKey (shareGroupId )) {
8158
+ return Optional .empty ();
8163
8159
}
8164
8160
8165
- if (topicDataList .isEmpty ()) {
8161
+ Map <Uuid , Set <Integer >> deleteCandidates = mergeShareGroupInitMaps (
8162
+ shareGroupPartitionMetadata .get (shareGroupId ).initializedTopics (),
8163
+ shareGroupPartitionMetadata .get (shareGroupId ).initializingTopics ()
8164
+ );
8165
+
8166
+ if (deleteCandidates .isEmpty ()) {
8166
8167
return Optional .empty ();
8167
8168
}
8168
8169
8169
- return Optional .of (
8170
- new DeleteShareGroupStateParameters .Builder ()
8171
- .setGroupTopicPartitionData (
8172
- new GroupTopicPartitionData .Builder <PartitionIdData >()
8173
- .setGroupId (shareGroup .groupId ())
8174
- .setTopicsData (topicDataList )
8175
- .build ()
8176
- )
8177
- .build ()
8170
+ List <TopicData <PartitionIdData >> topicDataList = new ArrayList <>(deleteCandidates .size ());
8171
+
8172
+ for (Map .Entry <Uuid , Set <Integer >> entry : deleteCandidates .entrySet ()) {
8173
+ topicDataList .add (new TopicData <>(
8174
+ entry .getKey (),
8175
+ entry .getValue ().stream ()
8176
+ .map (PartitionFactory ::newPartitionIdData )
8177
+ .toList ()
8178
+ ));
8179
+ }
8180
+
8181
+ // Remove all initializing and initialized topic info from record and add deleting.
8182
+ records .add (GroupCoordinatorRecordHelpers .newShareGroupStatePartitionMetadataRecord (
8183
+ shareGroupId ,
8184
+ Map .of (),
8185
+ Map .of (),
8186
+ attachTopicName (deleteCandidates .keySet ())
8187
+ ));
8188
+
8189
+ return Optional .of (new DeleteShareGroupStateParameters .Builder ()
8190
+ .setGroupTopicPartitionData (new GroupTopicPartitionData .Builder <PartitionIdData >()
8191
+ .setGroupId (shareGroupId )
8192
+ .setTopicsData (topicDataList )
8193
+ .build ())
8194
+ .build ()
8178
8195
);
8179
8196
}
8180
8197
0 commit comments