From c9a09d6926b258e205a4ff7998ce5a86bf5dbe3b Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Fri, 29 Jan 2016 08:12:54 -0800 Subject: [PATCH] YARN-4647. Make RegisterNodeManagerRequestPBImpl thread-safe. (kasha) --- hadoop-yarn-project/CHANGES.txt | 2 + .../pb/RegisterNodeManagerRequestPBImpl.java | 75 ++++++++++--------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 138e58184d9..76cad7fc011 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -113,6 +113,8 @@ Release 2.9.0 - UNRELEASED integrated ResourceHandler mechanism, and also deprecated the old LCEResourceHandler inteface hierarchy. (Varun Vasudev via vinodkv) + YARN-4647. Make RegisterNodeManagerRequestPBImpl thread-safe. (kasha) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/RegisterNodeManagerRequestPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/RegisterNodeManagerRequestPBImpl.java index 5b0e0a1f87c..2a1a26822cc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/RegisterNodeManagerRequestPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/protocolrecords/impl/pb/RegisterNodeManagerRequestPBImpl.java @@ -65,14 +65,14 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest viaProto = true; } - public RegisterNodeManagerRequestProto getProto() { - mergeLocalToProto(); + public synchronized RegisterNodeManagerRequestProto getProto() { + mergeLocalToProto(); proto = viaProto ? proto : builder.build(); viaProto = true; return proto; } - private void mergeLocalToBuilder() { + private synchronized void mergeLocalToBuilder() { if (this.containerStatuses != null) { addNMContainerStatusesToProto(); } @@ -107,15 +107,16 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } - private void mergeLocalToProto() { - if (viaProto) + private synchronized void mergeLocalToProto() { + if (viaProto) { maybeInitBuilder(); + } mergeLocalToBuilder(); proto = builder.build(); viaProto = true; } - private void maybeInitBuilder() { + private synchronized void maybeInitBuilder() { if (viaProto || builder == null) { builder = RegisterNodeManagerRequestProto.newBuilder(proto); } @@ -124,7 +125,7 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest @Override - public Resource getResource() { + public synchronized Resource getResource() { RegisterNodeManagerRequestProtoOrBuilder p = viaProto ? proto : builder; if (this.resource != null) { return this.resource; @@ -137,7 +138,7 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public void setResource(Resource resource) { + public synchronized void setResource(Resource resource) { maybeInitBuilder(); if (resource == null) builder.clearResource(); @@ -145,7 +146,7 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public NodeId getNodeId() { + public synchronized NodeId getNodeId() { RegisterNodeManagerRequestProtoOrBuilder p = viaProto ? proto : builder; if (this.nodeId != null) { return this.nodeId; @@ -158,15 +159,16 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public void setNodeId(NodeId nodeId) { + public synchronized void setNodeId(NodeId nodeId) { maybeInitBuilder(); - if (nodeId == null) + if (nodeId == null) { builder.clearNodeId(); + } this.nodeId = nodeId; } @Override - public int getHttpPort() { + public synchronized int getHttpPort() { RegisterNodeManagerRequestProtoOrBuilder p = viaProto ? proto : builder; if (!p.hasHttpPort()) { return 0; @@ -175,18 +177,18 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public void setHttpPort(int httpPort) { + public synchronized void setHttpPort(int httpPort) { maybeInitBuilder(); builder.setHttpPort(httpPort); } @Override - public List getRunningApplications() { + public synchronized List getRunningApplications() { initRunningApplications(); return runningApplications; } - private void initRunningApplications() { + private synchronized void initRunningApplications() { if (this.runningApplications != null) { return; } @@ -199,7 +201,7 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public void setRunningApplications(List apps) { + public synchronized void setRunningApplications(List apps) { if (apps == null) { return; } @@ -207,7 +209,7 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest this.runningApplications.addAll(apps); } - private void addRunningApplicationsToProto() { + private synchronized void addRunningApplicationsToProto() { maybeInitBuilder(); builder.clearRunningApplications(); if (runningApplications == null) { @@ -241,12 +243,12 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public List getNMContainerStatuses() { + public synchronized List getNMContainerStatuses() { initContainerRecoveryReports(); return containerStatuses; } - private void initContainerRecoveryReports() { + private synchronized void initContainerRecoveryReports() { if (this.containerStatuses != null) { return; } @@ -259,7 +261,7 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public void setContainerStatuses( + public synchronized void setContainerStatuses( List containerReports) { if (containerReports == null) { return; @@ -284,7 +286,7 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public String getNMVersion() { + public synchronized String getNMVersion() { RegisterNodeManagerRequestProtoOrBuilder p = viaProto ? proto : builder; if (!p.hasNmVersion()) { return ""; @@ -293,25 +295,25 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } @Override - public void setNMVersion(String version) { + public synchronized void setNMVersion(String version) { maybeInitBuilder(); builder.setNmVersion(version); } @Override - public Set getNodeLabels() { + public synchronized Set getNodeLabels() { initNodeLabels(); return this.labels; } @Override - public void setNodeLabels(Set nodeLabels) { + public synchronized void setNodeLabels(Set nodeLabels) { maybeInitBuilder(); builder.clearNodeLabels(); this.labels = nodeLabels; } - private void initNodeLabels() { + private synchronized void initNodeLabels() { if (this.labels != null) { return; } @@ -327,43 +329,46 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest } } - private NodeLabelPBImpl convertFromProtoFormat(NodeLabelProto p) { + private static NodeLabelPBImpl convertFromProtoFormat(NodeLabelProto p) { return new NodeLabelPBImpl(p); } - private NodeLabelProto convertToProtoFormat(NodeLabel t) { + private static NodeLabelProto convertToProtoFormat(NodeLabel t) { return ((NodeLabelPBImpl)t).getProto(); } - private ApplicationIdPBImpl convertFromProtoFormat(ApplicationIdProto p) { + private static ApplicationIdPBImpl convertFromProtoFormat( + ApplicationIdProto p) { return new ApplicationIdPBImpl(p); } - private ApplicationIdProto convertToProtoFormat(ApplicationId t) { + private static ApplicationIdProto convertToProtoFormat(ApplicationId t) { return ((ApplicationIdPBImpl)t).getProto(); } - private NodeIdPBImpl convertFromProtoFormat(NodeIdProto p) { + private static NodeIdPBImpl convertFromProtoFormat(NodeIdProto p) { return new NodeIdPBImpl(p); } - private NodeIdProto convertToProtoFormat(NodeId t) { + private static NodeIdProto convertToProtoFormat(NodeId t) { return ((NodeIdPBImpl)t).getProto(); } - private ResourcePBImpl convertFromProtoFormat(ResourceProto p) { + private static ResourcePBImpl convertFromProtoFormat(ResourceProto p) { return new ResourcePBImpl(p); } - private ResourceProto convertToProtoFormat(Resource t) { + private static ResourceProto convertToProtoFormat(Resource t) { return ((ResourcePBImpl)t).getProto(); } - private NMContainerStatusPBImpl convertFromProtoFormat(NMContainerStatusProto c) { + private static NMContainerStatusPBImpl convertFromProtoFormat( + NMContainerStatusProto c) { return new NMContainerStatusPBImpl(c); } - private NMContainerStatusProto convertToProtoFormat(NMContainerStatus c) { + private static NMContainerStatusProto convertToProtoFormat( + NMContainerStatus c) { return ((NMContainerStatusPBImpl)c).getProto(); } } \ No newline at end of file