Skip to content

[controller] Account for max read capacity in quota change#2235

Open
misyel wants to merge 12 commits intolinkedin:mainfrom
misyel:quota
Open

[controller] Account for max read capacity in quota change#2235
misyel wants to merge 12 commits intolinkedin:mainfrom
misyel:quota

Conversation

@misyel
Copy link
Contributor

@misyel misyel commented Oct 23, 2025

Problem Statement

When a new quota request comes in to the controller, we only validate the value against the default router capacity before approving or rejecting the request. There is a separate max read capacity that is used for router throttling and the correct calculation would be to approve the request if it is within the default router capacity or the max read capacity.

Solution

  • Approve the quota change if it is within the default router capacity or max read capacity

Code changes

  • Added new code behind a config. If so list the config names and their default values in the PR description.
  • Introduced new log lines.
    • Confirmed if logs need to be rate limited to avoid excessive logging.

Concurrency-Specific Checks

Both reviewer and PR author to verify

  • Code has no race conditions or thread safety issues.
  • Proper synchronization mechanisms (e.g., synchronized, RWLock) are used where needed.
  • No blocking calls inside critical sections that could lead to deadlocks or performance degradation.
  • Verified thread-safe collections are used (e.g., ConcurrentHashMap, CopyOnWriteArrayList).
  • Validated proper exception handling in multi-threaded code to avoid silent thread termination.

How was this PR tested?

  • New unit tests added.
  • New integration tests added.
  • Modified or extended existing tests.
  • Verified backward compatibility (if applicable).

New unit test

Does this PR introduce any user-facing or breaking changes?

  • No. You can skip the rest of this section.
  • Yes. Clearly explain the behavior change and its impact.

private final boolean disableParentRequestTopicForStreamPushes;

private final int defaultReadQuotaPerRouter;
private final long maxReadCapacityCu;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment on what these 2 variables mean and also revisit the name to make it more clear from the name? Lets also add router in the name if it's only for router quota

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - added a comment to describe the usage of the two variables and renamed the new config to include router

long maxReadCapacityCu = clusterConfig.getMaxReadCapacityCu();
long maxPerRouterCapacity = Math.max(defaultReadQuotaPerRouter, maxReadCapacityCu);
long totalClusterCapacity = maxPerRouterCapacity * routerCount;
if (Math.max(totalClusterCapacity, maxPerRouterCapacity) < readQuotaInCU.get()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

totalClusterCapacity will always be >= maxPerRouterCapacity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't true for the parent because the router count is 0 and totalClusterCapacity will be 0. We need to take the max of totalClusterCapacity and maxPerRouterCapacity to correctly account for this case

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add some comments, if not it looks like a bug (thats what we though when we encountered this if condition before your change 😆 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - added a comment to explain why we need to take the max of total cluster capacity and per router capacity

props.getBoolean(CONTROLLER_DISABLE_PARENT_REQUEST_TOPIC_FOR_STREAM_PUSHES, false);
this.defaultReadQuotaPerRouter =
props.getInt(CONTROLLER_DEFAULT_READ_QUOTA_PER_ROUTER, DEFAULT_PER_ROUTER_READ_QUOTA);
this.maxRouterReadCapacityCu = props.getLong(MAX_READ_CAPACITY, MAX_ROUTER_READ_CAPACITY_CU);
Copy link
Contributor

Choose a reason for hiding this comment

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

This config needs to be done on both the router and controller from now on?

Also, from router code, I see MAX_READ_CAPACITY with default of 100k and ROUTER_MAX_READ_CAPACITY with default of 6000. how are those different? can we also use the same static variable in router code as well to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it needs to be on both the controller and router from now on so that they share the same value.

ROUTER_MAX_READ_CAPACITY is used as an early throttler before any requests are processed and it will reject the request if the current number of requests for all stores is larger than the configured limit. I believe it's to prevent the router from being overwhelmed from too many requests at once. MAX_READ_CAPACITY is used to distribute the router quota fairly per store and it will decrease each store's quota by a factor if the total store quota is larger than the MAX_READ_CAPACITY value

long maxReadCapacityCu = clusterConfig.getMaxReadCapacityCu();
long maxPerRouterCapacity = Math.max(defaultReadQuotaPerRouter, maxReadCapacityCu);
long totalClusterCapacity = maxPerRouterCapacity * routerCount;
if (Math.max(totalClusterCapacity, maxPerRouterCapacity) < readQuotaInCU.get()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add some comments, if not it looks like a bug (thats what we though when we encountered this if condition before your change 😆 )

@github-actions
Copy link

Hi there. This pull request has been inactive for 30 days. To keep our review queue healthy, we plan to close it in 7 days unless there is new activity. If you are still working on this, please push a commit, leave a comment, or convert it to draft to signal intent. Thank you for your time and contributions.

@github-actions github-actions bot added the stale label Nov 29, 2025
@github-actions
Copy link

github-actions bot commented Dec 6, 2025

Closing this pull request due to 37 days of inactivity. This is not a judgment on the value of the work. If you would like to continue, please reopen or open a new PR and we will be happy to take another look. Thank you again for contributing.

Copilot AI review requested due to automatic review settings February 20, 2026 00:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes quota validation logic in the controller to properly account for the maximum read capacity when approving or rejecting quota change requests. Previously, the controller only validated against a default router capacity, but the correct logic should validate against the maximum router read capacity, which is the same value used by routers for actual throttling.

Changes:

  • Updated quota validation in VeniceHelixAdmin to use max router read capacity instead of default quota per router
  • Consolidated separate controller and router capacity constants into a single shared constant (MAX_ROUTER_READ_CAPACITY_CU)
  • Updated router config default from hardcoded 100,000 to 20,000,000 to align with deployed configurations

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
VeniceHelixAdmin.java Updated quota validation logic to use maxRouterReadCapacityCu and properly handle parent controller edge case (0 live routers)
VeniceControllerClusterConfig.java Replaced defaultReadQuotaPerRouter field with maxRouterReadCapacityCu, reading from MAX_READ_CAPACITY config key
VeniceRouterConfig.java Changed default value from hardcoded 100,000 to MAX_ROUTER_READ_CAPACITY_CU constant (20,000,000)
VeniceConstants.java Renamed DEFAULT_PER_ROUTER_READ_QUOTA to MAX_ROUTER_READ_CAPACITY_CU, updated documentation
TestVeniceHelixAdmin.java Added new test for quota validation with multiple test cases
Test utility files Updated references from old constant to new constant

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ZkRoutersClusterManager routersClusterManager = resources.getRoutersClusterManager();
int routerCount = routersClusterManager.getLiveRoutersCount();
VeniceControllerClusterConfig clusterConfig = resources.getConfig();
long totalClusterReadCapacity = clusterConfig.getMaxRouterReadCapacityCu() * routerCount;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to include server here? Do we have server read capacity estimation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can make the server read capacity estimation as a separate change because it will require ramping and rollout efforts

Copilot AI review requested due to automatic review settings February 20, 2026 22:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +597 to +599
* Configs to specify the default and max per router quota. This is used in {@link VeniceHelixAdmin} to determine whether
* a quota change should be approved or denied and for throttling reads. This value represents the maximum capacity a single
* router can handle
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The comment mentions "default and max per router quota" but after this PR there is only one config (maxRouterReadCapacityCu). The comment should be updated to say "max per router quota" or "per router read capacity" to accurately reflect that this is a single config value representing the maximum capacity.

Suggested change
* Configs to specify the default and max per router quota. This is used in {@link VeniceHelixAdmin} to determine whether
* a quota change should be approved or denied and for throttling reads. This value represents the maximum capacity a single
* router can handle
* Config to specify the max per router read capacity/quota. This is used in {@link VeniceHelixAdmin} to determine whether
* a quota change should be approved or denied and for throttling reads. This value represents the maximum capacity a single
* router can handle.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@majisourav99 majisourav99 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants