Jackie-Jiang commented on code in PR #8823:
URL: https://github.com/apache/pinot/pull/8823#discussion_r891808769


##########
pinot-common/src/main/java/org/apache/pinot/common/utils/FileUploadDownloadClient.java:
##########
@@ -73,6 +73,8 @@ public static class CustomHeaders {
     public static final String UPLOAD_TYPE = "UPLOAD_TYPE";
     public static final String REFRESH_ONLY = "REFRESH_ONLY";
     public static final String DOWNLOAD_URI = "DOWNLOAD_URI";
+
+    public static final String MOVE_SEGMENT_TO_DEEP_STORE = 
"MOVE_SEGMENT_TO_DEEP_STORE";

Review Comment:
   Consider changing it to `COPY_SEGMENT_TO_DEEP_STORE` and add some comments 
stating that is is for metadata push only



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -310,9 +313,34 @@ private void processNewSegment(String tableNameWithType, 
SegmentMetadata segment
     }
   }
 
+  private void segmentToFinalLocation(String tableNameWithType, String 
segmentName, FileUploadType uploadType,
+      File segmentFile, String sourceDownloadURIStr, URI 
finalSegmentLocationURI)
+      throws Exception {
+    if (uploadType == FileUploadType.METADATA) {
+      // In Metadata push, local segmentFile only contains metadata.
+      // Copy segment over from sourceDownloadURI to final location.
+      copySegmentToPermanentDirectory(new URI(sourceDownloadURIStr), 
finalSegmentLocationURI);
+      LOGGER.info("Copied segment: {} of table: {} to final location: {}", 
segmentName, tableNameWithType,
+          finalSegmentLocationURI);
+    } else {
+      // In push types other than METADATA, local segmentFile contains the 
complete segment.
+      // Move local segment to final location
+      moveSegmentToPermanentDirectory(segmentFile, finalSegmentLocationURI);
+      LOGGER.info("Moved segment: {} of table: {} to final location: {}", 
segmentName, tableNameWithType,
+          finalSegmentLocationURI);
+    }
+  }
+
   private void moveSegmentToPermanentDirectory(File segmentFile, URI 
finalSegmentLocationURI)
       throws Exception {
     LOGGER.info("Copying segment from: {} to: {}", 
segmentFile.getAbsolutePath(), finalSegmentLocationURI);
     
PinotFSFactory.create(finalSegmentLocationURI.getScheme()).copyFromLocalFile(segmentFile,
 finalSegmentLocationURI);
   }
+
+  private void copySegmentToPermanentDirectory(URI sourceDownloadURI, URI 
finalSegmentLocationURI)
+      throws Exception {
+    
Preconditions.checkState(sourceDownloadURI.getScheme().equals(finalSegmentLocationURI.getScheme()));
+    LOGGER.info("Copying segment from: {} to: {}", sourceDownloadURI, 
finalSegmentLocationURI);

Review Comment:
   Let's also check if they are the same URI before copying



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -310,9 +313,34 @@ private void processNewSegment(String tableNameWithType, 
SegmentMetadata segment
     }
   }
 
+  private void segmentToFinalLocation(String tableNameWithType, String 
segmentName, FileUploadType uploadType,
+      File segmentFile, String sourceDownloadURIStr, URI 
finalSegmentLocationURI)
+      throws Exception {
+    if (uploadType == FileUploadType.METADATA) {
+      // In Metadata push, local segmentFile only contains metadata.
+      // Copy segment over from sourceDownloadURI to final location.
+      copySegmentToPermanentDirectory(new URI(sourceDownloadURIStr), 
finalSegmentLocationURI);
+      LOGGER.info("Copied segment: {} of table: {} to final location: {}", 
segmentName, tableNameWithType,
+          finalSegmentLocationURI);
+    } else {
+      // In push types other than METADATA, local segmentFile contains the 
complete segment.
+      // Move local segment to final location
+      moveSegmentToPermanentDirectory(segmentFile, finalSegmentLocationURI);
+      LOGGER.info("Moved segment: {} of table: {} to final location: {}", 
segmentName, tableNameWithType,
+          finalSegmentLocationURI);
+    }
+  }
+
   private void moveSegmentToPermanentDirectory(File segmentFile, URI 
finalSegmentLocationURI)
       throws Exception {
     LOGGER.info("Copying segment from: {} to: {}", 
segmentFile.getAbsolutePath(), finalSegmentLocationURI);
     
PinotFSFactory.create(finalSegmentLocationURI.getScheme()).copyFromLocalFile(segmentFile,
 finalSegmentLocationURI);
   }
+
+  private void copySegmentToPermanentDirectory(URI sourceDownloadURI, URI 
finalSegmentLocationURI)
+      throws Exception {
+    
Preconditions.checkState(sourceDownloadURI.getScheme().equals(finalSegmentLocationURI.getScheme()));
+    LOGGER.info("Copying segment from: {} to: {}", sourceDownloadURI, 
finalSegmentLocationURI);

Review Comment:
   Let's also check if they are the same URI before copying



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java:
##########
@@ -230,20 +232,22 @@ private SuccessResponse uploadSegment(@Nullable String 
tableName, TableType tabl
                 "Segment file (as multipart/form-data) is required for SEGMENT 
upload mode",
                 Response.Status.BAD_REQUEST);
           }
-          if (!moveSegmentToFinalLocation && StringUtils.isEmpty(downloadURI)) 
{
+          if (!moveSegmentToFinalLocation && 
StringUtils.isEmpty(sourceDownloadURIStr)) {

Review Comment:
   Not introduced in this PR, but consider changing 
`moveSegmentToFinalLocation` to `copySegmentToDeepStore`



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -60,8 +62,9 @@ public ZKOperator(PinotHelixResourceManager 
pinotHelixResourceManager, Controlle
   }
 
   public void completeSegmentOperations(String tableNameWithType, 
SegmentMetadata segmentMetadata,
-      @Nullable URI finalSegmentLocationURI, File segmentFile, String 
downloadUrl, @Nullable String crypterName,
-      long segmentSizeInBytes, boolean enableParallelPushProtection, boolean 
allowRefresh, HttpHeaders headers)
+      FileUploadType uploadType, @Nullable URI finalSegmentLocationURI, File 
segmentFile, String sourceDownloadURIStr,

Review Comment:
   `sourceDownloadURIStr` should be nullable



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -60,8 +62,9 @@ public ZKOperator(PinotHelixResourceManager 
pinotHelixResourceManager, Controlle
   }
 
   public void completeSegmentOperations(String tableNameWithType, 
SegmentMetadata segmentMetadata,
-      @Nullable URI finalSegmentLocationURI, File segmentFile, String 
downloadUrl, @Nullable String crypterName,
-      long segmentSizeInBytes, boolean enableParallelPushProtection, boolean 
allowRefresh, HttpHeaders headers)
+      FileUploadType uploadType, @Nullable URI finalSegmentLocationURI, File 
segmentFile, String sourceDownloadURIStr,

Review Comment:
   Suggest not introducing upload type into this module. When it is configured 
to copy the segment to the deep store, we can check if `sourceDownloadURIStr` 
is provided, and copy accordingly.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java:
##########
@@ -230,20 +232,22 @@ private SuccessResponse uploadSegment(@Nullable String 
tableName, TableType tabl
                 "Segment file (as multipart/form-data) is required for SEGMENT 
upload mode",
                 Response.Status.BAD_REQUEST);
           }
-          if (!moveSegmentToFinalLocation && StringUtils.isEmpty(downloadURI)) 
{
+          if (!moveSegmentToFinalLocation && 
StringUtils.isEmpty(sourceDownloadURIStr)) {

Review Comment:
   Not introduced in this PR, but consider changing 
`moveSegmentToFinalLocation` to `copySegmentToDeepStore`



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -310,9 +313,34 @@ private void processNewSegment(String tableNameWithType, 
SegmentMetadata segment
     }
   }
 
+  private void segmentToFinalLocation(String tableNameWithType, String 
segmentName, FileUploadType uploadType,

Review Comment:
   Consider changing it to `copySegmentToDeepStore()`



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -60,8 +62,9 @@ public ZKOperator(PinotHelixResourceManager 
pinotHelixResourceManager, Controlle
   }
 
   public void completeSegmentOperations(String tableNameWithType, 
SegmentMetadata segmentMetadata,
-      @Nullable URI finalSegmentLocationURI, File segmentFile, String 
downloadUrl, @Nullable String crypterName,
-      long segmentSizeInBytes, boolean enableParallelPushProtection, boolean 
allowRefresh, HttpHeaders headers)
+      FileUploadType uploadType, @Nullable URI finalSegmentLocationURI, File 
segmentFile, String sourceDownloadURIStr,

Review Comment:
   Suggest not introducing upload type into this module. When it is configured 
to copy the segment to the deep store, we can check if `sourceDownloadURIStr` 
is provided, and copy accordingly.



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/SegmentMetadataPushIntegrationTest.java:
##########
@@ -0,0 +1,229 @@
+/**
+ * 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.integration.tests;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import 
org.apache.pinot.plugin.ingestion.batch.standalone.SegmentMetadataPushJobRunner;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.ingestion.batch.spec.PinotClusterSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.PinotFSSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.PushJobSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.SegmentGenerationJobSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.TableSpec;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.util.TestUtils;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+/**
+ * Test for advanced push types.
+ * Currently only tests METADATA push type.
+ * todo: add test for URI push
+ */
+public class SegmentMetadataPushIntegrationTest extends 
BaseClusterIntegrationTest {

Review Comment:
   Suggest changing it to `SegmentUploadIntegrationTest` and we can add more 
tests to cover all upload types in the future



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -310,9 +313,34 @@ private void processNewSegment(String tableNameWithType, 
SegmentMetadata segment
     }
   }
 
+  private void segmentToFinalLocation(String tableNameWithType, String 
segmentName, FileUploadType uploadType,

Review Comment:
   Consider changing it to `copySegmentToDeepStore()`



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/SegmentMetadataPushIntegrationTest.java:
##########
@@ -0,0 +1,229 @@
+/**
+ * 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.integration.tests;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import 
org.apache.pinot.plugin.ingestion.batch.standalone.SegmentMetadataPushJobRunner;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.ingestion.batch.spec.PinotClusterSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.PinotFSSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.PushJobSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.SegmentGenerationJobSpec;
+import org.apache.pinot.spi.ingestion.batch.spec.TableSpec;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.util.TestUtils;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+/**
+ * Test for advanced push types.
+ * Currently only tests METADATA push type.
+ * todo: add test for URI push
+ */
+public class SegmentMetadataPushIntegrationTest extends 
BaseClusterIntegrationTest {

Review Comment:
   Suggest changing it to `SegmentUploadIntegrationTest` and we can add more 
tests to cover all upload types in the future



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java:
##########
@@ -60,8 +62,9 @@ public ZKOperator(PinotHelixResourceManager 
pinotHelixResourceManager, Controlle
   }
 
   public void completeSegmentOperations(String tableNameWithType, 
SegmentMetadata segmentMetadata,
-      @Nullable URI finalSegmentLocationURI, File segmentFile, String 
downloadUrl, @Nullable String crypterName,
-      long segmentSizeInBytes, boolean enableParallelPushProtection, boolean 
allowRefresh, HttpHeaders headers)
+      FileUploadType uploadType, @Nullable URI finalSegmentLocationURI, File 
segmentFile, String sourceDownloadURIStr,

Review Comment:
   `sourceDownloadURIStr` should be nullable



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