YARN-4647. Make RegisterNodeManagerRequestPBImpl thread-safe. (kasha)

This commit is contained in:
Karthik Kambatla 2016-01-29 08:12:54 -08:00
parent a277bdc9ed
commit c9a09d6926
2 changed files with 42 additions and 35 deletions

View File

@ -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

View File

@ -65,14 +65,14 @@ public RegisterNodeManagerRequestPBImpl(RegisterNodeManagerRequestProto proto) {
viaProto = true;
}
public RegisterNodeManagerRequestProto getProto() {
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 @@ private synchronized void addNMContainerStatusesToProto() {
}
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 @@ private void maybeInitBuilder() {
@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 Resource getResource() {
}
@Override
public void setResource(Resource resource) {
public synchronized void setResource(Resource resource) {
maybeInitBuilder();
if (resource == null)
builder.clearResource();
@ -145,7 +146,7 @@ public void setResource(Resource resource) {
}
@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 NodeId getNodeId() {
}
@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 int getHttpPort() {
}
@Override
public void setHttpPort(int httpPort) {
public synchronized void setHttpPort(int httpPort) {
maybeInitBuilder();
builder.setHttpPort(httpPort);
}
@Override
public List<ApplicationId> getRunningApplications() {
public synchronized List<ApplicationId> getRunningApplications() {
initRunningApplications();
return runningApplications;
}
private void initRunningApplications() {
private synchronized void initRunningApplications() {
if (this.runningApplications != null) {
return;
}
@ -199,7 +201,7 @@ private void initRunningApplications() {
}
@Override
public void setRunningApplications(List<ApplicationId> apps) {
public synchronized void setRunningApplications(List<ApplicationId> apps) {
if (apps == null) {
return;
}
@ -207,7 +209,7 @@ public void setRunningApplications(List<ApplicationId> apps) {
this.runningApplications.addAll(apps);
}
private void addRunningApplicationsToProto() {
private synchronized void addRunningApplicationsToProto() {
maybeInitBuilder();
builder.clearRunningApplications();
if (runningApplications == null) {
@ -241,12 +243,12 @@ public void remove() {
}
@Override
public List<NMContainerStatus> getNMContainerStatuses() {
public synchronized List<NMContainerStatus> getNMContainerStatuses() {
initContainerRecoveryReports();
return containerStatuses;
}
private void initContainerRecoveryReports() {
private synchronized void initContainerRecoveryReports() {
if (this.containerStatuses != null) {
return;
}
@ -259,7 +261,7 @@ private void initContainerRecoveryReports() {
}
@Override
public void setContainerStatuses(
public synchronized void setContainerStatuses(
List<NMContainerStatus> containerReports) {
if (containerReports == null) {
return;
@ -284,7 +286,7 @@ public boolean equals(Object other) {
}
@Override
public String getNMVersion() {
public synchronized String getNMVersion() {
RegisterNodeManagerRequestProtoOrBuilder p = viaProto ? proto : builder;
if (!p.hasNmVersion()) {
return "";
@ -293,25 +295,25 @@ public String getNMVersion() {
}
@Override
public void setNMVersion(String version) {
public synchronized void setNMVersion(String version) {
maybeInitBuilder();
builder.setNmVersion(version);
}
@Override
public Set<NodeLabel> getNodeLabels() {
public synchronized Set<NodeLabel> getNodeLabels() {
initNodeLabels();
return this.labels;
}
@Override
public void setNodeLabels(Set<NodeLabel> nodeLabels) {
public synchronized void setNodeLabels(Set<NodeLabel> nodeLabels) {
maybeInitBuilder();
builder.clearNodeLabels();
this.labels = nodeLabels;
}
private void initNodeLabels() {
private synchronized void initNodeLabels() {
if (this.labels != null) {
return;
}
@ -327,43 +329,46 @@ private void initNodeLabels() {
}
}
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();
}
}