Guangnan Shi created KAFKA-21731:
------------------------------------
Summary: Resetting/altering source connector offsets fails when
the connector's producer target cluster is unresolvable, even though offsets
are stored in the worker's offsets topic
Key: KAFKA-21731
URL: https://issues.apache.org/jira/browse/KAFKA-21731
Project: Kafka
Issue Type: Bug
Components: connect
Affects Versions: 4.4.0, 4.3.0, 4.2.0, 4.1.0, 4.0.0, 3.9.0, 3.8.0, 3.7.0,
3.6.0
Reporter: Guangnan Shi
{{Worker.modifySourceConnectorOffsets}} (used by {{PATCH}} and {{DELETE
/connectors/\{name\}/offsets}}, KIP-875) always constructs a {{KafkaProducer}}
from the connector's producer configs, including any {{producer.override.*}}
settings:
{code:java}
Map<String, Object> producerProps = config.exactlyOnceSourceEnabled()
? exactlyOnceSourceTaskProducerConfigs(...)
: baseProducerConfigs(...);
KafkaProducer<byte[], byte[]> producer = new KafkaProducer<>(producerProps);
{code}
That producer is only used when exactly-once source support is enabled, or when
the connector uses a connector-specific offsets topic. In the common case,
where offsets live in the worker's global offsets topic,
{{offsetStoreForRegularSourceConnector}} closes the producer without using it,
and offsets are written through the worker's global offset store.
However, constructing the {{KafkaProducer}} still validates and resolves
{{bootstrap.servers}}. A source connector may legitimately produce to a
different Kafka cluster than the Connect cluster
({{producer.override.bootstrap.servers}}). If that cluster can no longer be
resolved (e.g. it was decommissioned before the connector's offsets were
cleaned up), the reset fails even though the cluster would never be contacted:
{noformat}
org.apache.kafka.common.KafkaException: Failed to construct kafka producer
at org.apache.kafka.clients.producer.KafkaProducer.<init>(...)
at org.apache.kafka.connect.runtime.Worker.modifySourceConnectorOffsets(...)
Caused by: org.apache.kafka.common.config.ConfigException: No resolvable
bootstrap urls given in bootstrap.servers
{noformat}
This leaves no supported way to clear the offsets of such a connector, so stale
offsets accumulate in the worker's offsets topic. The same applies to other
client-side failures at producer construction that are unrelated to the
worker's own cluster (e.g. SASL/OAUTHBEARER login configured via
{{producer.override.*}}).
*Steps to reproduce*
# Run a distributed worker with {{exactly.once.source.support=disabled}}
(default) and {{connector.client.config.override.policy=All}}.
# Create a source connector with
{{producer.override.bootstrap.servers=unresolvable-host.invalid:9092}}, then
stop it: {{PUT /connectors/\{name\}/stop}}.
# Call {{DELETE /connectors/\{name\}/offsets}}.
*Expected:* offsets are reset in the worker's global offsets topic.
*Actual:* the request fails with "Failed to construct kafka producer" / "No
resolvable bootstrap urls".
*Proposed fix*
Only construct the connector producer when it will actually be used, i.e. when
exactly-once source support is enabled or the connector uses a
connector-specific offsets store
({{regularSourceTaskUsesConnectorSpecificOffsetsStore}}), and pass {{null}}
otherwise. {{offsetStoreForRegularSourceConnector}} already handles the
global-only path without a producer, and {{Utils.closeQuietly}} tolerates
{{null}}. Behaviour is unchanged for exactly-once connectors and connectors
with their own offsets topic. I'm happy to submit a PR.
Related: KAFKA-15127
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)