Skip to content

Commit 7e91921

Browse files
committed
Revert "HDFS-16898. Make write lock fine-grain in method processCommandFromActor (#5330). Contributed by ZhangHB."
This reverts commit eb04ecd.
1 parent eb04ecd commit 7e91921

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPOfferService.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -679,20 +679,15 @@ boolean processCommandFromActor(DatanodeCommand cmd,
679679
actor.reRegister();
680680
return false;
681681
}
682-
boolean isActiveActor;
683-
InetSocketAddress nnSocketAddress;
684-
readLock();
682+
writeLock();
685683
try {
686-
isActiveActor = (actor == bpServiceToActive);
687-
nnSocketAddress = actor.getNNSocketAddress();
684+
if (actor == bpServiceToActive) {
685+
return processCommandFromActive(cmd, actor);
686+
} else {
687+
return processCommandFromStandby(cmd, actor);
688+
}
688689
} finally {
689-
readUnlock();
690-
}
691-
692-
if (isActiveActor) {
693-
return processCommandFromActive(cmd, nnSocketAddress);
694-
} else {
695-
return processCommandFromStandby(cmd, nnSocketAddress);
690+
writeUnlock();
696691
}
697692
}
698693

@@ -720,7 +715,7 @@ private String blockIdArrayToString(long ids[]) {
720715
* @throws IOException
721716
*/
722717
private boolean processCommandFromActive(DatanodeCommand cmd,
723-
InetSocketAddress nnSocketAddress) throws IOException {
718+
BPServiceActor actor) throws IOException {
724719
final BlockCommand bcmd =
725720
cmd instanceof BlockCommand? (BlockCommand)cmd: null;
726721
final BlockIdCommand blockIdCmd =
@@ -773,7 +768,7 @@ assert getBlockPoolId().equals(bp) :
773768
dn.finalizeUpgradeForPool(bp);
774769
break;
775770
case DatanodeProtocol.DNA_RECOVERBLOCK:
776-
String who = "NameNode at " + nnSocketAddress;
771+
String who = "NameNode at " + actor.getNNSocketAddress();
777772
dn.getBlockRecoveryWorker().recoverBlocks(who,
778773
((BlockRecoveryCommand)cmd).getRecoveringBlocks());
779774
break;
@@ -815,11 +810,11 @@ assert getBlockPoolId().equals(bp) :
815810
* DNA_REGISTER which should be handled earlier itself.
816811
*/
817812
private boolean processCommandFromStandby(DatanodeCommand cmd,
818-
InetSocketAddress nnSocketAddress) throws IOException {
813+
BPServiceActor actor) throws IOException {
819814
switch(cmd.getAction()) {
820815
case DatanodeProtocol.DNA_ACCESSKEYUPDATE:
821816
LOG.info("DatanodeCommand action from standby NN {}: DNA_ACCESSKEYUPDATE",
822-
nnSocketAddress);
817+
actor.getNNSocketAddress());
823818
if (dn.isBlockTokenEnabled) {
824819
dn.blockPoolTokenSecretManager.addKeys(
825820
getBlockPoolId(),
@@ -836,11 +831,11 @@ private boolean processCommandFromStandby(DatanodeCommand cmd,
836831
case DatanodeProtocol.DNA_UNCACHE:
837832
case DatanodeProtocol.DNA_ERASURE_CODING_RECONSTRUCTION:
838833
LOG.warn("Got a command from standby NN {} - ignoring command: {}",
839-
nnSocketAddress, cmd.getAction());
834+
actor.getNNSocketAddress(), cmd.getAction());
840835
break;
841836
default:
842837
LOG.warn("Unknown DatanodeCommand action: {} from standby NN {}",
843-
cmd.getAction(), nnSocketAddress);
838+
cmd.getAction(), actor.getNNSocketAddress());
844839
}
845840
return true;
846841
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BPServiceActor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ private boolean processCommand(DatanodeCommand[] cmds) {
14991499
dn.getMetrics().addNumProcessedCommands(processCommandsMs);
15001500
}
15011501
if (processCommandsMs > dnConf.getProcessCommandsThresholdMs()) {
1502-
LOG.warn("Took {} ms to process {} commands from NN",
1502+
LOG.info("Took {} ms to process {} commands from NN",
15031503
processCommandsMs, cmds.length);
15041504
}
15051505
}

0 commit comments

Comments
 (0)