Ejemplo n.º 1
0
    async def put(self, robj, return_body=True):
        bucket = robj.bucket

        req = riak_pb.RpbPutReq()

        if return_body:
            req.return_body = 1

        req.bucket = str_to_bytes(bucket.name)
        self._add_bucket_type(req, bucket.bucket_type)

        if robj.key:
            req.key = str_to_bytes(robj.key)
        if robj.vclock:
            req.vclock = robj.vclock.encode('binary')

        self._encode_content(robj, req.content)

        msg_code, resp = await self._request(messages.MSG_CODE_PUT_REQ, req,
                                             messages.MSG_CODE_PUT_RESP)

        if resp is not None:
            if resp.HasField('key'):
                robj.key = bytes_to_str(resp.key)
            if resp.HasField('vclock'):
                robj.vclock = VClock(resp.vclock, 'binary')
            if resp.content:
                self._decode_contents(resp.content, robj)
        elif not robj.key:
            raise RiakError("missing response object")

        return robj
Ejemplo n.º 2
0
    def put(self,
            robj,
            w=None,
            dw=None,
            pw=None,
            return_body=True,
            if_none_match=False,
            timeout=None):
        """
        Serialize get request and deserialize response
        """
        bucket = robj.bucket

        req = riak_pb.RpbPutReq()
        if w:
            req.w = self._encode_quorum(w)
        if dw:
            req.dw = self._encode_quorum(dw)
        if self.quorum_controls() and pw:
            req.pw = self._encode_quorum(pw)

        if return_body:
            req.return_body = 1
        if if_none_match:
            req.if_none_match = 1
        if self.client_timeouts() and timeout:
            req.timeout = timeout

        req.bucket = bucket.name
        if robj.key:
            req.key = robj.key
        if robj.vclock:
            req.vclock = robj.vclock.encode('binary')

        self._encode_content(robj, req.content)

        msg_code, resp = self._request(MSG_CODE_PUT_REQ, req,
                                       MSG_CODE_PUT_RESP)

        if resp is not None:
            if resp.HasField('key'):
                robj.key = resp.key
            if resp.HasField("vclock"):
                robj.vclock = VClock(resp.vclock, 'binary')
            if resp.content:
                self._decode_contents(resp.content, robj)
        elif not robj.key:
            raise RiakError("missing response object")

        return robj
Ejemplo n.º 3
0
    def put_new(self,
                robj,
                w=None,
                dw=None,
                pw=None,
                return_body=True,
                if_none_match=False):
        """Put a new object into the Riak store, returning its (new) key.

        If return_meta is False, then the vlock and metadata return values
        will be None.

        @return robj
        """
        # Note that this won't work on 0.14 nodes.
        bucket = robj.bucket

        req = riak_pb.RpbPutReq()
        if w:
            req.w = self.translate_rw_val(w)
        if dw:
            req.dw = self.translate_rw_val(dw)
        if self.quorum_controls() and pw:
            req.pw = self.translate_rw_val(pw)

        if return_body:
            req.return_body = 1
        if if_none_match:
            req.if_none_match = 1

        req.bucket = bucket.name

        self.encode_content(robj, req.content)

        msg_code, resp = self._request(MSG_CODE_PUT_REQ, req,
                                       MSG_CODE_PUT_RESP)
        if not resp:
            raise RiakError("missing response object")
        if len(resp.content) != 1:
            raise RiakError("siblings were returned from object creation")

        robj.key = resp.key
        robj.vclock = resp.vclock
        content = self.decode_content(resp.content[0], robj)
        return content
Ejemplo n.º 4
0
    def put_new(self,
                robj,
                w=None,
                dw=None,
                pw=None,
                return_body=True,
                if_none_match=False):
        """Put a new object into the Riak store, returning its (new) key.

        If return_meta is False, then the vlock and metadata return values
        will be None.

        @return (key, vclock, metadata)
        """
        # Note that this won't work on 0.14 nodes.
        bucket = robj.get_bucket()

        req = riak_pb.RpbPutReq()
        req.w = self.translate_rw_val(w)
        req.dw = self.translate_rw_val(dw)
        req.pw = self.translate_rw_val(pw)

        if return_body:
            req.return_body = 1
        if if_none_match:
            req.if_none_match = 1

        req.bucket = bucket.get_name()

        self.pbify_content(robj.get_metadata(), robj.get_encoded_data(),
                           req.content)

        msg_code, resp = self.send_msg(MSG_CODE_PUT_REQ, req,
                                       MSG_CODE_PUT_RESP)
        if not resp:
            raise RiakError("missing response object")
        if len(resp.content) != 1:
            raise RiakError("siblings were returned from object creation")

        metadata, content = self.decode_content(resp.content[0])
        return resp.key, resp.vclock, metadata
Ejemplo n.º 5
0
    def put(self,
            robj,
            w=None,
            dw=None,
            pw=None,
            return_body=True,
            if_none_match=False):
        """
        Serialize get request and deserialize response
        """
        bucket = robj.get_bucket()

        req = riak_pb.RpbPutReq()
        req.w = self.translate_rw_val(w)
        req.dw = self.translate_rw_val(dw)
        if self.quorum_controls():
            req.pw = self.translate_rw_val(pw)

        if return_body:
            req.return_body = 1
        if if_none_match:
            req.if_none_match = 1

        req.bucket = bucket.get_name()
        req.key = robj.get_key()
        vclock = robj.vclock()
        if vclock:
            req.vclock = vclock

        self.pbify_content(robj.get_metadata(), robj.get_encoded_data(),
                           req.content)

        msg_code, resp = self.send_msg(MSG_CODE_PUT_REQ, req,
                                       MSG_CODE_PUT_RESP)
        if resp is not None:
            contents = []
            for c in resp.content:
                contents.append(self.decode_content(c))
            return resp.vclock, contents
Ejemplo n.º 6
0
    def put(self,
            robj,
            w=None,
            dw=None,
            pw=None,
            return_body=True,
            if_none_match=False):
        """
        Serialize get request and deserialize response
        """
        bucket = robj.bucket

        req = riak_pb.RpbPutReq()
        if w:
            req.w = self.translate_rw_val(w)
        if dw:
            req.dw = self.translate_rw_val(dw)
        if self.quorum_controls() and pw:
            req.pw = self.translate_rw_val(pw)

        if return_body:
            req.return_body = 1
        if if_none_match:
            req.if_none_match = 1

        req.bucket = bucket.name
        req.key = robj.key
        if robj.vclock:
            req.vclock = robj.vclock

        self.encode_content(robj, req.content)

        msg_code, resp = self._request(MSG_CODE_PUT_REQ, req,
                                       MSG_CODE_PUT_RESP)
        if resp is not None:
            return self._decoded_contents(resp, robj)