deemoliu commented on code in PR #14686:
URL: https://github.com/apache/pinot/pull/14686#discussion_r1978430512


##########
pinot-server/src/main/java/org/apache/pinot/server/predownload/PredownloadScheduler.java:
##########
@@ -0,0 +1,423 @@
+/**
+ * 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.predownload;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.common.utils.TarCompressionUtils;
+import org.apache.pinot.common.utils.fetcher.SegmentFetcherFactory;
+import org.apache.pinot.server.conf.ServerConf;
+import org.apache.pinot.server.starter.helix.HelixInstanceDataManagerConfig;
+import org.apache.pinot.spi.config.instance.InstanceDataManagerConfig;
+import org.apache.pinot.spi.crypt.PinotCrypterFactory;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.filesystem.PinotFSFactory;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.spi.utils.retry.AttemptsExceededException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PredownloadScheduler {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PredownloadScheduler.class);
+  private static final String TMP_DIR_NAME = "tmp";
+  // Segment download dir in format of "tmp-" + segmentName + "-" + 
UUID.randomUUID()
+  private static final String TMP_DIR_FORMAT = "tmp-%s-%s";
+  private static final long DOWNLOAD_SEGMENTS_TIMEOUT_MIN = 60;
+  private static final long LOAD_SEGMENTS_TIMEOUT_MIN = 5;
+  private final PropertiesConfiguration _properties;
+  private final PinotConfiguration _pinotConfig;
+  private final InstanceDataManagerConfig _instanceDataManagerConfig;
+  private final String _clusterName;
+  private final String _instanceId;
+  private final String _zkAddress;
+  @VisibleForTesting
+  Executor _executor;
+  @VisibleForTesting
+  Set<String> _failedSegments;
+  @SuppressWarnings("NullAway.Init")
+  private PredownloadMetrics _predownloadMetrics;
+  private int _numOfSkippedSegments;
+  private int _numOfUnableToDownloadSegments;
+  private int _numOfDownloadSegments;
+  private long _totalDownloadedSizeBytes;
+  @SuppressWarnings("NullAway.Init")
+  private ZKClient _zkClient;
+  @SuppressWarnings("NullAway.Init")
+  private List<SegmentInfo> _segmentInfoList;
+  @SuppressWarnings("NullAway.Init")
+  private Map<String, TableInfo> _tableInfoMap;
+
+  public PredownloadScheduler(PropertiesConfiguration properties)
+      throws Exception {
+    _properties = properties;
+    _clusterName = 
properties.getString(CommonConstants.Helix.CONFIG_OF_CLUSTER_NAME);
+    _zkAddress = 
properties.getString(CommonConstants.Helix.CONFIG_OF_ZOOKEEPR_SERVER);
+    _instanceId = 
properties.getString(CommonConstants.Server.CONFIG_OF_INSTANCE_ID);
+    _pinotConfig = new PinotConfiguration(properties);
+    _instanceDataManagerConfig =
+        new HelixInstanceDataManagerConfig(new 
ServerConf(_pinotConfig).getInstanceDataManagerConfig());
+    // Get the number of available processors (vCPUs)
+    int numProcessors = Runtime.getRuntime().availableProcessors();
+    _failedSegments = ConcurrentHashMap.newKeySet();
+    // TODO: tune the value
+    _executor = Executors.newFixedThreadPool(numProcessors * 3);

Review Comment:
   shall we make it configurable thread pool size?
   then you can add the finding in a comment and use 3 as default.



-- 
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

Reply via email to