splett2 commented on a change in pull request #9386:
URL: https://github.com/apache/kafka/pull/9386#discussion_r519054824



##########
File path: core/src/main/scala/kafka/network/SocketServer.scala
##########
@@ -1659,19 +1648,22 @@ class ConnectionQuotas(config: KafkaConfig, time: Time, 
metrics: Metrics) extend
    * @param connectionQuotaEntity entity to create the sensor for
    */
   private def getOrCreateConnectionRateQuotaSensor(quotaLimit: Int, 
connectionQuotaEntity: ConnectionQuotaEntity): Sensor = {
-    sensorAccessor.getOrCreate(
-      connectionQuotaEntity.sensorName,
-      connectionQuotaEntity.sensorExpiration,
-      sensor => sensor.add(connectionRateMetricName(connectionQuotaEntity), 
new Rate, rateQuotaMetricConfig(quotaLimit))
-    )
+    Option(metrics.getSensor(connectionQuotaEntity.sensorName)).getOrElse {
+      val sensor = metrics.sensor(
+        connectionQuotaEntity.sensorName,
+        rateQuotaMetricConfig(quotaLimit),
+        connectionQuotaEntity.sensorExpiration
+      )
+      sensor.add(connectionRateMetricName(connectionQuotaEntity), new Rate, 
null)
+      sensor
+    }

Review comment:
       I removed use of `sensorAccess`, since all calls to 
`sensorAccessor.getOrCreate` were performed with the `counts` lock, so the 
read-write lock is redundant.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to