YARN-2387. Resource Manager crashes with NPE due to lack of synchronization. Contributed by Mit Desai

This commit is contained in:
Jason Lowe 2014-09-30 22:37:28 +00:00
parent 9582a50176
commit feaf139b4f
2 changed files with 14 additions and 11 deletions

View File

@ -485,6 +485,9 @@ Release 2.6.0 - UNRELEASED
YARN-2610. Hamlet should close table tags. (Ray Chiang via kasha) YARN-2610. Hamlet should close table tags. (Ray Chiang via kasha)
YARN-2387. Resource Manager crashes with NPE due to lack of
synchronization (Mit Desai via jlowe)
Release 2.5.1 - 2014-09-05 Release 2.5.1 - 2014-09-05
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -50,7 +50,7 @@ public class ContainerStatusPBImpl extends ContainerStatus {
viaProto = true; viaProto = true;
} }
public ContainerStatusProto getProto() { public synchronized ContainerStatusProto getProto() {
mergeLocalToProto(); mergeLocalToProto();
proto = viaProto ? proto : builder.build(); proto = viaProto ? proto : builder.build();
viaProto = true; viaProto = true;
@ -90,7 +90,7 @@ public class ContainerStatusPBImpl extends ContainerStatus {
} }
} }
private void mergeLocalToProto() { private synchronized void mergeLocalToProto() {
if (viaProto) if (viaProto)
maybeInitBuilder(); maybeInitBuilder();
mergeLocalToBuilder(); mergeLocalToBuilder();
@ -98,7 +98,7 @@ public class ContainerStatusPBImpl extends ContainerStatus {
viaProto = true; viaProto = true;
} }
private void maybeInitBuilder() { private synchronized void maybeInitBuilder() {
if (viaProto || builder == null) { if (viaProto || builder == null) {
builder = ContainerStatusProto.newBuilder(proto); builder = ContainerStatusProto.newBuilder(proto);
} }
@ -107,7 +107,7 @@ public class ContainerStatusPBImpl extends ContainerStatus {
@Override @Override
public ContainerState getState() { public synchronized ContainerState getState() {
ContainerStatusProtoOrBuilder p = viaProto ? proto : builder; ContainerStatusProtoOrBuilder p = viaProto ? proto : builder;
if (!p.hasState()) { if (!p.hasState()) {
return null; return null;
@ -116,7 +116,7 @@ public class ContainerStatusPBImpl extends ContainerStatus {
} }
@Override @Override
public void setState(ContainerState state) { public synchronized void setState(ContainerState state) {
maybeInitBuilder(); maybeInitBuilder();
if (state == null) { if (state == null) {
builder.clearState(); builder.clearState();
@ -125,7 +125,7 @@ public class ContainerStatusPBImpl extends ContainerStatus {
builder.setState(convertToProtoFormat(state)); builder.setState(convertToProtoFormat(state));
} }
@Override @Override
public ContainerId getContainerId() { public synchronized ContainerId getContainerId() {
ContainerStatusProtoOrBuilder p = viaProto ? proto : builder; ContainerStatusProtoOrBuilder p = viaProto ? proto : builder;
if (this.containerId != null) { if (this.containerId != null) {
return this.containerId; return this.containerId;
@ -138,32 +138,32 @@ public class ContainerStatusPBImpl extends ContainerStatus {
} }
@Override @Override
public void setContainerId(ContainerId containerId) { public synchronized void setContainerId(ContainerId containerId) {
maybeInitBuilder(); maybeInitBuilder();
if (containerId == null) if (containerId == null)
builder.clearContainerId(); builder.clearContainerId();
this.containerId = containerId; this.containerId = containerId;
} }
@Override @Override
public int getExitStatus() { public synchronized int getExitStatus() {
ContainerStatusProtoOrBuilder p = viaProto ? proto : builder; ContainerStatusProtoOrBuilder p = viaProto ? proto : builder;
return p.getExitStatus(); return p.getExitStatus();
} }
@Override @Override
public void setExitStatus(int exitStatus) { public synchronized void setExitStatus(int exitStatus) {
maybeInitBuilder(); maybeInitBuilder();
builder.setExitStatus(exitStatus); builder.setExitStatus(exitStatus);
} }
@Override @Override
public String getDiagnostics() { public synchronized String getDiagnostics() {
ContainerStatusProtoOrBuilder p = viaProto ? proto : builder; ContainerStatusProtoOrBuilder p = viaProto ? proto : builder;
return (p.getDiagnostics()); return (p.getDiagnostics());
} }
@Override @Override
public void setDiagnostics(String diagnostics) { public synchronized void setDiagnostics(String diagnostics) {
maybeInitBuilder(); maybeInitBuilder();
builder.setDiagnostics(diagnostics); builder.setDiagnostics(diagnostics);
} }