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)
def _block_write_demote(group_id, update_only): """Block and disable write access to the current master. """ group = _server.Group.fetch(group_id) if not group: raise _errors.GroupError("Group (%s) does not exist." % (group_id, )) if not group.master: raise _errors.GroupError("Group (%s) does not have a master." % (group_id, )) master = _server.MySQLServer.fetch(group.master) assert(master.status in \ (_server.MySQLServer.PRIMARY, _server.MySQLServer.FAULTY) ) if master.status == _server.MySQLServer.PRIMARY: master.connect() master.mode = _server.MySQLServer.READ_ONLY master.status = _server.MySQLServer.SECONDARY _utils.set_read_only(master, True) if not update_only: _events.trigger_within_procedure(WAIT_SLAVES_DEMOTE, group_id, str(master.uuid)) _set_group_master_replication(group, None, update_only)
def _block_write_demote(group_id, update_only): """Block and disable write access to the current master. """ group = _server.Group.fetch(group_id) if not group: raise _errors.GroupError("Group (%s) does not exist." % (group_id, )) if not group.master: raise _errors.GroupError("Group (%s) does not have a master." % (group_id, )) master = _server.MySQLServer.fetch(group.master) assert(master.status in \ (_server.MySQLServer.PRIMARY, _server.MySQLServer.FAULTY) ) if master.status == _server.MySQLServer.PRIMARY: master.connect() master.mode = _server.MySQLServer.READ_ONLY master.status = _server.MySQLServer.SECONDARY _utils.set_read_only(master, True) if not update_only: _events.trigger_within_procedure( WAIT_SLAVES_DEMOTE, group_id, str(master.uuid) ) _set_group_master_replication(group, None, update_only)
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 )
def _do_block_write_master(group_id, master_uuid, update_only=False): """Block and disable write access to the current master. Note that connections are not killed and blocking the master may take some time. """ master = _server.MySQLServer.fetch(_uuid.UUID(master_uuid)) assert(master.status == _server.MySQLServer.PRIMARY) master.mode = _server.MySQLServer.READ_ONLY master.status = _server.MySQLServer.SECONDARY if not update_only: master.connect() _utils.set_read_only(master, True) _utils.set_offline_mode(master, True) # Temporarily unset the master in this group. group = _server.Group.fetch(group_id) _set_group_master_replication(group, None) # At the end, we notify that a server was demoted. # 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. # # . Fencing off a server. _events.trigger("SERVER_DEMOTED", set([group_id]), group_id, str(master.uuid) )
def _do_block_write_master(group_id, master_uuid, update_only=False): """Block and disable write access to the current master. Note that connections are not killed and blocking the master may take some time. """ master = _server.MySQLServer.fetch(_uuid.UUID(master_uuid)) assert (master.status == _server.MySQLServer.PRIMARY) master.mode = _server.MySQLServer.READ_ONLY master.status = _server.MySQLServer.SECONDARY if not update_only: master.connect() _utils.set_read_only(master, True) # Temporarily unset the master in this group. group = _server.Group.fetch(group_id) _set_group_master_replication(group, None) # At the end, we notify that a server was demoted. # 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. # # . Fencing off a server. _events.trigger("SERVER_DEMOTED", set([group_id]), group_id, str(master.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 )
def _do_block_write_master(group_id, master_uuid, update_only=False): """Block and disable write access to the current master. Note that connections are not killed and blocking the master may take some time. """ master = _server.MySQLServer.fetch(_uuid.UUID(master_uuid)) assert (master.status == _server.MySQLServer.PRIMARY) master.mode = _server.MySQLServer.READ_ONLY master.status = _server.MySQLServer.SECONDARY if not update_only: master.connect() _utils.set_read_only(master, True) # Temporarily unset the master in this group. group = _server.Group.fetch(group_id) _set_group_master_replication(group, None) # At the end, we notify that a server was demoted. _events.trigger("SERVER_DEMOTED", set([group_id]), group_id, str(master.uuid))
def _do_block_write_master(group_id, master_uuid, update_only=False): """Block and disable write access to the current master. Note that connections are not killed and blocking the master may take some time. """ master = _server.MySQLServer.fetch(_uuid.UUID(master_uuid)) assert(master.status == _server.MySQLServer.PRIMARY) master.mode = _server.MySQLServer.READ_ONLY master.status = _server.MySQLServer.SECONDARY if not update_only: master.connect() _utils.set_read_only(master, True) # Temporarily unset the master in this group. group = _server.Group.fetch(group_id) _set_group_master_replication(group, None) # At the end, we notify that a server was demoted. _events.trigger("SERVER_DEMOTED", set([group_id]), group_id, str(master.uuid) )