Beispiel #1
0
class ConsistentHashingRouter(BaseRouter):
    """Router that returns the host_id based on a consistent hashing
    algorithm.  The consistent hashing algorithm only works if a key
    argument is provided.
    """
    def __init__(self, cluster):
        BaseRouter.__init__(self, cluster)
        self._host_id_id_map = dict(self.cluster.hosts.items())
        self._hash = Ketama(self._host_id_id_map.values())

    def get_host_for_key(self, key):
        rv = self._hash.get_node(key)
        if rv is None:
            raise UnroutableCommand('Did not find a suitable '
                                    'host for the key.')
        return rv
Beispiel #2
0
class ConsistentHashingRouter(BaseRouter):
    """Router that returns the host_id based on a consistent hashing
    algorithm.  The consistent hashing algorithm only works if a key
    argument is provided.
    """

    def __init__(self, cluster):
        BaseRouter.__init__(self, cluster)
        self._host_id_id_map = dict(self.cluster.hosts.items())
        self._hash = Ketama(self._host_id_id_map.values())

    def get_host_for_key(self, key):
        rv = self._hash.get_node(key)
        if rv is None:
            raise UnroutableCommand('Did not find a suitable '
                                    'host for the key.')
        return rv
Beispiel #3
0
class ConsistentHashingRouter(BaseRouter):
    """Router that returns the host_id based on a consistent hashing
    algorithm.  The consistent hashing algorithm only works if a key
    argument is provided.

    This router requires that the hosts are gapless which means that
    the IDs for N hosts range from 0 to N-1.
    """
    def __init__(self, cluster):
        BaseRouter.__init__(self, cluster)
        self._host_id_id_map = dict(self.cluster.hosts.items())
        self._hash = Ketama(self._host_id_id_map.values())
        assert_gapless_hosts(self.cluster.hosts)

    def get_host_for_key(self, key):
        rv = self._hash.get_node(key)
        if rv is None:
            raise UnroutableCommand("Did not find a suitable "
                                    "host for the key.")
        return rv
Beispiel #4
0
class ConsistentHashingRouter(BaseRouter):
    """Router that returns the host_id based on a consistent hashing
    algorithm.  The consistent hashing algorithm only works if a key
    argument is provided.

    This router requires that the hosts are gapless which means that
    the IDs for N hosts range from 0 to N-1.
    """

    def __init__(self, cluster):
        BaseRouter.__init__(self, cluster)
        self._host_id_id_map = dict(self.cluster.hosts.items())
        self._hash = Ketama(self._host_id_id_map.values())
        assert_gapless_hosts(self.cluster.hosts)

    def get_host_for_key(self, key):
        rv = self._hash.get_node(key)
        if rv is None:
            raise UnroutableCommand('Did not find a suitable '
                                    'host for the key.')
        return rv