private void checkRateLimit ( String quotaKey , Tracked trackedOp ) { String quotaValue = null ; try { if ( ! metadataStore . getQuotaEnforcingEnabledUnlocked ( ) ) { return ; } quotaValue = quotaStore . cacheGet ( quotaKey ) ; // Store may not have any quotas if ( quotaValue == null ) { return ; } // But, if it does float currentRate = getThroughput ( trackedOp ) ; float allowedRate = Float . parseFloat ( quotaValue ) ; // TODO the histogram should be reasonably accurate to do all // these things.. (ghost qps and all) // Report the current quota usage level quotaStats . reportQuotaUsed ( trackedOp , Utils . safeGetPercentage ( currentRate , allowedRate ) ) ; // check if we have exceeded rate. if ( currentRate > allowedRate ) { quotaStats . reportRateLimitedOp ( trackedOp ) ; throw new QuotaExceededException ( "Exceeded rate limit for " + quotaKey + ". Maximum allowed : " + allowedRate + " Current: " + currentRate ) ; } } catch ( NumberFormatException nfe ) { // move on, if we cannot parse quota value properly logger . debug ( "Invalid formatting of quota value for key " + quotaKey + " : " + quotaValue ) ; } }
Ensure the current throughput levels for the tracked operation does not exceed set quota limits . Throws an exception if exceeded quota .