Skip to content

Conversation

eduardagarici
Copy link
Collaborator

@eduardagarici eduardagarici commented Sep 17, 2025

Starting from linkedin#2267, added slight optimizations and code refactoring.

Summary

Why: In current CC goals, there is no goal to balance a topic leaders only which ensure a fair distribution of load for not log compacted topics. The rebalance looks at historic loads for replica placement and it's possible that load changes temporarily causing load-skew for brokers. A potential solution to this problem is to distribute topic leader partitions fairly across all the brokers.
Avoiding load-skew for brokers is also beneficial for clients that have quotas set up at broker level. Thus, we want to avoid one broker being throttled due to many leaders for a particular topic whilst the other broker remain idle.

What: Add a new Topic Replica Leader distribution goal.
This PR adds a new goal to distribute Leaders Replica for every topic in a fair manner across all the brokers. If the partition count is not a multiple of brokers, some brokers do end up with extra partitions.

The thresholds can be configured using 3 new knobs added to AnalyzerConfig.

The new goal is modeled after existing TopicReplicaDistributionGoal with following differences:

This is a soft goal goal
It looks at leader replicas in a broker only
For candidate brokers with equal number of leader replicas for a topic, it uses total leader replicas as a tie-break

Categorization

  • documentation
  • bugfix
  • new feature
  • refactor
  • security/CVE
  • other

Notes:

  • Currently the GOAL is configured to take into consideration all topics (except those in excludedTopics). But we can configure a set of predefined topics in order to experiment with this goal.
  • Certain logs are just temporarily while still in testing phase. They will be removed before merging into master.

@eduardagarici eduardagarici marked this pull request as ready for review September 24, 2025 13:27
@eduardagarici eduardagarici changed the title Core 135759 [CORE-135759] Added TopicLeaderReplicaDistributionGoal so we distribute leaders fairly across brokers Sep 24, 2025
Copy link

@ecojan ecojan left a comment

Choose a reason for hiding this comment

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

Everything looks good from my POV.
Just one small comment.

Broker broker) {
int numTopicLeaders = broker.numLeadersFor(topic);
int brokerBalanceUpperLimit = broker.isAlive()
? _balanceUpperLimitByTopic.get(topic)
Copy link

Choose a reason for hiding this comment

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

Not sure if this will ever be the case, but there is a possibility for the get() to return null here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not seeing how. The initgoalstate populates those maps for all the topics that it finds. Afterwards, the cluster model does not change between initGoalState and updateGoalState. Did you spot something that I did not see?

@eduardagarici eduardagarici merged commit 2fe8ac4 into master Oct 8, 2025
9 of 17 checks passed
@eduardagarici eduardagarici deleted the CORE-135759 branch October 8, 2025 10:17
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.

3 participants