Skip to content

Commit 8819fa4

Browse files
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.
1 parent a45de8a commit 8819fa4

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2SeedHostsProvider.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import static org.elasticsearch.discovery.ec2.AwsEc2Service.HostType.TAG_PREFIX;
5454

5555
class AwsEc2SeedHostsProvider implements SeedHostsProvider {
56-
56+
5757
private static final Logger logger = LogManager.getLogger(AwsEc2SeedHostsProvider.class);
5858

5959
private final TransportService transportService;
@@ -221,22 +221,13 @@ private DescribeInstancesRequest buildDescribeInstancesRequest() {
221221

222222
private final class TransportAddressesCache extends SingleObjectCache<List<TransportAddress>> {
223223

224-
private boolean empty = true;
225-
226224
protected TransportAddressesCache(TimeValue refreshInterval) {
227225
super(refreshInterval, new ArrayList<>());
228226
}
229227

230-
@Override
231-
protected boolean needsRefresh() {
232-
return (empty || super.needsRefresh());
233-
}
234-
235228
@Override
236229
protected List<TransportAddress> refresh() {
237-
final List<TransportAddress> nodes = fetchDynamicNodes();
238-
empty = nodes.isEmpty();
239-
return nodes;
230+
return fetchDynamicNodes();
240231
}
241232
}
242233
}

plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ protected List<TransportAddress> fetchDynamicNodes() {
306306
return new ArrayList<>();
307307
}
308308
};
309-
for (int i=0; i<3; i++) {
309+
for (int i = 0; i < 3; i++) {
310310
provider.getSeedAddresses(null);
311311
}
312-
assertThat(provider.fetchCount, is(3));
312+
assertThat(provider.fetchCount, is(1));
313313
}
314314

315315
public void testGetNodeListCached() throws Exception {

0 commit comments

Comments
 (0)