Skip to content

[SPARK-49442][SS] Cache Kafka partition metadata to reduce DescribeTopics RPCs per micro-batch#57351

Closed
vinodkc wants to merge 2 commits into
apache:masterfrom
vinodkc:spark-49442
Closed

[SPARK-49442][SS] Cache Kafka partition metadata to reduce DescribeTopics RPCs per micro-batch#57351
vinodkc wants to merge 2 commits into
apache:masterfrom
vinodkc:spark-49442

Conversation

@vinodkc

@vinodkc vinodkc commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Adds a new source option partition.metadata.cache.ttl.ms to KafkaOffsetReaderAdmin. When set to a positive value, the driver caches the set of assigned TopicPartitions and reuses it for all offset fetch calls within the TTL window, skipping the DescribeTopics RPC to the broker. The cache is invalidated on admin reset (i.e., on retry). Default is -1 (caching disabled, preserving existing behavior).

Why are the changes needed?

Every micro-batch unconditionally called consumerStrategy.assignedTopicPartitions(admin), which issues a DescribeTopics RPC to the Kafka broker even though partition assignments are stable in most production deployments. For deployments with large partition counts and short trigger intervals, this generates unnecessary metadata traffic.

Does this PR introduce any user-facing change?

Yes. Adds a new source option partition.metadata.cache.ttl.ms (long, default -1). Valid values are -1 (caching disabled) or any positive integer representing milliseconds. Documentation is updated accordingly. Existing behavior is unchanged when the option is not set.

Note: when caching is enabled, newly added partitions will not be discovered until the cache expires.

How was this patch tested?

Added tests in KafkaOffsetReaderSuite KafkaSourceProviderSuite, KafkaOffsetReaderSuite and KafkaSourceProviderSuite.

Was this patch authored or co-authored using generative AI tooling?

Yes, 'Generated-by: Claude (Sonnet 4.6)

@HeartSaVioR HeartSaVioR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 but let's see whether it's possible to give more room for the potential flakiness test issue.

@HeartSaVioR

Copy link
Copy Markdown
Contributor

Thanks! Merging to master/4.x.

HeartSaVioR pushed a commit that referenced this pull request Jul 20, 2026
…pics RPCs per micro-batch

### What changes were proposed in this pull request?

Adds a new source option `partition.metadata.cache.ttl.ms` to `KafkaOffsetReaderAdmin`. When set to a positive value, the driver caches the set of assigned `TopicPartition`s and reuses it for all offset fetch calls within the TTL window, skipping the `DescribeTopics` RPC to the broker. The cache is invalidated on admin reset (i.e., on retry). Default is `-1` (caching disabled, preserving existing behavior).

### Why are the changes needed?

Every micro-batch unconditionally called `consumerStrategy.assignedTopicPartitions(admin)`, which issues a `DescribeTopics` RPC to the Kafka broker even though partition assignments are stable in most production deployments. For deployments with large partition counts and short trigger intervals, this generates unnecessary metadata traffic.

### Does this PR introduce _any_ user-facing change?

Yes. Adds a new source option `partition.metadata.cache.ttl.ms` (long, default `-1`). Valid values are `-1` (caching disabled) or any positive integer representing milliseconds. Documentation is updated accordingly. Existing behavior is unchanged when the option is not set.

> **Note:** when caching is enabled, newly added partitions will not be discovered until the cache expires.

### How was this patch tested?

Added tests in `KafkaOffsetReaderSuite` `KafkaSourceProviderSuite`, `KafkaOffsetReaderSuite` and `KafkaSourceProviderSuite`.

### Was this patch authored or co-authored using generative AI tooling?

Yes, 'Generated-by:  Claude (Sonnet 4.6)

Closes #57351 from vinodkc/spark-49442.

Authored-by: Vinod KC <vinod.kc.in@gmail.com>
Signed-off-by: Jungtaek Lim <kabhwan.opensource@gmail.com>
(cherry picked from commit c369cf2)
Signed-off-by: Jungtaek Lim <kabhwan.opensource@gmail.com>
@HeartSaVioR

Copy link
Copy Markdown
Contributor

Merge Summary:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants