HDFS-12579. JournalNodeSyncer should use fromUrl field of EditLogManifestResponse to construct servlet Url. Contributed by Hanisha Koneru.

This commit is contained in:
Arpit Agarwal 2017-10-25 14:24:22 -07:00
parent f66ad1fab9
commit 7da15eac7a
1 changed files with 14 additions and 5 deletions

View File

@ -309,14 +309,22 @@ public class JournalNodeSyncer {
boolean success = false;
try {
if (remoteJNproxy.httpServerUrl == null) {
remoteJNproxy.httpServerUrl = getHttpServerURI("http",
remoteJNproxy.jnAddr.getHostName(), response.getHttpPort());
if (response.hasFromURL()) {
remoteJNproxy.httpServerUrl = getHttpServerURI(
response.getFromURL(), remoteJNproxy.jnAddr.getHostName());
} else {
LOG.error("EditLogManifest response does not have fromUrl " +
"field set. Aborting current sync attempt");
break;
}
}
String urlPath = GetJournalEditServlet.buildPath(jid, missingLog
.getStartTxId(), nsInfo, false);
url = new URL(remoteJNproxy.httpServerUrl, urlPath);
success = downloadMissingLogSegment(url, missingLog);
} catch (URISyntaxException e) {
LOG.error("EditLogManifest's fromUrl field syntax incorrect", e);
} catch (MalformedURLException e) {
LOG.error("MalformedURL when download missing log segment", e);
} catch (Exception e) {
@ -374,9 +382,10 @@ public class JournalNodeSyncer {
return missingEditLogs;
}
private URL getHttpServerURI(String scheme, String hostname, int port)
throws MalformedURLException {
return new URL(scheme, hostname, port, "");
private URL getHttpServerURI(String fromUrl, String hostAddr)
throws URISyntaxException, MalformedURLException {
URI uri = new URI(fromUrl);
return new URL(uri.getScheme(), hostAddr, uri.getPort(), "");
}
/**