Ejemplo n.º 1
0
def fix_migrating(host, port, password=None):
    nodes = dict()
    mig_srcs = []
    mig_dsts = []
    t = Connection(host, port, password)
    try:
        m = t.send_raw(CMD_CLUSTER_NODES)
        logging.debug('Ask `cluster nodes` Rsp %s', m)
        for node_info in m.split('\n'):
            if not _valid_node_info(node_info):
                continue
            node = ClusterNode(*node_info.split(' '))
            node.password = password
            node.host = node.host or host
            nodes[node.node_id] = node

            mig_dsts.extend([(node, {
                'slot': g[0],
                'id': g[1]
            }) for g in PAT_MIGRATING_IN.findall(node_info)])
            mig_srcs.extend([(node, {
                'slot': g[0],
                'id': g[1]
            }) for g in PAT_MIGRATING_OUT.findall(node_info)])

        for n, args in mig_dsts:
            node_id = args['id']
            if node_id not in nodes:
                logging.error(
                    'Fail to fix %s:%d <- (referenced from %s:%d)'
                    ' - node %s is missing', n.host, n.port, host, port,
                    node_id)
                continue
            _migr_one_slot(nodes[node_id], n, int(args['slot']),
                           nodes.itervalues())
        for n, args in mig_srcs:
            node_id = args['id']
            if node_id not in nodes:
                logging.error(
                    'Fail to fix %s:%d -> (referenced from %s:%d)'
                    ' - node %s is missing', n.host, n.port, host, port,
                    node_id)
                continue
            _migr_one_slot(n, nodes[node_id], int(args['slot']),
                           nodes.itervalues())
    finally:
        t.close()
        for n in nodes.itervalues():
            n.close()
Ejemplo n.º 2
0
def fix_migrating(host, port):
    nodes = dict()
    mig_srcs = []
    mig_dsts = []
    t = Talker(host, port)
    try:
        m = t.talk_raw(CMD_CLUSTER_NODES)
        logging.debug("Ask `cluster nodes` Rsp %s", m)
        for node_info in m.split("\n"):
            if not _valid_node_info(node_info):
                continue
            node = ClusterNode(*node_info.split(" "))
            node.host = node.host or host
            nodes[node.node_id] = node

            mig_dsts.extend([(node, {"slot": g[0], "id": g[1]}) for g in PAT_MIGRATING_IN.findall(node_info)])
            mig_srcs.extend([(node, {"slot": g[0], "id": g[1]}) for g in PAT_MIGRATING_OUT.findall(node_info)])

        for n, args in mig_dsts:
            node_id = args["id"]
            if node_id not in nodes:
                logging.error(
                    "Fail to fix %s:%d <- (referenced from %s:%d)" " - node %s is missing",
                    n.host,
                    n.port,
                    host,
                    port,
                    node_id,
                )
                continue
            _migr_one_slot(nodes[node_id], n, int(args["slot"]), nodes.itervalues())
        for n, args in mig_srcs:
            node_id = args["id"]
            if node_id not in nodes:
                logging.error(
                    "Fail to fix %s:%d -> (referenced from %s:%d)" " - node %s is missing",
                    n.host,
                    n.port,
                    host,
                    port,
                    node_id,
                )
                continue
            _migr_one_slot(n, nodes[node_id], int(args["slot"]), nodes.itervalues())
    finally:
        t.close()
        for n in nodes.itervalues():
            n.close()
Ejemplo n.º 3
0
def fix_migrating(host, port):
    nodes = dict()
    mig_srcs = []
    mig_dsts = []
    t = Talker(host, port)
    try:
        m = t.talk_raw(CMD_CLUSTER_NODES)
        logging.debug('Ask `cluster nodes` Rsp %s', m)
        for node_info in m.split('\n'):
            if not _valid_node_info(node_info):
                continue
            node = ClusterNode(*node_info.split(' '))
            node.host = node.host or host
            nodes[node.node_id] = node

            search = PAT_MIGRATING_IN.search(node_info)
            if search is not None:
                mig_dsts.append((node, search.groupdict()))

            search = PAT_MIGRATING_OUT.search(node_info)
            if search is not None:
                mig_srcs.append((node, search.groupdict()))

        for n, args in mig_dsts:
            node_id = args['id']
            if node_id not in nodes:
                logging.error('Fail to fix %s:%d <- (referenced from %s:%d)'
                              ' - node %s is missing', n.host, n.port,
                              host, port, node_id)
                continue
            _migr_one_slot(nodes[node_id], n, int(args['slot']),
                           nodes.itervalues())
        for n, args in mig_srcs:
            node_id = args['id']
            if node_id not in nodes:
                logging.error('Fail to fix %s:%d -> (referenced from %s:%d)'
                              ' - node %s is missing', n.host, n.port,
                              host, port, node_id)
                continue
            _migr_one_slot(n, nodes[node_id], int(args['slot']),
                           nodes.itervalues())
    finally:
        t.close()
        for n in nodes.itervalues():
            n.close()
Ejemplo n.º 4
0
def fix_migrating(host, port):
    nodes = dict()
    mig_srcs = []
    mig_dsts = []
    t = Talker(host, port)
    try:
        m = t.talk_raw(CMD_CLUSTER_NODES)
        logging.debug('Ask `cluster nodes` Rsp %s', m)
        for node_info in m.split('\n'):
            if not _valid_node_info(node_info):
                continue
            node = ClusterNode(*node_info.split(' '))
            node.host = node.host or host
            nodes[node.node_id] = node

            search = PAT_MIGRATING_IN.search(node_info)
            if search is not None:
                mig_dsts.append((node, search.groupdict()))

            search = PAT_MIGRATING_OUT.search(node_info)
            if search is not None:
                mig_srcs.append((node, search.groupdict()))

        for n, args in mig_dsts:
            node_id = args['id']
            if node_id not in nodes:
                logging.error('Fail to fix %s:%d <- (referenced from %s:%d)'
                              ' - node %s is missing', n.host, n.port,
                              host, port, node_id)
                continue
            _migr_one_slot(nodes[node_id], n, int(args['slot']),
                           nodes.itervalues())
        for n, args in mig_srcs:
            node_id = args['id']
            if node_id not in nodes:
                logging.error('Fail to fix %s:%d -> (referenced from %s:%d)'
                              ' - node %s is missing', n.host, n.port,
                              host, port, node_id)
                continue
            _migr_one_slot(n, nodes[node_id], int(args['slot']),
                           nodes.itervalues())
    finally:
        t.close()
        for n in nodes.itervalues():
            n.close()
Ejemplo n.º 5
0
def _list_nodes(conn,
                default_host=None,
                filter_func=lambda node: True,
                password=None):
    m = conn.send_raw(CMD_CLUSTER_NODES)
    logging.debug('Ask `cluster nodes` Rsp %s', m)
    default_host = default_host or conn.host

    nodes = []
    myself = None
    for node_info in m.split('\n'):
        if not _valid_node_info(node_info):
            continue
        node = ClusterNode(*node_info.split(' '))
        node.password = password
        if 'myself' in node_info:
            myself = node
            if myself.host == '':
                myself.host = default_host
        if filter_func(node):
            nodes.append(node)
    return nodes, myself