YARN-7393. RegistryDNS doesn't work in tcp channel. Contributed by Eric Yang

This commit is contained in:
Billie Rinaldi 2017-10-27 11:44:55 -07:00 committed by Jian He
parent d2775fbcca
commit 8ec9e72cc3

View File

@ -189,8 +189,7 @@ public void initializeChannels(Configuration conf) throws Exception {
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 void nioTCPClient(SocketChannel ch) throws IOException {
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 void nioTCPClient(SocketChannel ch) throws IOException {
}
ByteBuffer out = ByteBuffer.allocate(response.length + 2);
out.putShort(0, (short) (response.length & 0xffff));
out.put(response);
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 Boolean call() throws Exception {
}
});
} else {
Thread.sleep(500);
}
}
} catch (IOException e) {