Jackie-Jiang commented on code in PR #14894:
URL: https://github.com/apache/pinot/pull/14894#discussion_r1926149292
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentLoader.java:
##########
@@ -81,44 +82,48 @@ public static ImmutableSegment load(File indexDir, ReadMode
readMode, TableConfi
throws Exception {
IndexLoadingConfig defaultIndexLoadingConfig = new
IndexLoadingConfig(tableConfig, schema);
defaultIndexLoadingConfig.setReadMode(readMode);
- return load(indexDir, defaultIndexLoadingConfig, false);
+ return load(indexDir, defaultIndexLoadingConfig, false, null);
}
/**
* Loads the segment with specified IndexLoadingConfig.
* This method modifies the segment like to convert segment format, add or
remove indices.
* Mostly used by UT cases to add some specific index for testing purpose.
*/
- public static ImmutableSegment load(File indexDir, IndexLoadingConfig
indexLoadingConfig)
+ public static ImmutableSegment load(File indexDir, IndexLoadingConfig
indexLoadingConfig,
+ SegmentPreprocessThrottler segmentPreprocessThrottler)
Review Comment:
Annotate it as `@Nullable`, same for other methods
##########
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/DefaultClusterConfigChangeHandler.java:
##########
@@ -0,0 +1,86 @@
+/**
+ * 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.server.starter.helix;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.helix.HelixManager;
+import org.apache.helix.HelixManagerFactory;
+import org.apache.helix.InstanceType;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.BatchMode;
+import org.apache.helix.api.listeners.ClusterConfigChangeListener;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@BatchMode(enabled = false)
+public class DefaultClusterConfigChangeHandler implements
ClusterConfigChangeListener, PinotClusterConfigProvider {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(DefaultClusterConfigChangeHandler.class);
+
+ private volatile Map<String, String> _properties;
+ private final Set<PinotClusterConfigChangeListener>
_clusterConfigChangeListeners = ConcurrentHashMap.newKeySet();
+
+ public void init(String zkAddress, String clusterName) {
+ LOGGER.info("Handling Cluster ConfigChanges: INIT START");
+ try {
+ HelixManager helixManager =
+ HelixManagerFactory.getZKHelixManager(clusterName, "admin",
InstanceType.ADMINISTRATOR, zkAddress);
+ helixManager.connect();
+ ClusterConfig clusterConfig =
helixManager.getConfigAccessor().getClusterConfig(clusterName);
+ process(clusterConfig.getRecord().getSimpleFields());
+ helixManager.disconnect();
+ } catch (Exception e) {
+ LOGGER.error("Exception while initializing
DefaultClusterConfigChangeHandler for zk: {} and clusterName: {}",
+ zkAddress, clusterName, e);
+ }
+ LOGGER.info("Handling Cluster ConfigChanges: INIT END");
+ }
+
+ @Override
+ public void onClusterConfigChange(ClusterConfig clusterConfig,
NotificationContext notificationContext) {
+ LOGGER.info("Handling Cluster ConfigChanges: CALLBACK START");
+ process(clusterConfig.getRecord().getSimpleFields());
+ LOGGER.info("Handling Cluster ConfigChanges: CALLBACK DONE");
+ }
+
+ private void process(Map<String, String> properties) {
Review Comment:
We probably want to synchronize this to avoid race condition in listener
##########
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/DefaultClusterConfigChangeHandler.java:
##########
@@ -0,0 +1,86 @@
+/**
+ * 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.server.starter.helix;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.helix.HelixManager;
+import org.apache.helix.HelixManagerFactory;
+import org.apache.helix.InstanceType;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.BatchMode;
+import org.apache.helix.api.listeners.ClusterConfigChangeListener;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@BatchMode(enabled = false)
+public class DefaultClusterConfigChangeHandler implements
ClusterConfigChangeListener, PinotClusterConfigProvider {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(DefaultClusterConfigChangeHandler.class);
+
+ private volatile Map<String, String> _properties;
+ private final Set<PinotClusterConfigChangeListener>
_clusterConfigChangeListeners = ConcurrentHashMap.newKeySet();
+
+ public void init(String zkAddress, String clusterName) {
+ LOGGER.info("Handling Cluster ConfigChanges: INIT START");
+ try {
Review Comment:
This shouldn't be required. When registering this handler, there should be a
Helix callback to set up the configs
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/provider/PinotClusterConfigChangeListener.java:
##########
@@ -0,0 +1,26 @@
+/**
+ * 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.Map;
+
+
+public interface PinotClusterConfigChangeListener {
+ void onChange(Map<String, String> clusterConfigs);
Review Comment:
Add some javadoc for interfaces
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java:
##########
@@ -0,0 +1,139 @@
+/**
+ * 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 java.util.Map;
+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);
+
+ /**
+ * If _maxPreprocessConcurrency is <= 0, it means that the cluster is not
configured to limit the number of
+ * index rebuilds that can be executed concurrently. This class sets the
semaphore permit to be a large value
+ * in this scenario.
+ */
+ private int _maxPreprocessConcurrency;
+ private boolean _relaxThrottling;
+ private volatile AdjustableSemaphore _semaphore;
+
+ public SegmentPreprocessThrottler(int maxPreprocessConcurrency, boolean
relaxThrottling) {
+ LOGGER.info("Initializing SegmentPreprocessThrottler,
maxPreprocessConcurrency: {}, relaxThrottling: {}",
+ maxPreprocessConcurrency, relaxThrottling);
+ if (maxPreprocessConcurrency <= 0) {
+ int defaultSegmentPreprocessParallelism =
+
Integer.parseInt(CommonConstants.Helix.DEFAULT_MAX_SEGMENT_PREPROCESS_PARALLELISM);
+ LOGGER.warn("Max preprocess concurrency is negative: {}, resetting to
{}", maxPreprocessConcurrency,
+ defaultSegmentPreprocessParallelism);
+ maxPreprocessConcurrency = defaultSegmentPreprocessParallelism;
+ }
+ _maxPreprocessConcurrency = maxPreprocessConcurrency;
+ _relaxThrottling = relaxThrottling;
+
+ int relaxThrottlingThreshold = Math.max(_maxPreprocessConcurrency,
+
CommonConstants.Helix.DEFAULT_MAX_SEGMENT_PREPROCESS_PARALLELISM_BEFORE_SERVING_QUERIES);
+ int preprocessConcurrency = _maxPreprocessConcurrency;
+ if (relaxThrottling) {
+ preprocessConcurrency = relaxThrottlingThreshold;
+ LOGGER.info("Relax throttling enabled, setting preprocess concurrency
to: {}", preprocessConcurrency);
+ }
+ _semaphore = new AdjustableSemaphore(preprocessConcurrency, true);
+ LOGGER.info("Created semaphore with available permits: {}",
_semaphore.availablePermits());
+ }
+
+ public void resetThrottling() {
Review Comment:
Will there be race condition between this method and `onChange()`?
##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/OfflineClusterIntegrationTest.java:
##########
@@ -188,12 +188,15 @@ public void setUp()
// Start the Pinot cluster
startZk();
startController();
- // Set hyperloglog log2m value to 12.
HelixConfigScope scope =
new
HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(getHelixClusterName())
.build();
+ // Set hyperloglog log2m value to 12.
_helixManager.getConfigAccessor()
.set(scope, CommonConstants.Helix.DEFAULT_HYPERLOGLOG_LOG2M_KEY,
Integer.toString(12));
+ // Set max segment preprocess parallelism to 1
+ _helixManager.getConfigAccessor()
+ .set(scope,
CommonConstants.Helix.CONFIG_OF_MAX_SEGMENT_PREPROCESS_PARALLELISM,
Integer.toString(1));
Review Comment:
Will this drastically slow down the test? Suggest adding some comments
explaining why this number is picked
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/data/manager/TableDataManager.java:
##########
@@ -53,7 +54,8 @@ public interface TableDataManager {
*/
void init(InstanceDataManagerConfig instanceDataManagerConfig, HelixManager
helixManager, SegmentLocks segmentLocks,
TableConfig tableConfig, @Nullable ExecutorService
segmentPreloadExecutor,
- @Nullable Cache<Pair<String, String>, SegmentErrorInfo> errorCache);
+ @Nullable Cache<Pair<String, String>, SegmentErrorInfo> errorCache,
+ SegmentPreprocessThrottler segmentPreprocessThrottler);
Review Comment:
Add `@Nullable` annotation, same for other places where this new parameter
is added
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentLoader.java:
##########
@@ -81,44 +82,48 @@ public static ImmutableSegment load(File indexDir, ReadMode
readMode, TableConfi
throws Exception {
IndexLoadingConfig defaultIndexLoadingConfig = new
IndexLoadingConfig(tableConfig, schema);
defaultIndexLoadingConfig.setReadMode(readMode);
- return load(indexDir, defaultIndexLoadingConfig, false);
+ return load(indexDir, defaultIndexLoadingConfig, false, null);
}
/**
* Loads the segment with specified IndexLoadingConfig.
* This method modifies the segment like to convert segment format, add or
remove indices.
* Mostly used by UT cases to add some specific index for testing purpose.
*/
- public static ImmutableSegment load(File indexDir, IndexLoadingConfig
indexLoadingConfig)
+ public static ImmutableSegment load(File indexDir, IndexLoadingConfig
indexLoadingConfig,
Review Comment:
Let's keep the original method, and add a new one with extra
`segmentPreprocessThrottler` to avoid the changes in the tests. This is a
fairly commonly used one
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentLoader.java:
##########
@@ -158,15 +163,25 @@ public static ImmutableSegment load(File indexDir,
IndexLoadingConfig indexLoadi
/**
* Preprocess the local segment directory according to the current table
config and schema.
*/
- public static void preprocess(File indexDir, IndexLoadingConfig
indexLoadingConfig, @Nullable Schema schema)
+ public static void preprocess(File indexDir, IndexLoadingConfig
indexLoadingConfig, @Nullable Schema schema,
+ SegmentPreprocessThrottler segmentPreprocessThrottler)
throws Exception {
Preconditions.checkArgument(indexDir.isDirectory(), "Index directory: %s
does not exist or is not a directory",
indexDir);
SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(indexDir);
if (segmentMetadata.getTotalDocs() > 0) {
convertSegmentFormat(indexDir, indexLoadingConfig, segmentMetadata);
Review Comment:
I'd also include the format conversion as part of the preprocess since it
also involves a lot of IO
##########
pinot-spi/src/main/java/org/apache/pinot/spi/config/provider/PinotClusterConfigChangeListener.java:
##########
@@ -0,0 +1,26 @@
+/**
+ * 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.Map;
+
+
+public interface PinotClusterConfigChangeListener {
+ void onChange(Map<String, String> clusterConfigs);
Review Comment:
Consider calculating the changed keys. We don't want to process all keys
every time any key changes
##########
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/DefaultClusterConfigChangeHandler.java:
##########
@@ -0,0 +1,86 @@
+/**
+ * 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.server.starter.helix;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.helix.HelixManager;
+import org.apache.helix.HelixManagerFactory;
+import org.apache.helix.InstanceType;
+import org.apache.helix.NotificationContext;
+import org.apache.helix.api.listeners.BatchMode;
+import org.apache.helix.api.listeners.ClusterConfigChangeListener;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener;
+import org.apache.pinot.spi.config.provider.PinotClusterConfigProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@BatchMode(enabled = false)
+public class DefaultClusterConfigChangeHandler implements
ClusterConfigChangeListener, PinotClusterConfigProvider {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(DefaultClusterConfigChangeHandler.class);
+
+ private volatile Map<String, String> _properties;
+ private final Set<PinotClusterConfigChangeListener>
_clusterConfigChangeListeners = ConcurrentHashMap.newKeySet();
Review Comment:
We probably don't need a concurrent set. Suggest using a regular `ArrayList`
since register is always single-threaded
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java:
##########
@@ -0,0 +1,139 @@
+/**
+ * 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 java.util.Map;
+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);
+
+ /**
+ * If _maxPreprocessConcurrency is <= 0, it means that the cluster is not
configured to limit the number of
+ * index rebuilds that can be executed concurrently. This class sets the
semaphore permit to be a large value
+ * in this scenario.
+ */
+ private int _maxPreprocessConcurrency;
+ private boolean _relaxThrottling;
+ private volatile AdjustableSemaphore _semaphore;
Review Comment:
This can be `final`
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java:
##########
@@ -0,0 +1,139 @@
+/**
+ * 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 java.util.Map;
+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);
+
+ /**
+ * If _maxPreprocessConcurrency is <= 0, it means that the cluster is not
configured to limit the number of
+ * index rebuilds that can be executed concurrently. This class sets the
semaphore permit to be a large value
+ * in this scenario.
+ */
+ private int _maxPreprocessConcurrency;
+ private boolean _relaxThrottling;
+ private volatile AdjustableSemaphore _semaphore;
+
+ public SegmentPreprocessThrottler(int maxPreprocessConcurrency, boolean
relaxThrottling) {
+ LOGGER.info("Initializing SegmentPreprocessThrottler,
maxPreprocessConcurrency: {}, relaxThrottling: {}",
+ maxPreprocessConcurrency, relaxThrottling);
+ if (maxPreprocessConcurrency <= 0) {
+ int defaultSegmentPreprocessParallelism =
Review Comment:
Let's directly throw exception here to not let server starts. Using default
for invalid config could cause very confusing behavior
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/SegmentPreprocessThrottler.java:
##########
@@ -0,0 +1,139 @@
+/**
+ * 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 java.util.Map;
+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);
+
+ /**
+ * If _maxPreprocessConcurrency is <= 0, it means that the cluster is not
configured to limit the number of
+ * index rebuilds that can be executed concurrently. This class sets the
semaphore permit to be a large value
+ * in this scenario.
+ */
+ private int _maxPreprocessConcurrency;
+ private boolean _relaxThrottling;
+ private volatile AdjustableSemaphore _semaphore;
+
+ public SegmentPreprocessThrottler(int maxPreprocessConcurrency, boolean
relaxThrottling) {
+ LOGGER.info("Initializing SegmentPreprocessThrottler,
maxPreprocessConcurrency: {}, relaxThrottling: {}",
+ maxPreprocessConcurrency, relaxThrottling);
+ if (maxPreprocessConcurrency <= 0) {
+ int defaultSegmentPreprocessParallelism =
+
Integer.parseInt(CommonConstants.Helix.DEFAULT_MAX_SEGMENT_PREPROCESS_PARALLELISM);
+ LOGGER.warn("Max preprocess concurrency is negative: {}, resetting to
{}", maxPreprocessConcurrency,
+ defaultSegmentPreprocessParallelism);
+ maxPreprocessConcurrency = defaultSegmentPreprocessParallelism;
+ }
+ _maxPreprocessConcurrency = maxPreprocessConcurrency;
+ _relaxThrottling = relaxThrottling;
+
+ int relaxThrottlingThreshold = Math.max(_maxPreprocessConcurrency,
+
CommonConstants.Helix.DEFAULT_MAX_SEGMENT_PREPROCESS_PARALLELISM_BEFORE_SERVING_QUERIES);
Review Comment:
We might want a even higher number so that it doesn't throttle. Also
consider making it configurable in case we really need to throttle during
server restart
--
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]