Victsm commented on a change in pull request #29855: URL: https://github.com/apache/spark/pull/29855#discussion_r497065670
########## File path: common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ErrorHandler.java ########## @@ -0,0 +1,72 @@ +/* + * 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.spark.network.shuffle; + +import java.net.ConnectException; + +/** + * Plugs into {@link RetryingBlockFetcher} to further control when an exception should be retried + * and logged. + * Note: {@link RetryingBlockFetcher} will delegate the exception to this handler only when + * - remaining retries < max retries + * - exception is an IOException + */ + +public interface ErrorHandler { + boolean shouldRetryError(Throwable t); + + default boolean shouldLogError(Throwable t) { + return true; + } + + /** + * A no-op error handler instance. + */ + ErrorHandler NOOP_ERROR_HANDLER = t -> true; + + /** + * The error handler for pushing shuffle blocks to remote shuffle services. + */ + class BlockPushErrorHandler implements ErrorHandler { + + @Override + public boolean shouldRetryError(Throwable t) { + // If it is a connection time out or a connection closed exception, no need to retry. + if (t.getCause() != null && t.getCause() instanceof ConnectException) { + return false; + } + // If the block is too late, there is no need to retry it + return (t.getMessage() == null || + !t.getMessage().contains(BlockPushException.TOO_LATE_MESSAGE_SUFFIX)) && + (t.getCause() == null || t.getCause().getMessage() == null || + !t.getCause().getMessage().contains(BlockPushException.TOO_LATE_MESSAGE_SUFFIX)); + } + + @Override + public boolean shouldLogError(Throwable t) { + return (t.getMessage() == null || + (!t.getMessage().contains(BlockPushException.COULD_NOT_FIND_OPPORTUNITY_MSG_PREFIX) && Review comment: The context is less in in this PR. Basically, we adopt a best-effort approach for pushing and merging blocks. On the shuffle service side, there are 2 common reasons that a block might not be merged. One (TOO_LATE_MESSAGE_SUFFIX) is that a block is received after the shuffle service has received the finalize request from the Spark driver for the corresponding shuffle partition. The other (COULD_NOT_FIND_OPPORTUNITY_MSG_PREFIX) is more specific to the current implementation of how we process the block push request on the server side (SPARK-32916). We leverage SPARK-6237 to perform stream push of blocks. When we have 2 or more concurrent streams open for blocks from different mappers belonging to the same shuffle partition, only 1 of these blocks can get hold of the lock and be appended to the corresponding merged shuffle file (to ensure continuity of the block appended to the file). The other blocks will be temporarily buffered in memory, until the corresponding stream ends. Multiple attempts will be tried to append these blocks to the merged shuffle file, if one of them can successfully get hold of the lock before the stream ends. If by the time the stream ends and the block still couldn't get hold of the lock, then we give up on appending that block. Note that we randomize the order of the blocks before pushing them, similar to what happens with the block fetch, thus the chance of block collision on the shuffle service side is small. For both these 2 types of exceptions, they are not really an error. Logging them might mislead users. Also, for TOO_LATE_MESSAGE type exception, we could potentially flood both the server and client side log if the total number of blocks in a shuffle is very large. We can have in-depth discussion on these 2 exceptions and how we handle them once we send out the PR for SPARK-32916. We are waiting on the finalization of this current PR before doing that. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
