kfaraz commented on code in PR #17816: URL: https://github.com/apache/druid/pull/17816#discussion_r2007103941
########## indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentPublishAction.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.druid.indexing.common.actions; + +import org.apache.druid.indexing.common.task.IndexTaskUtils; +import org.apache.druid.indexing.common.task.Task; +import org.apache.druid.indexing.overlord.SegmentPublishResult; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.RetryUtils; +import org.apache.druid.java.util.common.StringUtils; + +/** + * Task action to publish segments. Contains common code used by insert, replace + * and append actions. + */ +public abstract class SegmentPublishAction implements TaskAction<SegmentPublishResult> +{ + private static final int QUIET_RETRIES = 3; + private static final int MAX_RETRIES = 5; + + @Override + public SegmentPublishResult perform(Task task, TaskActionToolbox toolbox) + { + int attemptCount = 0; + final String taskId = task.getId(); + + // Retry until success or until max retries are exhausted + SegmentPublishResult result = tryPublishSegments(task, toolbox); + while (!result.isSuccess() && result.canRetry() && attemptCount++ < MAX_RETRIES) { + awaitNextRetry(taskId, result, attemptCount); + result = tryPublishSegments(task, toolbox); + } + + IndexTaskUtils.emitSegmentPublishMetrics(result, task, toolbox); + return result; + } + + /** + * Sleeps until the next attempt. + */ + private static void awaitNextRetry(String taskId, SegmentPublishResult lastResult, int attemptCount) + { + try { + RetryUtils.awaitNextRetry( Review Comment: Re-trying too soon might not be beneficial. To free up the jetty thread, it would be better to perform the retry on the client side. But for the reasons called out in the description, I decided not to do that. I guess we can live with this for now until this becomes a real problem with jetty threads? What do you think? Anyway, the max number of retries is low and this error should not be very frequent. -- 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]
