Make EC2 Discovery Cache Empty Seed Hosts List (#50607) (#50626)

Follow up to #50550. Cache empty nodes lists (`fetchDynamicNodes` will return an empty list in case of failure)
now that the plugin properly retries requests to AWS EC2 APIs.
This commit is contained in:
Armin Braun 2020-01-03 21:32:36 +01:00 committed by GitHub
parent a45de8a96b
commit 8819fa4ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 13 deletions

View File

@ -53,7 +53,7 @@ import static org.elasticsearch.discovery.ec2.AwsEc2Service.HostType.PUBLIC_IP;
import static org.elasticsearch.discovery.ec2.AwsEc2Service.HostType.TAG_PREFIX;
class AwsEc2SeedHostsProvider implements SeedHostsProvider {
private static final Logger logger = LogManager.getLogger(AwsEc2SeedHostsProvider.class);
private final TransportService transportService;
@ -221,22 +221,13 @@ class AwsEc2SeedHostsProvider implements SeedHostsProvider {
private final class TransportAddressesCache extends SingleObjectCache<List<TransportAddress>> {
private boolean empty = true;
protected TransportAddressesCache(TimeValue refreshInterval) {
super(refreshInterval, new ArrayList<>());
}
@Override
protected boolean needsRefresh() {
return (empty || super.needsRefresh());
}
@Override
protected List<TransportAddress> refresh() {
final List<TransportAddress> nodes = fetchDynamicNodes();
empty = nodes.isEmpty();
return nodes;
return fetchDynamicNodes();
}
}
}

View File

@ -306,10 +306,10 @@ public class Ec2DiscoveryTests extends ESTestCase {
return new ArrayList<>();
}
};
for (int i=0; i<3; i++) {
for (int i = 0; i < 3; i++) {
provider.getSeedAddresses(null);
}
assertThat(provider.fetchCount, is(3));
assertThat(provider.fetchCount, is(1));
}
public void testGetNodeListCached() throws Exception {