wombatu-kun commented on code in PR #20217: URL: https://github.com/apache/hudi/pull/20217#discussion_r4384521541
########## hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/client/utils/ConnectionPoolShutdownExecutorHalter.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.hudi.client.utils; + +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.IdentityHashMap; +import java.util.Set; +import java.util.function.IntConsumer; + +/** + * Halts the executor JVM when a write task failed because the storage client's HTTP connection pool was shut down. + * + * <p>The pool belongs to the JVM-wide cached file system, so once it is shut down every later task on the executor + * fails the same way while the executor keeps heartbeating. Halting the JVM lets Spark replace the executor. + * {@link Runtime#halt} is used rather than {@link System#exit} because shutdown hooks (such as the Hadoop file + * system cache close) can block on the same dead client. + * + * <p>Detection matches the exact exception type and message the HTTP client raises, so it is a best-effort + * safeguard rather than a contract: if that message is ever reworded the failure mode is that this stops halting + * and the executor behaves as it did before, never that an unrelated failure halts the JVM. + */ +@Slf4j +public class ConnectionPoolShutdownExecutorHalter { + + /** Message of the {@link IllegalStateException} Apache HttpClient throws when a shut-down pool is used. */ + static final String CONNECTION_POOL_SHUT_DOWN_MESSAGE = "Connection pool shut down"; + + /** Distinct from the exit codes Spark itself uses (0-3, 11, 50-56, 127), so the cause is identifiable. */ + static final int HALT_EXIT_CODE = 57; Review Comment: Spark 4.x already defines exit code 57 as `ExecutorExitCode.KILLED_BY_TASK_REAPER` (and 58 as `BLOCK_MANAGER_REREGISTRATION_FAILED`), so on Spark 4 YARN this halt shows up as "Possible causes: Executor killed by TaskReaper." Could you pick a code outside 50-58 and update the list in the comment above? ########## hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/BaseSparkCommitActionExecutor.java: ########## @@ -413,6 +414,9 @@ protected Iterator<List<WriteStatus>> handleUpsertPartition(String instantTime, } catch (Throwable t) { String msg = "Error upserting bucketType " + btype + " for partition :" + partition; log.error(msg, t); + if (config.shouldHaltExecutorOnConnectionPoolShutdown()) { Review Comment: +1; registering the halter as a `TaskContext.get().addTaskFailureListener` in the `mapPartitionsAsRDD` lambda would see the failure wherever the task throws it, lazy `SparkLazyInsertIterable` and `SparkInsertOverwriteCommitActionExecutor.handleInsertPartition` included, with no iterator wrapping. -- 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]
