Пример #1
0
 def _make_pending_key_from_key(self, key):
     """
     Return the pending_key for a given key. This is used
     to route a key into the correct pending buffer. If partitioning
     is disabled, route into the no partition buffer.
     """
     if self.pending_partitions == 1:
         return self.pending_key
     return self._make_pending_key(crc32(key) % self.pending_partitions)
Пример #2
0
    def make_counter_key(self, model, rollup, timestamp, key, environment_id):
        """
        Make a key that is used for counter values.

        Returns a 2-tuple that contains the hash key and the hash field.
        """
        model_key = self.get_model_key(key)

        if isinstance(model_key, six.integer_types):
            vnode = model_key % self.vnodes
        else:
            vnode = crc32(force_bytes(model_key)) % self.vnodes

        return (
            u"{prefix}{model}:{epoch}:{vnode}".format(
                prefix=self.prefix,
                model=model.value,
                epoch=self.normalize_to_rollup(timestamp, rollup),
                vnode=vnode,
            ),
            self.add_environment_parameter(model_key, environment_id),
        )