ivandasch commented on a change in pull request #2:
URL: 
https://github.com/apache/ignite-python-thin-client/pull/2#discussion_r560809283



##########
File path: pyignite/client.py
##########
@@ -88,9 +103,156 @@ def __init__(self, compact_footer: bool=None, *args, 
**kwargs):
          Default is to use the same approach the server is using (None).
          Apache Ignite binary protocol documentation on this topic:
          
https://apacheignite.readme.io/docs/binary-client-protocol-data-format#section-schema
+        :param partition_aware: (optional) try to calculate the exact data
+         placement from the key before to issue the key operation to the
+         server node:
+         
https://cwiki.apache.org/confluence/display/IGNITE/IEP-23%3A+Best+Effort+Affinity+for+thin+clients
+         The feature is in experimental status, so the parameter is `False`
+         by default. This will be changed later.
         """
         self._compact_footer = compact_footer
-        super().__init__(*args, **kwargs)
+        self._connection_args = kwargs
+        self._nodes = []
+        self._current_node = 0
+        self._partition_aware = partition_aware
+        self.affinity_version = (0, 0)
+
+    def get_protocol_version(self) -> Optional[Tuple]:
+        """
+        Returns the tuple of major, minor, and revision numbers of the used
+        thin protocol version, or None, if no connection to the Ignite cluster
+        was not yet established.
+
+        This method is not a part of the public API. Unless you wish to
+        extend the `pyignite` capabilities (with additional testing, logging,
+        examining connections, et c.) you probably should not use it.
+        """
+        return self.protocol_version
+
+    @property
+    def partition_aware(self):
+        return self._partition_aware
+
+    def connect(self, *args):
+        """
+        Connect to Ignite cluster node(s).
+
+        :param args: (optional) host(s) and port(s) to connect to.
+        """
+        if len(args) == 0:
+            # no parameters − use default Ignite host and port
+            nodes = [(IGNITE_DEFAULT_HOST, IGNITE_DEFAULT_PORT)]
+        elif len(args) == 1 and is_iterable(args[0]):
+            # iterable of host-port pairs is given
+            nodes = args[0]
+        elif (
+            len(args) == 2
+            and isinstance(args[0], str)
+            and isinstance(args[1], int)
+        ):
+            # host and port are given
+            nodes = [args]
+        else:
+            raise ConnectionError('Connection parameters are not valid.')
+
+        # the following code is quite twisted, because the protocol version
+        # is initially unknown
+
+        # TODO: open first node in foregroung, others − in background
+        for i, node in enumerate(nodes):
+            host, port = node
+            conn = Connection(self, **self._connection_args)
+            conn.host = host
+            conn.port = port
+
+            try:
+                if (
+                    self.protocol_version is None
+                    or self.protocol_version >= (1, 4, 0)
+                ):
+                    # open connection before adding to the pool
+                    conn.connect(host, port)
+
+                    # now we have the protocol version
+                    if self.protocol_version < (1, 4, 0):
+                        # do not try to open more nodes
+                        self._current_node = i
+                    else:
+                        # take a chance to schedule the reconnection
+                        # for all the failed connections, that was probed
+                        # before this
+                        for failed_node in self._nodes[:i]:
+                            failed_node.reconnect()
+
+            except connection_errors:
+                conn._fail()
+                if (
+                    self.protocol_version
+                    and self.protocol_version >= (1, 4, 0)
+                ):
+                    # schedule the reconnection
+                    conn.reconnect()
+
+            self._nodes.append(conn)
+
+        if self.protocol_version is None:
+            raise ReconnectError('Can not connect.')
+
+    def close(self):
+        for conn in self._nodes:
+            conn.close()
+        self._nodes.clear()
+
+    @property
+    @select_version
+    def random_node(self) -> Connection:

Review comment:
       Here the same -- `@select_version` is antipattern




----------------------------------------------------------------
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