YARN-7393. RegistryDNS doesn't work in tcp channel. 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/8ec9e72c Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8ec9e72c Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8ec9e72c Branch: refs/heads/yarn-native-services Commit: 8ec9e72cc37957d8cf9af5a7b78086441ae64b00 Parents: d2775fb Author: Billie Rinaldi <bil...@apache.org> Authored: Fri Oct 27 11:44:55 2017 -0700 Committer: Jian He <jia...@apache.org> Committed: Mon Nov 6 13:30:19 2017 -0800 ---------------------------------------------------------------------- .../hadoop/registry/server/dns/RegistryDNS.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/8ec9e72c/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 9097c46..d7ebece 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 @@ -189,8 +189,7 @@ public class RegistryDNS extends AbstractService implements DNSOperations, LOG.info("Opening TCP and UDP channels on {} port {}", addr, port); addNIOUDP(addr, port); - //TODO Fix dns lookup over TCP -// addNIOTCP(addr, port); + addNIOTCP(addr, port); } /** @@ -768,7 +767,7 @@ public class RegistryDNS extends AbstractService implements DNSOperations, buf.get(in, 0, messageLength); Message query; - byte[] response = null; + byte[] response; try { query = new Message(in); LOG.info("received TCP query {}", query.getQuestion()); @@ -781,10 +780,19 @@ public class RegistryDNS extends AbstractService implements DNSOperations, } ByteBuffer out = ByteBuffer.allocate(response.length + 2); - out.putShort(0, (short) (response.length & 0xffff)); + out.clear(); + byte[] data = new byte[2]; + + data[1] = (byte)(response.length & 0xFF); + data[0] = (byte)((response.length >> 8) & 0xFF); + out.put(data); out.put(response); + out.flip(); + + while(out.hasRemaining()) { + ch.write(out); + } - ch.write(out); } catch (IOException e) { throw NetUtils.wrapException(ch.socket().getInetAddress().getHostName(), ch.socket().getPort(), @@ -836,6 +844,8 @@ public class RegistryDNS extends AbstractService implements DNSOperations, } }); + } else { + Thread.sleep(500); } } } catch (IOException e) { --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org