Skip to content

Commit bb49935

Browse files
committed
rework
Change-Id: Ic72fbe3d490e2729ece74f07b42891d1c191b1c5
1 parent 547c859 commit bb49935

4 files changed

Lines changed: 43 additions & 40 deletions

File tree

tez-api/src/main/java/org/apache/tez/common/counters/DAGCounter.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,10 @@ public enum DAGCounter {
9191

9292
/*
9393
* Number of nodes to which task attempts were assigned in this DAG.
94-
* Nodes are distinguished by the Yarn NodeId.
94+
* Nodes are distinguished by the Yarn NodeId.getHost().
9595
*/
9696
NODE_USED_COUNT,
9797

98-
/*
99-
* Number of node hosts to which task attempts were assigned in this DAG.
100-
* Nodes are distinguished by Yarn NodeId.getHost()
101-
*/
102-
NODE_HOSTS_USED_COUNT,
103-
10498
/*
10599
* Total number of nodes visible to the task scheduler (regardless of
106100
* task assignments). This is typically exposed by a resource manager

tez-dag/src/main/java/org/apache/tez/dag/app/dag/impl/DAGImpl.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,7 @@ public class DAGImpl implements org.apache.tez.dag.app.dag.DAG,
253253
private final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
254254
private final Set<ContainerId> containersUsedByCurrentDAG = new HashSet<>();
255255
@VisibleForTesting
256-
final Set<NodeId> nodesUsedByCurrentDAG = new HashSet<>();
257-
@VisibleForTesting
258-
final Set<String> nodeHostsUsedByCurrentDAG = new HashSet<>();
259-
256+
final Set<String> nodesUsedByCurrentDAG = new HashSet<>();
260257

261258
protected static final
262259
StateMachineFactory<DAGImpl, DAGState, DAGEventType, DAGEvent>
@@ -2588,14 +2585,12 @@ void stopVertexServices() {
25882585
@Override
25892586
public void addUsedContainer(Container container) {
25902587
containersUsedByCurrentDAG.add(container.getId());
2591-
nodesUsedByCurrentDAG.add(container.getNodeId());
2592-
nodeHostsUsedByCurrentDAG.add(container.getNodeId().getHost());
2588+
nodesUsedByCurrentDAG.add(container.getNodeId().getHost());
25932589
}
25942590

25952591
private void updateCounters() {
25962592
setDagCounter(DAGCounter.TOTAL_CONTAINERS_USED, containersUsedByCurrentDAG.size());
25972593
setDagCounter(DAGCounter.NODE_USED_COUNT, nodesUsedByCurrentDAG.size());
2598-
setDagCounter(DAGCounter.NODE_HOSTS_USED_COUNT, nodeHostsUsedByCurrentDAG.size());
2599-
setDagCounter(DAGCounter.NODE_TOTAL_COUNT, appContext.getTaskScheduler().getNumClusterNodes());
2594+
setDagCounter(DAGCounter.NODE_TOTAL_COUNT, appContext.getTaskScheduler().getNumClusterNodes(true));
26002595
}
26012596
}

tez-dag/src/main/java/org/apache/tez/dag/app/rm/TaskSchedulerManager.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,29 @@ public void setSignalled(boolean isSignalled) {
224224
}
225225

226226
public int getNumClusterNodes() {
227+
return getNumClusterNodes(false);
228+
}
229+
230+
public int getNumClusterNodes(boolean tryUpdate){
231+
if (cachedNodeCount == -1 && tryUpdate){
232+
cachedNodeCount = countAllNodes();
233+
}
227234
return cachedNodeCount;
228235
}
229-
236+
237+
private int countAllNodes() {
238+
int nodeCount = 0;
239+
int schedulerId = 0;
240+
try {
241+
for (schedulerId = 0; schedulerId < taskSchedulers.length; schedulerId++) {
242+
nodeCount += taskSchedulers[schedulerId].getClusterNodeCount();
243+
}
244+
} catch (Exception e) {
245+
handleTaskSchedulerException(e, schedulerId);
246+
}
247+
return nodeCount;
248+
}
249+
230250
public Resource getAvailableResources(int schedulerId) {
231251
try {
232252
return taskSchedulers[schedulerId].getAvailableResources();
@@ -887,14 +907,7 @@ public float getProgress(int schedulerId) {
887907
try {
888908
nodeCount = taskSchedulers[0].getClusterNodeCount();
889909
} catch (Exception e) {
890-
String msg = "Error in TaskScheduler while getting node count"
891-
+ ", scheduler=" + Utils.getTaskSchedulerIdentifierString(schedulerId, appContext);
892-
LOG.error(msg, e);
893-
sendEvent(
894-
new DAGAppMasterEventUserServiceFatalError(
895-
DAGAppMasterEventType.TASK_SCHEDULER_SERVICE_FATAL_ERROR,
896-
msg, e));
897-
throw new RuntimeException(e);
910+
handleTaskSchedulerException(e, 0);
898911
}
899912
if (nodeCount != cachedNodeCount) {
900913
cachedNodeCount = nodeCount;
@@ -903,6 +916,17 @@ public float getProgress(int schedulerId) {
903916
return dagAppMaster.getProgress();
904917
}
905918

919+
private void handleTaskSchedulerException(Exception e, int schedulerId) {
920+
String msg = "Error in TaskScheduler while getting node count"
921+
+ ", scheduler=" + Utils.getTaskSchedulerIdentifierString(schedulerId, appContext);
922+
LOG.error(msg, e);
923+
sendEvent(
924+
new DAGAppMasterEventUserServiceFatalError(
925+
DAGAppMasterEventType.TASK_SCHEDULER_SERVICE_FATAL_ERROR,
926+
msg, e));
927+
throw new RuntimeException(e);
928+
}
929+
906930
public void reportError(int taskSchedulerIndex, ServicePluginError servicePluginError,
907931
String diagnostics,
908932
DagInfo dagInfo) {

tez-dag/src/test/java/org/apache/tez/dag/app/dag/impl/TestDAGImpl.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.tez.dag.app.dag.impl;
2020

2121
import static org.mockito.Mockito.any;
22+
import static org.mockito.Mockito.anyBoolean;
2223
import static org.mockito.Mockito.anyInt;
2324
import static org.mockito.Mockito.doAnswer;
2425
import static org.mockito.Mockito.doReturn;
@@ -2399,35 +2400,24 @@ public void testNodesUsedCounter() {
23992400
spy.addUsedContainer(containerOnDifferentHost);
24002401
spy.addUsedContainer(containerOnSameHostWithDifferentPort);
24012402

2402-
when(taskSchedulerManager.getNumClusterNodes()).thenReturn(10);
2403+
when(taskSchedulerManager.getNumClusterNodes(anyBoolean())).thenReturn(10);
24032404

24042405
spy.onFinish();
24052406
// 4 calls to addUsedContainer
24062407
verify(spy, times(4)).addUsedContainer(any(Container.class));
2407-
// 3 nodes were used: localhost:0, otherhost:0, localhost:1
2408-
// localhost:0 and localhost:1 might be on the same physical host, but as long as
2409-
// yarn considers them different nodes, we consider them different too
2410-
Assert.assertEquals(3,
2411-
spy.getAllCounters().getGroup(DAGCounter.class.getName()).findCounter(DAGCounter.NODE_USED_COUNT.name())
2412-
.getValue());
2413-
2414-
Assert.assertTrue(spy.nodesUsedByCurrentDAG.contains(NodeId.fromString("localhost:0")));
2415-
Assert.assertTrue(spy.nodesUsedByCurrentDAG.contains(NodeId.fromString("otherhost:0")));
2416-
Assert.assertTrue(spy.nodesUsedByCurrentDAG.contains(NodeId.fromString("localhost:1")));
24172408

24182409
// 2 distinct node hosts were seen: localhost, otherhost
24192410
Assert.assertEquals(2,
2420-
spy.getAllCounters().getGroup(DAGCounter.class.getName())
2421-
.findCounter(DAGCounter.NODE_HOSTS_USED_COUNT.name())
2411+
spy.getAllCounters().getGroup(DAGCounter.class.getName()).findCounter(DAGCounter.NODE_USED_COUNT.name())
24222412
.getValue());
24232413

2414+
Assert.assertTrue(spy.nodesUsedByCurrentDAG.contains("localhost"));
2415+
Assert.assertTrue(spy.nodesUsedByCurrentDAG.contains("otherhost"));
2416+
24242417
Assert.assertEquals(10,
24252418
spy.getAllCounters().getGroup(DAGCounter.class.getName())
24262419
.findCounter(DAGCounter.NODE_TOTAL_COUNT.name())
24272420
.getValue());
2428-
2429-
Assert.assertTrue(spy.nodeHostsUsedByCurrentDAG.contains("localhost"));
2430-
Assert.assertTrue(spy.nodeHostsUsedByCurrentDAG.contains("otherhost"));
24312421
}
24322422

24332423
private DAGImpl getDagSpy() {

0 commit comments

Comments
 (0)