mqliang commented on code in PR #14536: URL: https://github.com/apache/pinot/pull/14536#discussion_r1905939467
########## 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) { + InstanceConfig instanceConfig = _pinotHelixResourceManager.getHelixInstanceConfig(instanceId); + if (instanceConfig == null || !InstanceTypeUtils.isServer(instanceId)) { + return null; + } + List<String> tags = instanceConfig.getTags(); + ZNRecord record = instanceConfig.getRecord(); + boolean helixEnabled = record.getBooleanField( + InstanceConfig.InstanceConfigProperty.HELIX_ENABLED.name(), false); Review Comment: > Use instanceConfig.getInstanceEnabled(). done > We can simplify the ServerQueryInfo to combine all 3 booleans, and call it queryEnabled Although in this PR it's OK to combine all the 3 boolean into a single one, it's better to keep them separate. We may will have a PR to emit a metric about "how many or how many percentage of servers for a table that were marked as `QUERIES_DISABLED`". We has some situation where some server been configured as `QUERIES_DISABLED` during debugging/testing but we forget to recover the config and it cause problem some time later, so we may need emit a metric for that specifically. -- 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