Skip to content

Commit 740bc98

Browse files
committed
YARN-1986. In Fifo Scheduler, node heartbeat in between creating app and attempt causes NPE (Hong Zhiguo via Sandy Ryza)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1594476 13f79535-47bb-0310-9956-ffa450edef68
1 parent ebaafb2 commit 740bc98

File tree

3 files changed

+41
-3
lines changed
  • hadoop-yarn-project

3 files changed

+41
-3
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ Release 2.4.1 - UNRELEASED
222222
YARN-1957. Consider the max capacity of the queue when computing the ideal
223223
capacity for preemption. (Carlo Curino via cdouglas)
224224

225+
YARN-1986. In Fifo Scheduler, node heartbeat in between creating app and
226+
attempt causes NPE (Hong Zhiguo via Sandy Ryza)
227+
225228
Release 2.4.0 - 2014-04-07
226229

227230
INCOMPATIBLE CHANGES

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fifo/FifoScheduler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ private FiCaSchedulerNode getNode(NodeId nodeId) {
360360
return nodes.get(nodeId);
361361
}
362362

363-
private synchronized void addApplication(ApplicationId applicationId,
363+
@VisibleForTesting
364+
public synchronized void addApplication(ApplicationId applicationId,
364365
String queue, String user) {
365366
SchedulerApplication application =
366367
new SchedulerApplication(DEFAULT_QUEUE, user);
@@ -372,7 +373,8 @@ private synchronized void addApplication(ApplicationId applicationId,
372373
.handle(new RMAppEvent(applicationId, RMAppEventType.APP_ACCEPTED));
373374
}
374375

375-
private synchronized void
376+
@VisibleForTesting
377+
public synchronized void
376378
addApplicationAttempt(ApplicationAttemptId appAttemptId,
377379
boolean transferStateFromPreviousAttempt) {
378380
SchedulerApplication application =
@@ -458,6 +460,9 @@ private void assignContainers(FiCaSchedulerNode node) {
458460
.entrySet()) {
459461
FiCaSchedulerApp application =
460462
(FiCaSchedulerApp) e.getValue().getCurrentAppAttempt();
463+
if (application == null) {
464+
continue;
465+
}
461466
LOG.debug("pre-assignContainers");
462467
application.showRequests();
463468
synchronized (application) {
@@ -497,6 +502,9 @@ private void assignContainers(FiCaSchedulerNode node) {
497502
for (SchedulerApplication application : applications.values()) {
498503
FiCaSchedulerApp attempt =
499504
(FiCaSchedulerApp) application.getCurrentAppAttempt();
505+
if (attempt == null) {
506+
continue;
507+
}
500508
attempt.setHeadroom(Resources.subtract(clusterResource, usedResource));
501509
}
502510
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestFifoScheduler.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent;
5353
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler;
5454
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
55+
import org.apache.hadoop.yarn.util.resource.Resources;
5556
import org.apache.log4j.Level;
5657
import org.apache.log4j.LogManager;
5758
import org.apache.log4j.Logger;
@@ -66,7 +67,7 @@ public class TestFifoScheduler {
6667

6768
private final int GB = 1024;
6869
private static YarnConfiguration conf;
69-
70+
7071
@BeforeClass
7172
public static void setup() {
7273
conf = new YarnConfiguration();
@@ -213,6 +214,32 @@ public void test() throws Exception {
213214
rm.stop();
214215
}
215216

217+
@Test
218+
public void testNodeUpdateBeforeAppAttemptInit() throws Exception {
219+
FifoScheduler scheduler = new FifoScheduler();
220+
MockRM rm = new MockRM(conf);
221+
scheduler.reinitialize(conf, rm.getRMContext());
222+
223+
RMNode node = MockNodes.newNodeInfo(1,
224+
Resources.createResource(1024, 4), 1, "127.0.0.1");
225+
scheduler.handle(new NodeAddedSchedulerEvent(node));
226+
227+
ApplicationId appId = ApplicationId.newInstance(0, 1);
228+
scheduler.addApplication(appId, "queue1", "user1");
229+
230+
NodeUpdateSchedulerEvent updateEvent = new NodeUpdateSchedulerEvent(node);
231+
try {
232+
scheduler.handle(updateEvent);
233+
} catch (NullPointerException e) {
234+
Assert.fail();
235+
}
236+
237+
ApplicationAttemptId attId = ApplicationAttemptId.newInstance(appId, 1);
238+
scheduler.addApplicationAttempt(attId, false);
239+
240+
rm.stop();
241+
}
242+
216243
private void testMinimumAllocation(YarnConfiguration conf, int testAlloc)
217244
throws Exception {
218245
MockRM rm = new MockRM(conf);

0 commit comments

Comments
 (0)