apache / apache/pulsar

[improve code]Optimize the method computeLocalQuota() in ResourceQuotaCalculatorImpl class

Open
#18,586 1 comment 0 reactions 0 assignees View on GitHub
Stale
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Motivation

To optimize the method computeLocalQuota() in ResourceQuotaCalculatorImpl class. We can move `confUsage` before the `totalUsage`.
Please refer to [if (confUsage < 0) {](https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceQuotaCalculatorImpl.java#L40)

### Solution

We can move `confUsage` before the `totalUsage`.

e.g.
```
if (confUsage < 0) {
// This can happen if the RG is not configured with this particular limit (message or byte count) yet.
val retVal = -1;
if (log.isDebugEnabled()) {
log.debug("Configured usage ({}) is not set; returning a special value ({}) for calculated quota",
confUsage, retVal);
}
return retVal;
}

long totalUsage = 0;

for (long usage : allUsages) {
totalUsage += usage;
}
```

### Alternatives

N/A

### Anything else?

N/A

### Are you willing to submit a PR?

- [X] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start by reading pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceQuotaCalculatorImpl.java, focusing on computeLocalQuota() and the linked confUsage check. Done means the confUsage check occurs before totalUsage is calculated, while the existing special return and debug logging behavior remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, distributed-systems
Issue type
Refactor
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.