yuanbenson commented on code in PR #9295: URL: https://github.com/apache/pinot/pull/9295#discussion_r960085549
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/ConsistentDataPushUtils.java: ########## @@ -0,0 +1,296 @@ +/** + * 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.base.Preconditions; +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.ws.rs.core.Response; +import org.apache.pinot.common.auth.AuthProviderUtils; +import org.apache.pinot.common.exception.HttpErrorStatusException; +import org.apache.pinot.common.restlet.resources.StartReplaceSegmentsRequest; +import org.apache.pinot.common.segment.generation.SegmentGenerationUtils; +import org.apache.pinot.common.utils.FileUploadDownloadClient; +import org.apache.pinot.common.utils.SimpleHttpResponse; +import org.apache.pinot.common.utils.http.HttpClient; +import org.apache.pinot.spi.auth.AuthProvider; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.ingestion.batch.spec.PinotClusterSpec; +import org.apache.pinot.spi.ingestion.batch.spec.SegmentGenerationJobSpec; +import org.apache.pinot.spi.ingestion.batch.spec.SegmentNameGeneratorSpec; +import org.apache.pinot.spi.utils.IngestionConfigUtils; +import org.apache.pinot.spi.utils.JsonUtils; +import org.apache.pinot.spi.utils.retry.RetryPolicies; +import org.apache.pinot.spi.utils.retry.RetryPolicy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class ConsistentDataPushUtils { + private ConsistentDataPushUtils() { + } + + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentPushUtils.class); + private static final FileUploadDownloadClient FILE_UPLOAD_DOWNLOAD_CLIENT = new FileUploadDownloadClient(); + private static final RetryPolicy DEFAULT_RETRY_POLICY = RetryPolicies.exponentialBackoffRetryPolicy(5, 10_000L, 2.0); Review Comment: @snleee @jtao15 Please lmk if these params are appropriate. ########## pinot-common/src/main/java/org/apache/pinot/common/utils/FileUploadDownloadClient.java: ########## @@ -747,6 +754,72 @@ public SimpleHttpResponse uploadSegment(URI uri, String segmentName, InputStream return uploadSegment(uri, segmentName, inputStream, null, parameters, HttpClient.DEFAULT_SOCKET_TIMEOUT_MS); } + /** + * Returns a map from a given tableType to a list of segments for that given tableType (OFFLINE or REALTIME) + * If tableType is left unspecified, both OFFLINE and REALTIME segments will be returned in the map. + */ + public Map<String, List<String>> getSegments(URI controllerUri, String rawTableName, @Nullable TableType tableType, + boolean excludeReplacedSegments) throws Exception { + List<String> tableTypes; + if (tableType == null) { + tableTypes = Arrays.asList(TableType.OFFLINE.toString(), TableType.REALTIME.toString()); + } else { + tableTypes = Arrays.asList(tableType.toString()); + } + ControllerRequestURLBuilder controllerRequestURLBuilder = + ControllerRequestURLBuilder.baseUrl(controllerUri.toString()); + Map<String, List<String>> tableTypeToSegments = new HashMap<>(); + for (String tableTypeToFilter : tableTypes) { + tableTypeToSegments.put(tableTypeToFilter, new ArrayList<>()); + String uri = controllerRequestURLBuilder.forSegmentListAPIWithTableTypeAndExcludeReplacedSegments(rawTableName, + tableTypeToFilter, excludeReplacedSegments); + RequestBuilder requestBuilder = RequestBuilder.get(uri).setVersion(HttpVersion.HTTP_1_1); + HttpClient.setTimeout(requestBuilder, HttpClient.DEFAULT_SOCKET_TIMEOUT_MS); + RetryPolicies.exponentialBackoffRetryPolicy(5, 10_000L, 2.0).attempt(() -> { Review Comment: Same for this.. -- 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