From b6698e2a828a652e995d4cfe83d8fcd095fdeee2 Mon Sep 17 00:00:00 2001 From: Yiqun Lin Date: Tue, 9 Oct 2018 10:33:13 +0800 Subject: [PATCH] HDFS-13962. Add null check for add-replica pool to avoid lock acquiring. Contributed by Surendra Singh Lilhore. (cherry picked from commit 1043795f7fe44c98a34f8ea3cea708c801c3043b) --- .../hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java | 6 ++++-- .../hdfs/server/datanode/fsdataset/impl/ReplicaMap.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java index b9b581fedca..4a4fef9d1fe 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java @@ -183,8 +183,10 @@ class BlockPoolSlice { .setConf(conf) .setInitialUsed(loadDfsUsed()) .build(); - // initialize add replica fork join pool - initializeAddReplicaPool(conf); + if (addReplicaThreadPool == null) { + // initialize add replica fork join pool + initializeAddReplicaPool(conf); + } // Make the dfs usage to be saved during shutdown. shutdownHook = new Runnable() { @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/ReplicaMap.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/ReplicaMap.java index c630b951a81..73d3c600b9c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/ReplicaMap.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/ReplicaMap.java @@ -154,7 +154,7 @@ class ReplicaMap { if (oldReplicaInfo != null) { return oldReplicaInfo; } else { - set.add(replicaInfo); + set.addOrReplace(replicaInfo); } return replicaInfo; }