ohnoitsyou commented on code in PR #11903:
URL: https://github.com/apache/nifi/pull/11903#discussion_r4602370557


##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ControlRate.java:
##########
@@ -418,26 +415,33 @@ private void clearExpiredThrottles(final ProcessContext 
context) {
         final long throttleExpirationMillis = getCurrentTimeMillis() - 2 * 
context.getProperty(TIME_PERIOD).asTimePeriod(TimeUnit.MILLISECONDS);
         if (lastClearTime < throttleExpirationMillis) {
             if (lastThrottleClearTime.compareAndSet(lastClearTime, 
getCurrentTimeMillis())) {
-                final Set<Map.Entry<String, Throttle>> throttleSet = new 
HashSet<>();
                 if (dataThrottleRequired()) {
-                    throttleSet.addAll(dataThrottleMap.entrySet());
+                    filterThrottleMap(dataThrottleMap, lastClearTime);
                 }
                 if (countThrottleRequired()) {
-                    throttleSet.addAll(countThrottleMap.entrySet());
+                    filterThrottleMap(countThrottleMap, lastClearTime);
                 }
-                final Iterator<Map.Entry<String, Throttle>> itr = 
throttleSet.iterator();
-                while (itr.hasNext()) {
-                    final Map.Entry<String, Throttle> entry = itr.next();
-                    final Throttle throttle = entry.getValue();
-                    if (throttle.tryLock()) {
-                        try {
-                            if (throttle.lastUpdateTime() < lastClearTime) {
-                                itr.remove();
-                            }
-                        } finally {
-                            throttle.unlock();
-                        }
+            }
+        }
+    }
+
+    /**
+     * Loop over the entries in a throttleMap and clear out any that have a 
lastUpdateTime less than lastClearTime
+     * @param throttleMap the throttleMap to be filtered
+     * @param lastClearTime threshold of lastUpdateTime of the throttle 
entries in the map
+     */
+    private void filterThrottleMap(final ConcurrentMap<String, Throttle> 
throttleMap, final long lastClearTime) {
+        final Iterator<Map.Entry<String, Throttle>> itr = 
throttleMap.entrySet().iterator();
+        while (itr.hasNext()) {
+            final Map.Entry<String, Throttle> entry = itr.next();
+            final Throttle throttle = entry.getValue();
+            if (throttle.tryLock()) {
+                try {
+                    if (throttle.lastUpdateTime() < lastClearTime) {
+                        itr.remove();

Review Comment:
   I'll see what I can work up!



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

Reply via email to