You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tez.apache.org by rb...@apache.org on 2020/05/22 06:00:34 UTC

[tez] branch master updated: TEZ-4179: [Kubernetes] Extend NodeId in tez to support unique worker identity (Prasanth Jayachandran, Attila Magyar, reviewed by Rajesh Balamohan)

This is an automated email from the ASF dual-hosted git repository.

rbalamohan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tez.git


The following commit(s) were added to refs/heads/master by this push:
     new f047d4a  TEZ-4179: [Kubernetes] Extend NodeId in tez to support unique worker identity (Prasanth Jayachandran, Attila Magyar, reviewed by Rajesh Balamohan)
f047d4a is described below

commit f047d4a712b7da6985561d2fa99de734002d71d9
Author: Rajesh Balamohan <rb...@apache.org>
AuthorDate: Fri May 22 11:30:05 2020 +0530

    TEZ-4179: [Kubernetes] Extend NodeId in tez to support unique worker identity (Prasanth Jayachandran, Attila Magyar, reviewed by Rajesh Balamohan)
---
 .../apache/tez/dag/app/rm/node/AMNodeEvent.java    | 11 ++-
 .../apache/tez/dag/app/rm/node/ExtendedNodeId.java | 97 ++++++++++++++++++++++
 .../tez/dag/app/rm/node/TestAMNodeTracker.java     | 54 ++++++++++--
 3 files changed, 156 insertions(+), 6 deletions(-)

diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/rm/node/AMNodeEvent.java b/tez-dag/src/main/java/org/apache/tez/dag/app/rm/node/AMNodeEvent.java
index 1a975b0..d9e249a 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/rm/node/AMNodeEvent.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/rm/node/AMNodeEvent.java
@@ -25,15 +25,24 @@ public class AMNodeEvent extends AbstractEvent<AMNodeEventType> {
 
   private final NodeId nodeId;
   private final int schedulerId;
+  private final ExtendedNodeId amNodeId;
 
   public AMNodeEvent(NodeId nodeId, int schedulerId, AMNodeEventType type) {
     super(type);
     this.nodeId = nodeId;
     this.schedulerId = schedulerId;
+    this.amNodeId = null;
+  }
+
+  public AMNodeEvent(ExtendedNodeId amNodeId, int schedulerId, AMNodeEventType type) {
+    super(type);
+    this.nodeId = null;
+    this.schedulerId = schedulerId;
+    this.amNodeId = amNodeId;
   }
 
   public NodeId getNodeId() {
-    return this.nodeId;
+    return amNodeId == null ? this.nodeId : this.amNodeId;
   }
 
   public int getSchedulerId() {
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/rm/node/ExtendedNodeId.java b/tez-dag/src/main/java/org/apache/tez/dag/app/rm/node/ExtendedNodeId.java
new file mode 100644
index 0000000..ea58d86
--- /dev/null
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/rm/node/ExtendedNodeId.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tez.dag.app.rm.node;
+
+import java.util.Objects;
+
+import org.apache.hadoop.yarn.api.records.NodeId;
+import org.apache.tez.common.Preconditions;
+
+/**
+ * ExtendedNodeId extends NodeId with unique identifier in addition to hostname and port.
+ */
+public class ExtendedNodeId extends NodeId {
+  private NodeId nodeId;
+  private String host;
+  private int port;
+  private final String uniqueIdentifier;
+
+  public ExtendedNodeId(NodeId nodeId, String uniqueIdentifier) {
+    Preconditions.checkArgument(nodeId != null);
+    this.nodeId = nodeId;
+    this.uniqueIdentifier = uniqueIdentifier == null ? "" : uniqueIdentifier.trim();
+  }
+
+  @Override
+  public String getHost() {
+    return nodeId.getHost();
+  }
+
+  @Override
+  protected void setHost(final String host) {
+    this.host = host;
+    build();
+  }
+
+  @Override
+  public int getPort() {
+    return nodeId.getPort();
+  }
+
+  @Override
+  protected void setPort(final int port) {
+    this.port = port;
+    build();
+  }
+
+  @Override
+  protected void build() {
+    this.nodeId = NodeId.newInstance(host, port);
+  }
+
+  @Override
+  public String toString() {
+    if (!uniqueIdentifier.isEmpty()) {
+      return super.toString() + ":" + uniqueIdentifier;
+    }
+    return super.toString();
+  }
+
+  @Override
+  public int hashCode() {
+    if (!uniqueIdentifier.isEmpty()) {
+      return super.hashCode() + 31 * uniqueIdentifier.hashCode();
+    }
+    return super.hashCode();
+  }
+
+  @Override
+  public boolean equals(final Object obj) {
+    if (this == obj) {
+      return true;
+    } else if (obj == null) {
+      return false;
+    } else if (this.getClass() != obj.getClass()) {
+      return false;
+    } else {
+      ExtendedNodeId amNodeId = (ExtendedNodeId) obj;
+      return super.equals(obj) && Objects.equals(uniqueIdentifier, amNodeId.uniqueIdentifier);
+    }
+  }
+}
diff --git a/tez-dag/src/test/java/org/apache/tez/dag/app/rm/node/TestAMNodeTracker.java b/tez-dag/src/test/java/org/apache/tez/dag/app/rm/node/TestAMNodeTracker.java
index 11d3b7a..060cdc4 100644
--- a/tez-dag/src/test/java/org/apache/tez/dag/app/rm/node/TestAMNodeTracker.java
+++ b/tez-dag/src/test/java/org/apache/tez/dag/app/rm/node/TestAMNodeTracker.java
@@ -327,6 +327,33 @@ public class TestAMNodeTracker {
     }
   }
 
+  @Test(timeout=10000)
+  public void testMultipleAMNodeIDs() {
+    AppContext appContext = mock(AppContext.class);
+    Configuration conf = new Configuration(false);
+    conf.setInt(TezConfiguration.TEZ_AM_MAX_TASK_FAILURES_PER_NODE, 2);
+    TestEventHandler handler = new TestEventHandler();
+    AMNodeTracker amNodeTracker = new AMNodeTracker(handler, appContext);
+    doReturn(amNodeTracker).when(appContext).getNodeTracker();
+    AMContainerMap amContainerMap = mock(AMContainerMap.class);
+    TaskSchedulerManager taskSchedulerManager =
+      mock(TaskSchedulerManager.class);
+    dispatcher.register(AMNodeEventType.class, amNodeTracker);
+    dispatcher.register(AMContainerEventType.class, amContainerMap);
+    dispatcher.register(AMSchedulerEventType.class, taskSchedulerManager);
+    amNodeTracker.init(conf);
+    amNodeTracker.start();
+    try {
+      amNodeTracker.nodeSeen(new ExtendedNodeId(NodeId.newInstance("host", 2222), "uuid1"), 0);
+      amNodeTracker.nodeSeen(new ExtendedNodeId(NodeId.newInstance("host", 2222), "uuid1"), 0);
+      amNodeTracker.nodeSeen(new ExtendedNodeId(NodeId.newInstance("host", 2222), "uuid2"), 0);
+      amNodeTracker.nodeSeen(new ExtendedNodeId(NodeId.newInstance("host", 2222), "uuid2"), 0);
+      assertEquals(2, amNodeTracker.getNumNodes(0));
+    } finally {
+      amNodeTracker.stop();
+    }
+  }
+
   @Test(timeout = 10000L)
   public void testNodeCompletedAndCleanup() {
     AppContext appContext = mock(AppContext.class);
@@ -401,15 +428,26 @@ public class TestAMNodeTracker {
 
   @Test(timeout=10000)
   public void testNodeUnhealthyRescheduleTasksEnabled() throws Exception {
-    _testNodeUnhealthyRescheduleTasks(true);
+    _testNodeUnhealthyRescheduleTasks(true, false);
   }
 
   @Test(timeout=10000)
   public void testNodeUnhealthyRescheduleTasksDisabled() throws Exception {
-    _testNodeUnhealthyRescheduleTasks(false);
+    _testNodeUnhealthyRescheduleTasks(false, false);
+  }
+
+
+  @Test(timeout=10000)
+  public void testNodeUnhealthyRescheduleTasksEnabledAMNode() throws Exception {
+    _testNodeUnhealthyRescheduleTasks(true, true);
+  }
+
+  @Test(timeout=10000)
+  public void testNodeUnhealthyRescheduleTasksDisabledAMNode() throws Exception {
+    _testNodeUnhealthyRescheduleTasks(false, true);
   }
 
-  private void _testNodeUnhealthyRescheduleTasks(boolean rescheduleTasks) {
+  private void _testNodeUnhealthyRescheduleTasks(boolean rescheduleTasks, boolean useExtendedNodeId) {
     AppContext appContext = mock(AppContext.class);
     Configuration conf = new Configuration(false);
     conf.setBoolean(TezConfiguration.TEZ_AM_NODE_UNHEALTHY_RESCHEDULE_TASKS,
@@ -422,8 +460,14 @@ public class TestAMNodeTracker {
 
     // add a node
     amNodeTracker.handle(new AMNodeEventNodeCountUpdated(1, 0));
-    NodeId nodeId = NodeId.newInstance("host1", 1234);
-    amNodeTracker.nodeSeen(nodeId, 0);
+    NodeId nodeId;
+    if (useExtendedNodeId) {
+      nodeId = new ExtendedNodeId(NodeId.newInstance("host1", 1234), "uuid2");
+      amNodeTracker.nodeSeen(nodeId, 0);
+    } else {
+      nodeId = NodeId.newInstance("host1", 1234);
+      amNodeTracker.nodeSeen(nodeId, 0);
+    }
     AMNodeImpl node = (AMNodeImpl) amNodeTracker.get(nodeId, 0);
 
     // simulate task starting on node