ankitsultana commented on code in PR #12960:
URL: https://github.com/apache/pinot/pull/12960#discussion_r1605559297


##########
pinot-plugins/pinot-minion-tasks/pinot-minion-builtin-tasks/src/test/java/org/apache/pinot/plugin/minion/tasks/MinionTaskUtilsTest.java:
##########
@@ -0,0 +1,108 @@
+/**
+ * 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.plugin.minion.tasks;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.pinot.core.common.MinionConstants;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableTaskConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.filesystem.LocalPinotFS;
+import org.apache.pinot.spi.filesystem.PinotFS;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+
+public class MinionTaskUtilsTest {
+
+  @Test
+  public void testGetInputPinotFS() throws Exception {
+    Map<String, String> taskConfigs = new HashMap<>();
+    taskConfigs.put("input.fs.className", 
"org.apache.pinot.spi.filesystem.LocalPinotFS");
+    URI fileURI = new URI("file:///path/to/file");
+
+    PinotFS pinotFS = MinionTaskUtils.getInputPinotFS(taskConfigs, fileURI);
+
+    assertTrue(pinotFS instanceof LocalPinotFS);
+  }
+
+  @Test
+  public void testGetOutputPinotFS() throws Exception {
+    Map<String, String> taskConfigs = new HashMap<>();
+    taskConfigs.put("output.fs.className", 
"org.apache.pinot.spi.filesystem.LocalPinotFS");
+    URI fileURI = new URI("file:///path/to/file");
+
+    PinotFS pinotFS = MinionTaskUtils.getOutputPinotFS(taskConfigs, fileURI);
+
+    assertTrue(pinotFS instanceof LocalPinotFS);
+  }
+
+  @Test
+  public void testIsLocalOutputDir() {
+    assertTrue(MinionTaskUtils.isLocalOutputDir("file"));
+    assertFalse(MinionTaskUtils.isLocalOutputDir("hdfs"));
+  }
+
+  @Test
+  public void testGetLocalPinotFs() {
+    assertTrue(MinionTaskUtils.getLocalPinotFs() instanceof LocalPinotFS);
+  }
+
+  @Test
+  public void testNormalizeDirectoryURI() {
+    assertEquals("file:///path/to/dir/", 
MinionTaskUtils.normalizeDirectoryURI("file:///path/to/dir"));
+    assertEquals("file:///path/to/dir/", 
MinionTaskUtils.normalizeDirectoryURI("file:///path/to/dir/"));
+  }
+
+  @Test
+  public void testExtractMinionAllowDownloadFromServer() {

Review Comment:
   this test looks good. but why do we have the other test functions? they seem 
unrelated to the PR.



##########
pinot-plugins/pinot-minion-tasks/pinot-minion-builtin-tasks/src/main/java/org/apache/pinot/plugin/minion/tasks/BaseTaskExecutor.java:
##########
@@ -101,4 +106,29 @@ private void addTaskMeterMetrics(MinionMeter meter, long 
unitCount, String table
     _minionMetrics.addMeteredTableValue(tableName, meter, unitCount);
     _minionMetrics.addMeteredTableValue(tableName, taskType, meter, unitCount);
   }
+
+  protected void downloadSegmentToLocal(String tableNameWithType, String 
segmentName, String deepstoreURL,
+      String taskType, File tarredSegmentFile, String crypterName)
+      throws Exception {
+    LOGGER.info("Downloading segment from {} to {}", deepstoreURL, 
tarredSegmentFile.getAbsolutePath());
+    try {
+      // download from deepstore first
+      SegmentFetcherFactory.fetchAndDecryptSegmentToLocal(deepstoreURL, 
tarredSegmentFile, crypterName);
+    } catch (Exception e) {
+      LOGGER.error("Segment download failed from deepstore for {}, 
crypter:{}", deepstoreURL, crypterName, e);
+      TableConfig tableConfig = getTableConfig(tableNameWithType);
+      String peerDownloadScheme = 
tableConfig.getValidationConfig().getPeerSegmentDownloadScheme();
+      if (MinionTaskUtils.extractMinionAllowDownloadFromServer(tableConfig, 
taskType) && peerDownloadScheme != null) {
+        LOGGER.info("Trying to download from servers for segment {} post 
deepstore download failed", segmentName);
+        SegmentFetcherFactory.getSegmentFetcher(
+                
getTableConfig(tableNameWithType).getValidationConfig().getPeerSegmentDownloadScheme())
+            .fetchSegmentToLocal(segmentName, () ->
+                
PeerServerSegmentFinder.getPeerServerURIs(MINION_CONTEXT.getHelixManager(),

Review Comment:
   one final nit: let's shuffle URIs here. Since the uriSupplier based method 
doesn't shuffle itself across retries. it lets the supplier control that 
behavior.



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

Reply via email to