Пример #1
0
def _set_group_master_replication(group, server_id, update_only=False):
    """Set the master for the given group and also reset the
    replication with the other group masters. Any change of master
    for a group will be initiated through this method. The method also
    takes care of resetting the master and the slaves that are registered
    with this group to connect with the new master.

    The idea is that operations like switchover, failover, promote all are
    finally master changing operations. Hence the right place to handle
    these operations is at the place where the master is being changed.

    The following operations need to be done

    - Stop the slave on the old master
    - Stop the slaves replicating from the old master
    - Start the slave on the new master
    - Start the slaves with the new master

    :param group: The group whose master needs to be changed.
    :param server_id: The server id of the server that is becoming the master.
    :param update_only: Only update the state store and skip provisioning.
    """
    # Set the new master if update-only is true.
    if update_only:
        group.master = server_id
        return

    try:
        # Otherwise, stop the slave running on the current master
        if group.master_group_id is not None and group.master is not None:
            _group_replication.stop_group_slave(
                group.master_group_id, group.group_id, False
            )
        # Stop the Groups replicating from the current group.
        _group_replication.stop_group_slaves(group.group_id)
    except (_errors.GroupError, _errors.DatabaseError) as error:
        _LOGGER.error(
            "Error accessing groups related to (%s): %s.", group.group_id,
            error
        )

    # Set the new master
    group.master = server_id

    try:
        # If the master is not None setup the master and the slaves.
        if group.master is not None:
            # Start the slave groups for this group.
            _group_replication.start_group_slaves(group.group_id)
            if group.master_group_id is not None:
                # Start the slave on this group
                _group_replication.setup_group_replication(
                    group.master_group_id, group.group_id
                )
    except (_errors.GroupError, _errors.DatabaseError) as error:
        _LOGGER.error(
            "Error accessing groups related to (%s): %s.", group.group_id,
            error
        )
Пример #2
0
def _set_group_master_replication(group, server_id, update_only=False):
    """Set the master for the given group and also reset the
    replication with the other group masters. Any change of master
    for a group will be initiated through this method. The method also
    takes care of resetting the master and the slaves that are registered
    with this group to connect with the new master.

    The idea is that operations like switchover, failover, promote all are
    finally master changing operations. Hence the right place to handle
    these operations is at the place where the master is being changed.

    The following operations need to be done

    - Stop the slave on the old master
    - Stop the slaves replicating from the old master
    - Start the slave on the new master
    - Start the slaves with the new master

    :param group: The group whose master needs to be changed.
    :param server_id: The server id of the server that is becoming the master.
    :param update_only: Only update the state store and skip provisioning.
    """
    # Set the new master if update-only is true.
    if update_only:
        group.master = server_id
        return

    try:
        # Otherwise, stop the slave running on the current master
        if group.master_group_id is not None and group.master is not None:
            _group_replication.stop_group_slave(group.master_group_id,
                                                group.group_id, False)
        # Stop the Groups replicating from the current group.
        _group_replication.stop_group_slaves(group.group_id)
    except (_errors.GroupError, _errors.DatabaseError) as error:
        _LOGGER.error("Error accessing groups related to (%s): %s.",
                      group.group_id, error)

    # Set the new master
    group.master = server_id

    try:
        # If the master is not None setup the master and the slaves.
        if group.master is not None:
            # Start the slave groups for this group.
            _group_replication.start_group_slaves(group.group_id)
            if group.master_group_id is not None:
                # Start the slave on this group
                _group_replication.setup_group_replication(
                    group.master_group_id, group.group_id)
    except (_errors.GroupError, _errors.DatabaseError) as error:
        _LOGGER.error("Error accessing groups related to (%s): %s.",
                      group.group_id, error)
Пример #3
0
 def test_sync_readonly_servers(self):
     status = self.proxy.group.lookup_servers("GROUPID3")
     for info in self.check_xmlrpc_iter(status):
         if info['status'] == MySQLServer.SECONDARY:
             slave_uuid = info['server_uuid']
             slave_server = fetch_test_server(slave_uuid)
             slave_server.connect()
     _group_replication.setup_group_replication("GROUPID2", "GROUPID3")
     _replication.synchronize_with_read_only(slave_server,
                                             self.shard_server, 3, 5)
     _group_replication.stop_group_slave("GROUPID2", "GROUPID3", True)
     try:
         rows = self.shard_server.exec_stmt("SELECT NAME FROM db1.t1",
                                            {"fetch": True})
     except _errors.DatabaseError:
         raise Exception("Enable Shard failed to enable shard.")
     self.assertEqual(len(rows), 15)
 def test_sync_readonly_servers(self):
     status = self.proxy.group.lookup_servers("GROUPID3")
     self.assertEqual(status[0], True)
     self.assertEqual(status[1], "")
     obtained_server_list = status[2]
     for idx in range(0, 2):
         if obtained_server_list[idx]["status"] == MySQLServer.SECONDARY:
             slave_uuid = obtained_server_list[idx]["server_uuid"]
             slave_server = MySQLServer.fetch(slave_uuid)
             slave_server.connect()
     _group_replication.setup_group_replication("GROUPID2", "GROUPID3")
     _replication.synchronize_with_read_only(
         slave_server, self.shard_server, 3, 5
     )
     _group_replication.stop_group_slave("GROUPID2", "GROUPID3", True)
     try:
         rows = self.shard_server.exec_stmt(
                             "SELECT NAME FROM db1.t1",
                             {"fetch" : True})
     except _errors.DatabaseError:
         raise Exception("Enable Shard failed to enable shard.")
     self.assertEqual(len(rows), 15)