Skip to content

KAFKA-19193 Support rack-aware partitioning for Kafka producer#19850

Open
ivanyu wants to merge 1 commit intoapache:trunkfrom
ivanyu:kip-1123-rack-aware-partitioning
Open

KAFKA-19193 Support rack-aware partitioning for Kafka producer#19850
ivanyu wants to merge 1 commit intoapache:trunkfrom
ivanyu:kip-1123-rack-aware-partitioning

Conversation

@ivanyu
Copy link
Copy Markdown
Contributor

@ivanyu ivanyu commented May 29, 2025

According to KIP-1123, this commit adds the support for rack-aware partitioning to BuiltInPartitioner. It comes with two new configs for the producer: partitioner.rack.aware and client.rack, which allows enabling the new behavior.

Apart from the added unit tests, the desired behavior was tested by kafka-producer-perf-test.sh with an existing and a non-existing rack against a 4 node cluster with two racks and 12-partition topic:

./kafka_2.13-4.1.0-SNAPSHOT/bin/kafka-producer-perf-test.sh \
  --topic test-topic --num-records 100000 --throughput -1 --record-size 1 \
  --producer-props bootstrap.servers=127.0.0.1:9092 \
  client.rack=rack0 partitioner.rack.aware=true

Delete this text and replace it with a detailed description of your change. The
PR title and body will become the squashed commit message.

If you would like to tag individuals, add some commentary, upload images, or
include other supplemental information that should not be part of the eventual
commit message, please use a separate comment.

If applicable, please include a summary of the testing strategy (including
rationale) for the proposed change. Unit and/or integration tests are expected
for any behavior change and system tests should be considered for larger
changes.

@github-actions github-actions bot added triage PRs from the community producer clients labels May 29, 2025
@ivanyu ivanyu force-pushed the kip-1123-rack-aware-partitioning branch 11 times, most recently from 1af9189 to 564e60f Compare May 31, 2025 06:14
@ivanyu ivanyu marked this pull request as ready for review May 31, 2025 06:20
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 6, 2025

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

@marcospassos
Copy link
Copy Markdown

Is there any chance this feature will be included in the next release?

@ivanyu
Copy link
Copy Markdown
Contributor Author

ivanyu commented Aug 22, 2025

@marcospassos I'm waiting for 4.1 release to be cut, after that I'll ping the mailing list for review.

@github-actions
Copy link
Copy Markdown

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

@github-actions
Copy link
Copy Markdown

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

Copy link
Copy Markdown
Contributor

@LiamClarkeNZ LiamClarkeNZ left a comment

Choose a reason for hiding this comment

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

Love the tests.

private final String rack;

private volatile PartitionLoadStats partitionLoadStats = null;
private volatile PartitionLoadStatsHolder partitionLoadStats = null;
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.

Suggested change
private volatile PartitionLoadStatsHolder partitionLoadStats = null;
private volatile PartitionLoadStatsHolder partitionLoadStatsHolder = null;

As it got a bit confusing when later the code is retrieving partitionLoadStats.inThisRack which is a member of PartitionLoadStatsHolder of type PartitionLoadStats. :D


// Create partitions with "sticky" batch size to accommodate 3 records.
BuiltInPartitioner builtInPartitionerA = new SequentialPartitioner(logContext, TOPIC_A, 3);
BuiltInPartitioner builtInPartitionerA = new SequentialPartitioner(logContext, TOPIC_A, 3, false, "");
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.

Suggested change
BuiltInPartitioner builtInPartitionerA = new SequentialPartitioner(logContext, TOPIC_A, 3, false, "");
final boolean rackAware = false;
final String clientRackId = "";
BuiltInPartitioner builtInPartitionerA = new SequentialPartitioner(logContext, TOPIC_A, 3, rackAware, clientRackId);


// Check that switching works even when there is one partition.
BuiltInPartitioner builtInPartitionerB = new SequentialPartitioner(logContext, TOPIC_B, 1);
BuiltInPartitioner builtInPartitionerB = new SequentialPartitioner(logContext, TOPIC_B, 1, false, "");
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.

Suggested change
BuiltInPartitioner builtInPartitionerB = new SequentialPartitioner(logContext, TOPIC_B, 1, false, "");
BuiltInPartitioner builtInPartitionerB = new SequentialPartitioner(logContext, TOPIC_B, 1, rackAware, clientRackId);

Just to make the meaning of false and "" obvious at a glance :)

partitionRacks[i] = leader.rack();
}
allPartitions.add(new PartitionInfo(TOPIC_A, i, leader, NODES, NODES));
expectedFrequencies[i] = 6 - queueSizes[i]; // 6 is max(queueSizes) + 1
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.

Love the comment :)

@github-actions github-actions bot removed needs-attention triage PRs from the community labels Oct 5, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 3, 2026

This PR is being marked as stale since it has not had any activity in 90 days. If you
would like to keep this PR alive, please leave a comment asking for a review. If the PR has
merge conflicts, update it with the latest from the base branch.

If you are having difficulty finding a reviewer, please reach out on the [mailing list](https://kafka.apache.org/contact).

If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions bot added the stale Stale PRs label Jan 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 2, 2026

This PR has been closed since it has not had any activity in 120 days. If you feel like this
was a mistake, or you would like to continue working on it, please feel free to re-open the
PR and ask for a review.

@github-actions github-actions bot added the closed-stale PRs that were closed due to inactivity label Feb 2, 2026
@github-actions github-actions bot closed this Feb 2, 2026
@SoerenHenning
Copy link
Copy Markdown

Hi, unfortunately this was closed. Are there any plan to continue this effort or anything we could do to support it?

@marcospassos
Copy link
Copy Markdown

This issue would definitely benefit the community and should not be closed.

@kirktrue
Copy link
Copy Markdown
Contributor

@ivanyu—are you still able to work on this? Or do you need the community to follow up? LMK. Thanks!

@ivanyu
Copy link
Copy Markdown
Contributor Author

ivanyu commented Mar 19, 2026

@kirktrue sure, I will review the PR soon!

@ivanyu
Copy link
Copy Markdown
Contributor Author

ivanyu commented Mar 28, 2026

For some reason, I cannot reopen the PR (the button isn't even there). Maybe someone else can?

@viktorsomogyi viktorsomogyi reopened this Mar 30, 2026
@github-actions github-actions bot added the triage PRs from the community label Mar 30, 2026
@viktorsomogyi viktorsomogyi removed stale Stale PRs closed-stale PRs that were closed due to inactivity labels Mar 30, 2026
@ivanyu ivanyu force-pushed the kip-1123-rack-aware-partitioning branch from 564e60f to 6816a21 Compare March 30, 2026 08:45
@ivanyu
Copy link
Copy Markdown
Contributor Author

ivanyu commented Mar 30, 2026

Thank you @LiamClarkeNZ, I addressed your comments

@viktorsomogyi viktorsomogyi added ci-approved and removed triage PRs from the community labels Mar 30, 2026
According to KIP-1123, this commit adds the support for rack-aware partitioning to `BuiltInPartitioner`. It comes with two new configs for the producer: `partitioner.rack.aware` and `client.rack`, which allows enabling the new behavior.

Apart from the added unit tests, the desired behavior was validated by `kafka-producer-perf-test.sh` with an existing and a non-existing rack against a 4 node cluster with two racks and 12-partition topic:
```shell
./kafka_2.13-4.1.0-SNAPSHOT/bin/kafka-producer-perf-test.sh \
  --topic test-topic --num-records 100000 --throughput -1 --record-size 1 \
  --producer-props bootstrap.servers=127.0.0.1:9092 \
  client.rack=rack0 partitioner.rack.aware=true
```
@ivanyu ivanyu force-pushed the kip-1123-rack-aware-partitioning branch from 6816a21 to 605e049 Compare March 30, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants