def _change_to_candidate(group_id, master_uuid, update_only=False):
    """Switch to candidate slave.
    """
    forbidden_status = (_server.MySQLServer.FAULTY, )
    master = _server.MySQLServer.fetch(_uuid.UUID(master_uuid))
    master.mode = _server.MySQLServer.READ_WRITE
    master.status = _server.MySQLServer.PRIMARY

    if not update_only:
        # Prepare the server to be the master
        master.connect()
        _utils.reset_slave(master)
        _utils.set_read_only(master, False)

    group = _server.Group.fetch(group_id)
    _set_group_master_replication(group, master.uuid, update_only)

    if not update_only:
        # Make slaves point to the master.
        for server in group.servers():
            if server.uuid != _uuid.UUID(master_uuid) and \
                server.status not in forbidden_status:
                try:
                    server.connect()
                    _utils.switch_master(server, master)
                except _errors.DatabaseError as error:
                    _LOGGER.debug(
                        "Error configuring slave (%s).", server.uuid,
                        exc_info=error
                    )

    # At the end, we notify that a server was promoted.
    _events.trigger("SERVER_PROMOTED", set([group_id]),
        group_id, master_uuid
    )
Exemple #2
0
def _change_to_candidate(group_id, master_uuid, update_only=False):
    """Switch to candidate slave.
    """
    forbidden_status = (_server.MySQLServer.FAULTY, )
    master = _server.MySQLServer.fetch(_uuid.UUID(master_uuid))
    master.mode = _server.MySQLServer.READ_WRITE
    master.status = _server.MySQLServer.PRIMARY

    if not update_only:
        # Prepare the server to be the master
        master.connect()
        _utils.reset_slave(master)
        _utils.set_read_only(master, False)

    group = _server.Group.fetch(group_id)
    _set_group_master_replication(group, master.uuid, update_only)

    if not update_only:
        # Make slaves point to the master.
        for server in group.servers():
            if server.uuid != _uuid.UUID(master_uuid) and \
                server.status not in forbidden_status:
                try:
                    server.connect()
                    _utils.switch_master(server, master)
                except _errors.DatabaseError as error:
                    _LOGGER.debug("Error configuring slave (%s): %s.",
                                  server.uuid, error)

    # At the end, we notify that a server was promoted.
    _events.trigger("SERVER_PROMOTED", set([group_id]), group_id, master_uuid)
Exemple #3
0
def _configure_as_slave(group, server):
    """Configure the server as a slave.
    """
    try:
        if group.master:
            master = _server.MySQLServer.fetch(group.master)
            master.connect()
            _utils.switch_master(server, master)
    except _errors.DatabaseError as error:
        msg = "Error trying to configure server ({0}) as slave: {1}.".format(
            server.uuid, error)
        _LOGGER.debug(msg)
        raise _errors.ServerError(msg)
Exemple #4
0
def _configure_as_slave(group, server):
    """Configure the server as a slave.
    """
    try:
        if group.master:
            master = _server.MySQLServer.fetch(group.master)
            master.connect()
            _utils.switch_master(server, master)
    except _errors.DatabaseError as error:
        msg = "Error trying to configure server ({0}) as slave: {1}.".format(
            server.uuid, error)
        _LOGGER.debug(msg)
        raise _errors.ServerError(msg)
Exemple #5
0
def _configure_as_slave(group, server):
    """Configure the server as a slave.
    """
    try:
        if group.master:
            master = _server.MySQLServer.fetch(group.master)
            master.connect()
            _utils.switch_master(server, master)
    except _errors.DatabaseError as error:
        _LOGGER.debug(
            "Error configuring slave (%s)...", server.uuid, exc_info=error
        )
        raise _errors.ServerError(
            "Error trying to configure Server (%s) as slave."
            % (server.uuid, )
        )
def _change_to_candidate(group_id, master_uuid, update_only=False):
    """Switch to candidate slave.
    """
    forbidden_status = (_server.MySQLServer.FAULTY, )
    master = _server.MySQLServer.fetch(_uuid.UUID(master_uuid))
    master.mode = _server.MySQLServer.READ_WRITE
    master.status = _server.MySQLServer.PRIMARY

    if not update_only:
        # Prepare the server to be the master
        master.connect()
        _utils.reset_slave(master)
        _utils.set_read_only(master, False)
        _utils.set_offline_mode(master, False)

    group = _server.Group.fetch(group_id)
    _set_group_master_replication(group, master.uuid, update_only)

    if not update_only:
        # Make slaves point to the master.
        for server in group.servers():
            if server.uuid != _uuid.UUID(master_uuid) and \
                server.status not in forbidden_status:
                try:
                    server.connect()
                    _utils.switch_master(server, master)
                except _errors.DatabaseError as error:
                    _LOGGER.debug(
                        "Error configuring slave (%s): %s.", server.uuid, error
                    )


    ### Restore FailureDetector's status before starting failover/switchover
    if _detector.FailureDetector.was_active:
        _detector.FailureDetector.was_active = None
        group.status = _server.Group.ACTIVE
        _detector.FailureDetector.register_group(group_id)

    # At the end, we notify that a server was promoted.
    # Any function that implements this event should not
    # run any action that updates Fabric. The event was
    # designed to trigger external actions such as:
    #
    # . Updating an external entity.
    _events.trigger("SERVER_PROMOTED", set([group_id]),
        group_id, master_uuid
    )
Exemple #7
0
def _configure_as_slave(group, server):
    """Configure the server as a slave.
    """
    try:
        ### When master has been already elected, throw CREATE USER into master.
        if group.master:
            master = _server.MySQLServer.fetch(group.master)
            master.connect()
            host, port = split_host_port(server.address)
            master.exec_stmt(_server.MySQLServer.DROP_REPLICATION_USER,
                             {"params": (server.repl_user, host,)})
            master.exec_stmt(_server.MySQLServer.CREATE_REPLICATION_USER,
                             {"params": (server.repl_user, host,
                                         server.repl_pass,)})
            master.exec_stmt(_server.MySQLServer.GRANT_REPLICATION_USER,
                             {"params": (server.repl_user, host,)})
            _services_utils.switch_master(server, master)
        else:
            
            ### When master hasn't been elected yet and adding server is very first server in the group,
            ### throw CREATE USER into server itself.
            _LOGGER.critical(group.servers())

            if len(group.servers()) == 1:
                server.connect()
                host, port = split_host_port(server.address)
                server.exec_stmt(_server.MySQLServer.DROP_REPLICATION_USER,
                                 {"params": (server.repl_user, host,)})
                server.exec_stmt(_server.MySQLServer.CREATE_REPLICATION_USER,
                                 {"params": (server.repl_user, host,
                                             server.repl_pass,)})
                server.exec_stmt(_server.MySQLServer.GRANT_REPLICATION_USER,
                                 {"params": (server.repl_user, host,)})
            else:
                ### This means group has at least 1 server but master doesn't elect yet.
                raise _errors.ServerError("Master server doesn't elect yet")
            
    except _errors.DatabaseError as error:
        msg = "Error trying to configure server ({0}) as slave: {1}.".format(
            server.uuid, error)
        _LOGGER.debug(msg)
        raise _errors.ServerError(msg)