def _setup_sync(shard_id, source_group_id, destn_group_id, split_value, prune_limit, cmd): """sync the source and the destination groups. :param shard_id: The shard ID of the shard that needs to be moved. :param source_group_id: The group_id of the source shard. :param destn_group_id: The ID of the group to which the shard needs to be moved. :param split_value: Indicates the value at which the range for the particular shard will be split. Will be set only for shard split operations. :param prune_limit: The number of DELETEs that should be done in one batch. :param cmd: Indicates the type of re-sharding operation """ source_group = Group.fetch(source_group_id) if source_group is None: raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND % (source_group_id, )) destination_group = Group.fetch(destn_group_id) if destination_group is None: raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND % (destn_group_id, )) master = MySQLServer.fetch(source_group.master) if master is None: raise _errors.ShardingError( _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND) master.connect() slave = MySQLServer.fetch(destination_group.master) if slave is None: raise _errors.ShardingError( _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND) slave.connect() #Synchronize until the slave catches up with the master. _replication.synchronize_with_read_only(slave, master) #Reset replication once the syncing is done. _replication.stop_slave(slave, wait=True) _replication.reset_slave(slave, clean=True) #Trigger changing the mappings for the shard that was copied _events.trigger_within_procedure( SETUP_RESHARDING_SWITCH, shard_id, source_group_id, destn_group_id, split_value, prune_limit, cmd )
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)
def _setup_move_sync(shard_id, source_group_id, destn_group_id, split_value, cmd): """Setup replication between the source and the destination groups and ensure that they are in sync. :param shard_id: The shard ID of the shard that needs to be moved. :param source_group_id: The group_id of the source shard. :param destn_group_id: The ID of the group to which the shard needs to be moved. :param split_value: Indicates the value at which the range for the particular shard will be split. Will be set only for shard split operations. :param cmd: Indicates the type of re-sharding operation """ source_group = Group.fetch(source_group_id) if source_group is None: raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND % (source_group_id, )) destination_group = Group.fetch(destn_group_id) if destination_group is None: raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND % (destination_group_id, )) master = MySQLServer.fetch(source_group.master) if master is None: raise _errors.ShardingError( _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND) master.connect() slave = MySQLServer.fetch(destination_group.master) if slave is None: raise _errors.ShardingError( _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND) slave.connect() #Stop and reset any slave that might be running on the slave server. _replication.stop_slave(slave, wait=True) _replication.reset_slave(slave, clean=True) #Change the master to the shard group master. _replication.switch_master(slave, master, master. user, master.passwd) #Start the slave so that syncing of the data begins _replication.start_slave(slave, wait=True) #Synchronize until the slave catches up with the master. _replication.synchronize_with_read_only(slave, master) #Reset replication once the syncing is done. _replication.stop_slave(slave, wait=True) _replication.reset_slave(slave, clean=True) #Trigger changing the mappings for the shard that was copied _events.trigger_within_procedure( SETUP_RESHARDING_SWITCH, shard_id, source_group_id, destn_group_id, split_value, cmd )