github-actions[bot] commented on code in PR #65420:
URL: https://github.com/apache/doris/pull/65420#discussion_r3595009331
##########
common/cpp/token_bucket_rate_limiter.cpp:
##########
@@ -127,30 +127,35 @@ int64_t TokenBucketRateLimiter::add(size_t amount) {
TokenBucketRateLimiterHolder::TokenBucketRateLimiterHolder(size_t max_speed,
size_t max_burst,
size_t limit,
std::function<void(int64_t)> metric_func)
- : rate_limiter(std::make_unique<TokenBucketRateLimiter>(max_speed,
max_burst, limit)),
+ : rate_limiter(std::make_shared<TokenBucketRateLimiter>(max_speed,
max_burst, limit)),
+ _enabled(max_speed > 0 || limit > 0),
metric_func(std::move(metric_func)) {}
int64_t TokenBucketRateLimiterHolder::add(size_t amount) {
return add_with_config(amount).sleep_duration;
}
TokenBucketRateLimiterResult
TokenBucketRateLimiterHolder::add_with_config(size_t amount) {
- TokenBucketRateLimiterResult result;
+ std::shared_ptr<TokenBucketRateLimiter> limiter;
{
std::shared_lock read {rate_limiter_rw_lock};
- result = {.sleep_duration = rate_limiter->add(amount),
- .max_speed = rate_limiter->get_max_speed(),
- .max_burst = rate_limiter->get_max_burst(),
- .limit = rate_limiter->get_limit()};
+ limiter = rate_limiter;
}
Review Comment:
[P1] Preserve one rate/debt timeline across reset.
`TokenBucketRateLimiter::add()` debits the bucket and then sleeps, but this now
drops the holder lock before calling it. If requests are sleeping when a
periodic/config callback lowers the rate, `reset()` publishes a fresh full
bucket and returns while those retired waiters still wake on the old schedule;
new requests consume the new bucket concurrently, so process traffic can exceed
the newly configured cap. This also affects meta-service RPC and recycler
resets that share this holder. Please carry outstanding debt/reservations into
the replacement or gate the new generation until retired admissions drain
without holding the mutex during sleep, and add a barrier-based
reset-with-waiters test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]