timoninmaxim commented on a change in pull request #8206:
URL: https://github.com/apache/ignite/pull/8206#discussion_r486089622



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
##########
@@ -98,265 +101,291 @@
     /** Channels reinit was scheduled. */
     private final AtomicBoolean scheduledChannelsReinit = new AtomicBoolean();
 
-    /** Affinity map update is in progress. */
-    private final AtomicBoolean affinityUpdateInProgress = new AtomicBoolean();
-
     /** Channel is closed. */
     private volatile boolean closed;
 
     /** Fail (disconnect) listeners. */
-    private ArrayList<Runnable> chFailLsnrs = new ArrayList<>();
+    private final ArrayList<Runnable> chFailLsnrs = new ArrayList<>();
 
-    /**
-     * Constructor.
-     */
-    ReliableChannel(
-        Function<ClientChannelConfiguration, ClientChannel> chFactory,
-        ClientConfiguration clientCfg,
-        IgniteBinary binary
-    ) throws ClientException {
+    /** Fail (disconnect) listeners. */
+    private final ArrayList<Predicate<ClientChannel>> topChangeFilters = new 
ArrayList<>();
+
+    /** Guard channels and curChIdx together. */
+    private final ReadWriteLock curChannelsGuard = new 
ReentrantReadWriteLock();
+
+    /** Constructor. */
+    ReliableChannel(ClientConfiguration clientCfg,
+                    Function<ClientChannelConfiguration, ClientChannel> 
chFactory,
+                    boolean initAllChannels) {
         if (chFactory == null)
             throw new NullPointerException("chFactory");
 
         if (clientCfg == null)
             throw new NullPointerException("clientCfg");
 
+        this.clientCfg = clientCfg;
         this.chFactory = chFactory;
+        this.initAllChannels = initAllChannels;
+    }
+
+    /** Should the channel initialization be stopped. */
+    private boolean stopInitCondition() {
+        return scheduledChannelsReinit.get() || closed;
+    }
 
-        List<InetSocketAddress> addrs = 
parseAddresses(clientCfg.getAddresses());
+    /** Callback is invoked after new ClientChannel has created. */
+    private final BiConsumer<ClientChannelHolder, ClientChannel> 
onChannelCreate = (holder, ch) -> {
+        ch.addTopologyChangeListener(channel -> {
+            if (topChangeFilters.stream().allMatch(s -> s.test(channel)))
+                channelsInit(true);
+        });
 
-        channels = new ClientChannelHolder[addrs.size()];
+        ch.addNotificationListener(this);
 
-        for (int i = 0; i < channels.length; i++)
-            channels[i] = new ClientChannelHolder(new 
ClientChannelConfiguration(clientCfg, addrs.get(i)));
+        nodeChannels.values().remove(holder);
+        nodeChannels.put(ch.serverNodeId(), holder);
+    };
 
-        curChIdx = new Random().nextInt(channels.length); // We already 
verified there is at least one address.
+    /** Callback is invoked after a ClientChannel has closed. */
+    private final Consumer<ClientChannel> onChannelClose = ch -> {
+        for (Consumer<ClientChannel> lsnr : channelCloseLsnrs)
+            lsnr.accept(ch);
+    };
 
-        partitionAwarenessEnabled = clientCfg.isPartitionAwarenessEnabled() && 
channels.length > 1;
+    /**
+     * Init channel holders to all nodes.
+     * @param force enable to replace existing channels with new holders.
+     */
+    private synchronized void initChannelHolders(boolean force) {
+        // enable parallel threads to schedule new init of channel holders
+        scheduledChannelsReinit.set(false);
+
+        if (!force && channels.get() != null)
+            return;
+
+        List<InetSocketAddress> resolvedAddrs = 
parseAddresses(clientCfg.getAddresses());
+
+        List<ClientChannelHolder> holders = 
Optional.ofNullable(channels.get()).orElse(new ArrayList<>());
+
+        // addr -> (holder, delete)
+        Map<InetSocketAddress, T2<ClientChannelHolder, Boolean>> addrs = 
holders.stream()
+            .collect(Collectors.toMap(
+                c -> c.chCfg.getAddress(),
+                c -> new T2<>(c, null)
+        ));
+
+        // mark for delete addrs that aren't provided by clientConfig now
+        addrs.keySet()
+            .stream()
+            .filter(addr -> !resolvedAddrs.contains(addr))

Review comment:
       replaced  with Set

##########
File path: 
modules/core/src/main/java/org/apache/ignite/configuration/ClientConfiguration.java
##########
@@ -115,18 +116,30 @@
     /** Reconnect throttling retries. See {@code reconnectThrottlingPeriod}. */
     private int reconnectThrottlingRetries = 3;
 
+    /** Retry limit. */
+    private int retryLimit = 0;
+
     /**
      * @return Host addresses.
      */
     public String[] getAddresses() {
-        return addrs;
+        return addrFinder.get();

Review comment:
       fixed

##########
File path: 
modules/kubernetes/src/main/java/org/apache/ignite/client/ThinClientKubernetesAddressFinder.java
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client;
+
+import java.net.InetAddress;
+import java.util.function.Supplier;
+import 
org.apache.ignite.internal.kubernetes.connection.KubernetesServiceAddressResolver;
+import 
org.apache.ignite.kubernetes.configuration.KubernetesConnectionConfiguration;
+
+/**
+ * Address finder for automatic lookup of Ignite server nodes running in 
Kubernetes environment. All Ignite nodes have
+ * to be deployed as Kubernetes pods in order to be found. Applications and 
Ignite nodes running outside of Kubernetes
+ * will not be able to reach the containerized counterparts.
+ * <p>
+ * The implementation is based on a distinct Kubernetes service. The name of 
the service must be set with
+ * {@code KubernetesConnectionConfiguration}. As for Ignite pods, it's 
recommended to label them in such a way that
+ * the service will target only server nodes.
+ * <p>
+ * The address finder, in its turn, will call this service to retrieve Ignite 
pods IP addresses. The port will be
+ * set later within {@link IgniteClient}. Make sure that all Ignite pods 
occupy a similar ClientConnector port,
+ * otherwise they will not be able to connect each other using this address 
finder.
+ * <p>
+ */
+public class ThinClientKubernetesAddressFinder implements Supplier<String[]> {
+    /** Kubernetes connection configuration */
+    private final KubernetesConnectionConfiguration cfg;
+
+    /** Constructor */
+    public ThinClientKubernetesAddressFinder(KubernetesConnectionConfiguration 
cfg) {
+        this.cfg = cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String[] get() {
+        return new KubernetesServiceAddressResolver(cfg)

Review comment:
       fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to