@@ -112,12 +112,16 @@ void SessionCredit::receive_credit(
112112
113113 // Floor represent the previous value of ALLOWED counters before grant is applied
114114 // They will only be updated if a valid grant is received
115- buckets_[ALLOWED_FLOOR_TOTAL] =
116- calculate_allowed_floor (gsu.total (), ALLOWED_TOTAL, ALLOWED_FLOOR_TOTAL);
117- buckets_[ALLOWED_FLOOR_TX] =
118- calculate_allowed_floor (gsu.total (), ALLOWED_TX, ALLOWED_FLOOR_TX);
119- buckets_[ALLOWED_FLOOR_RX] =
120- calculate_allowed_floor (gsu.total (), ALLOWED_RX, ALLOWED_FLOOR_RX);
115+ uint64_t delta_allowed_floor_total =
116+ calculate_delta_allowed_floor (gsu.total (), ALLOWED_TOTAL, ALLOWED_FLOOR_TOTAL);
117+ uint64_t delta_allowed_floor_tx =
118+ calculate_delta_allowed_floor (gsu.total (), ALLOWED_TX, ALLOWED_FLOOR_TX);
119+ uint64_t delta_allowed_floor_rx =
120+ calculate_delta_allowed_floor (gsu.total (), ALLOWED_RX, ALLOWED_FLOOR_RX);
121+
122+ buckets_[ALLOWED_FLOOR_TOTAL] += delta_allowed_floor_total;
123+ buckets_[ALLOWED_FLOOR_TX] += delta_allowed_floor_tx;
124+ buckets_[ALLOWED_FLOOR_RX] += delta_allowed_floor_rx;
121125
122126 // Clear invalid values
123127 uint64_t total_volume = gsu.total ().is_valid () ? gsu.total ().volume () : 0 ;
@@ -150,21 +154,27 @@ void SessionCredit::receive_credit(
150154 uc->bucket_deltas [REPORTED_RX] += buckets_[REPORTING_RX];
151155 uc->bucket_deltas [REPORTED_TX] += buckets_[REPORTING_TX];
152156
153- uc->bucket_deltas [ALLOWED_FLOOR_TOTAL] = buckets_[ALLOWED_FLOOR_TOTAL] ;
154- uc->bucket_deltas [ALLOWED_FLOOR_TX] = buckets_[ALLOWED_FLOOR_TX] ;
155- uc->bucket_deltas [ALLOWED_FLOOR_RX] = buckets_[ALLOWED_FLOOR_RX] ;
157+ uc->bucket_deltas [ALLOWED_FLOOR_TOTAL] += delta_allowed_floor_total ;
158+ uc->bucket_deltas [ALLOWED_FLOOR_TX] += delta_allowed_floor_tx ;
159+ uc->bucket_deltas [ALLOWED_FLOOR_RX] += delta_allowed_floor_rx ;
156160 }
157161
158162 reset_reporting_credit (uc);
159163 log_quota_and_usage ();
160164}
161165
162- uint64_t SessionCredit::calculate_allowed_floor (CreditUnit cu, Bucket allowed, Bucket floor){
166+ uint64_t SessionCredit::calculate_delta_allowed_floor (CreditUnit cu, Bucket allowed, Bucket floor){
163167 if (cu.is_valid () && cu.volume () !=0 ) {
164168 // only advance floor when there is a new grant
165- return buckets_[allowed];
169+ if (buckets_[allowed]<buckets_[floor]){
170+ MLOG (MERROR) << " Error in calculate_delta_allowed_floor, "
171+ " floor bigger than allowed "
172+ << buckets_[floor] << " >" << buckets_[allowed];
173+ return 0 ;
174+ }
175+ return buckets_[allowed]-buckets_[floor];
166176 }
167- return buckets_[floor] ;
177+ return 0 ;
168178}
169179
170180bool SessionCredit::is_quota_exhausted (float threshold) const {
0 commit comments