Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        tmp = None
        if len(args) > 0:
            tmp = args[0]
        else:
            tmp = kwargs["metas"]

        self._metas = {}
        self._threads = {}
        self._readonly_threads = {}
        for meta in tmp:
            self._metas[meta.get_identity()] = meta

            thread = ThreadPoolExecutor(3)
            thread.meta = meta

            if meta.readonly:
                self._readonly_threads[meta.get_identity()] = thread
            else:
                self._threads[meta.get_identity()] = thread

        self._hashring = hashring.HashRing(self._threads.keys())
        self._readonly_hashring = hashring.HashRing(
            self._readonly_threads.keys())

        self._th_local = threading.local()
Ejemplo n.º 2
0
 def __init__(self,
              addr: Union[Addr, List[Addr]] = None,
              *,
              load_func: LoadFunc = load,
              dump_func: DumpFunc = dump):
     addr = addr or ("localhost", 11211)
     if isinstance(addr, list):
         self._connections = hashring.HashRing([
             Connection(x, load_func=load_func, dump_func=dump_func)
             for x in addr
         ])
     else:
         self._connections = hashring.HashRing(
             [Connection(addr, load_func=load_func, dump_func=dump_func)])
Ejemplo n.º 3
0
 def _load(self):
     v = [x for x in open(self._topology_file).readlines() if x.strip() and not x.strip().startswith('#')]
     data = {}
     for x in v:
         ip, vnodes, datacenter = x.split()
         print "UPDATE storage_topology set vnodes=%s where data_center='%s' and host='%s';"%(vnodes, datacenter, ip)
         vnodes = int(vnodes)
         if datacenter not in data:
             data[datacenter] = {}
         dc = data[datacenter]
         dc[ip] = {'vnodes':vnodes}
     import hashring
     self.rings = [(dc, hashring.HashRing(d)) for dc, d in data.iteritems()]
     self.rings.sort()
     self.topology = data