sajjad-moradi commented on a change in pull request #6291:
URL: https://github.com/apache/pinot/pull/6291#discussion_r795905532



##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeConsumptionRateManager.java
##########
@@ -42,25 +43,35 @@
  */
 public class RealtimeConsumptionRateManager {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(RealtimeConsumptionRateManager.class);
-  private static final RealtimeConsumptionRateManager INSTANCE = new 
RealtimeConsumptionRateManager();
   private static final int CACHE_ENTRY_EXPIRATION_TIME_IN_MINUTES = 10;
 
+  private static volatile RealtimeConsumptionRateManager INSTANCE;
+
   // stream config object is required for fetching the partition count from 
the stream
-  private final LoadingCache<StreamConfig, Integer> 
_streamConfigToTopicPartitionCountMap = buildCache();
+  private final LoadingCache<StreamConfig, Integer> 
_streamConfigToTopicPartitionCountMap;
   private volatile boolean _isThrottlingAllowed = false;
 
-  private RealtimeConsumptionRateManager() {
+  @VisibleForTesting
+  RealtimeConsumptionRateManager(LoadingCache<StreamConfig, Integer> 
streamConfigToTopicPartitionCountMap) {
+    _streamConfigToTopicPartitionCountMap = 
streamConfigToTopicPartitionCountMap;
   }
 
   public static RealtimeConsumptionRateManager getInstance() {
+    if (INSTANCE == null) {

Review comment:
       Performance is not an issue here because getting an instance is not in a 
critical execution path (it gets called every few hours or so). For 
readability, I thought using double checked singleton reads better, but after I 
changed it to a holder class, it looks more concise. 
   




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