MAPREDUCE-4384. Race conditions in IndexCache (Kihwal Lee via tgraves)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1357937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9a43f05129
commit
3d5a44f919
|
@ -638,6 +638,8 @@ Release 0.23.3 - UNRELEASED
|
||||||
MAPREDUCE-4392. Counters.makeCompactString() changed behavior from 0.20
|
MAPREDUCE-4392. Counters.makeCompactString() changed behavior from 0.20
|
||||||
(Jason Lowe via bobby)
|
(Jason Lowe via bobby)
|
||||||
|
|
||||||
|
MAPREDUCE-4384. Race conditions in IndexCache (Kihwal Lee via tgraves)
|
||||||
|
|
||||||
Release 0.23.2 - UNRELEASED
|
Release 0.23.2 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -67,15 +67,15 @@ class IndexCache {
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
info = readIndexFileToCache(fileName, mapId, expectedIndexOwner);
|
info = readIndexFileToCache(fileName, mapId, expectedIndexOwner);
|
||||||
} else {
|
} else {
|
||||||
synchronized (info) {
|
while (isUnderConstruction(info)) {
|
||||||
while (null == info.mapSpillRecord) {
|
|
||||||
try {
|
try {
|
||||||
info.wait();
|
// In case the entry is ready after the above check but
|
||||||
|
// before the following wait, we do timed wait.
|
||||||
|
info.wait(200);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IOException("Interrupted waiting for construction", e);
|
throw new IOException("Interrupted waiting for construction", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
LOG.debug("IndexCache HIT: MapId " + mapId + " found");
|
LOG.debug("IndexCache HIT: MapId " + mapId + " found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,12 @@ class IndexCache {
|
||||||
return info.mapSpillRecord.getIndex(reduce);
|
return info.mapSpillRecord.getIndex(reduce);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isUnderConstruction(IndexInformation info) {
|
||||||
|
synchronized(info) {
|
||||||
|
return (null == info.mapSpillRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IndexInformation readIndexFileToCache(Path indexFileName,
|
private IndexInformation readIndexFileToCache(Path indexFileName,
|
||||||
String mapId,
|
String mapId,
|
||||||
String expectedIndexOwner)
|
String expectedIndexOwner)
|
||||||
|
@ -95,15 +101,15 @@ class IndexCache {
|
||||||
IndexInformation info;
|
IndexInformation info;
|
||||||
IndexInformation newInd = new IndexInformation();
|
IndexInformation newInd = new IndexInformation();
|
||||||
if ((info = cache.putIfAbsent(mapId, newInd)) != null) {
|
if ((info = cache.putIfAbsent(mapId, newInd)) != null) {
|
||||||
synchronized (info) {
|
while (isUnderConstruction(info)) {
|
||||||
while (null == info.mapSpillRecord) {
|
|
||||||
try {
|
try {
|
||||||
info.wait();
|
// In case the entry is ready after the above check but
|
||||||
|
// before the following wait, we do timed wait.
|
||||||
|
info.wait(200);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IOException("Interrupted waiting for construction", e);
|
throw new IOException("Interrupted waiting for construction", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
LOG.debug("IndexCache HIT: MapId " + mapId + " found");
|
LOG.debug("IndexCache HIT: MapId " + mapId + " found");
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +145,7 @@ class IndexCache {
|
||||||
*/
|
*/
|
||||||
public void removeMap(String mapId) {
|
public void removeMap(String mapId) {
|
||||||
IndexInformation info = cache.get(mapId);
|
IndexInformation info = cache.get(mapId);
|
||||||
if ((info != null) && (info.getSize() == 0)) {
|
if (info == null || ((info != null) && isUnderConstruction(info))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
info = cache.remove(mapId);
|
info = cache.remove(mapId);
|
||||||
|
|
Loading…
Reference in New Issue