提交 d1a4bb7b 编写于 作者: K kohsuke

[FIXED HUDSON-3981] Increased the timeout to 3secs as suggested. Added caching...

[FIXED HUDSON-3981] Increased the timeout to 3secs as suggested. Added caching so that successive look-ups go faster. This fix will be in 1.315.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@19436 71c3de6d-444a-0410-be80-ed276b4c234a
上级 a86fe5e9
...@@ -112,6 +112,12 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces ...@@ -112,6 +112,12 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
*/ */
protected String nodeName; protected String nodeName;
/**
* @see #getHostName()
*/
private volatile String cachedHostName;
private volatile boolean hostNameCached;
public Computer(Node node) { public Computer(Node node) {
assert node.getNumExecutors()!=0 : "Computer created with 0 executors"; assert node.getNumExecutors()!=0 : "Computer created with 0 executors";
setNode(node); setNode(node);
...@@ -563,7 +569,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces ...@@ -563,7 +569,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* *
* <p> * <p>
* Since it's possible that the slave is not reachable from the master (it may be behind a firewall, * Since it's possible that the slave is not reachable from the master (it may be behind a firewall,
* connecting to master via JNLP), in which case this method returns null. * connecting to master via JNLP), this method may return null.
* *
* It's surprisingly tricky for a machine to know a name that other systems can get to, * It's surprisingly tricky for a machine to know a name that other systems can get to,
* especially between things like DNS search suffix, the hosts file, and YP. * especially between things like DNS search suffix, the hosts file, and YP.
...@@ -572,9 +578,16 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces ...@@ -572,9 +578,16 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* So the technique here is to compute possible interfaces and names on the slave, * So the technique here is to compute possible interfaces and names on the slave,
* then try to ping them from the master, and pick the one that worked. * then try to ping them from the master, and pick the one that worked.
* *
* <p>
* The computation may take some time, so it employs caching to make the successive lookups faster.
*
* @since 1.300 * @since 1.300
*/ */
public String getHostName() throws IOException, InterruptedException { public String getHostName() throws IOException, InterruptedException {
if(hostNameCached)
// in the worst case we end up having multiple threads computing the host name simultaneously, but that's not harmful, just wasteful.
return cachedHostName;
for( String address : getChannel().call(new ListPossibleNames())) { for( String address : getChannel().call(new ListPossibleNames())) {
try { try {
InetAddress ia = InetAddress.getByName(address); InetAddress ia = InetAddress.getByName(address);
...@@ -582,16 +595,20 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces ...@@ -582,16 +595,20 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
LOGGER.fine(address+" is not an IPv4 address"); LOGGER.fine(address+" is not an IPv4 address");
continue; continue;
} }
if(!ia.isReachable(500)) { if(!ia.isReachable(3000)) {
LOGGER.fine(address+" didn't respond to ping"); LOGGER.fine(address+" didn't respond to ping");
continue; continue;
} }
return ia.getCanonicalHostName(); cachedHostName = ia.getCanonicalHostName();
hostNameCached = true;
return cachedHostName;
} catch (IOException e) { } catch (IOException e) {
// if a given name fails to parse on this host, we get this error // if a given name fails to parse on this host, we get this error
LOGGER.log(Level.FINE, "Failed to parse "+address,e); LOGGER.log(Level.FINE, "Failed to parse "+address,e);
} }
} }
hostNameCached = true;
return null; return null;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册