hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bot...@apache.org
Subject [33/50] [abbrv] hadoop git commit: YARN-8600. RegistryDNS hang when remote lookup does not reply. Contributed by Eric Yang
Date Thu, 02 Aug 2018 17:17:56 GMT
YARN-8600. RegistryDNS hang when remote lookup does not reply. Contributed by Eric Yang


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/603a5747
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/603a5747
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/603a5747

Branch: refs/heads/YARN-7402
Commit: 603a57476ce0bf9514f0432a235f29432ca4c323
Parents: 67c65da
Author: Shane Kumpf <skumpf@apache.org>
Authored: Wed Aug 1 12:22:01 2018 -0600
Committer: Shane Kumpf <skumpf@apache.org>
Committed: Wed Aug 1 12:22:01 2018 -0600

----------------------------------------------------------------------
 .../hadoop/registry/server/dns/LookupTask.java  | 39 ++++++++++++++++++++
 .../hadoop/registry/server/dns/RegistryDNS.java | 21 ++++++++---
 .../registry/server/dns/TestRegistryDNS.java    |  8 ++++
 3 files changed, 63 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/603a5747/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java
new file mode 100644
index 0000000..c2fc4a9
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java
@@ -0,0 +1,39 @@
+/*
+ * 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.hadoop.registry.server.dns;
+
+import java.util.concurrent.Callable;
+
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.Name;
+import org.xbill.DNS.Record;
+
+public class LookupTask implements Callable<Record[]> {
+
+  private Name name;
+  private int type;
+
+  public LookupTask(Name name, int type) {
+    this.name = name;
+    this.type = type;
+  }
+
+  @Override
+  public Record[] call() throws Exception {
+    return new Lookup(name, type).run();
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/603a5747/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RegistryDNS.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RegistryDNS.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RegistryDNS.java
index 0022843..52e49a3 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RegistryDNS.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RegistryDNS.java
@@ -99,9 +99,13 @@ import java.util.Properties;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -941,7 +945,7 @@ public class RegistryDNS extends AbstractService implements DNSOperations,
    * @param port    local port.
    * @throws IOException if the UDP processing fails.
    */
-  private void serveNIOUDP(DatagramChannel channel,
+  private synchronized void serveNIOUDP(DatagramChannel channel,
       InetAddress addr, int port) throws Exception {
     SocketAddress remoteAddress = null;
     try {
@@ -1177,13 +1181,20 @@ public class RegistryDNS extends AbstractService implements DNSOperations,
    * @return DNS records
    */
   protected Record[] getRecords(Name name, int type) {
+    Record[] result = null;
+    ExecutorService executor = Executors.newSingleThreadExecutor();
+    Future<Record[]> future = executor.submit(new LookupTask(name, type));
     try {
-      return new Lookup(name, type).run();
-    } catch (NullPointerException |
+      result = future.get(1500, TimeUnit.MILLISECONDS);
+      return result;
+    } catch (InterruptedException | ExecutionException |
+        TimeoutException | NullPointerException |
         ExceptionInInitializerError e) {
-      LOG.error("Fail to lookup: " + name, e);
+      LOG.warn("Failed to lookup: {} type: {}", name, Type.string(type), e);
+      return result;
+    } finally {
+      executor.shutdown();
     }
-    return null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/603a5747/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
index 969faf9..a0c4ca3 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
@@ -697,6 +697,14 @@ public class TestRegistryDNS extends Assert {
     assertTrue("not an ARecord", recs[0] instanceof ARecord);
     assertTrue("not an ARecord", recs[1] instanceof ARecord);
   }
+
+  @Test(timeout=5000)
+  public void testUpstreamFault() throws Exception {
+    Name name = Name.fromString("19.0.17.172.in-addr.arpa.");
+    Record[] recs = getRegistryDNS().getRecords(name, Type.CNAME);
+    assertNull("Record is not null", recs);
+  }
+
   public RegistryDNS getRegistryDNS() {
     return registryDNS;
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message