saurabhd336 commented on code in PR #8467:
URL: https://github.com/apache/pinot/pull/8467#discussion_r851237004


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/BrokerCacheUpdaterPeriodic.java:
##########
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.client;
+
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Maintains broker cache this is updated periodically
+ */
+public class BrokerCacheUpdaterPeriodic implements UpdatableBrokerCache {
+  private final BrokerCache _brokerCache;
+  private final ScheduledExecutorService _scheduledExecutorService;
+  private final long _brokerUpdateFreqInMillis;
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(BrokerCacheUpdaterPeriodic.class);
+
+  public BrokerCacheUpdaterPeriodic(String scheme, String controllerHost,
+      int controllerPort, long brokerUpdateFreqInMillis) {
+    _brokerCache = new BrokerCache(scheme, controllerHost, controllerPort);
+    _scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
+    _brokerUpdateFreqInMillis = brokerUpdateFreqInMillis;
+  }
+
+  public void init() {
+    try {
+      _brokerCache.updateBrokerData();
+      _scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
+        @Override
+        public void run() {
+          try {
+            _brokerCache.updateBrokerData();
+          } catch (Exception e) {
+            LOGGER.error("Broker cache update failed", e);
+          }
+        }
+      }, 0, _brokerUpdateFreqInMillis, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      LOGGER.error("Broker cache update failed", e);

Review Comment:
   Ack. Yes _brokerCache.updateBrokerData() is called in sync first, followed 
by a scheduled task being submitted to the executor to run it periodically. 
WIll wrap the exception in an `InitializationException` and throw here.



##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ControllerBasedBrokerSelector.java:
##########
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.pinot.client;
+
+import java.util.List;
+
+
+/**
+ * Maintains broker cache using controller APIs
+ */
+public class ControllerBasedBrokerSelector implements BrokerSelector {
+    private final UpdatableBrokerCache _brokerCache;

Review Comment:
   Ack



-- 
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: commits-unsubscr...@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to