xiangfu0 commented on code in PR #8467: URL: https://github.com/apache/pinot/pull/8467#discussion_r850918760
########## pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/UpdatableBrokerCache.java: ########## @@ -0,0 +1,34 @@ +/** + * 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; + + +public interface UpdatableBrokerCache { Review Comment: Can you add some java docs? ########## pinot-spi/pom.xml: ########## @@ -149,6 +149,20 @@ <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> Review Comment: Shall we move [HttpClient](https://github.com/apache/pinot/blob/master/pinot-common/src/main/java/org/apache/pinot/common/utils/http/HttpClient.java) to `pinot-spi` and reuse this instead of having a new HTTP client? ########## pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/UpdatableBrokerCache.java: ########## @@ -0,0 +1,34 @@ +/** + * 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; + + +public interface UpdatableBrokerCache { + void init(); + + String getBroker(String tableName); + + List<String> getBrokers(); Review Comment: What is this used for? feel `List<String> getBrokers(String tableName);` might be more useful. ########## 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: I think you intent to run this method: `_brokerCache.updateBrokerData();` once during `init()` phase then schedule the background thread. If that is the case, this catch should throw the exception so the client-side should get the error if the initialization is failed. -- 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