Ejemplo n.º 1
0
    def call(self, method, args, reply=None):
        """Call invokes the KV command synchronously and returns the response.

        If preceeding calls have been made to prepare() without a call
        to flush(), this call is prepared and then all prepared calls
        are flushed.
        """
        if len(self.prepared) > 0:
            if reply is None:
                reply = method.response_type()
            self.prepare(method, args, reply)
            self.flush()
            return reply
        if not args.header.user:
            args.header.user = self.user
        if not args.header.HasField('user_priority') and self.user_priority != 0:
            args.header.user_priority = self.user_priority
        call = Call(method, args, reply)
        call.reset_client_cmd_id()
        self._sender.send(call)
        errors.raise_from_header(call.reply.header)
        return call.reply
Ejemplo n.º 2
0
    def prepare(self, method, args, reply):
        """Prepare accepts a KV API call to be called later.

        The call will be buffered locally until the first call to
        flush(), at which time it will be sent for execution as part
        of a batch call. Using prepare/flush parallelizes queries and
        updates and should be used where possible for efficiency.

        For clients using an HTTP sender, prepare/flush allows multiple
        commands to be sent over the same connection. For transactional
        clients, prepare/flush can dramatically improve efficiency by
        compressing multiple writes into a single atomic update in the
        event that the writes are to keys within a single range. However,
        using prepare/flush alone will not guarantee atomicity. Clients
        must use a transaction for that purpose.

        The supplied reply struct will not be valid until after a call
        to flush().
        """
        call = Call(method, args, reply)
        call.reset_client_cmd_id()
        self.prepared.append(call)
Ejemplo n.º 3
0
 def test_reset_client_cmd_id(self):
     call = Call(Methods.Increment, api_pb2.IncrementRequest())
     call.reset_client_cmd_id()
     self.assertNotEqual(call.args.header.cmd_id.wall_time, 0)
     self.assertNotEqual(call.args.header.cmd_id.random, 0)