From 6baebcaedceb266c5aa65151ef7bba9cc7838595 Mon Sep 17 00:00:00 2001 From: Wangda Tan Date: Thu, 23 Jul 2015 10:07:57 -0700 Subject: [PATCH] YARN-3941. Proportional Preemption policy should try to avoid sending duplicate PREEMPT_CONTAINER event to scheduler. (Sunil G via wangda) (cherry picked from commit 3bba1800513b38a4827f7552f348db87dc47c783) --- hadoop-yarn-project/CHANGES.txt | 2 ++ .../capacity/ProportionalCapacityPreemptionPolicy.java | 9 ++++++--- .../TestProportionalCapacityPreemptionPolicy.java | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 7905676ff3c..711e88d5467 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -612,6 +612,8 @@ Release 2.8.0 - UNRELEASED YARN-3956. Fix TestNodeManagerHardwareUtils fails on Mac (Varun Vasudev via wangda) + YARN-3941. Proportional Preemption policy should try to avoid sending duplicate PREEMPT_CONTAINER event to scheduler. (Sunil G via wangda) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicy.java index 1152cef3778..77df05989d7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/ProportionalCapacityPreemptionPolicy.java @@ -260,13 +260,16 @@ public class ProportionalCapacityPreemptionPolicy implements SchedulingEditPolic SchedulerEventType.KILL_CONTAINER)); preempted.remove(container); } else { + if (preempted.get(container) != null) { + // We already updated the information to scheduler earlier, we need + // not have to raise another event. + continue; + } //otherwise just send preemption events rmContext.getDispatcher().getEventHandler().handle( new ContainerPreemptEvent(appAttemptId, container, SchedulerEventType.PREEMPT_CONTAINER)); - if (preempted.get(container) == null) { - preempted.put(container, clock.getTime()); - } + preempted.put(container, clock.getTime()); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java index bc4d0dc9d05..8d9f48a8354 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/capacity/TestProportionalCapacityPreemptionPolicy.java @@ -280,14 +280,14 @@ public class TestProportionalCapacityPreemptionPolicy { // requests reiterated when(mClock.getTime()).thenReturn(killTime / 2); policy.editSchedule(); - verify(mDisp, times(20)).handle(argThat(new IsPreemptionRequestFor(appC))); + verify(mDisp, times(10)).handle(argThat(new IsPreemptionRequestFor(appC))); // kill req sent when(mClock.getTime()).thenReturn(killTime + 1); policy.editSchedule(); - verify(mDisp, times(30)).handle(evtCaptor.capture()); + verify(mDisp, times(20)).handle(evtCaptor.capture()); List events = evtCaptor.getAllValues(); - for (ContainerPreemptEvent e : events.subList(20, 30)) { + for (ContainerPreemptEvent e : events.subList(20, 20)) { assertEquals(appC, e.getAppId()); assertEquals(KILL_CONTAINER, e.getType()); }