shounakmk219 commented on code in PR #13544: URL: https://github.com/apache/pinot/pull/13544#discussion_r1701123366
########## pinot-broker/src/main/java/org/apache/pinot/broker/queryquota/HelixExternalViewBasedQueryQuotaManager.java: ########## @@ -230,6 +253,114 @@ private void createOrUpdateRateLimiter(String tableNameWithType, ExternalView br } } + /** + * Updates the database rate limiter if it already exists. Will not create a new database rate limiter. + * @param databaseName database name for which rate limiter needs to be updated + */ + public void updateDatabaseRateLimiter(String databaseName) { + if (!_databaseRateLimiterMap.containsKey(databaseName)) { + return; + } + createOrUpdateDatabaseRateLimiter(Collections.singletonList(databaseName)); + } + + public synchronized void createOrUpdateDatabaseRateLimiter(List<String> databaseNames) { + ExternalView brokerResource = HelixHelper + .getExternalViewForResource(_helixManager.getClusterManagmentTool(), _helixManager.getClusterName(), + CommonConstants.Helix.BROKER_RESOURCE_INSTANCE); + for (String databaseName : databaseNames) { + double databaseQpsQuota = getEffectiveQueryQuotaOnDatabase(databaseName); + if (databaseQpsQuota < 0) { + buildEmptyOrResetDatabaseRateLimiter(databaseName); + continue; + } + int quotaSplitFactor = getPerBrokerQpsQuotaSplit(databaseName, brokerResource); + double perBrokerQpsQuota = databaseQpsQuota / quotaSplitFactor; + QueryQuotaEntity oldRateLimiter = _databaseRateLimiterMap.get(databaseName); + String message; + if (oldRateLimiter == null) { + message = String.format("New query rate limiter added for database %s with rate %s.", databaseName, + perBrokerQpsQuota); + } else { + boolean changeDetected = false; + double oldRate = oldRateLimiter.getRateLimiter() != null ? oldRateLimiter.getRateLimiter().getRate() : -1; + message = String.format("Updated existing query rate limiter for database %s from rate %s to %s", databaseName, + oldRate, perBrokerQpsQuota); + if (oldRateLimiter.getOverallRate() != databaseQpsQuota) { + changeDetected = true; + message += ". Overall quota changed for the database from " + oldRateLimiter.getOverallRate() + " to " + + databaseQpsQuota; + } + if (oldRateLimiter.getNumOnlineBrokers() != quotaSplitFactor) { + changeDetected = true; + message += ". Quota split factor changed for the database from " + oldRateLimiter.getOverallRate() + " to " + + quotaSplitFactor; + } + if (!changeDetected) { + LOGGER.info("No change detected with the query rate limiter for database {}", databaseName); + return; Review Comment: My bad, will add a UT. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org