Exemplo n.º 1
0
    def call(self,
             func_name,
             *args,
             msgpack_packer=None,
             msgpack_unpacker=None):
        '''
        Execute CALL request. Call stored Lua function.

        :param func_name: stored Lua function name
        :type func_name: str
        :param args: list of function arguments
        :type args: list or tuple

        :rtype: `Response` instance
        '''
        assert isinstance(func_name, str)

        # This allows to use a tuple or list as an argument
        if len(args) == 1 and isinstance(args[0], (list, tuple)):
            args = args[0]

        request = RequestCall(self,
                              func_name,
                              args,
                              self.call_16,
                              packer=msgpack_packer)
        response = self._send_request(request, unpacker=msgpack_unpacker)
        return response
Exemplo n.º 2
0
    def call(self, func_name, *args):
        assert isinstance(func_name, str)

        if len(args) == 1 and isinstance(args[0], (list, tuple)):
            args = args[0]

        resp = yield from self._send_request(RequestCall(self, func_name, args))
        return resp
Exemplo n.º 3
0
    async def call(self, func_name, *args):
        assert isinstance(func_name, str)

        if len(args) == 1 and isinstance(args[0], (list, tuple)):
            args = args[0]

        co_varnames = RequestCall.__init__.__code__.co_varnames
        params = {
            "conn": self,
            "name": func_name,
            "args": args,
        }

        if "call_16" in co_varnames:
            # tarantool-python >= 0.6.1
            #
            params["call_16"] = None

        resp = await self._send_request(RequestCall(**params))
        return resp
Exemplo n.º 4
0
    def call(self, func_name, *args, **kwargs):
        '''\
        Execute CALL request. Call stored Lua function.

        :param func_name: stored Lua function name
        :type func_name: str
        :param args: list of function arguments
        :type args: list or tuple
        :param return_tuple: True indicates that it is required to return the inserted tuple back
        :type return_tuple: bool
        :param field_defs: field definitions used for types conversion,
               e.g. [('field0', tarantool.NUM), ('field1', tarantool.STR)]
        :type field_defs: None or  [(name, type) or None]
        :param default_type: None a default type used for result conversion, as defined in ``schema[space_no]['default_type']``
        :type default_type: None or int
        :param space_name: space number or name. A schema for the space will be used for type conversion.
        :type space_name: None or int or str

        :rtype: `Response` instance
        '''
        assert isinstance(func_name, str)
        assert len(args) != 0

        # This allows to use a tuple or list as an argument
        if isinstance(args[0], (list, tuple)):
            args = args[0]

        # Check if 'field_defs' and 'default_type' keyword arguments are passed
        field_defs = kwargs.get("field_defs", None)
        default_type = kwargs.get("default_type", None)
        space_name = kwargs.get("space_name", None)

        request = RequestCall(self, func_name, args, return_tuple=True)
        response = self._send_request(request,
                                      space_name=space_name,
                                      field_defs=field_defs,
                                      default_type=default_type)
        return response
Exemplo n.º 5
0
 def pack(self, connection):
     return RequestCall(connection, self.proc_name, self.value_list)
Exemplo n.º 6
0
    def _opt_refresh_instances(self):
        '''
        Refresh list of tarantool instances in a cluster.
        Reconnect if a current instance was gone from the list.
        '''
        now = time.time()

        if not self.connected or not self.cluster_discovery_function or \
                now - self.last_nodes_refresh < self.cluster_discovery_delay:
            return

        # Call a cluster discovery function w/o reconnection. If
        # something going wrong: warn about that and ignore.
        request = RequestCall(self, self.cluster_discovery_function, (),
                              self.call_16)
        try:
            resp = self._send_request_wo_reconnect(request)
        except DatabaseError as e:
            msg = 'got "%s" error, skipped addresses updating' % str(e)
            warn(msg, ClusterDiscoveryWarning)
            return

        if not resp.data or not resp.data[0] or \
                not isinstance(resp.data[0], list):
            msg = "got incorrect response instead of URI list, " + \
                  "skipped addresses updating"
            warn(msg, ClusterDiscoveryWarning)
            return

        # Validate received address list.
        new_addrs = []
        for uri in resp.data[0]:
            addr, msg = parse_uri(uri)
            if not addr:
                warn(msg, ClusterDiscoveryWarning)
                continue

            ok, msg = validate_address(addr)
            if not ok:
                warn(msg, ClusterDiscoveryWarning)
                continue

            new_addrs.append(addr)

        if not new_addrs:
            msg = "got no correct URIs, skipped addresses updating"
            warn(msg, ClusterDiscoveryWarning)
            return

        self.strategy.update(new_addrs)
        self.last_nodes_refresh = now

        # Disconnect from a current instance if it was gone from
        # an instance list and connect to one of new instances.
        current_addr = {'host': self.host, 'port': self.port}
        if current_addr not in self.strategy.addrs:
            self.close()
            addr = self.strategy.getnext()
            self.host = addr['host']
            self.port = addr['port']
            self._opt_reconnect()