Skip to content

ConcurrentMessageListenerContainer#isInExpectedState consistency problem #3063

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import org.apache.kafka.common.Metric;
import org.apache.kafka.common.MetricName;
Expand Down Expand Up @@ -121,12 +120,12 @@ public void setAlwaysClientIdSuffix(boolean alwaysClientIdSuffix) {
public List<KafkaMessageListenerContainer<K, V>> getContainers() {
this.lifecycleLock.lock();
try {
return Collections.unmodifiableList(new ArrayList<>(this.containers));
return List.copyOf(this.containers);
}
finally {
this.lifecycleLock.unlock();
}
}
}

@Override
public MessageListenerContainer getContainerFor(String topic, int partition) {
Expand Down Expand Up @@ -157,7 +156,7 @@ public Collection<TopicPartition> getAssignedPartitions() {
.map(KafkaMessageListenerContainer::getAssignedPartitions)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.collect(Collectors.toList());
.toList();
}
finally {
this.lifecycleLock.unlock();
Expand Down Expand Up @@ -259,7 +258,6 @@ protected void doStart() {
}
}

@SuppressWarnings("deprecation")
private void configureChildContainer(int index, KafkaMessageListenerContainer<K, V> container) {
String beanName = getBeanName();
beanName = (beanName == null ? "consumer" : beanName) + "-" + index;
Expand Down Expand Up @@ -308,13 +306,17 @@ private KafkaMessageListenerContainer<K, V> constructContainer(ContainerProperti
return container;
}

@Nullable
private TopicPartitionOffset[] partitionSubset(ContainerProperties containerProperties, int index) {
TopicPartitionOffset[] topicPartitions = containerProperties.getTopicPartitions();
if (topicPartitions == null) {
return null;
}
if (this.concurrency == 1) {
return topicPartitions; // NOSONAR
return topicPartitions;
}
else {
int numPartitions = topicPartitions.length; // NOSONAR
int numPartitions = topicPartitions.length;
if (numPartitions == this.concurrency) {
return new TopicPartitionOffset[] { topicPartitions[index] };
}
Expand Down Expand Up @@ -389,7 +391,7 @@ && getContainerProperties().isRestartAfterAuthExceptions()
if (exec == null) {
exec = new SimpleAsyncTaskExecutor(getListenerId() + ".authRestart");
}
exec.execute(() -> start());
exec.execute(this::start);
}
}

Expand Down Expand Up @@ -477,10 +479,15 @@ public boolean isPartitionPaused(TopicPartition topicPartition) {
public boolean isInExpectedState() {
this.lifecycleLock.lock();
try {
return (isRunning() || isStoppedNormally()) && this.containers
.stream()
.map(container -> container.isInExpectedState())
.allMatch(bool -> Boolean.TRUE.equals(bool));
boolean isInExpectedState = isRunning() || isStoppedNormally();
if (isInExpectedState) {
for (KafkaMessageListenerContainer<K, V> container : this.containers) {
if (!container.isInExpectedState()) {
return false;
}
}
}
return isInExpectedState;
}
finally {
this.lifecycleLock.unlock();
Expand Down