Example #1
0
    def send_pkt(self, conn, pkt):
        attempt = 0
        e = None
        for attempt in xrange(self._max_attempts):
            e = None
            try:
                conn.maybe_connect()

                # If the last client_id used on this connection is
                # different than our client_id, then set a new ID on
                # the connection.
                if conn.last_client_id != self._client_id:
                    req = riak_pb.RpbSetClientIdReq()
                    req.client_id = self._client_id
                    conn.send(self.encode_msg(MSG_CODE_SET_CLIENT_ID_REQ, req))
                    conn.last_client_id = self._client_id
                    self.recv_msg(conn, MSG_CODE_SET_CLIENT_ID_RESP)

                conn.send(pkt)
                break
            except socket.error, e:
                # If this is some unknown socket error bail out
                # instead of retrying
                if e[0] not in CONN_CLOSED_ERRORS:
                    raise
    def _set_client_id(self, client_id):
        req = riak_pb.RpbSetClientIdReq()
        req.client_id = client_id

        msg_code, resp = self._request(MSG_CODE_SET_CLIENT_ID_REQ, req,
                                       MSG_CODE_SET_CLIENT_ID_RESP)

        self._client_id = client_id
Example #3
0
    async def set_client_id(self, client_id):
        req = riak_pb.RpbSetClientIdReq()
        req.client_id = client_id

        code, res = await self._request(
            messages.MSG_CODE_SET_CLIENT_ID_REQ,
            req,
            expect=messages.MSG_CODE_SET_CLIENT_ID_RESP)
        if code == messages.MSG_CODE_SET_CLIENT_ID_RESP:
            return True
        else:
            return False
Example #4
0
    def set_client_id(self, client_id):
        """
        Set the client id used by this connection
        """
        req = riak_pb.RpbSetClientIdReq()
        req.client_id = client_id

        msg_code, resp = self.send_msg(MSG_CODE_SET_CLIENT_ID_REQ, req,
                                       MSG_CODE_SET_CLIENT_ID_RESP)

        # Using different client_id values across connections is a bad idea
        # since you never know which connection you might use for a given
        # API call. Setting the client_id manually (rather than as part of
        # the transport construction) can be error-prone since the connection
        # could drop and be reinstated using self._client_id.
        #
        # To minimize the potential impact of variant client_id values across
        # connections, we'll store this new client_id and use it for all
        # future connections.
        self._client_id = client_id

        return True