hudi-agent commented on code in PR #20217:
URL: https://github.com/apache/hudi/pull/20217#discussion_r4235341998


##########
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;
+
+  /** Shared instance for the write path; the halter holds no per-failure 
state. */
+  public static final ConnectionPoolShutdownExecutorHalter DEFAULT = new 
ConnectionPoolShutdownExecutorHalter();
+
+  private final IntConsumer halter;
+
+  public ConnectionPoolShutdownExecutorHalter() {
+    this(exitCode -> Runtime.getRuntime().halt(exitCode));
+  }
+
+  ConnectionPoolShutdownExecutorHalter(IntConsumer halter) {
+    this.halter = halter;
+  }
+
+  /**
+   * Halts the JVM with {@link #HALT_EXIT_CODE} if {@code failure} or any 
exception in its cause chain is the
+   * connection pool shutdown; otherwise returns normally so the caller can 
rethrow.
+   */
+  public void haltIfConnectionPoolShutDown(Throwable failure) {
+    if (isConnectionPoolShutDown(failure)) {
+      log.error("Halting the executor JVM with exit code {}: the storage 
client's connection pool is shut down, "
+          + "so every later task on this executor would fail the same way", 
HALT_EXIT_CODE);
+      halter.accept(HALT_EXIT_CODE);

Review Comment:
   🤖 non-blocking: in Spark local mode the tasks run in the driver JVM, so with 
this config on, a pool shutdown would `halt(57)` the whole application, driver 
included, with no shutdown hooks; would it make sense to skip the halt when 
`SparkEnv.get().executorId()` is `SparkContext.DRIVER_IDENTIFIER()`?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
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:
   🤖 non-blocking: `handleInsert` returns a lazy `SparkLazyInsertIterable`, so 
create-handle failures from the dead pool are thrown later, when Spark iterates 
the result in `flatMap`, and never reach this catch; INSERT-bucket tasks (and 
`SparkInsertOverwriteCommitActionExecutor.handleInsertPartition`, which has no 
catch at all) will keep failing on the poisoned executor without halting. Would 
it make sense to wrap the returned iterator so failures from 
`hasNext()`/`next()` also go through the halter?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
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;
+
+  /** Shared instance for the write path; the halter holds no per-failure 
state. */
+  public static final ConnectionPoolShutdownExecutorHalter DEFAULT = new 
ConnectionPoolShutdownExecutorHalter();
+
+  private final IntConsumer halter;

Review Comment:
   🤖 nit: could you rename the `halter` field to something like `haltAction`? A 
field of the same name as the class type reads a bit confusingly.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/config/HoodieWriteConfig.java:
##########
@@ -781,6 +781,15 @@ public class HoodieWriteConfig extends HoodieConfig {
       .withDocumentation("When enabled, records in older schema are rewritten 
into newer schema during upsert,delete and background"
           + " compaction,clustering operations.");
 
+  public static final ConfigProperty<Boolean> 
HALT_EXECUTOR_ON_CONNECTION_POOL_SHUTDOWN = ConfigProperty
+      .key("hoodie.write.halt.executor.on.connection.pool.shutdown")
+      .defaultValue(false)
+      .markAdvanced()

Review Comment:
   🤖 non-blocking: could you add `.sinceVersion("1.3.0")` here, like the 
neighboring new configs?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
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]

Reply via email to