You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by he...@apache.org on 2026/09/18 04:06:53 UTC

(hadoop) branch trunk updated: HADOOP-19986. MiniDFSCluster.shutdownDataNodes() should signal all DataNodes before joining any (#8723). Contributed by Jose Luis López.

This is an automated email from the ASF dual-hosted git repository.

Hexiaoqiao pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new fa368e813f0 HADOOP-19986. MiniDFSCluster.shutdownDataNodes() should signal all DataNodes before joining any (#8723). Contributed by Jose Luis López.
fa368e813f0 is described below

commit fa368e813f023ae26a6860345df19bdb03742ad1
Author: Jose Luis López López <jo...@gmail.com>
AuthorDate: Fri Sep 18 06:06:46 2026 +0200

    HADOOP-19986. MiniDFSCluster.shutdownDataNodes() should signal all DataNodes before joining any (#8723). Contributed by Jose Luis López.
    
    Signed-off-by: He Xiaoqiao <he...@apache.org>
---
 .../hdfs/server/datanode/BlockPoolManager.java     | 12 ++++++++++-
 .../hadoop/hdfs/server/datanode/DataNode.java      | 25 ++++++++++++++++++++++
 .../org/apache/hadoop/hdfs/MiniDFSCluster.java     | 14 ++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java
index 1611c3c9ce5..3ed373b3a50 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolManager.java
@@ -110,10 +110,20 @@ synchronized void remove(BPOfferService t) {
     }
   }
   
-  void shutDownAll(List<BPOfferService> bposList) throws InterruptedException {
+  /**
+   * Signal the services to stop without joining them. This is the first half
+   * of {@link #shutDownAll}, split out so a caller shutting down several
+   * DataNodes in one JVM can signal them all before joining any. stop() is
+   * idempotent, so shutDownAll may still be called afterwards.
+   */
+  void signalShutDownAll(List<BPOfferService> bposList) {
     for (BPOfferService bpos : bposList) {
       bpos.stop(); //interrupts the threads
     }
+  }
+
+  void shutDownAll(List<BPOfferService> bposList) throws InterruptedException {
+    signalShutDownAll(bposList);
     //now join
     for (BPOfferService bpos : bposList) {
       bpos.join();
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
index bfae1829349..c773e01710f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
@@ -2236,6 +2236,31 @@ List<BPOfferService> getAllBpOs() {
     return blockPoolManager.getAllNamenodeThreads();
   }
 
+  /**
+   * Signal every block pool service to stop, without waiting for its threads
+   * to exit, so that a caller shutting down several DataNodes in one JVM can
+   * signal them all before joining any of them. A later {@code shutdown()} on
+   * this DataNode still does the joining; {@code stop()} is idempotent.
+   *
+   * <p>Joining one DataNode while the others still run can hang: DataNodes in
+   * a single JVM share an {@link org.apache.hadoop.ipc.Client} through
+   * ClientCache, so they share its per-address Connection objects too. A
+   * BPServiceActor that is still retrying a dead NameNode holds that
+   * Connection's monitor across its connect-retry sleeps, and an actor of the
+   * DataNode being shut down can sit BLOCKED on that monitor. A BLOCKED thread
+   * cannot observe the interrupt that {@code stop()} sends, so the join waits
+   * for as long as the surviving DataNodes keep re-acquiring the monitor.
+   * Signalling everyone first lets the holder abort its sleep and release it.
+   */
+  @VisibleForTesting
+  public void signalBlockPoolShutdown() {
+    if (blockPoolManager == null) {
+      return;
+    }
+    blockPoolManager.signalShutDownAll(
+        blockPoolManager.getAllNamenodeThreads());
+  }
+
   BPOfferService getBPOfferService(String bpid){
     return blockPoolManager.get(bpid);
   }
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java
index 6c20c141a15..b4b5742df6a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java
@@ -2218,6 +2218,20 @@ public void shutdown(boolean deleteDfsDir, boolean closeFileSystem) {
    * is left running so that new DataNodes may be started.
    */
   public void shutdownDataNodes() {
+    // Signal every DataNode before joining any of them. Shutting them down one
+    // at a time -- stop, join, next -- lets the DataNodes not yet reached keep
+    // hammering a NameNode the test has already killed. Because DataNodes in
+    // one JVM share an ipc.Client, and so its Connection objects, a surviving
+    // DataNode's BPServiceActor can hold a Connection monitor across its
+    // connect-retry sleeps while an actor of the DataNode being joined sits
+    // BLOCKED on it. Interrupts do not reach a BLOCKED thread, so the join
+    // waits on scheduling luck: it has been measured at 165s, overrunning the
+    // test's timeout. See DataNode#signalBlockPoolShutdown.
+    for (DataNodeProperties dnProp : dataNodes) {
+      if (dnProp.datanode != null) {
+        dnProp.datanode.signalBlockPoolShutdown();
+      }
+    }
     for (int i = dataNodes.size()-1; i >= 0; i--) {
       shutdownDataNode(i);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org