Jackie-Jiang commented on code in PR #14894: URL: https://github.com/apache/pinot/pull/14894#discussion_r1931285359
########## pinot-spi/src/main/java/org/apache/pinot/spi/config/provider/PinotClusterConfigProvider.java: ########## @@ -0,0 +1,81 @@ +/** + * 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.spi.config.provider; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.commons.collections.MapUtils; + + +/** + * Interface for ZK cluster config providers. Will be registered with Helix to listen on cluster config changes and + * will propagate changes to all registered listeners + */ +public interface PinotClusterConfigProvider { + /** + * Get the cluster configs + * @return map of cluster configs + */ + Map<String, String> getClusterConfigs(); + + /** + * Register cluster config change listener + * @param clusterConfigChangeListener change listener to be registered to obtain cluster config changes + * @return returns 'true' if the registration was successful + */ + boolean registerClusterConfigChangeListener(PinotClusterConfigChangeListener clusterConfigChangeListener); + + /** + * Calculates the set of keys that changed in ZK cluster configs between the old and new + * @param oldProperties map of previously cached ZK cluster configs + * @param newProperties map of newly fetched ZK cluster configs + * @return set of changed (added/deleted/updated) cluster config keys + */ + default Set<String> getChangedProperties(@Nullable Map<String, String> oldProperties, + @Nullable Map<String, String> newProperties) { + if (MapUtils.isEmpty(oldProperties)) { + return newProperties == null ? Collections.emptySet() : newProperties.keySet(); + } + + if (MapUtils.isEmpty(newProperties)) { + return oldProperties.keySet(); + } + + Set<String> changedProperties = new HashSet<>(); + // Add all properties that are newly added or whose value changed + for (Map.Entry<String, String> entry : newProperties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (!value.equals(oldProperties.get(key))) { + changedProperties.add(key); + } + } + + // Add all properties that were deleted + Set<String> originalPropertyKeys = new HashSet<>(); + originalPropertyKeys.addAll(oldProperties.keySet()); Review Comment: (minor) ```suggestion Set<String> originalPropertyKeys = new HashSet<>(oldProperties.keySet()); ``` ########## pinot-spi/src/main/java/org/apache/pinot/spi/config/provider/PinotClusterConfigProvider.java: ########## @@ -0,0 +1,81 @@ +/** + * 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.spi.config.provider; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.commons.collections.MapUtils; + + +/** + * Interface for ZK cluster config providers. Will be registered with Helix to listen on cluster config changes and + * will propagate changes to all registered listeners + */ +public interface PinotClusterConfigProvider { + /** + * Get the cluster configs + * @return map of cluster configs + */ + Map<String, String> getClusterConfigs(); + + /** + * Register cluster config change listener + * @param clusterConfigChangeListener change listener to be registered to obtain cluster config changes + * @return returns 'true' if the registration was successful + */ + boolean registerClusterConfigChangeListener(PinotClusterConfigChangeListener clusterConfigChangeListener); + + /** + * Calculates the set of keys that changed in ZK cluster configs between the old and new + * @param oldProperties map of previously cached ZK cluster configs + * @param newProperties map of newly fetched ZK cluster configs + * @return set of changed (added/deleted/updated) cluster config keys + */ + default Set<String> getChangedProperties(@Nullable Map<String, String> oldProperties, + @Nullable Map<String, String> newProperties) { Review Comment: (minor) Checking the usage, both `oldProperties` and `newProperties` are always not null. We can probably remove the null annotation and handling ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java: ########## @@ -0,0 +1,226 @@ +/** + * 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.segment.local.utils; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.util.Map; +import java.util.Set; +import org.apache.commons.collections.CollectionUtils; +import org.apache.pinot.common.concurrency.AdjustableSemaphore; +import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Used to throttle the total concurrent index rebuilds that can happen on a given Pinot server. + * Code paths that do no need to rebuild the index or which don't happen on the server need not utilize this throttler. + */ +public class SegmentPreprocessThrottler implements PinotClusterConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentPreprocessThrottler.class); + + /** + * _maxPreprocessConcurrency and _maxConcurrentPreprocessesBeforeServingQueries must be >= 0. To effectively disable Review Comment: (minor) ```suggestion * _maxPreprocessConcurrency and _maxConcurrentPreprocessesBeforeServingQueries must be > 0. To effectively disable ``` ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java: ########## @@ -0,0 +1,226 @@ +/** + * 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.segment.local.utils; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.util.Map; +import java.util.Set; +import org.apache.commons.collections.CollectionUtils; +import org.apache.pinot.common.concurrency.AdjustableSemaphore; +import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Used to throttle the total concurrent index rebuilds that can happen on a given Pinot server. + * Code paths that do no need to rebuild the index or which don't happen on the server need not utilize this throttler. + */ +public class SegmentPreprocessThrottler implements PinotClusterConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentPreprocessThrottler.class); + + /** + * _maxPreprocessConcurrency and _maxConcurrentPreprocessesBeforeServingQueries must be >= 0. To effectively disable + * throttling, this can be set to a very high value + */ + private int _maxPreprocessConcurrency; + private int _maxPreprocessConcurrencyBeforeServingQueries; + private boolean _isServingQueries; + private final AdjustableSemaphore _semaphore; + + /** + * @param maxPreprocessConcurrency configured preprocessing concurrency + * @param maxPreprocessConcurrencyBeforeServingQueries configured preprocessing concurrency before serving queries + * @param isServingQueries whether the server is ready to serve queries or not + */ + public SegmentPreprocessThrottler(int maxPreprocessConcurrency, int maxPreprocessConcurrencyBeforeServingQueries, + boolean isServingQueries) { + LOGGER.info("Initializing SegmentPreprocessThrottler, maxPreprocessConcurrency: {}, " + + "maxPreprocessConcurrencyBeforeServingQueries: {}, isServingQueries: {}", + maxPreprocessConcurrency, maxPreprocessConcurrencyBeforeServingQueries, isServingQueries); + Preconditions.checkArgument(maxPreprocessConcurrency > 0, + "Max preprocess parallelism must be > 0, but found to be: " + maxPreprocessConcurrency); + Preconditions.checkArgument(maxPreprocessConcurrencyBeforeServingQueries > 0, + "Max preprocess parallelism before serving queries must be > 0, but found to be: " + + maxPreprocessConcurrencyBeforeServingQueries); + + _maxPreprocessConcurrency = maxPreprocessConcurrency; + _maxPreprocessConcurrencyBeforeServingQueries = maxPreprocessConcurrencyBeforeServingQueries; + _isServingQueries = isServingQueries; + + // maxConcurrentPreprocessesBeforeServingQueries is only used prior to serving queries and once the server is + // ready to serve queries this is not used again. Thus, it is safe to only pick up this configuration during + // server startup. There is no need to allow updates to this via the ZK CLUSTER config handler Review Comment: This comment no longer apply ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java: ########## @@ -0,0 +1,226 @@ +/** + * 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.segment.local.utils; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.util.Map; +import java.util.Set; +import org.apache.commons.collections.CollectionUtils; +import org.apache.pinot.common.concurrency.AdjustableSemaphore; +import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Used to throttle the total concurrent index rebuilds that can happen on a given Pinot server. + * Code paths that do no need to rebuild the index or which don't happen on the server need not utilize this throttler. + */ +public class SegmentPreprocessThrottler implements PinotClusterConfigChangeListener { + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentPreprocessThrottler.class); + + /** + * _maxPreprocessConcurrency and _maxConcurrentPreprocessesBeforeServingQueries must be >= 0. To effectively disable + * throttling, this can be set to a very high value + */ + private int _maxPreprocessConcurrency; + private int _maxPreprocessConcurrencyBeforeServingQueries; + private boolean _isServingQueries; + private final AdjustableSemaphore _semaphore; + + /** + * @param maxPreprocessConcurrency configured preprocessing concurrency + * @param maxPreprocessConcurrencyBeforeServingQueries configured preprocessing concurrency before serving queries + * @param isServingQueries whether the server is ready to serve queries or not + */ + public SegmentPreprocessThrottler(int maxPreprocessConcurrency, int maxPreprocessConcurrencyBeforeServingQueries, + boolean isServingQueries) { + LOGGER.info("Initializing SegmentPreprocessThrottler, maxPreprocessConcurrency: {}, " + + "maxPreprocessConcurrencyBeforeServingQueries: {}, isServingQueries: {}", + maxPreprocessConcurrency, maxPreprocessConcurrencyBeforeServingQueries, isServingQueries); + Preconditions.checkArgument(maxPreprocessConcurrency > 0, + "Max preprocess parallelism must be > 0, but found to be: " + maxPreprocessConcurrency); + Preconditions.checkArgument(maxPreprocessConcurrencyBeforeServingQueries > 0, + "Max preprocess parallelism before serving queries must be > 0, but found to be: " + + maxPreprocessConcurrencyBeforeServingQueries); + + _maxPreprocessConcurrency = maxPreprocessConcurrency; + _maxPreprocessConcurrencyBeforeServingQueries = maxPreprocessConcurrencyBeforeServingQueries; + _isServingQueries = isServingQueries; + + // maxConcurrentPreprocessesBeforeServingQueries is only used prior to serving queries and once the server is + // ready to serve queries this is not used again. Thus, it is safe to only pick up this configuration during + // server startup. There is no need to allow updates to this via the ZK CLUSTER config handler + int preServeQueryParallelism = Math.max(_maxPreprocessConcurrency, _maxPreprocessConcurrencyBeforeServingQueries); Review Comment: We probably don't want this max logic. It doesn't align with logic in `handleMaxPreprocessConcurrencyBeforeServingQueriesChange()` -- 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]
