From 7e919212c4672c99072dbecf8a1ec48fcb6de5f0 Mon Sep 17 00:00:00 2001 From: He Xiaoqiao Date: Wed, 8 Feb 2023 11:15:22 +0800 Subject: [PATCH] Revert "HDFS-16898. Make write lock fine-grain in method processCommandFromActor (#5330). Contributed by ZhangHB." This reverts commit eb04ecd29d4a38b1b00612cbb3a56ed3a34a9572. --- .../hdfs/server/datanode/BPOfferService.java | 31 ++++++++----------- .../hdfs/server/datanode/BPServiceActor.java | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java index fdd66cb05d..d660970c72 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java @@ -679,20 +679,15 @@ boolean processCommandFromActor(DatanodeCommand cmd, actor.reRegister(); return false; } - boolean isActiveActor; - InetSocketAddress nnSocketAddress; - readLock(); + writeLock(); try { - isActiveActor = (actor == bpServiceToActive); - nnSocketAddress = actor.getNNSocketAddress(); + if (actor == bpServiceToActive) { + return processCommandFromActive(cmd, actor); + } else { + return processCommandFromStandby(cmd, actor); + } } finally { - readUnlock(); - } - - if (isActiveActor) { - return processCommandFromActive(cmd, nnSocketAddress); - } else { - return processCommandFromStandby(cmd, nnSocketAddress); + writeUnlock(); } } @@ -720,7 +715,7 @@ private String blockIdArrayToString(long ids[]) { * @throws IOException */ private boolean processCommandFromActive(DatanodeCommand cmd, - InetSocketAddress nnSocketAddress) throws IOException { + BPServiceActor actor) throws IOException { final BlockCommand bcmd = cmd instanceof BlockCommand? (BlockCommand)cmd: null; final BlockIdCommand blockIdCmd = @@ -773,7 +768,7 @@ assert getBlockPoolId().equals(bp) : dn.finalizeUpgradeForPool(bp); break; case DatanodeProtocol.DNA_RECOVERBLOCK: - String who = "NameNode at " + nnSocketAddress; + String who = "NameNode at " + actor.getNNSocketAddress(); dn.getBlockRecoveryWorker().recoverBlocks(who, ((BlockRecoveryCommand)cmd).getRecoveringBlocks()); break; @@ -815,11 +810,11 @@ assert getBlockPoolId().equals(bp) : * DNA_REGISTER which should be handled earlier itself. */ private boolean processCommandFromStandby(DatanodeCommand cmd, - InetSocketAddress nnSocketAddress) throws IOException { + BPServiceActor actor) throws IOException { switch(cmd.getAction()) { case DatanodeProtocol.DNA_ACCESSKEYUPDATE: LOG.info("DatanodeCommand action from standby NN {}: DNA_ACCESSKEYUPDATE", - nnSocketAddress); + actor.getNNSocketAddress()); if (dn.isBlockTokenEnabled) { dn.blockPoolTokenSecretManager.addKeys( getBlockPoolId(), @@ -836,11 +831,11 @@ private boolean processCommandFromStandby(DatanodeCommand cmd, case DatanodeProtocol.DNA_UNCACHE: case DatanodeProtocol.DNA_ERASURE_CODING_RECONSTRUCTION: LOG.warn("Got a command from standby NN {} - ignoring command: {}", - nnSocketAddress, cmd.getAction()); + actor.getNNSocketAddress(), cmd.getAction()); break; default: LOG.warn("Unknown DatanodeCommand action: {} from standby NN {}", - cmd.getAction(), nnSocketAddress); + cmd.getAction(), actor.getNNSocketAddress()); } return true; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java index e9f424604b..35ab619314 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java @@ -1499,7 +1499,7 @@ private boolean processCommand(DatanodeCommand[] cmds) { dn.getMetrics().addNumProcessedCommands(processCommandsMs); } if (processCommandsMs > dnConf.getProcessCommandsThresholdMs()) { - LOG.warn("Took {} ms to process {} commands from NN", + LOG.info("Took {} ms to process {} commands from NN", processCommandsMs, cmds.length); } }