Skip to content

Commit 4546c75

Browse files
committed
YARN-4392. ApplicationCreatedEvent event time resets after RM
restart/failover. Contributed by Naganarasimha G R and Xuan Gong
1 parent 01a641b commit 4546c75

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,9 @@ Release 2.8.0 - UNRELEASED
11031103
YARN-4408. Fix issue that NodeManager reports negative running containers.
11041104
(Robert Kanter via junping_du)
11051105

1106+
YARN-4392. ApplicationCreatedEvent event time resets after RM restart/failover.
1107+
(Naganarasimha G R and Xuan Gong via xgong)
1108+
11061109
Release 2.7.3 - UNRELEASED
11071110

11081111
INCOMPATIBLE CHANGES

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMAppManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.commons.logging.LogFactory;
2727
import org.apache.hadoop.conf.Configuration;
2828
import org.apache.hadoop.io.DataInputByteBuffer;
29-
import org.apache.hadoop.ipc.CallerContext;
3029
import org.apache.hadoop.security.Credentials;
3130
import org.apache.hadoop.security.UserGroupInformation;
3231
import org.apache.hadoop.util.StringUtils;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,6 @@ public RMAppImpl(ApplicationId applicationId, RMContext rmContext,
444444

445445
this.callerContext = CallerContext.getCurrent();
446446

447-
rmContext.getRMApplicationHistoryWriter().applicationStarted(this);
448-
rmContext.getSystemMetricsPublisher().appCreated(this, startTime);
449-
450447
long localLogAggregationStatusTimeout =
451448
conf.getLong(YarnConfiguration.LOG_AGGREGATION_STATUS_TIME_OUT_MS,
452449
YarnConfiguration.DEFAULT_LOG_AGGREGATION_STATUS_TIME_OUT_MS);
@@ -813,6 +810,9 @@ public void recover(RMState state) {
813810
this.startTime = appState.getStartTime();
814811
this.callerContext = appState.getCallerContext();
815812

813+
// send the ATS create Event
814+
sendATSCreateEvent(this, this.startTime);
815+
816816
for(int i=0; i<appState.getAttemptCount(); ++i) {
817817
// create attempt
818818
createNewAttempt();
@@ -1084,6 +1084,9 @@ public void transition(RMAppImpl app, RMAppEvent event) {
10841084
// communication
10851085
LOG.info("Storing application with id " + app.applicationId);
10861086
app.rmContext.getStateStore().storeNewApplication(app);
1087+
1088+
// send the ATS create Event
1089+
app.sendATSCreateEvent(app, app.startTime);
10871090
}
10881091
}
10891092

@@ -1734,4 +1737,9 @@ public String getAmNodeLabelExpression() {
17341737
public CallerContext getCallerContext() {
17351738
return callerContext;
17361739
}
1740+
1741+
private void sendATSCreateEvent(RMApp app, long startTime) {
1742+
rmContext.getRMApplicationHistoryWriter().applicationStarted(app);
1743+
rmContext.getSystemMetricsPublisher().appCreated(app, startTime);
1744+
}
17371745
}

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager;
2020

21+
import static org.mockito.Matchers.any;
22+
import static org.mockito.Matchers.anyLong;
2123
import static org.mockito.Matchers.isA;
2224
import static org.mockito.Mockito.mock;
2325
import static org.mockito.Mockito.spy;
2426
import static org.mockito.Mockito.timeout;
25-
import static org.mockito.Mockito.times;
2627
import static org.mockito.Mockito.verify;
2728
import static org.mockito.Mockito.when;
2829

29-
import com.google.common.base.Supplier;
3030
import java.io.File;
3131
import java.io.FileOutputStream;
3232
import java.io.IOException;
@@ -87,6 +87,7 @@
8787
import org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus;
8888
import org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse;
8989
import org.apache.hadoop.yarn.server.api.records.NodeAction;
90+
import org.apache.hadoop.yarn.server.resourcemanager.metrics.SystemMetricsPublisher;
9091
import org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager;
9192
import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore;
9293
import org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStore;
@@ -113,7 +114,9 @@
113114
import org.junit.Assert;
114115
import org.junit.Before;
115116
import org.junit.Test;
117+
import org.mockito.Mockito;
116118

119+
import com.google.common.base.Supplier;
117120
import com.google.common.collect.ImmutableMap;
118121
import com.google.common.collect.Sets;
119122

@@ -896,7 +899,13 @@ public void testRMRestartGetApplicationList() throws Exception {
896899
memStore.init(conf);
897900

898901
// start RM
899-
MockRM rm1 = createMockRM(conf, memStore);
902+
MockRM rm1 = new MockRM(conf, memStore) {
903+
@Override
904+
protected SystemMetricsPublisher createSystemMetricsPublisher() {
905+
return spy(super.createSystemMetricsPublisher());
906+
}
907+
};
908+
rms.add(rm1);
900909
rm1.start();
901910
MockNM nm1 =
902911
new MockNM("127.0.0.1:1234", 15120, rm1.getResourceTrackerService());
@@ -925,17 +934,27 @@ public void testRMRestartGetApplicationList() throws Exception {
925934
rm1.waitForState(app2.getApplicationId(), RMAppState.KILLED);
926935
rm1.waitForState(am2.getApplicationAttemptId(), RMAppAttemptState.KILLED);
927936

937+
verify(rm1.getRMContext().getSystemMetricsPublisher(),Mockito.times(3))
938+
.appCreated(any(RMApp.class), anyLong());
928939
// restart rm
929940

930941
MockRM rm2 = new MockRM(conf, memStore) {
931942
@Override
932943
protected RMAppManager createRMAppManager() {
933944
return spy(super.createRMAppManager());
934945
}
946+
947+
@Override
948+
protected SystemMetricsPublisher createSystemMetricsPublisher() {
949+
return spy(super.createSystemMetricsPublisher());
950+
}
935951
};
936952
rms.add(rm2);
937953
rm2.start();
938954

955+
verify(rm2.getRMContext().getSystemMetricsPublisher(),Mockito.times(3))
956+
.appCreated(any(RMApp.class), anyLong());
957+
939958
GetApplicationsRequest request1 =
940959
GetApplicationsRequest.newInstance(EnumSet.of(
941960
YarnApplicationState.FINISHED, YarnApplicationState.KILLED,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager.rmapp;
2020

21-
import org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData;
2221
import static org.mockito.Matchers.any;
2322
import static org.mockito.Matchers.anyLong;
2423
import static org.mockito.Mockito.doReturn;
@@ -64,6 +63,7 @@
6463
import org.apache.hadoop.yarn.server.resourcemanager.metrics.SystemMetricsPublisher;
6564
import org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStore;
6665
import org.apache.hadoop.yarn.server.resourcemanager.recovery.RMStateStore.RMState;
66+
import org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData;
6767
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.AMLivelinessMonitor;
6868
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
6969
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEvent;
@@ -368,8 +368,6 @@ private void sendAttemptUpdateSavedEvent(RMApp application) {
368368
protected RMApp testCreateAppNewSaving(
369369
ApplicationSubmissionContext submissionContext) throws IOException {
370370
RMApp application = createNewTestApp(submissionContext);
371-
verify(writer).applicationStarted(any(RMApp.class));
372-
verify(publisher).appCreated(any(RMApp.class), anyLong());
373371
// NEW => NEW_SAVING event RMAppEventType.START
374372
RMAppEvent event =
375373
new RMAppEvent(application.getApplicationId(), RMAppEventType.START);

0 commit comments

Comments
 (0)