def diagnose_cluster_candidate()

in mysqloperator/controller/diagnose.py [0:0]


def diagnose_cluster_candidate(primary_session: 'ClassicSession', cluster: 'Cluster', pod: MySQLPod, pod_dba: 'Dba', logger) -> CandidateStatus:
    """
    Check status of an instance that's about to be added to the cluster or
    rejoin it, relative to the given cluster. Also checks whether the instance
    can join it.
    """

    status = CandidateStatus()

    istatus = diagnose_instance(pod, logger, pod_dba)

    if istatus.status == InstanceDiagStatus.UNKNOWN:
        status.status = CandidateDiagStatus.UNREACHABLE
    elif istatus.status in (InstanceDiagStatus.ONLINE, InstanceDiagStatus.RECOVERING):
        status.status = CandidateDiagStatus.MEMBER
        logger.debug(f"{pod} is {istatus.status} -> {status.status}")
    elif istatus.status in (InstanceDiagStatus.NOT_MANAGED, InstanceDiagStatus.UNMANAGED):
        status.bad_gtid_set = check_errant_gtids(
            primary_session, pod, pod_dba, logger)
        if status.bad_gtid_set:
            logger.warning(
                f"{pod} has errant transactions relative to the cluster: errant_gtids={status.bad_gtid_set}")

        if not status.bad_gtid_set:
            status.status = CandidateDiagStatus.JOINABLE
        else:
            status.status = CandidateDiagStatus.UNSUITABLE

        logger.debug(
            f"{pod} is {istatus.status}, errant_gtids={status.bad_gtid_set} -> {status.status}")
    elif istatus.status in (InstanceDiagStatus.OFFLINE, InstanceDiagStatus.ERROR):
        if istatus.status == InstanceDiagStatus.ERROR:
            # check for fatal GR errors
            fatal_error = None
        else:
            fatal_error = None

        status.bad_gtid_set = check_errant_gtids(
            primary_session, pod, pod_dba, logger)
        if status.bad_gtid_set:
            logger.warning(
                f"{pod} has errant transactions relative to the cluster: errant_gtids={status.bad_gtid_set}")
        # TODO disable queryMembers
        if pod.endpoint in cluster.status()["defaultReplicaSet"]["topology"].keys():
            # already a member of the cluster
            if not status.bad_gtid_set and not fatal_error:
                status.status = CandidateDiagStatus.REJOINABLE
            else:
                status.status = CandidateDiagStatus.BROKEN
        else:
            if not status.bad_gtid_set and not fatal_error:
                status.status = CandidateDiagStatus.JOINABLE
            else:
                status.status = CandidateDiagStatus.UNSUITABLE

        logger.debug(
            f"{pod} is {istatus.status}  errant_gtids={status.bad_gtid_set}  fatal_error={fatal_error} -> {status.status}")
    else:
        raise Exception(
            f"Unexpected pod state pod={pod} status={istatus.status}")

    return status