Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Under-documented "Manually Assigning All Partitions" #2891

Closed
michaldo opened this issue Nov 10, 2023 · 5 comments · Fixed by #2900 or #2903
Closed

Under-documented "Manually Assigning All Partitions" #2891

michaldo opened this issue Nov 10, 2023 · 5 comments · Fixed by #2900 or #2903

Comments

@michaldo
Copy link
Contributor

In what version(s) of Spring for Apache Kafka are you seeing this issue?

3.0.12

Describe the bug
Doc says

it can be useful to manually assign the partitions and not use Kafka’s group management (...) You should also set the container’s AckMode to MANUAL to prevent the container from committing offsets for a null consumer group

That is not enough, because DefaultErrorHandler by default has ackAfterHandle == true and commit the offset on exception.
Should I create and Doc PR to mention

+ You should also set the container’s error handler setAckAfterHandle(false) to prevent the container from committing offsets on error

?

To be honest, preventing the container from committing offsets should work automatically when @TopicPartition is detected...

@garyrussell
Copy link
Contributor

Thanks. The container should detect manual assignment with no group and ignore ackAfterHandle. We can’t assume MANUAL when there is no group. It might be a configuration error.

@michaldo
Copy link
Contributor Author

Do you mean that

KafkaMessageListenerContainer

private void commitOffsetsIfNeeded(final ConsumerRecords<K, V> records) {
  if ((!this.autoCommit && this.commonErrorHandler.isAckAfterHandle())
	|| this.producer != null) {

should be replaced by

private void commitOffsetsIfNeeded(final ConsumerRecords<K, V> records) {
  if ((!this.autoCommit && this.commonErrorHandler.isAckAfterHandle() && this.containerProperties.getTopicPartitions() != null )
	|| this.producer != null) {

?

@garyrussell
Copy link
Contributor

No, we must only skip the commit if the group is null in that case.

@michaldo
Copy link
Contributor Author

We can’t assume MANUAL when there is no group. It might be a configuration error.

That sounds inconsistent:

  1. Do not commit record on exception according to property ackAfterHandle, because ack does not have a sense, when there is no group.
  2. Commit record according to property ackMode, even when there is no group.

If no group + ack is OK, it should be acked always, according to configuration
If no group + ack is NOK, it should never be acked, regardless of configuration

@garyrussell
Copy link
Contributor

That sounds inconsistent:

I agree; we can change the default behavior in the upcoming 3.1 release (due next week(, but not in earlier versions.

garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Nov 16, 2023
Resolves spring-projects#2891

When using manual partition assignment and `AckMode.MANUAL`, it is possible
to have a `null` `group.id`, whereby Kafka does not maintain any committed offsets.

In this case, we should not attempt to commit the offset, even if the error handler
`ackAfterHandle` property is true.

**cherry-pick to 3.0.x, 2.9.x**
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Nov 16, 2023
Resolves spring-projects#2891

When using manual partition assignment and `AckMode.MANUAL`, it is possible
to have a `null` `group.id`, whereby Kafka does not maintain any committed offsets.

In this case, we should not attempt to commit the offset after recovery, even if
the error handler `ackAfterHandle` property is true.

**cherry-pick to 3.0.x, 2.9.x**
artembilan pushed a commit that referenced this issue Nov 16, 2023
Resolves #2891

When using manual partition assignment and `AckMode.MANUAL`, it is possible
to have a `null` `group.id`, whereby Kafka does not maintain any committed offsets.

In this case, we should not attempt to commit the offset after recovery, even if
the error handler `ackAfterHandle` property is true.

**cherry-pick to 3.0.x, 2.9.x**
artembilan pushed a commit that referenced this issue Nov 16, 2023
Resolves #2891

When using manual partition assignment and `AckMode.MANUAL`, it is possible
to have a `null` `group.id`, whereby Kafka does not maintain any committed offsets.

In this case, we should not attempt to commit the offset after recovery, even if
the error handler `ackAfterHandle` property is true.

**cherry-pick to 3.0.x, 2.9.x**

(cherry picked from commit 9f1050a)
@garyrussell garyrussell reopened this Nov 16, 2023
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Nov 16, 2023
Resolves spring-projects#2891

When using manual partition assignment with `null` `group.id` always
coerce `AckMode` to `MANUAL`.
artembilan pushed a commit that referenced this issue Nov 16, 2023
Resolves #2891

When using manual partition assignment and `AckMode.MANUAL`, it is possible
to have a `null` `group.id`, whereby Kafka does not maintain any committed offsets.

In this case, we should not attempt to commit the offset after recovery, even if
the error handler `ackAfterHandle` property is true.

**cherry-pick to 3.0.x, 2.9.x**

(cherry picked from commit 9f1050a)

# Conflicts:
#	spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java
artembilan pushed a commit that referenced this issue Nov 16, 2023
Resolves #2891

When using manual partition assignment with `null` `group.id` always
coerce `AckMode` to `MANUAL`.
artembilan added a commit to spring-projects/spring-integration that referenced this issue Nov 18, 2023
Related to spring-projects/spring-kafka#2891

Starting with Spring for Apache Kafka `3.1`, the `ackMode` for
listener container is coerced to `MANUAL` if no `groupId` assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment