From b2ce764093ba3007df67022b3bcbc43d3fe2b173 Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Thu, 6 Feb 2014 00:40:24 +0000 Subject: [PATCH] HDFS-5890. Avoid NPE in Datanode heartbeat. Contributed by Vinay git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-5535@1565023 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt | 2 ++ .../DatanodeProtocolClientSideTranslatorPB.java | 10 +++++++--- .../DatanodeProtocolServerSideTranslatorPB.java | 9 +++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt index 1bae747730f..5feb1c47f39 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt @@ -20,3 +20,5 @@ HDFS-5535 subtasks: DataNodeLayoutVersion. (Brandon Li via szetszwo) HDFS-5848. Add rolling upgrade status to heartbeat response. (szetszwo) + + HDFS-5890. Avoid NPE in Datanode heartbeat. (Vinay via brandonli) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolClientSideTranslatorPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolClientSideTranslatorPB.java index aa3695e82e1..9a8503c99c2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolClientSideTranslatorPB.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolClientSideTranslatorPB.java @@ -34,6 +34,7 @@ import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.LocatedBlock; +import org.apache.hadoop.hdfs.protocol.RollingUpgradeStatus; import org.apache.hadoop.hdfs.protocol.proto.DatanodeProtocolProtos.BlockReceivedAndDeletedRequestProto; import org.apache.hadoop.hdfs.protocol.proto.DatanodeProtocolProtos.BlockReportRequestProto; import org.apache.hadoop.hdfs.protocol.proto.DatanodeProtocolProtos.BlockReportResponseProto; @@ -183,9 +184,12 @@ public class DatanodeProtocolClientSideTranslatorPB implements cmds[index] = PBHelper.convert(p); index++; } - return new HeartbeatResponse(cmds, - PBHelper.convert(resp.getHaStatus()), - PBHelper.convert(resp.getRollingUpgradeStatus())); + RollingUpgradeStatus rollingUpdateStatus = null; + if (resp.hasRollingUpgradeStatus()) { + rollingUpdateStatus = PBHelper.convert(resp.getRollingUpgradeStatus()); + } + return new HeartbeatResponse(cmds, PBHelper.convert(resp.getHaStatus()), + rollingUpdateStatus); } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolServerSideTranslatorPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolServerSideTranslatorPB.java index d3063c9290d..b7071f60366 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolServerSideTranslatorPB.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/DatanodeProtocolServerSideTranslatorPB.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.LocatedBlock; +import org.apache.hadoop.hdfs.protocol.RollingUpgradeStatus; import org.apache.hadoop.hdfs.protocol.proto.DatanodeProtocolProtos.BlockReceivedAndDeletedRequestProto; import org.apache.hadoop.hdfs.protocol.proto.DatanodeProtocolProtos.BlockReceivedAndDeletedResponseProto; import org.apache.hadoop.hdfs.protocol.proto.DatanodeProtocolProtos.BlockReportRequestProto; @@ -121,8 +122,12 @@ public class DatanodeProtocolServerSideTranslatorPB implements } } builder.setHaStatus(PBHelper.convert(response.getNameNodeHaState())); - builder.setRollingUpgradeStatus(PBHelper.convertRollingUpgradeStatus( - response.getRollingUpdateStatus())); + RollingUpgradeStatus rollingUpdateStatus = response + .getRollingUpdateStatus(); + if (rollingUpdateStatus != null) { + builder.setRollingUpgradeStatus(PBHelper + .convertRollingUpgradeStatus(rollingUpdateStatus)); + } return builder.build(); }