ahuang98 commented on code in PR #19742:
URL: https://github.com/apache/kafka/pull/19742#discussion_r2101157535
##########
core/src/main/scala/kafka/server/ClientQuotaManager.scala:
##########
@@ -451,6 +452,43 @@ class ClientQuotaManager(private val config:
ClientQuotaManagerConfig,
}
}
+ /**
+ * Helper method to update quota types counts and quotaTypesEnabled flag.
+ * @param quotaTypeKey The QuotaTypes constant (e.g.,
QuotaTypes.UserClientIdQuotaEnabled)
+ * @param increment True to increment count, false to decrement
+ */
+ private def updateQuotaTypes(quotaTypeKey: Int, increment: Boolean): Unit = {
+ if (quotaTypeKey == QuotaTypes.NoQuotas) {
+ return
+ }
+ val previousQuotaTypesEnabled = quotaTypesEnabled
+
+ // Update activeQuotaTypes counts
+ activeQuotaTypes.compute(quotaTypeKey, (_, count) =>
+ if (increment) Option(count).getOrElse(0) + 1
+ else if (Option(count).exists(_ > 1)) count - 1
+ else 0
+ )
+
+ // Update quotaTypesEnabled based on activeQuotaTypes counts
+ quotaTypesEnabled = clientQuotaCallbackPlugin match {
+ case Some(_) => QuotaTypes.CustomQuotas
+ case None =>
+ var newQuotaTypes = QuotaTypes.NoQuotas
+ if (activeQuotaTypes.getOrDefault(QuotaTypes.UserClientIdQuotaEnabled,
0) > 0)
+ newQuotaTypes |= QuotaTypes.UserClientIdQuotaEnabled
+ if (activeQuotaTypes.getOrDefault(QuotaTypes.UserQuotaEnabled, 0) > 0)
+ newQuotaTypes |= QuotaTypes.UserQuotaEnabled
+ if (activeQuotaTypes.getOrDefault(QuotaTypes.ClientIdQuotaEnabled, 0)
> 0)
+ newQuotaTypes |= QuotaTypes.ClientIdQuotaEnabled
+ newQuotaTypes
+ }
+
+ if (previousQuotaTypesEnabled != quotaTypesEnabled) {
+ debug(s"Quota types enabled changed from $previousQuotaTypesEnabled to
$quotaTypesEnabled")
Review Comment:
let's say we have positive counts for QuotaTypes.UserClientIdQuotaEnabled
and QuotaTypes.UserQuotaEnabled, when we print the `quotaTypesEnabled` we would
expect to see `6` printed? perhaps out of scope for this change, but it would
definitely be more friendly if the specific quotas enabled were printed instead.
--
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]