MAPREDUCE-3931. Changed PB implementation of LocalResource to take locks so that race conditions don't fail tasks by inadvertantly changing the timestamps. Contributed by Siddarth Seth.
svn merge --ignore-ancestry -c 1294970 ../../trunk git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1294973 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4f586249ac
commit
cf56c58fd9
|
@ -130,6 +130,10 @@ Release 0.23.2 - UNRELEASED
|
||||||
task attempt without an assigned container. (Robert Joseph Evans via
|
task attempt without an assigned container. (Robert Joseph Evans via
|
||||||
sseth)
|
sseth)
|
||||||
|
|
||||||
|
MAPREDUCE-3931. Changed PB implementation of LocalResource to take locks
|
||||||
|
so that race conditions don't fail tasks by inadvertantly changing the
|
||||||
|
timestamps. (Siddarth Seth via vinodkv)
|
||||||
|
|
||||||
Release 0.23.1 - 2012-02-17
|
Release 0.23.1 - 2012-02-17
|
||||||
|
|
||||||
NEW FEATURES
|
NEW FEATURES
|
||||||
|
|
|
@ -32,14 +32,14 @@ import org.apache.hadoop.yarn.util.ProtoUtils;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto> implements LocalResource {
|
public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto>
|
||||||
|
implements LocalResource {
|
||||||
LocalResourceProto proto = LocalResourceProto.getDefaultInstance();
|
LocalResourceProto proto = LocalResourceProto.getDefaultInstance();
|
||||||
LocalResourceProto.Builder builder = null;
|
LocalResourceProto.Builder builder = null;
|
||||||
boolean viaProto = false;
|
boolean viaProto = false;
|
||||||
|
|
||||||
private URL url = null;
|
private URL url = null;
|
||||||
|
|
||||||
|
|
||||||
public LocalResourcePBImpl() {
|
public LocalResourcePBImpl() {
|
||||||
builder = LocalResourceProto.newBuilder();
|
builder = LocalResourceProto.newBuilder();
|
||||||
}
|
}
|
||||||
|
@ -49,59 +49,54 @@ public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto> implement
|
||||||
viaProto = true;
|
viaProto = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalResourceProto getProto() {
|
public synchronized LocalResourceProto getProto() {
|
||||||
mergeLocalToProto();
|
mergeLocalToBuilder();
|
||||||
proto = viaProto ? proto : builder.build();
|
proto = viaProto ? proto : builder.build();
|
||||||
viaProto = true;
|
viaProto = true;
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeLocalToBuilder() {
|
private synchronized void mergeLocalToBuilder() {
|
||||||
if (this.url != null) {
|
LocalResourceProtoOrBuilder l = viaProto ? proto : builder;
|
||||||
|
if (this.url != null
|
||||||
|
&& !(l.getResource().equals(((URLPBImpl) url).getProto()))) {
|
||||||
|
maybeInitBuilder();
|
||||||
|
l = builder;
|
||||||
builder.setResource(convertToProtoFormat(this.url));
|
builder.setResource(convertToProtoFormat(this.url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeLocalToProto() {
|
private synchronized void maybeInitBuilder() {
|
||||||
if (viaProto)
|
|
||||||
maybeInitBuilder();
|
|
||||||
mergeLocalToBuilder();
|
|
||||||
proto = builder.build();
|
|
||||||
viaProto = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void maybeInitBuilder() {
|
|
||||||
if (viaProto || builder == null) {
|
if (viaProto || builder == null) {
|
||||||
builder = LocalResourceProto.newBuilder(proto);
|
builder = LocalResourceProto.newBuilder(proto);
|
||||||
}
|
}
|
||||||
viaProto = false;
|
viaProto = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getSize() {
|
public synchronized long getSize() {
|
||||||
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
||||||
return (p.getSize());
|
return (p.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSize(long size) {
|
public synchronized void setSize(long size) {
|
||||||
maybeInitBuilder();
|
maybeInitBuilder();
|
||||||
builder.setSize((size));
|
builder.setSize((size));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public long getTimestamp() {
|
public synchronized long getTimestamp() {
|
||||||
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
||||||
return (p.getTimestamp());
|
return (p.getTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTimestamp(long timestamp) {
|
public synchronized void setTimestamp(long timestamp) {
|
||||||
maybeInitBuilder();
|
maybeInitBuilder();
|
||||||
builder.setTimestamp((timestamp));
|
builder.setTimestamp((timestamp));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public LocalResourceType getType() {
|
public synchronized LocalResourceType getType() {
|
||||||
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
||||||
if (!p.hasType()) {
|
if (!p.hasType()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -110,7 +105,7 @@ public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto> implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setType(LocalResourceType type) {
|
public synchronized void setType(LocalResourceType type) {
|
||||||
maybeInitBuilder();
|
maybeInitBuilder();
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
builder.clearType();
|
builder.clearType();
|
||||||
|
@ -119,7 +114,7 @@ public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto> implement
|
||||||
builder.setType(convertToProtoFormat(type));
|
builder.setType(convertToProtoFormat(type));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public URL getResource() {
|
public synchronized URL getResource() {
|
||||||
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
||||||
if (this.url != null) {
|
if (this.url != null) {
|
||||||
return this.url;
|
return this.url;
|
||||||
|
@ -132,14 +127,14 @@ public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto> implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResource(URL resource) {
|
public synchronized void setResource(URL resource) {
|
||||||
maybeInitBuilder();
|
maybeInitBuilder();
|
||||||
if (resource == null)
|
if (resource == null)
|
||||||
builder.clearResource();
|
builder.clearResource();
|
||||||
this.url = resource;
|
this.url = resource;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public LocalResourceVisibility getVisibility() {
|
public synchronized LocalResourceVisibility getVisibility() {
|
||||||
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
LocalResourceProtoOrBuilder p = viaProto ? proto : builder;
|
||||||
if (!p.hasVisibility()) {
|
if (!p.hasVisibility()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -148,7 +143,7 @@ public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto> implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVisibility(LocalResourceVisibility visibility) {
|
public synchronized void setVisibility(LocalResourceVisibility visibility) {
|
||||||
maybeInitBuilder();
|
maybeInitBuilder();
|
||||||
if (visibility == null) {
|
if (visibility == null) {
|
||||||
builder.clearVisibility();
|
builder.clearVisibility();
|
||||||
|
@ -180,7 +175,4 @@ public class LocalResourcePBImpl extends ProtoBase<LocalResourceProto> implement
|
||||||
private LocalResourceVisibility convertFromProtoFormat(LocalResourceVisibilityProto e) {
|
private LocalResourceVisibility convertFromProtoFormat(LocalResourceVisibilityProto e) {
|
||||||
return ProtoUtils.convertFromProtoFormat(e);
|
return ProtoUtils.convertFromProtoFormat(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue