HDFS-11280. Allow WebHDFS to reuse HTTP connections to NN. Contributed by Zheng Shao.

This commit is contained in:
Haohui Mai 2016-12-30 22:17:49 -08:00
parent 8cb7aa2b52
commit 1bc9b316ba
1 changed files with 9 additions and 2 deletions

View File

@ -667,7 +667,9 @@ protected HttpURLConnection connect(URL url) throws IOException {
url = new URL(conn.getHeaderField("Location")); url = new URL(conn.getHeaderField("Location"));
redirectHost = url.getHost() + ":" + url.getPort(); redirectHost = url.getHost() + ":" + url.getPort();
} finally { } finally {
conn.disconnect(); // Don't call conn.disconnect() to allow connection reuse
// See http://tinyurl.com/java7-http-keepalive
conn.getInputStream().close();
} }
} }
try { try {
@ -899,7 +901,9 @@ final T getResponse(HttpURLConnection conn) throws IOException {
LOG.debug("Response decoding failure.", e); LOG.debug("Response decoding failure.", e);
throw ioe; throw ioe;
} finally { } finally {
conn.disconnect(); // Don't call conn.disconnect() to allow connection reuse
// See http://tinyurl.com/java7-http-keepalive
conn.getInputStream().close();
} }
} }
@ -946,6 +950,9 @@ public void close() throws IOException {
try { try {
validateResponse(op, conn, true); validateResponse(op, conn, true);
} finally { } finally {
// This is a connection to DataNode. Let's disconnect since
// there is little chance that the connection will be reused
// any time soonl
conn.disconnect(); conn.disconnect();
} }
} }