Jackie-Jiang commented on code in PR #13597: URL: https://github.com/apache/pinot/pull/13597#discussion_r1678167065
########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java: ########## @@ -403,6 +413,173 @@ private SuccessResponse uploadSegment(@Nullable String tableName, TableType tabl } } + // Method used to update a list of segments in batch mode with the METADATA upload type. + private SuccessResponse uploadSegments(String tableName, TableType tableType, + FormDataMultiPart multiParts, boolean enableParallelPushProtection, + boolean allowRefresh, HttpHeaders headers, Request request) { + String rawTableName = TableNameBuilder.extractRawTableName(tableName); + String tableNameWithType = tableType == TableType.OFFLINE + ? TableNameBuilder.OFFLINE.tableNameWithType(rawTableName) + : TableNameBuilder.REALTIME.tableNameWithType(rawTableName); + + TableConfig tableConfig = _pinotHelixResourceManager.getTableConfig(tableNameWithType); + if (tableConfig == null) { + throw new ControllerApplicationException(LOGGER, "Failed to fetch table config for table: " + tableNameWithType, + Response.Status.BAD_REQUEST); + } + + String clientAddress; + try { + clientAddress = InetAddress.getByName(request.getRemoteAddr()).getHostName(); + } catch (UnknownHostException ex) { Review Comment: (minor) I most of the places we just use `e` to represent exception. Shall we keep the same convention for consistency? ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/SegmentUploadMetadata.java: ########## @@ -0,0 +1,103 @@ +/** + * 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.controller.api.upload; + +import java.io.File; +import java.net.URI; +import java.util.Objects; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.pinot.segment.spi.SegmentMetadata; + + +public class SegmentUploadMetadata { Review Comment: Good job extracting this. Please add some javadoc explaining this class and each field ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java: ########## @@ -403,6 +413,173 @@ private SuccessResponse uploadSegment(@Nullable String tableName, TableType tabl } } + // Method used to update a list of segments in batch mode with the METADATA upload type. + private SuccessResponse uploadSegments(String tableName, TableType tableType, + FormDataMultiPart multiParts, boolean enableParallelPushProtection, + boolean allowRefresh, HttpHeaders headers, Request request) { + String rawTableName = TableNameBuilder.extractRawTableName(tableName); + String tableNameWithType = tableType == TableType.OFFLINE + ? TableNameBuilder.OFFLINE.tableNameWithType(rawTableName) + : TableNameBuilder.REALTIME.tableNameWithType(rawTableName); + + TableConfig tableConfig = _pinotHelixResourceManager.getTableConfig(tableNameWithType); + if (tableConfig == null) { + throw new ControllerApplicationException(LOGGER, "Failed to fetch table config for table: " + tableNameWithType, + Response.Status.BAD_REQUEST); + } + + String clientAddress; + try { + clientAddress = InetAddress.getByName(request.getRemoteAddr()).getHostName(); + } catch (UnknownHostException ex) { + throw new ControllerApplicationException(LOGGER, "Failed to resolve hostname from input request", + Response.Status.BAD_REQUEST, ex); + } + + String uploadTypeStr = extractHttpHeader(headers, FileUploadDownloadClient.CustomHeaders.UPLOAD_TYPE); + FileUploadType uploadType = getUploadType(uploadTypeStr); + if (!FileUploadType.METADATA.equals(uploadType)) { + throw new ControllerApplicationException(LOGGER, "Unsupported upload type: " + uploadTypeStr, + Response.Status.BAD_REQUEST); + } + + String crypterClassNameInHeader = extractHttpHeader(headers, FileUploadDownloadClient.CustomHeaders.CRYPTER); + String ingestionDescriptor = extractHttpHeader(headers, CommonConstants.Controller.INGESTION_DESCRIPTOR); + ControllerFilePathProvider provider = ControllerFilePathProvider.getInstance(); + List<SegmentUploadMetadata> segmentUploadMetadataList = new ArrayList<>(); + List<File> tempEncryptedFiles = new ArrayList<>(); + List<File> tempDecryptedFiles = new ArrayList<>(); + List<File> tempSegmentDirs = new ArrayList<>(); + List<String> segmentNames = new ArrayList<>(); + + for (BodyPart bodyPartFromReq: multiParts.getBodyParts()) { Review Comment: (format) reformat the changes ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java: ########## @@ -555,6 +750,67 @@ public void uploadSegmentAsMultiPart(FormDataMultiPart multiPart, } } + @POST + @ManagedAsync + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.MULTIPART_FORM_DATA) + @Path("/segmentList") Review Comment: Suggest making the API path `segments/{tableName}/batchUpload`. `POST /segmentList` is quite misleading to me ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/upload/ZKOperator.java: ########## @@ -62,52 +66,58 @@ public ZKOperator(PinotHelixResourceManager pinotHelixResourceManager, Controlle _controllerMetrics = controllerMetrics; } - public void completeSegmentOperations(String tableNameWithType, SegmentMetadata segmentMetadata, - FileUploadType uploadType, @Nullable URI finalSegmentLocationURI, File segmentFile, - @Nullable String sourceDownloadURIStr, String segmentDownloadURIStr, @Nullable String crypterName, - long segmentSizeInBytes, boolean enableParallelPushProtection, boolean allowRefresh, HttpHeaders headers) + public void completeSegmentsOperations(String tableNameWithType, FileUploadType uploadType, Review Comment: Consider using different method to handle single segment upload vs batch segment upload. We may extract common part as needed, but modifying the existing flow can be risky. It can cause backward incompatible if any error handling behavior is changed -- 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