Skip to content

Conversation

@DaveCTurner
Copy link
Contributor

The PeerFinder, introduced in #32246, obtains the collection of seed
addresses configured by the user from a ConfiguredHostsResolver. In reality
this collection comes from the UnicastHostsProvider via a slightly
complicated threading model that performs the resolution of hostnames to
addresses using a dedicated ExecutorService. This commit introduces an
adapter to allow the PeerFinder to obtain its seed addresses in this manner.

The `PeerFinder`, introduced in elastic#32246, obtains the collection of seed
addresses configured by the user from a `ConfiguredHostsResolver`. In reality
this collection comes from the `UnicastHostsProvider` via a slightly
complicated threading model that performs the resolution of hostnames to
addresses using a dedicated `ExecutorService`. This commit introduces an
adapter to allow the `PeerFinder` to obtain its seed addresses in this manner.
@DaveCTurner DaveCTurner added >enhancement v7.0.0 :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. labels Aug 6, 2018
@DaveCTurner DaveCTurner requested a review from ywelsch August 6, 2018 14:47
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@ywelsch ywelsch mentioned this pull request Aug 6, 2018
61 tasks

@Override
public void onAfter() {
super.onAfter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does nothing. Not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, 20fc946

transportService.getThreadPool().generic().execute(new AbstractRunnable() {
@Override
public void onFailure(Exception e) {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's log the exception here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, 3e6e51b

}

public void resolveConfiguredHosts(Consumer<List<TransportAddress>> consumer) {
assert lifecycle.started() : lifecycle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this might be called while the service is being stopped.
Note that we might also make use of AbstractLifecycleRunnable here (just found that class by chance)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the assert to a guard in a8a6393 but won't use AbstractLifecycleRunnable since it doesn't run onAfterInLifecycle method if the lifecycle state is STOPPED, which means this might break if stopped and then started again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However I also added a check for the lifecycle state in the action itself in c06a786

@Before
public void startResolver() {
final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), "node").build();
threadPool = new ThreadPool(settings);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestThreadPool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 26166a4

private final Supplier<ExecutorService> executorServiceFactory;

public UnicastConfiguredHostsResolver(Settings settings, TransportService transportService, UnicastHostsProvider hostsProvider,
Supplier<ExecutorService> executorServiceFactory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not create the executorservice in the doStart method of this class? AFAICS, this will be the only user of this factory, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's nicer. I chose appropriate-looking names for things based on those in UnicastZenPing in 4c3060a

protected void doClose() {
}

public void resolveConfiguredHosts(Consumer<List<TransportAddress>> consumer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add @Override annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 1fe8e97


unicastConfiguredHostsResolver.resolveConfiguredHosts(resolvedAddresses -> {
try {
assertTrue(startLatch.await(1, TimeUnit.SECONDS));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 secs


assertThat(resolvedAddressesRef.get(), nullValue());
startLatch.countDown();
assertTrue(endLatch.await(1, TimeUnit.SECONDS));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 secs


import static org.elasticsearch.discovery.zen.UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING;

public class UnicastConfiguredHostsResolver extends AbstractLifecycleComponent implements ConfiguredHostsResolver {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should call this PeerFinderHostsResolver. This class, with its quite unusual interface (i.e. calling the callback only sometimes) is very much tailored towards use in PeerFinder whereas the name here suggests it is more than that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this and will leave it as-is for now, but will contemplate folding some of the interfaces with a single production implementation into methods on PeerFinder at a later date.

@DaveCTurner DaveCTurner merged commit f44ba04 into elastic:zen2 Aug 7, 2018
@DaveCTurner DaveCTurner deleted the 2018-08-06-UnicastConfiguredHostsResolver branch August 7, 2018 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. >enhancement v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants