mjsax commented on code in PR #21826:
URL: https://github.com/apache/kafka/pull/21826#discussion_r4699054369
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -153,7 +156,13 @@ public int execute(final String[] args, final Properties
config) {
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
bootstrapServerValue);
try (Admin adminClient = Admin.create(properties)) {
- maybeDeleteActiveConsumers(groupId, adminClient,
options.hasForce());
+ final boolean force = options.hasForce();
+
+ maybeDeleteActiveConsumers(groupId, adminClient, force);
+
+ if (!force) {
+ validateApplicationIdExists(groupId, adminClient);
Review Comment:
Why are we doing this check only after `maybeDeleteActiveConsumers()`?
Should we not make this check upfront, and fail before any steps are executed?
##########
tools/src/test/java/org/apache/kafka/tools/ResetIntegrationTest.java:
##########
@@ -196,6 +196,7 @@ public void
shouldNotAllowToResetWhenInputTopicAbsent(ClusterInstance cluster) {
final String appId = generateAppId();
final String[] parameters = new String[] {
"--application-id", appId,
+ "--force",
Review Comment:
Not sure why we need to pass `--force` here? I am worried it could maybe
weaken the test, and prevent that the test catching regression bugs? -- Can you
explain? If passing in `--force` is indeed the right thing to do, would be good
to add a comment to explain why.
(similar below for other tests)
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
+ final Admin adminClient)
+ throws InterruptedException, TimeoutException {
+ ConsumerGroupDescription description = null;
+ try {
+ final Map<String, ConsumerGroupDescription> groups = adminClient
+ .describeConsumerGroups(Set.of(applicationId))
Review Comment:
We are already issuing a "describe RPC" inside
`maybeDeleteActiveConsumers()` -- might be worth to not sent it twice but only
once and reuse the result?
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
+ final Admin adminClient)
+ throws InterruptedException, TimeoutException {
Review Comment:
```suggestion
void validateApplicationIdExists(
final String applicationId,
final Admin adminClient
) throws InterruptedException, TimeoutException {
```
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
+ final Admin adminClient)
+ throws InterruptedException, TimeoutException {
+ ConsumerGroupDescription description = null;
+ try {
+ final Map<String, ConsumerGroupDescription> groups = adminClient
+ .describeConsumerGroups(Set.of(applicationId))
+ .all()
+ .get(60, TimeUnit.SECONDS);
+
+ description = groups.get(applicationId);
+ } catch (final ExecutionException e) {
+ if (!(e.getCause() instanceof GroupIdNotFoundException)) {
+ throw new RuntimeException(e.getCause());
+ }
Review Comment:
```suggestion
if (e.getCause() instanceof GroupIdNotFoundException) {
throw new IllegalArgumentException(...);
} else {
throw new RuntimeException(e);
}
```
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
+ final Admin adminClient)
+ throws InterruptedException, TimeoutException {
+ ConsumerGroupDescription description = null;
+ try {
+ final Map<String, ConsumerGroupDescription> groups = adminClient
+ .describeConsumerGroups(Set.of(applicationId))
+ .all()
+ .get(60, TimeUnit.SECONDS);
+
+ description = groups.get(applicationId);
+ } catch (final ExecutionException e) {
+ if (!(e.getCause() instanceof GroupIdNotFoundException)) {
+ throw new RuntimeException(e.getCause());
+ }
Review Comment:
Btw: why are we rethrowing `e.getCause()` and just not `e` ? I don't see a
reason why we would want to strip off the most outer layer of the error stack
trace?
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
+ final Admin adminClient)
+ throws InterruptedException, TimeoutException {
+ ConsumerGroupDescription description = null;
+ try {
+ final Map<String, ConsumerGroupDescription> groups = adminClient
+ .describeConsumerGroups(Set.of(applicationId))
+ .all()
+ .get(60, TimeUnit.SECONDS);
+
+ description = groups.get(applicationId);
+ } catch (final ExecutionException e) {
+ if (!(e.getCause() instanceof GroupIdNotFoundException)) {
+ throw new RuntimeException(e.getCause());
+ }
Review Comment:
It seems cleaner to just throw directly for either case, and drop the code
blow?
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
Review Comment:
Why is this not `private`? Maybe add `// visible for testing` similar to
other methods?
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
+ final Admin adminClient)
+ throws InterruptedException, TimeoutException {
+ ConsumerGroupDescription description = null;
+ try {
+ final Map<String, ConsumerGroupDescription> groups = adminClient
+ .describeConsumerGroups(Set.of(applicationId))
+ .all()
+ .get(60, TimeUnit.SECONDS);
+
+ description = groups.get(applicationId);
+ } catch (final ExecutionException e) {
+ if (!(e.getCause() instanceof GroupIdNotFoundException)) {
+ throw new RuntimeException(e.getCause());
+ }
+ }
+
+ if (description == null ||
GroupState.DEAD.equals(description.groupState())) {
Review Comment:
I think we need to explain the DEAD check here with a comment? I was also
not sure why we have it, and CLAUDE figure it out for me:
```
The classic describe calls classicGroup(), which throws
GroupIdNotFoundException
("not a classic group", GroupMetadataManager.java:1208). The result depends
on the
request version:
- v6 or later: the error code is GROUP_ID_NOT_FOUND, so the future fails
with
GroupIdNotFoundException, carrying the "not a consumer group" message
saved
in stepĀ 2. The PR's catch handles it, and the user gets "No consumer
group found ...".
- Before v6: the group comes back as DEAD with no error
(GroupMetadataManager.java:874-885).
The PR's DEAD check catches it, and the user gets the same message.
```
Assuming we want the 4.5.0 version of this tool work correctly against 3.x
broker -- cannot hurt I guess.
##########
tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java:
##########
@@ -181,6 +190,38 @@ public int execute(final String[] args, final Properties
config) {
}
}
+ // Note: this check confirms the application.id exists as a consumer group,
+ // but cannot prevent topic deletion for other applications whose IDs share
+ // this application.id as a prefix (e.g. resetting "foo" may affect
"foo-v2"
+ // topics). This is a known limitation of prefix-based topic inference.
+ void validateApplicationIdExists(final String applicationId,
+ final Admin adminClient)
+ throws InterruptedException, TimeoutException {
+ ConsumerGroupDescription description = null;
+ try {
+ final Map<String, ConsumerGroupDescription> groups = adminClient
+ .describeConsumerGroups(Set.of(applicationId))
+ .all()
+ .get(60, TimeUnit.SECONDS);
+
+ description = groups.get(applicationId);
+ } catch (final ExecutionException e) {
+ if (!(e.getCause() instanceof GroupIdNotFoundException)) {
Review Comment:
We also get a `GroupIdNotFoundException` for "streams" groups and should
handle this case differently, ie, provide a different error message and maybe
point to `bin/kafka-streams-group.sh` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]