belliottsmith commented on code in PR #4895:
URL: https://github.com/apache/cassandra/pull/4895#discussion_r3578239804


##########
src/java/org/apache/cassandra/metrics/ThreadLocalMetrics.java:
##########
@@ -374,26 +373,108 @@ static void recycleMetricId(int metricId)
             lock.unlock();
         }
 
-        // there's no an obvious happens-before relation between 
currentCounterValues[metricId] = 0 write we just did
-        // and an initial read of the entry by a thread which updates the 
reused metric
-        // as a workaround we introduce a delay in recyling to provide the 
write visibility in practice
-        //  even if it is not formally guaranteed by the JMM
-        ScheduledExecutors.scheduledTasks.schedule(() -> {
+        freeMetricIdSetTracker.markAsFree(metricId);
+    }
+
+    @VisibleForTesting
+    static class FreeMetricIdSetTracker
+    {
+
+        private final Object freeMetricIdSetGuard = new Object();
+
+        private final BitSet freeMetricIdSet = new BitSet();
+
+        private final BitSet tickDelayedToFreeMetricIdSet = new BitSet();
+        private final BitSet tockDelayedToFreeMetricIdSet = new BitSet();
+
+        private BitSet delayedToFreeMetricIdSet = tickDelayedToFreeMetricIdSet;
+        private volatile boolean anythingToFree;
+
+        FreeMetricIdSetTracker()
+        {
+            this(true);
+        }
+
+        @VisibleForTesting
+        FreeMetricIdSetTracker(boolean scheduleTask)
+        {
+            if (scheduleTask)
+                
ScheduledExecutors.scheduledTasks.scheduleAtFixedRate(this::triggerRecycling, 
5, 5, TimeUnit.SECONDS);

Review Comment:
   This is fine, but I generally prefer to only schedule when there is work to 
do, which we can manage with a simple boolean or Future representing whether 
work is scheduled, that we clear before we begin undertaking the recycling work?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to