ESExporter moves failed hosts to the end of the host list to avoid retrying them every 5s.
This commit is contained in:
parent
62ce5369b3
commit
4c4ea87b7f
|
@ -53,7 +53,7 @@ import java.util.Map;
|
|||
|
||||
public class ESExporter extends AbstractLifecycleComponent<ESExporter> implements StatsExporter<ESExporter> {
|
||||
|
||||
final String[] hosts;
|
||||
volatile String[] hosts;
|
||||
final String indexPrefix;
|
||||
final DateTimeFormatter indexTimeFormatter;
|
||||
final int timeout;
|
||||
|
@ -239,7 +239,10 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
}
|
||||
|
||||
private HttpURLConnection openConnection(String method, String uri, String contentType) {
|
||||
for (String host : hosts) {
|
||||
int hostIndex = 0;
|
||||
try {
|
||||
for (; hostIndex < hosts.length; hostIndex++) {
|
||||
String host = hosts[hostIndex];
|
||||
try {
|
||||
URL templateUrl = new URL("http://" + host + uri);
|
||||
HttpURLConnection conn = (HttpURLConnection) templateUrl.openConnection();
|
||||
|
@ -259,6 +262,16 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
|
|||
logger.error("error connecting to [{}]", e, host);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (hostIndex > 0 && hostIndex < hosts.length) {
|
||||
logger.debug("moving [{}] failed hosts to the end of the list", hostIndex + 1);
|
||||
String[] newHosts = new String[hosts.length];
|
||||
System.arraycopy(hosts, hostIndex, newHosts, 0, hosts.length - hostIndex);
|
||||
System.arraycopy(hosts, 0, newHosts, hosts.length - hostIndex - 1, hostIndex + 1);
|
||||
hosts = newHosts;
|
||||
logger.debug("preferred target host is now [{}]", hosts[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue