You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/02/08 13:05:09 UTC

[GitHub] [ignite-python-thin-client] isapego commented on a change in pull request #10: IGNITE-13967 Optimize and refactor of parsing response from server.

isapego commented on a change in pull request #10:
URL: https://github.com/apache/ignite-python-thin-client/pull/10#discussion_r571976014



##########
File path: pyignite/connection/__init__.py
##########
@@ -97,7 +97,7 @@ def _check_ssl_params(params):
                 ).format(param))
 
     def __init__(
-        self, client: 'Client', prefetch: bytes = b'', timeout: int = None,
+        self, client: 'Client', timeout: float = 2.0,

Review comment:
       Why timeout is `float`? Is it a common practice for python?

##########
File path: pyignite/stream/binary_stream.py
##########
@@ -0,0 +1,114 @@
+# 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.
+import ctypes
+from io import BytesIO
+
+import pyignite.utils as ignite_utils
+
+READ_FORWARD = 0
+READ_BACKWARD = 1
+
+
+class BinaryStream:
+    def __init__(self, *args):
+        """
+        Initialize binary stream around buffers.
+
+        :param buf: Buffer, optional parameter. If not passed, creates empty BytesIO.
+        :param conn: Connection instance, required.
+        """
+        from pyignite.connection import Connection
+
+        buf = None
+        if len(args) == 1:
+            self.conn = args[0]
+        elif len(args) == 2:
+            buf = args[0]
+            self.conn = args[1]

Review comment:
       Why don't we make a `conn` argument to always be a first one?

##########
File path: pyignite/connection/__init__.py
##########
@@ -234,9 +238,10 @@ def connect(
         """
         detecting_protocol = False
 
-        # go non-blocking for faster reconnect
-        if not self._in_use.acquire(blocking=False):
-            raise ConnectionError('Connection is in use.')
+        with self._mux:
+            if self._in_use:
+                raise ConnectionError('Connection is in use.')
+            self._in_use = True

Review comment:
       What is the point of this flag? I don't really get it.

##########
File path: pyignite/stream/binary_stream.py
##########
@@ -0,0 +1,114 @@
+# 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.
+import ctypes
+from io import BytesIO
+
+import pyignite.utils as ignite_utils
+
+READ_FORWARD = 0
+READ_BACKWARD = 1
+
+
+class BinaryStream:
+    def __init__(self, *args):
+        """
+        Initialize binary stream around buffers.
+
+        :param buf: Buffer, optional parameter. If not passed, creates empty BytesIO.
+        :param conn: Connection instance, required.
+        """
+        from pyignite.connection import Connection
+
+        buf = None
+        if len(args) == 1:
+            self.conn = args[0]
+        elif len(args) == 2:
+            buf = args[0]
+            self.conn = args[1]
+
+        if not isinstance(self.conn, Connection):
+            raise TypeError(f"invalid parameter: expected instance of {Connection}")
+
+        if buf and not isinstance(buf, (bytearray, bytes, memoryview)):
+            raise TypeError(f"invalid parameter: expected bytes-like object")
+
+        self.stream = BytesIO(buf) if buf else BytesIO()
+
+    @property
+    def compact_footer(self) -> bool:
+        return self.conn.client.compact_footer
+
+    @compact_footer.setter
+    def compact_footer(self, value: bool):
+        self.conn.client.compact_footer = value
+

Review comment:
       It looks like we only need a `conn` here for binary configuration parameters. Maybe it makes sense to make a separate class for that? Like, `BinaryContext`, `BinaryMetaProvider` or something like that?




----------------------------------------------------------------
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:
users@infra.apache.org