Hi,

We are having trouble with our Ignite Cluster at start-up.
If we attempt to start, say, 10 Nodes simultaneously, it appears that we get
into a race condition and we get more than one Cluster created.
We'd love to figure out a way around this.
Our workaround today is to start 1 Node. Then start the other N-1 Nodes. But
that requires too much manual intervention.

Some background.
We are using Consul for Service Discovery on AWS. 
And we have written our own `ConsulIpFinder extends
TcpDiscoveryIpFinderAdapter`

It works like this:
1) As Nodes are started (in Docker containers), their Ignite Discovery Port
is registered with Consul (using Container Pilot within our start-up script)
2) When Ignite is started in a given Node;  a `ConsulIpFinder` is registered
with `discoverySpi.setIpFinder()`
3) In this `ConsulIpFinder` -- it queries Consul for all “passing” Services
with a registered Ignite Discovery Port. 
4) And then creates the pertinent List of Host:Port for all Cluster members.
(for getRegisteredAddresses())

It is pretty clear that we’re doing something wrong here.
But reading other `TcpDiscoveryIpFinder` code, I cannot see what.

Any help would be greatly appreciated.

Thanks, 
--Chris 

This is the pertinent code:
```
    @Override
    public Collection<InetSocketAddress> getRegisteredAddresses() throws
IgniteSpiException {
        List<InetSocketAddress> remoteAddresses = getAddressesFromConsul();
        Collection<InetSocketAddress> addresses =
mergeRemoteAndLocalAddresses(remoteAddresses);
        return addresses;
    }

   @Override
    public void registerAddresses(Collection<InetSocketAddress> addrs)
throws IgniteSpiException {
        locallyRegisteredAddresses.addAll(addrs);
    }

   @Override
    public void unregisterAddresses(Collection<InetSocketAddress> addrs)
throws IgniteSpiException {
        locallyRegisteredAddresses.removeAll(addrs);
    }

    private Collection<InetSocketAddress>
mergeRemoteAndLocalAddresses(List<InetSocketAddress> remoteAddresses) {
        Set<InetSocketAddress> addresses = new HashSet<>();
        if (remoteAddresses != null) {
            addresses.addAll(remoteAddresses);
        }
        addresses.addAll(locallyRegisteredAddresses);
        return remoteAddresses;
    }

    private List<InetSocketAddress> getAddressesFromConsul() {
       try {
            HttpUrl.Builder urlBuilder =
HttpUrl.parse(consulUrl).newBuilder();
            urlBuilder.addQueryParameter("passing", null);
            String url = urlBuilder.build().toString();

            Request request = new Request.Builder().url(url).build();
            Response response = okHttpClient.newCall(request).execute();
            if (!response.isSuccessful()) {
                  throw new IOException("event=errorResponseCodeReceived,
response=" + response);
            }

            String responseData = response.body().string();
            JsonNode root = objectMapper.readTree(responseData);

            return processConsulJson(root);

        } catch (IOException ee) {
            log.error("event=ErrorReadingFromConsul, consulUrl={}",
consulUrl, ee);
            return Collections.emptyList();
        }
    }
```






--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/ConsulIpFinder-TcpDiscoveryIpFinder-issue-tp12974.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to