YARN-4647. Make RegisterNodeManagerRequestPBImpl thread-safe. (kasha)
This commit is contained in:
parent
a277bdc9ed
commit
c9a09d6926
|
@ -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
|
||||
|
|
|
@ -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<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 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setRunningApplications(List<ApplicationId> apps) {
|
||||
public synchronized void setRunningApplications(List<ApplicationId> 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<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 @@ public class RegisterNodeManagerRequestPBImpl extends RegisterNodeManagerRequest
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setContainerStatuses(
|
||||
public synchronized void setContainerStatuses(
|
||||
List<NMContainerStatus> 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<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 @@ 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue