mqliang commented on code in PR #14536: URL: https://github.com/apache/pinot/pull/14536#discussion_r1905923300
########## pinot-controller/src/main/java/org/apache/pinot/controller/util/ServerQueryInfoFetcher.java: ########## @@ -0,0 +1,131 @@ +/** + * 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.controller.util; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.helix.model.InstanceConfig; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.pinot.controller.helix.core.PinotHelixResourceManager; +import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.InstanceTypeUtils; + + +/** + * This is a helper class that fetch server information from Helix/ZK. It caches the server information to avoid + * repeated ZK access. This class is NOT thread-safe. + */ +public class ServerQueryInfoFetcher { + private PinotHelixResourceManager _pinotHelixResourceManager; + private Map<String, ServerQueryInfo> _cache; + + public ServerQueryInfoFetcher(PinotHelixResourceManager pinotHelixResourceManager) { + _pinotHelixResourceManager = pinotHelixResourceManager; + _cache = new HashMap<>(); + } + + public ServerQueryInfo getServerQueryInfo(String instanceId) { + return _cache.computeIfAbsent(instanceId, this::getServerQueryInfoOndemand); + } + + private ServerQueryInfo getServerQueryInfoOndemand(String instanceId) { Review Comment: done ########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/SegmentStatusChecker.java: ########## @@ -330,46 +336,49 @@ private void updateSegmentMetrics(String tableNameWithType, TableConfig tableCon } } - int numEVReplicas = 0; + int numEVReplicasUp = 0; if (externalView != null) { Map<String, String> stateMap = externalView.getStateMap(segment); if (stateMap != null) { for (Map.Entry<String, String> entry : stateMap.entrySet()) { - String state = entry.getValue(); - if (state.equals(SegmentStateModel.ONLINE) || state.equals(SegmentStateModel.CONSUMING)) { - numEVReplicas++; + String serverInstanceId = entry.getKey(); + String segmentState = entry.getValue(); + if (isServerQueryable(serverQueryInfoFetcher.getServerQueryInfo(serverInstanceId)) Review Comment: done -- 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