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

View File

@ -309,14 +309,22 @@ private void getMissingLogSegments(List<RemoteEditLog> thisJournalEditLogs,
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 @@ private List<RemoteEditLog> getMissingLogList(
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(), "");
}
/**