Пример #1
0
    def _UpdateIdSets(self, id_tuples):
        """Update the sets of Client IDs and Taba Names.

    Args:
      id_tuples - List of tuples of the form (client_id, name).

    Returns:
      Operation object with the query results.
    """
        op = CompoundOperation()

        # Build a map of Client ID to Taba Names
        client_id_names_map = defaultdict(list)
        for client_id, name in id_tuples:
            client_id_names_map[client_id].append(name)

        try:
            # Add the Client IDs to the Set of all Client IDs.
            op_clients = self.ClientIdsAdd(client_id_names_map.keys())
            op.AddOp(op_clients)

            # Add all the Taba Names to the Set of all names across all Client IDs.
            all_names = set()
            all_names.update(*client_id_names_map.values())
            op_names_all = self.TabaNamesForAllAdd(all_names)
            op.AddOp(op_names_all)

            # Add the Taba Names for each Client ID.
            for client_id, names in client_id_names_map.iteritems():
                op_names = self.TabaNamesForClientAdd(client_id, names)
                op.AddOp(op_names)

        except Exception:
            LOG.error("Error updating Client/Name sets")
            LOG.error(traceback.format_exc())
            op.AddOp(Operation(success=False,
                               traceback=traceback.format_exc()))

        return op
Пример #2
0
    def _ShardCheckAndSet(self, shard, keys, vkeys, values):
        op = CompoundOperation()

        # Split the request into batches to avoid locking too many keys at once.
        greenlets = [
            gevent.spawn(self._ShardCheckAndSetBatch, shard,
                         keys[i:i + CAS_BATCH_SIZE],
                         vkeys[i:i + CAS_BATCH_SIZE],
                         values[i:i + CAS_BATCH_SIZE])
            for i in xrange(0, len(keys), CAS_BATCH_SIZE)
        ]

        gevent.joinall(greenlets)

        # Get the results and combine them into a single Operation.
        [op.AddOp(g.get()) for g in greenlets]
        op.response_value = []
        for sub_op in op.sub_operations:
            if sub_op.success:
                op.response_value.extend(sub_op.response_value)

        return op