def _remove_shard_mapping_defn(shard_mapping_id): """Remove the shard mapping definition of the given table. :param shard_mapping_id: The shard mapping ID of the shard mapping definition that needs to be removed. """ ShardMapping.remove_sharding_definition(shard_mapping_id)
def _add_shard_mapping(shard_mapping_id, table_name, column_name, range_check=False, update_only=False): """Add a table to a shard mapping. :param shard_mapping_id: The shard mapping id to which the input table is attached. :param table_name: The table being sharded. :param column_name: The column whose value is used in the sharding scheme being applied :param range_check: Indicates if range check should be turned on for this table. :param update_only: Only update the state store and skip adding range checks. :return: True if the the table was successfully added. False otherwise. """ ShardMapping.add(shard_mapping_id, table_name, column_name, range_check) if range_check and not update_only: _, sharding_type, global_group_id = \ ShardMapping.fetch_shard_mapping_defn(shard_mapping_id) SHARD_METADATA_VERIFIER.add_shard_range_trigger( global_group_id, sharding_type, table_name, column_name)
def _add_shard_mapping(shard_mapping_id, table_name, column_name, range_check=False, update_only=False): """Add a table to a shard mapping. :param shard_mapping_id: The shard mapping id to which the input table is attached. :param table_name: The table being sharded. :param column_name: The column whose value is used in the sharding scheme being applied :param range_check: Indicates if range check should be turned on for this table. :param update_only: Only update the state store and skip adding range checks. :return: True if the the table was successfully added. False otherwise. """ ShardMapping.add(shard_mapping_id, table_name, column_name, range_check) if range_check and not update_only: _, sharding_type, global_group_id = \ ShardMapping.fetch_shard_mapping_defn(shard_mapping_id) SHARD_METADATA_VERIFIER.add_shard_range_trigger( global_group_id, sharding_type, table_name, column_name )
def _lookup(lookup_arg, key, hint): """Given a table name and a key return the servers of the Group where the shard of this table can be found :param lookup_arg: table name for "LOCAL" lookups Shard Mapping ID for "GLOBAL" lookups. :param key: The key value that needs to be looked up :param hint: A hint indicates if the query is LOCAL or GLOBAL :return: The servers of the Group that contains the range in which the key belongs. """ VALID_HINTS = ('LOCAL', 'GLOBAL') hint = hint.upper() if hint not in VALID_HINTS: raise _errors.ShardingError(INVALID_SHARDING_HINT) group = None #Perform the lookup for the group contaning the lookup data. if hint == "GLOBAL": #Fetch the shard mapping object. In the case of GLOBAL lookups #the shard mapping ID is passed directly. In the case of "LOCAL" #lookups it is the table name that is passed. shard_mapping = ShardMapping.fetch_by_id(lookup_arg) if shard_mapping is None: raise _errors.ShardingError( SHARD_MAPPING_NOT_FOUND % (lookup_arg, ) ) #GLOBAL lookups. There can be only one global group, hence using #shard_mapping[0] is safe. group = Group.fetch(shard_mapping[0].global_group) else: shard_mapping = ShardMapping.fetch(lookup_arg) if shard_mapping is None: raise _errors.ShardingError(TABLE_NAME_NOT_FOUND % (lookup_arg, )) sharding_specification =\ SHARDING_SPECIFICATION_HANDLER[shard_mapping.type_name].\ lookup(key, shard_mapping.shard_mapping_id, shard_mapping.type_name) if sharding_specification is None: raise _errors.ShardingError(INVALID_SHARDING_KEY % (key, )) shard = Shards.fetch(str(sharding_specification.shard_id)) if shard.state == "DISABLED": raise _errors.ShardingError(SHARD_NOT_ENABLED) #group cannot be None since there is a foreign key on the group_id. #An exception will be thrown nevertheless. group = Group.fetch(shard.group_id) if group is None: raise _errors.ShardingError(SHARD_LOCATION_NOT_FOUND) ret = [] #An empty list will be returned if the registered group has not #servers. for server in group.servers(): ret.append([str(server.uuid), server.address, group.master == server.uuid]) return ret
def verify_and_fetch_shard(shard_id): """Find out if the shard_id exists and return the sharding specification for it. If it does not exist throw an exception. :param shard_id: The ID for the shard whose specification needs to be fetched. :return: The sharding specification class representing the shard ID. :raises: ShardingError if the shard ID is not found. """ #Here the underlying sharding specification might be a RANGE #or a HASH. The type of sharding specification is obtained from the #shard mapping. range_sharding_spec = RangeShardingSpecification.fetch(shard_id) if range_sharding_spec is None: raise _errors.ShardingError(SHARD_NOT_FOUND % (shard_id, )) #Fetch the shard mappings and use them to find the type of sharding #scheme. shard_mappings = ShardMapping.fetch_by_id( range_sharding_spec.shard_mapping_id ) if shard_mappings is None: raise _errors.ShardingError( SHARD_MAPPING_NOT_FOUND % ( range_sharding_spec.shard_mapping_id, ) ) #Fetch the shard mapping definition. There is only one shard mapping #definition associated with all of the shard mappings. shard_mapping_defn = ShardMapping.fetch_shard_mapping_defn( range_sharding_spec.shard_mapping_id ) if shard_mapping_defn is None: raise _errors.ShardingError( SHARD_MAPPING_DEFN_NOT_FOUND % ( range_sharding_spec.shard_mapping_id, ) ) shard = Shards.fetch(shard_id) if shard is None: raise _errors.ShardingError(SHARD_NOT_FOUND % (shard_id, )) #Both of the shard_mappings retrieved will be of the same sharding #type. Hence it is safe to use one of them to retireve the sharding type. if shard_mappings[0].type_name == "HASH": return HashShardingSpecification.fetch(shard_id), \ shard, shard_mappings, shard_mapping_defn else: return range_sharding_spec, shard, shard_mappings, shard_mapping_defn
def test_fetch_shard_mapping(self): shard_mapping_1 = ShardMapping.fetch("db1.t1") shard_mapping_2 = ShardMapping.fetch("db2.t2") shard_mapping_3 = ShardMapping.fetch("db3.t3") shard_mapping_4 = ShardMapping.fetch("db4.t4") self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_1, shard_mapping_1)) self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_2, shard_mapping_2)) self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_3, shard_mapping_3)) self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_4, shard_mapping_4))
def _add_shard_mapping(shard_mapping_id, table_name, column_name): """Add a table to a shard mapping. :param shard_mapping_id: The shard mapping id to which the input table is attached. :param table_name: The table being sharded. :param column_name: The column whose value is used in the sharding scheme being applied :return: True if the the table was successfully added. False otherwise. """ ShardMapping.add(shard_mapping_id, table_name, column_name)
def _lookup(lookup_arg, key, hint): """Given a table name and a key return the servers of the Group where the shard of this table can be found :param lookup_arg: table name for "LOCAL" lookups Shard Mapping ID for "GLOBAL" lookups. :param key: The key value that needs to be looked up :param hint: A hint indicates if the query is LOCAL or GLOBAL :return: The servers of the Group that contains the range in which the key belongs. """ VALID_HINTS = ('LOCAL', 'GLOBAL') hint = hint.upper() if hint not in VALID_HINTS: raise _errors.ShardingError(INVALID_SHARDING_HINT) group = None #Perform the lookup for the group contaning the lookup data. if hint == "GLOBAL": #Fetch the shard mapping object. In the case of GLOBAL lookups #the shard mapping ID is passed directly. In the case of "LOCAL" #lookups it is the table name that is passed. shard_mapping = ShardMapping.fetch_by_id(lookup_arg) if shard_mapping is None: raise _errors.ShardingError(SHARD_MAPPING_NOT_FOUND % (lookup_arg, )) #GLOBAL lookups. There can be only one global group, hence using #shard_mapping[0] is safe. group_id = shard_mapping[0].global_group else: shard_mapping = ShardMapping.fetch(lookup_arg) if shard_mapping is None: raise _errors.ShardingError(TABLE_NAME_NOT_FOUND % (lookup_arg, )) sharding_specification = \ SHARDING_SPECIFICATION_HANDLER[shard_mapping.type_name].\ lookup(key, shard_mapping.shard_mapping_id, shard_mapping.type_name) if sharding_specification is None: raise _errors.ShardingError(INVALID_SHARDING_KEY % (key, )) shard = Shards.fetch(str(sharding_specification.shard_id)) if shard.state == "DISABLED": raise _errors.ShardingError(SHARD_NOT_ENABLED) #group cannot be None since there is a foreign key on the group_id. #An exception will be thrown nevertheless. group_id = shard.group_id return ServerLookups().execute(group_id=group_id)
def _lookup_shard_mapping(table_name): """Fetch the shard specification mapping for the given table :param table_name: The name of the table for which the sharding specification is being queried. :return: A dictionary that contains the shard mapping information for the given table. """ shard_mapping = ShardMapping.fetch(table_name) if shard_mapping is not None: return [{ "mapping_id": shard_mapping.shard_mapping_id, "table_name": shard_mapping.table_name, "column_name": shard_mapping.column_name, "type_name": shard_mapping.type_name, "global_group": shard_mapping.global_group }] else: #We return an empty shard mapping because if an Error is thrown #it would cause the executor to rollback which is an unnecessary #action. It is enough if we inform the user that the lookup returned #nothing. return [{ "mapping_id": "", "table_name": "", "column_name": "", "type_name": "", "global_group": "" }]
def _prune_shard_tables(table_name, prune_limit): """Delete the data from the copied data directories based on the sharding configuration uploaded in the sharding tables of the state store. The basic logic consists of a) Querying the sharding scheme name corresponding to the sharding table b) Querying the sharding key range using the sharding scheme name. c) Deleting the sharding keys that fall outside the range for a given server. :param table_name: The table_name who's shards need to be pruned. :param prune_limit: The number of DELETEs that should be done in one batch. """ shard_mapping = ShardMapping.fetch(table_name) try: SHARDING_SPECIFICATION_HANDLER[shard_mapping.type_name].\ delete_from_shard_db(table_name, shard_mapping.type_name, prune_limit) except _errors.DatabaseError as error: if error.errno == ER_NO_SUCH_TABLE: #Error happens because the actual tables are not present in the #server. We will ignore this. pass else: raise error
def _list(sharding_type): """The method returns all the shard mappings (names) of a particular sharding_type. For example if the method is called with 'range' it returns all the sharding specifications that exist of type range. :param sharding_type: The sharding type for which the sharding specification needs to be returned. :return: A list of dictionaries of shard mappings that are of the sharding type An empty list of the sharding type is valid but no shard mapping definition is found An error if the sharding type is invalid. :raises: Sharding Error if Sharding type is not found. """ if sharding_type not in Shards.VALID_SHARDING_TYPES: raise _errors.ShardingError(INVALID_SHARDING_TYPE % (sharding_type, )) ret_shard_mappings = [] shard_mappings = ShardMapping.list(sharding_type) for shard_mapping in shard_mappings: ret_shard_mappings.append({ "mapping_id": shard_mapping.shard_mapping_id, "table_name": shard_mapping.table_name, "column_name": shard_mapping.column_name, "type_name": shard_mapping.type_name, "global_group": shard_mapping.global_group }) return ret_shard_mappings
def _list(sharding_type): """The method returns all the shard mappings (names) of a particular sharding_type. For example if the method is called with 'range' it returns all the sharding specifications that exist of type range. :param sharding_type: The sharding type for which the sharding specification needs to be returned. :return: A list of dictionaries of shard mappings that are of the sharding type An empty list of the sharding type is valid but no shard mapping definition is found An error if the sharding type is invalid. :raises: Sharding Error if Sharding type is not found. """ if sharding_type not in Shards.VALID_SHARDING_TYPES: raise _errors.ShardingError(INVALID_SHARDING_TYPE % (sharding_type,)) ret_shard_mappings = [] shard_mappings = ShardMapping.list(sharding_type) for shard_mapping in shard_mappings: ret_shard_mappings.append({ "mapping_id":shard_mapping.shard_mapping_id, "table_name":shard_mapping.table_name, "column_name":shard_mapping.column_name, "type_name":shard_mapping.type_name, "global_group":shard_mapping.global_group}) return ret_shard_mappings
def test_list_shard_mapping(self): """Test the listing of HASH shards in a shard mapping. """ expected_shard_mapping_list1 = [1, "HASH", "GROUPID1"] obtained_shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEqual(set(expected_shard_mapping_list1), set(obtained_shard_mapping_list[0]))
def test_shard_mapping_list_mappings(self): """Test the listing of all HASH shards in a shard mapping. """ shard_mappings = ShardMapping.list("HASH") self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_1, shard_mappings[0]))
def test_list_shard_mapping(self): expected_shard_mapping_list1 = [1, "RANGE", "GROUPID10"] expected_shard_mapping_list2 = [2, "RANGE", "GROUPID11"] expected_shard_mapping_list3 = [3, "RANGE", "GROUPID12"] expected_shard_mapping_list4 = [4, "RANGE", "GROUPID13"] expected_shard_mapping_list5 = [5, "RANGE", "GROUPID14"] obtained_shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEqual( set(expected_shard_mapping_list1), set(obtained_shard_mapping_list[0]) ) self.assertEqual( set(expected_shard_mapping_list2), set(obtained_shard_mapping_list[1]) ) self.assertEqual( set(expected_shard_mapping_list3), set(obtained_shard_mapping_list[2]) ) self.assertEqual( set(expected_shard_mapping_list4), set(obtained_shard_mapping_list[3]) ) self.assertEqual( set(expected_shard_mapping_list5), set(obtained_shard_mapping_list[4]) )
def _lookup_shard_mapping(table_name): """Fetch the shard specification mapping for the given table :param table_name: The name of the table for which the sharding specification is being queried. :return: A dictionary that contains the shard mapping information for the given table. """ shard_mapping = ShardMapping.fetch(table_name) if shard_mapping is not None: return [{"mapping_id":shard_mapping.shard_mapping_id, "table_name":shard_mapping.table_name, "column_name":shard_mapping.column_name, "type_name":shard_mapping.type_name, "global_group":shard_mapping.global_group}] else: #We return an empty shard mapping because if an Error is thrown #it would cause the executor to rollback which is an unnecessary #action. It is enough if we inform the user that the lookup returned #nothing. return [{"mapping_id":"", "table_name":"", "column_name":"", "type_name":"", "global_group":""}]
def test_fetch_shard_mapping(self): shard_mapping_1 = ShardMapping.fetch("db1.t1") shard_mapping_2 = ShardMapping.fetch("db2.t2") shard_mapping_3 = ShardMapping.fetch("db3.t3") shard_mapping_4 = ShardMapping.fetch("db4.t4") self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_1, shard_mapping_1)) self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_2, shard_mapping_2)) self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_3, shard_mapping_3)) self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_4, shard_mapping_4))
def execute(self, connector_version=None, patterns=""): """Return information about all shard mappings matching any of the provided patterns. :param connector_version: The connectors version of the data. :param patterns: shard mapping pattern. """ return ShardMapping.dump_shard_maps(connector_version, patterns)
def verify_and_fetch_shard(shard_id): """Find out if the shard_id exists and return the sharding specification for it. If it does not exist throw an exception. :param shard_id: The ID for the shard whose specification needs to be fetched. :return: The sharding specification class representing the shard ID. :raises: ShardingError if the shard ID is not found. """ #Here the underlying sharding specification might be a RANGE #or a HASH. The type of sharding specification is obtained from the #shard mapping. range_sharding_spec = RangeShardingSpecification.fetch(shard_id) if range_sharding_spec is None: raise _errors.ShardingError(SHARD_NOT_FOUND % (shard_id, )) #Fetch the shard mappings and use them to find the type of sharding #scheme. shard_mappings = ShardMapping.fetch_by_id( range_sharding_spec.shard_mapping_id) if shard_mappings is None: raise _errors.ShardingError(SHARD_MAPPING_NOT_FOUND % (range_sharding_spec.shard_mapping_id, )) #Fetch the shard mapping definition. There is only one shard mapping #definition associated with all of the shard mappings. shard_mapping_defn = ShardMapping.fetch_shard_mapping_defn( range_sharding_spec.shard_mapping_id) if shard_mapping_defn is None: raise _errors.ShardingError(SHARD_MAPPING_DEFN_NOT_FOUND % (range_sharding_spec.shard_mapping_id, )) shard = Shards.fetch(shard_id) if shard is None: raise _errors.ShardingError(SHARD_NOT_FOUND % (shard_id, )) #Both of the shard_mappings retrieved will be of the same sharding #type. Hence it is safe to use one of them to retireve the sharding type. if shard_mappings[0].type_name == "HASH": return HashShardingSpecification.fetch(shard_id), \ shard, shard_mappings, shard_mapping_defn else: return range_sharding_spec, shard, shard_mappings, shard_mapping_defn
def execute(self, connector_version=None, patterns=""): """Return all the sharding information about the tables passed as patterns. If no patterns are provided, dump sharding information about all tables. :param connector_version: The connectors version of the data. :param patterns: shard table pattern. """ return ShardMapping.dump_sharding_info(connector_version, patterns)
def test_shard_mapping_list_mappings(self): shard_mappings = ShardMapping.list("RANGE") self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_1, shard_mappings[0])) self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_2, shard_mappings[1])) self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_3, shard_mappings[2])) self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_4, shard_mappings[3]))
def execute(self): """The method returns all the shard mapping definitions. :return: A list of shard mapping definitions An Empty List if no shard mapping definition is found. """ rset = ResultSet( names=('mapping_id', 'type_name', 'global_group_id'), types=(int, str, str), ) for row in ShardMapping.list_shard_mapping_defn(): rset.append_row(row) return CommandResult(None, results=rset)
def _remove_shard_mapping(table_name): """Remove the shard mapping for the given table. :param table_name: The name of the table for which the shard mapping needs to be removed. :return: True if the remove succeeded False if the query failed :raises: ShardingError if the table name is not found. """ shard_mapping = ShardMapping.fetch(table_name) if shard_mapping is None: raise _errors.ShardingError(TABLE_NAME_NOT_FOUND % (table_name, )) shard_mapping.remove()
def test_shard_mapping_list_mappings(self): shard_mappings = ShardMapping.list("RANGE") self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_1, shard_mappings[0])) self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_2, shard_mappings[1])) self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_3, shard_mappings[2])) self.assertTrue( ShardingUtils.compare_shard_mapping(self.__shard_mapping_4, shard_mappings[3]))
def _prune_shard_tables(table_name): """Delete the data from the copied data directories based on the sharding configuration uploaded in the sharding tables of the state store. The basic logic consists of a) Querying the sharding scheme name corresponding to the sharding table b) Querying the sharding key range using the sharding scheme name. c) Deleting the sharding keys that fall outside the range for a given server. :param table_name: The table_name who's shards need to be pruned. """ shard_mapping = ShardMapping.fetch(table_name) SHARDING_SPECIFICATION_HANDLER[shard_mapping.type_name].\ delete_from_shard_db(table_name, shard_mapping.type_name)
def _define_shard_mapping(type_name, global_group_id): """Define a shard mapping. :param type_name: The type of sharding scheme - RANGE, HASH, LIST etc :param global_group: Every shard mapping is associated with a Global Group that stores the global updates and the schema changes for this shard mapping and dissipates these to the shards. :return: The shard_mapping_id generated for the shard mapping. :raises: ShardingError if the sharding type is invalid. """ type_name = type_name.upper() if type_name not in Shards.VALID_SHARDING_TYPES: raise _errors.ShardingError(INVALID_SHARDING_TYPE % (type_name, )) shard_mapping_id = ShardMapping.define(type_name, global_group_id) return shard_mapping_id
def execute(self, connector_version=None, patterns=""): """Return information about all shard mappings matching any of the provided patterns. :param connector_version: The connectors version of the data. :param patterns: shard mapping pattern. """ rset = ResultSet( names=('mapping_id', 'type_name', 'global_group_id'), types=(int, str, str), ) for row in ShardMapping.dump_shard_maps(connector_version, patterns): rset.append_row(row) return CommandResult(None, results=rset)
def execute(self, connector_version=None, patterns=""): """Return information about all tables belonging to mappings matching any of the provided patterns. :param connector_version: The connectors version of the data. :param patterns: shard mapping pattern. """ rset = ResultSet( names=('schema_name', 'table_name', 'column_name', 'mapping_id'), types=(str, str, str, int), ) for row in ShardMapping.dump_shard_tables(connector_version, patterns): rset.append_row(row) return CommandResult(None, results=rset)
def test_list_shard_mapping(self): expected_shard_mapping_list1 = [1, "RANGE", "GROUPID10"] expected_shard_mapping_list2 = [2, "RANGE", "GROUPID11"] expected_shard_mapping_list3 = [3, "RANGE", "GROUPID12"] expected_shard_mapping_list4 = [4, "RANGE", "GROUPID13"] expected_shard_mapping_list5 = [5, "RANGE", "GROUPID14"] obtained_shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEqual(set(expected_shard_mapping_list1), set(obtained_shard_mapping_list[0])) self.assertEqual(set(expected_shard_mapping_list2), set(obtained_shard_mapping_list[1])) self.assertEqual(set(expected_shard_mapping_list3), set(obtained_shard_mapping_list[2])) self.assertEqual(set(expected_shard_mapping_list4), set(obtained_shard_mapping_list[3])) self.assertEqual(set(expected_shard_mapping_list5), set(obtained_shard_mapping_list[4]))
def execute(self, connector_version=None, patterns=""): """Return information about all tables belonging to mappings matching any of the provided patterns. :param connector_version: The connectors version of the data. :param patterns: shard mapping pattern. """ rset = ResultSet( names=('schema_name', 'table_name', 'column_name', 'mapping_id', 'range_check'), types=(str, str, str, int, int), ) for row in ShardMapping.dump_shard_tables(connector_version, patterns): rset.append_row(row) return CommandResult(None, results=rset)
def execute(self, connector_version=None, patterns=""): """Return all the sharding information about the tables passed as patterns. If no patterns are provided, dump sharding information about all tables. :param connector_version: The connectors version of the data. :param patterns: shard table pattern. """ rset = ResultSet( names=('schema_name', 'table_name', 'column_name', 'lower_bound', 'shard_id', 'type_name', 'group_id', 'global_group'), types=(str, str, str, str, int, str, str, str), ) for row in ShardMapping.dump_sharding_info(connector_version, patterns): rset.append_row(row) return CommandResult(None, results=rset)
def test_shard_mapping_remove(self): self.__range_sharding_specification_1.remove() self.__range_sharding_specification_2.remove() self.__range_sharding_specification_3.remove() self.__range_sharding_specification_4.remove() self.__range_sharding_specification_5.remove() self.__range_sharding_specification_6.remove() self.__range_sharding_specification_7.remove() self.__range_sharding_specification_8.remove() self.__range_sharding_specification_9.remove() self.__range_sharding_specification_10.remove() self.__shard_id_1.remove() self.__shard_id_2.remove() self.__shard_id_3.remove() self.__shard_id_4.remove() self.__shard_id_5.remove() self.__shard_id_6.remove() self.__shard_id_7.remove() self.__shard_id_8.remove() self.__shard_id_9.remove() self.__shard_id_10.remove() shard_mapping_1 = ShardMapping.fetch("db1.t1") shard_mapping_1.remove()
def setUp(self): self.manager, self.proxy = tests.utils.setup_xmlrpc() self.__options_1 = { "uuid": _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(0), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"]) self.__options_1["uuid"] = _uuid.UUID(uuid_server1) self.__server_1 = MySQLServer(**self.__options_1) MySQLServer.add(self.__server_1) self.__group_1 = Group("GROUPID1", "First description.") Group.add(self.__group_1) self.__group_1.add_server(self.__server_1) tests.utils.configure_decoupled_master(self.__group_1, self.__server_1) self.__options_2 = { "uuid": _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(1), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"]) self.__options_2["uuid"] = _uuid.UUID(uuid_server2) self.__server_2 = MySQLServer(**self.__options_2) MySQLServer.add(self.__server_2) self.__server_2.connect() self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_2.exec_stmt("CREATE DATABASE db1") self.__server_2.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_2.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_2 = Group("GROUPID2", "Second description.") Group.add(self.__group_2) self.__group_2.add_server(self.__server_2) tests.utils.configure_decoupled_master(self.__group_2, self.__server_2) self.__options_3 = { "uuid": _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(2), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"]) self.__options_3["uuid"] = _uuid.UUID(uuid_server3) self.__server_3 = MySQLServer(**self.__options_3) MySQLServer.add(self.__server_3) self.__server_3.connect() self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_3.exec_stmt("CREATE DATABASE db1") self.__server_3.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_3.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_3 = Group("GROUPID3", "Third description.") Group.add(self.__group_3) self.__group_3.add_server(self.__server_3) tests.utils.configure_decoupled_master(self.__group_3, self.__server_3) self.__options_4 = { "uuid": _uuid.UUID("{bb45b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(3), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server4 = MySQLServer.discover_uuid(self.__options_4["address"]) self.__options_4["uuid"] = _uuid.UUID(uuid_server4) self.__server_4 = MySQLServer(**self.__options_4) MySQLServer.add(self.__server_4) self.__server_4.connect() self.__server_4.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_4.exec_stmt("CREATE DATABASE db1") self.__server_4.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_4.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_4 = Group("GROUPID4", "Fourth description.") Group.add(self.__group_4) self.__group_4.add_server(self.__server_4) tests.utils.configure_decoupled_master(self.__group_4, self.__server_4) self.__options_5 = { "uuid": _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(4), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"]) self.__options_5["uuid"] = _uuid.UUID(uuid_server5) self.__server_5 = MySQLServer(**self.__options_5) MySQLServer.add(self.__server_5) self.__server_5.connect() self.__server_5.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_5.exec_stmt("CREATE DATABASE db1") self.__server_5.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_5.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_5 = Group("GROUPID5", "Fifth description.") Group.add(self.__group_5) self.__group_5.add_server(self.__server_5) tests.utils.configure_decoupled_master(self.__group_5, self.__server_5) self.__options_6 = { "uuid": _uuid.UUID("{cc45b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(5), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server6 = MySQLServer.discover_uuid(self.__options_6["address"]) self.__options_6["uuid"] = _uuid.UUID(uuid_server6) self.__server_6 = MySQLServer(**self.__options_6) MySQLServer.add(self.__server_6) self.__server_6.connect() self.__server_6.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_6.exec_stmt("CREATE DATABASE db1") self.__server_6.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_6.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_6 = Group("GROUPID6", "Sixth description.") Group.add(self.__group_6) self.__group_6.add_server(self.__server_6) tests.utils.configure_decoupled_master(self.__group_6, self.__server_6) self.__shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEquals(self.__shard_mapping_list, []) self.__shard_mapping_id_1 = ShardMapping.define("HASH", "GROUPID1") self.__shard_mapping_1 = ShardMapping.add(self.__shard_mapping_id_1, "db1.t1", "userID") self.__shard_1 = Shards.add("GROUPID2") self.__shard_2 = Shards.add("GROUPID3") self.__shard_3 = Shards.add("GROUPID4") self.__shard_4 = Shards.add("GROUPID5") self.__shard_5 = Shards.add("GROUPID6") self.__hash_sharding_specification_1 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_1.shard_id) self.__hash_sharding_specification_2 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_2.shard_id) self.__hash_sharding_specification_3 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_3.shard_id) self.__hash_sharding_specification_4 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_4.shard_id) self.__hash_sharding_specification_5 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_5.shard_id)
def setUp(self): """Configure the existing environment """ self.__options_1 = { "uuid": _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"), "address": "server_1.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_1 = MySQLServer(**self.__options_1) MySQLServer.add(self.__server_1) self.__options_2 = { "uuid": _uuid.UUID("{aa75a12a-98d1-414c-96af-9e9d4b179678}"), "address": "server_2.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_2 = MySQLServer(**self.__options_2) MySQLServer.add(self.__server_2) self.__group_1 = Group("GROUPID1", "First description.") Group.add(self.__group_1) self.__group_1.add_server(self.__server_1) self.__group_1.add_server(self.__server_2) self.__options_3 = { "uuid": _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(0), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"]) self.__options_3["uuid"] = _uuid.UUID(uuid_server3) self.__server_3 = MySQLServer(**self.__options_3) MySQLServer.add(self.__server_3) self.__server_3.connect() self.__server_3.exec_stmt("DROP DATABASE IF EXISTS prune_db") self.__server_3.exec_stmt("CREATE DATABASE prune_db") self.__server_3.exec_stmt("CREATE TABLE prune_db.prune_table" "(userID INT, name VARCHAR(30))") self.__server_3.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(101, 'TEST 1')") self.__server_3.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(202, 'TEST 2')") self.__options_4 = { "uuid": _uuid.UUID("{dd75a12a-98d1-414c-96af-9e9d4b179678}"), "address": "server_4.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_4 = MySQLServer(**self.__options_4) MySQLServer.add(self.__server_4) self.__group_2 = Group("GROUPID2", "Second description.") Group.add(self.__group_2) self.__group_2.add_server(self.__server_3) self.__group_2.add_server(self.__server_4) tests.utils.configure_decoupled_master(self.__group_2, self.__server_3) self.__options_5 = { "uuid": _uuid.UUID("{ee75b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(2), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"]) self.__options_5["uuid"] = _uuid.UUID(uuid_server5) self.__server_5 = MySQLServer(**self.__options_5) MySQLServer.add(self.__server_5) self.__server_5.connect() self.__server_5.exec_stmt("DROP DATABASE IF EXISTS prune_db") self.__server_5.exec_stmt("CREATE DATABASE prune_db") self.__server_5.exec_stmt("CREATE TABLE prune_db.prune_table" "(userID INT, name VARCHAR(30))") self.__server_5.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(101, 'TEST 1')") self.__server_5.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(202, 'TEST 2')") self.__options_6 = { "uuid": _uuid.UUID("{ff75a12a-98d1-414c-96af-9e9d4b179678}"), "address": "server_6.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_6 = MySQLServer(**self.__options_6) MySQLServer.add(self.__server_6) self.__group_3 = Group("GROUPID3", "Third description.") Group.add(self.__group_3) self.__group_3.add_server(self.__server_5) self.__group_3.add_server(self.__server_6) tests.utils.configure_decoupled_master(self.__group_3, self.__server_5) group_4 = Group("GROUPID4", "4TH description.") Group.add(group_4) group_5 = Group("GROUPID5", "5TH description.") Group.add(group_5) group_6 = Group("GROUPID6", "6TH description.") Group.add(group_6) group_7 = Group("GROUPID7", "7TH description.") Group.add(group_7) group_8 = Group("GROUPID8", "8TH description.") Group.add(group_8) group_9 = Group("GROUPID9", "9TH description.") Group.add(group_9) group_10 = Group("GROUPID10", "10TH description.") Group.add(group_10) group_11 = Group("GROUPID11", "11TH description.") Group.add(group_11) group_12 = Group("GROUPID12", "12TH description.") Group.add(group_12) group_13 = Group("GROUPID13", "13TH description.") Group.add(group_13) group_14 = Group("GROUPID14", "14TH description.") Group.add(group_14) self.__shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEquals(self.__shard_mapping_list, []) self.__shard_mapping_id_1 = ShardMapping.define("RANGE", "GROUPID10") self.__shard_mapping_id_2 = ShardMapping.define("RANGE", "GROUPID11") self.__shard_mapping_id_3 = ShardMapping.define("RANGE", "GROUPID12") #Test with sharding type values in lower case self.__shard_mapping_id_4 = ShardMapping.define("range", "GROUPID13") self.__shard_mapping_id_5 = ShardMapping.define("range", "GROUPID14") self.__shard_mapping_1 = \ ShardMapping.add(self.__shard_mapping_id_1, "db1.t1", "userID1") self.__shard_mapping_2 = \ ShardMapping.add(self.__shard_mapping_id_2, "db2.t2", "userID2") self.__shard_mapping_3 = \ ShardMapping.add(self.__shard_mapping_id_3, "db3.t3", "userID3") self.__shard_mapping_4 = \ ShardMapping.add(self.__shard_mapping_id_4, "db4.t4", "userID4") self.__shard_mapping_5 = \ ShardMapping.add(self.__shard_mapping_id_5, "prune_db.prune_table", "userID") self.__shard_id_1 = Shards.add("GROUPID1") self.__shard_id_2 = Shards.add("GROUPID10") self.__shard_id_3 = Shards.add("GROUPID11") self.__shard_id_4 = Shards.add("GROUPID4") self.__shard_id_5 = Shards.add("GROUPID5") self.__shard_id_6 = Shards.add("GROUPID6") self.__shard_id_7 = Shards.add("GROUPID7") self.__shard_id_8 = Shards.add("GROUPID8") self.__shard_id_9 = Shards.add("GROUPID9") self.__shard_id_10 = Shards.add("GROUPID2") self.__shard_id_11 = Shards.add("GROUPID3") self.__range_sharding_specification_1 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 0, self.__shard_id_1.shard_id) self.__range_sharding_specification_2 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 1001, self.__shard_id_2.shard_id) self.__range_sharding_specification_3 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 2001, self.__shard_id_3.shard_id) self.__range_sharding_specification_4 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 3001, self.__shard_id_4.shard_id) self.__range_sharding_specification_5 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 4001, self.__shard_id_5.shard_id) self.__range_sharding_specification_6 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 6001, self.__shard_id_6.shard_id) self.__range_sharding_specification_7 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 7001, self.__shard_id_7.shard_id) self.__range_sharding_specification_8 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 8001, self.__shard_id_8.shard_id) self.__range_sharding_specification_9 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 10001, self.__shard_id_9.shard_id) self.__range_sharding_specification_10 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 100, self.__shard_id_10.shard_id) self.__range_sharding_specification_11 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 201, self.__shard_id_11.shard_id)
def setUp(self): """Configure the existing environment """ self.manager, self.proxy = tests.utils.setup_xmlrpc() self.__options_1 = { "uuid": _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"), "address": "server_1.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_1 = MySQLServer(**self.__options_1) MySQLServer.add(self.__server_1) self.__options_2 = { "uuid": _uuid.UUID("{aa75a12a-98d1-414c-96af-9e9d4b179678}"), "address": "server_2.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_2 = MySQLServer(**self.__options_2) MySQLServer.add(self.__server_2) self.__group_1 = Group("GROUPID1", "First description.") Group.add(self.__group_1) self.__group_1.add_server(self.__server_1) self.__group_1.add_server(self.__server_2) self.__options_3 = { "uuid": _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(0), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"]) self.__options_3["uuid"] = _uuid.UUID(uuid_server3) self.__server_3 = MySQLServer(**self.__options_3) MySQLServer.add(self.__server_3) self.__options_4 = { "uuid": _uuid.UUID("{dd75a12a-98d1-414c-96af-9e9d4b179678}"), "address": "server_4.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_4 = MySQLServer(**self.__options_4) MySQLServer.add(self.__server_4) self.__group_2 = Group("GROUPID2", "Second description.") Group.add(self.__group_2) self.__group_2.add_server(self.__server_3) self.__group_2.add_server(self.__server_4) tests.utils.configure_decoupled_master(self.__group_2, self.__server_3) self.__options_5 = { "uuid": _uuid.UUID("{ee75b12b-98d1-414c-96af-9e9d4b179678}"), "address": MySQLInstances().get_address(2), "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"]) self.__options_5["uuid"] = _uuid.UUID(uuid_server5) self.__server_5 = MySQLServer(**self.__options_5) MySQLServer.add(self.__server_5) self.__options_6 = { "uuid": _uuid.UUID("{ff75a12a-98d1-414c-96af-9e9d4b179678}"), "address": "server_6.mysql.com:3060", "user": MySQLInstances().user, "passwd": MySQLInstances().passwd, } self.__server_6 = MySQLServer(**self.__options_6) MySQLServer.add(self.__server_6) self.__group_3 = Group("GROUPID3", "Third description.") Group.add(self.__group_3) self.__group_3.add_server(self.__server_5) self.__group_3.add_server(self.__server_6) tests.utils.configure_decoupled_master(self.__group_3, self.__server_5) self.__options_1_host, self.__options_1_port = \ server_utils.split_host_port(self.__options_1["address"], 13001) self.__options_2_host, self.__options_2_port = \ server_utils.split_host_port(self.__options_2["address"], 13001) self.__options_3_host, self.__options_3_port = \ server_utils.split_host_port(self.__options_3["address"], 13001) self.__options_4_host, self.__options_4_port = \ server_utils.split_host_port(self.__options_4["address"], 13001) self.__options_5_host, self.__options_5_port = \ server_utils.split_host_port(self.__options_5["address"], 13001) self.__options_6_host, self.__options_6_port = \ server_utils.split_host_port(self.__options_6["address"], 13001) group_4 = Group("GROUPID4", "4TH description.") Group.add(group_4) group_5 = Group("GROUPID5", "5TH description.") Group.add(group_5) group_6 = Group("GROUPID6", "6TH description.") Group.add(group_6) group_7 = Group("GROUPID7", "7TH description.") Group.add(group_7) group_8 = Group("GROUPID8", "8TH description.") Group.add(group_8) group_9 = Group("GROUPID9", "9TH description.") Group.add(group_9) group_10 = Group("GROUPID10", "10TH description.") Group.add(group_10) group_11 = Group("GROUPID11", "11TH description.") Group.add(group_11) group_12 = Group("GROUPID12", "12TH description.") Group.add(group_12) group_13 = Group("GROUPID13", "13TH description.") Group.add(group_13) group_14 = Group("GROUPID14", "14TH description.") Group.add(group_14) self.__shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEquals(self.__shard_mapping_list, []) self.__shard_mapping_id_1 = ShardMapping.define("RANGE", "GROUPID10") self.__shard_mapping_id_2 = ShardMapping.define("RANGE", "GROUPID11") self.__shard_mapping_id_3 = ShardMapping.define("RANGE", "GROUPID12") #Test with sharding type values in lower case self.__shard_mapping_id_4 = ShardMapping.define("range", "GROUPID13") self.__shard_mapping_id_5 = ShardMapping.define("range", "GROUPID14") self.__shard_mapping_1 = \ ShardMapping.add(self.__shard_mapping_id_1, "db1.t1", "userID1") self.__shard_mapping_2 = \ ShardMapping.add(self.__shard_mapping_id_2, "db2.t2", "userID2") self.__shard_mapping_3 = \ ShardMapping.add(self.__shard_mapping_id_3, "db3.t3", "userID3") self.__shard_mapping_4 = \ ShardMapping.add(self.__shard_mapping_id_4, "db4.t4", "userID4") self.__shard_mapping_5 = \ ShardMapping.add(self.__shard_mapping_id_5, "prune_db.prune_table", "userID") self.__shard_id_1 = Shards.add("GROUPID1", "ENABLED") self.__shard_id_2 = Shards.add("GROUPID10", "ENABLED") self.__shard_id_3 = Shards.add("GROUPID11", "DISABLED") self.__shard_id_4 = Shards.add("GROUPID4", "ENABLED") self.__shard_id_5 = Shards.add("GROUPID5", "ENABLED") self.__shard_id_6 = Shards.add("GROUPID6", "ENABLED") self.__shard_id_7 = Shards.add("GROUPID7", "ENABLED") self.__shard_id_8 = Shards.add("GROUPID8", "ENABLED") self.__shard_id_9 = Shards.add("GROUPID9", "ENABLED") self.__shard_id_10 = Shards.add("GROUPID2", "ENABLED") self.__shard_id_11 = Shards.add("GROUPID3", "ENABLED") self.__range_sharding_specification_1 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 0, self.__shard_id_1.shard_id) self.__range_sharding_specification_2 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 1001, self.__shard_id_2.shard_id) self.__range_sharding_specification_3 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 2001, self.__shard_id_3.shard_id) self.__range_sharding_specification_4 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 3001, self.__shard_id_4.shard_id) self.__range_sharding_specification_5 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 4001, self.__shard_id_5.shard_id) self.__range_sharding_specification_6 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 6001, self.__shard_id_6.shard_id) self.__range_sharding_specification_7 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 7001, self.__shard_id_7.shard_id) self.__range_sharding_specification_8 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 8001, self.__shard_id_8.shard_id) self.__range_sharding_specification_9 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 10001, self.__shard_id_9.shard_id) self.__range_sharding_specification_10 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 100, self.__shard_id_10.shard_id) self.__range_sharding_specification_11 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 201, self.__shard_id_11.shard_id) READ_ONLY = MySQLServer.get_mode_idx(MySQLServer.READ_ONLY) READ_WRITE = MySQLServer.get_mode_idx(MySQLServer.READ_WRITE) SECONDARY = MySQLServer.get_status_idx(MySQLServer.SECONDARY) PRIMARY = MySQLServer.get_status_idx(MySQLServer.PRIMARY) self.__setofservers = tests.utils.make_servers_result( [[ str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_3.uuid), 'GROUPID2', self.__options_3_host, self.__options_3_port, READ_WRITE, PRIMARY, 1.0 ], [ str(self.__server_4.uuid), 'GROUPID2', self.__options_4_host, self.__options_4_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_5.uuid), 'GROUPID3', self.__options_5_host, self.__options_5_port, READ_WRITE, PRIMARY, 1.0 ], [ str(self.__server_6.uuid), 'GROUPID3', self.__options_6_host, self.__options_6_port, READ_ONLY, SECONDARY, 1.0 ]]) self.__setofservers_1 = tests.utils.make_servers_result( [[ str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0 ]]) self.__setofservers_2 = tests.utils.make_servers_result( [[ str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_3.uuid), 'GROUPID2', self.__options_3_host, self.__options_3_port, READ_WRITE, PRIMARY, 1.0 ], [ str(self.__server_4.uuid), 'GROUPID2', self.__options_4_host, self.__options_4_port, READ_ONLY, SECONDARY, 1.0 ]]) self.__setofservers_3 = tests.utils.make_servers_result( [[ str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_3.uuid), 'GROUPID2', self.__options_3_host, self.__options_3_port, READ_WRITE, PRIMARY, 1.0 ], [ str(self.__server_4.uuid), 'GROUPID2', self.__options_4_host, self.__options_4_port, READ_ONLY, SECONDARY, 1.0 ], [ str(self.__server_5.uuid), 'GROUPID3', self.__options_5_host, self.__options_5_port, READ_WRITE, PRIMARY, 1.0 ], [ str(self.__server_6.uuid), 'GROUPID3', self.__options_6_host, self.__options_6_port, READ_ONLY, SECONDARY, 1.0 ]]) self.__setoftables = tests.utils.make_tables_result( [['db1', 't1', 'userID1', '1'], ['db2', 't2', 'userID2', '2'], ['db3', 't3', 'userID3', '3'], ['db4', 't4', 'userID4', '4'], ['prune_db', 'prune_table', 'userID', '5']]) self.__setoftables_1 = tests.utils.make_tables_result( [['db1', 't1', 'userID1', '1']]) self.__setoftables_2 = tests.utils.make_tables_result( [['db1', 't1', 'userID1', '1'], ['db2', 't2', 'userID2', '2']]) self.__setoftables_3 = tests.utils.make_tables_result( [['db1', 't1', 'userID1', '1'], ['db2', 't2', 'userID2', '2'], ['db3', 't3', 'userID3', '3']]) self.__setofshardmaps = tests.utils.make_mapping_result( [['1', 'RANGE', 'GROUPID10'], ['2', 'RANGE', 'GROUPID11'], ['3', 'RANGE', 'GROUPID12'], ['4', 'RANGE', 'GROUPID13'], ['5', 'RANGE', 'GROUPID14']]) self.__setofshardmaps_1 = tests.utils.make_mapping_result( [['1', 'RANGE', 'GROUPID10']]) self.__setofshardmaps_2 = tests.utils.make_mapping_result( [['1', 'RANGE', 'GROUPID10'], ['2', 'RANGE', 'GROUPID11']]) self.__setofshardmaps_3 = tests.utils.make_mapping_result( [['1', 'RANGE', 'GROUPID10'], ['2', 'RANGE', 'GROUPID11'], ['3', 'RANGE', 'GROUPID12']]) self.__setofshardindexes = tests.utils.make_index_result( [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10'], ['3001', '2', '4', 'GROUPID4'], ['4001', '2', '5', 'GROUPID5'], ['6001', '3', '6', 'GROUPID6'], ['7001', '3', '7', 'GROUPID7'], ['8001', '4', '8', 'GROUPID8'], ['10001', '4', '9', 'GROUPID9'], ['100', '5', '10', 'GROUPID2'], ['201', '5', '11', 'GROUPID3']]) self.__setofshardindexes_1 = tests.utils.make_index_result( [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10']]) self.__setofshardindexes_3 = tests.utils.make_index_result( [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10'], ['3001', '2', '4', 'GROUPID4'], ['4001', '2', '5', 'GROUPID5'], ['6001', '3', '6', 'GROUPID6'], ['7001', '3', '7', 'GROUPID7']]) self.__setofshardindexes_5 = tests.utils.make_index_result( [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10'], ['3001', '2', '4', 'GROUPID4'], ['4001', '2', '5', 'GROUPID5'], ['6001', '3', '6', 'GROUPID6'], ['7001', '3', '7', 'GROUPID7'], ['8001', '4', '8', 'GROUPID8'], ['10001', '4', '9', 'GROUPID9'], ['100', '5', '10', 'GROUPID2'], ['201', '5', '11', 'GROUPID3']]) self.__shardinginformation_1 = tests.utils.make_info_result( [[ 'db1', 't1', 'userID1', '0', '1', 'RANGE', 'GROUPID1', 'GROUPID10' ], [ 'db1', 't1', 'userID1', '1001', '2', 'RANGE', 'GROUPID10', 'GROUPID10' ]]) self.__shardinginformation_2 = tests.utils.make_info_result( [[ 'db1', 't1', 'userID1', '0', '1', 'RANGE', 'GROUPID1', 'GROUPID10' ], [ 'db1', 't1', 'userID1', '1001', '2', 'RANGE', 'GROUPID10', 'GROUPID10' ], [ 'db2', 't2', 'userID2', '3001', '4', 'RANGE', 'GROUPID4', 'GROUPID11' ], [ 'db2', 't2', 'userID2', '4001', '5', 'RANGE', 'GROUPID5', 'GROUPID11' ]]) self.__shardinginformation_3 = tests.utils.make_info_result( [[ 'db1', 't1', 'userID1', '0', '1', 'RANGE', 'GROUPID1', 'GROUPID10' ], [ 'db1', 't1', 'userID1', '1001', '2', 'RANGE', 'GROUPID10', 'GROUPID10' ], [ 'db2', 't2', 'userID2', '3001', '4', 'RANGE', 'GROUPID4', 'GROUPID11' ], [ 'db2', 't2', 'userID2', '4001', '5', 'RANGE', 'GROUPID5', 'GROUPID11' ], [ 'db3', 't3', 'userID3', '6001', '6', 'RANGE', 'GROUPID6', 'GROUPID12' ], [ 'db3', 't3', 'userID3', '7001', '7', 'RANGE', 'GROUPID7', 'GROUPID12' ]])
def setUp(self): """Configure the existing environment """ self.__options_1 = { "uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : "server_1.mysql.com:3060", } self.__server_1 = MySQLServer(**self.__options_1) MySQLServer.add(self.__server_1) self.__options_2 = { "uuid" : _uuid.UUID("{aa75a12a-98d1-414c-96af-9e9d4b179678}"), "address" : "server_2.mysql.com:3060", } self.__server_2 = MySQLServer(**self.__options_2) MySQLServer.add(self.__server_2) self.__group_1 = Group("GROUPID1", "First description.") Group.add(self.__group_1) self.__group_1.add_server(self.__server_1) self.__group_1.add_server(self.__server_2) self.__options_3 = { "uuid" : _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(0), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"]) self.__options_3["uuid"] = _uuid.UUID(uuid_server3) self.__server_3 = MySQLServer(**self.__options_3) MySQLServer.add(self.__server_3) self.__server_3.connect() self.__server_3.exec_stmt("DROP DATABASE IF EXISTS prune_db") self.__server_3.exec_stmt("CREATE DATABASE prune_db") self.__server_3.exec_stmt("CREATE TABLE prune_db.prune_table" "(userID INT, name VARCHAR(30))") self.__server_3.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(101, 'TEST 1')") self.__server_3.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(202, 'TEST 2')") self.__options_4 = { "uuid" : _uuid.UUID("{dd75a12a-98d1-414c-96af-9e9d4b179678}"), "address" : "server_4.mysql.com:3060", } self.__server_4 = MySQLServer(**self.__options_4) MySQLServer.add(self.__server_4) self.__group_2 = Group("GROUPID2", "Second description.") Group.add(self.__group_2) self.__group_2.add_server(self.__server_3) self.__group_2.add_server(self.__server_4) tests.utils.configure_decoupled_master(self.__group_2, self.__server_3) self.__options_5 = { "uuid" : _uuid.UUID("{ee75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(2), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"]) self.__options_5["uuid"] = _uuid.UUID(uuid_server5) self.__server_5 = MySQLServer(**self.__options_5) MySQLServer.add(self.__server_5) self.__server_5.connect() self.__server_5.exec_stmt("DROP DATABASE IF EXISTS prune_db") self.__server_5.exec_stmt("CREATE DATABASE prune_db") self.__server_5.exec_stmt("CREATE TABLE prune_db.prune_table" "(userID INT, name VARCHAR(30))") self.__server_5.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(101, 'TEST 1')") self.__server_5.exec_stmt("INSERT INTO prune_db.prune_table " "VALUES(202, 'TEST 2')") self.__options_6 = { "uuid" : _uuid.UUID("{ff75a12a-98d1-414c-96af-9e9d4b179678}"), "address" : "server_6.mysql.com:3060", } self.__server_6 = MySQLServer(**self.__options_6) MySQLServer.add(self.__server_6) self.__group_3 = Group("GROUPID3", "Third description.") Group.add(self.__group_3) self.__group_3.add_server(self.__server_5) self.__group_3.add_server(self.__server_6) tests.utils.configure_decoupled_master(self.__group_3, self.__server_5) group_4 = Group("GROUPID4", "4TH description.") Group.add(group_4) group_5 = Group("GROUPID5", "5TH description.") Group.add(group_5) group_6 = Group("GROUPID6", "6TH description.") Group.add(group_6) group_7 = Group("GROUPID7", "7TH description.") Group.add(group_7) group_8 = Group("GROUPID8", "8TH description.") Group.add(group_8) group_9 = Group("GROUPID9", "9TH description.") Group.add(group_9) group_10 = Group("GROUPID10", "10TH description.") Group.add(group_10) group_11 = Group("GROUPID11", "11TH description.") Group.add(group_11) group_12 = Group("GROUPID12", "12TH description.") Group.add(group_12) group_13 = Group("GROUPID13", "13TH description.") Group.add(group_13) group_14 = Group("GROUPID14", "14TH description.") Group.add(group_14) self.__shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEquals( self.__shard_mapping_list, []) self.__shard_mapping_id_1 = ShardMapping.define("RANGE", "GROUPID10") self.__shard_mapping_id_2 = ShardMapping.define("RANGE", "GROUPID11") self.__shard_mapping_id_3 = ShardMapping.define("RANGE", "GROUPID12") #Test with sharding type values in lower case self.__shard_mapping_id_4 = ShardMapping.define("range", "GROUPID13") self.__shard_mapping_id_5 = ShardMapping.define("range", "GROUPID14") self.__shard_mapping_1 = \ ShardMapping.add(self.__shard_mapping_id_1, "db1.t1", "userID1") self.__shard_mapping_2 = \ ShardMapping.add(self.__shard_mapping_id_2, "db2.t2", "userID2") self.__shard_mapping_3 = \ ShardMapping.add(self.__shard_mapping_id_3, "db3.t3", "userID3") self.__shard_mapping_4 = \ ShardMapping.add(self.__shard_mapping_id_4, "db4.t4", "userID4") self.__shard_mapping_5 = \ ShardMapping.add(self.__shard_mapping_id_5, "prune_db.prune_table", "userID") self.__shard_id_1 = Shards.add("GROUPID1") self.__shard_id_2 = Shards.add("GROUPID10") self.__shard_id_3 = Shards.add("GROUPID11") self.__shard_id_4 = Shards.add("GROUPID4") self.__shard_id_5 = Shards.add("GROUPID5") self.__shard_id_6 = Shards.add("GROUPID6") self.__shard_id_7 = Shards.add("GROUPID7") self.__shard_id_8 = Shards.add("GROUPID8") self.__shard_id_9 = Shards.add("GROUPID9") self.__shard_id_10 = Shards.add("GROUPID2") self.__shard_id_11 = Shards.add("GROUPID3") self.__range_sharding_specification_1 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 0, self.__shard_id_1.shard_id ) self.__range_sharding_specification_2 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 1001, self.__shard_id_2.shard_id ) self.__range_sharding_specification_3 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 2001, self.__shard_id_3.shard_id ) self.__range_sharding_specification_4 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 3001, self.__shard_id_4.shard_id ) self.__range_sharding_specification_5 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 4001, self.__shard_id_5.shard_id ) self.__range_sharding_specification_6 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 6001, self.__shard_id_6.shard_id ) self.__range_sharding_specification_7 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 7001, self.__shard_id_7.shard_id ) self.__range_sharding_specification_8 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 8001, self.__shard_id_8.shard_id ) self.__range_sharding_specification_9 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 10001, self.__shard_id_9.shard_id ) self.__range_sharding_specification_10 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 100, self.__shard_id_10.shard_id) self.__range_sharding_specification_11 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 201, self.__shard_id_11.shard_id)
def setUp(self): """Configure the existing environment """ self.manager, self.proxy = tests.utils.setup_xmlrpc() self.__options_1 = { "uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : "server_1.mysql.com:3060", } self.__server_1 = MySQLServer(**self.__options_1) MySQLServer.add(self.__server_1) self.__options_2 = { "uuid" : _uuid.UUID("{aa75a12a-98d1-414c-96af-9e9d4b179678}"), "address" : "server_2.mysql.com:3060", } self.__server_2 = MySQLServer(**self.__options_2) MySQLServer.add(self.__server_2) self.__group_1 = Group("GROUPID1", "First description.") Group.add(self.__group_1) self.__group_1.add_server(self.__server_1) self.__group_1.add_server(self.__server_2) self.__options_3 = { "uuid" : _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(0), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"]) self.__options_3["uuid"] = _uuid.UUID(uuid_server3) self.__server_3 = MySQLServer(**self.__options_3) MySQLServer.add(self.__server_3) self.__options_4 = { "uuid" : _uuid.UUID("{dd75a12a-98d1-414c-96af-9e9d4b179678}"), "address" : "server_4.mysql.com:3060", } self.__server_4 = MySQLServer(**self.__options_4) MySQLServer.add(self.__server_4) self.__group_2 = Group("GROUPID2", "Second description.") Group.add(self.__group_2) self.__group_2.add_server(self.__server_3) self.__group_2.add_server(self.__server_4) tests.utils.configure_decoupled_master(self.__group_2, self.__server_3) self.__options_5 = { "uuid" : _uuid.UUID("{ee75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(2), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"]) self.__options_5["uuid"] = _uuid.UUID(uuid_server5) self.__server_5 = MySQLServer(**self.__options_5) MySQLServer.add(self.__server_5) self.__options_6 = { "uuid" : _uuid.UUID("{ff75a12a-98d1-414c-96af-9e9d4b179678}"), "address" : "server_6.mysql.com:3060", } self.__server_6 = MySQLServer(**self.__options_6) MySQLServer.add(self.__server_6) self.__group_3 = Group("GROUPID3", "Third description.") Group.add(self.__group_3) self.__group_3.add_server(self.__server_5) self.__group_3.add_server(self.__server_6) tests.utils.configure_decoupled_master(self.__group_3, self.__server_5) self.__options_1_host, self.__options_1_port = \ server_utils.split_host_port(self.__options_1["address"], 13001) self.__options_2_host, self.__options_2_port = \ server_utils.split_host_port(self.__options_2["address"], 13001) self.__options_3_host, self.__options_3_port = \ server_utils.split_host_port(self.__options_3["address"], 13001) self.__options_4_host, self.__options_4_port = \ server_utils.split_host_port(self.__options_4["address"], 13001) self.__options_5_host, self.__options_5_port = \ server_utils.split_host_port(self.__options_5["address"], 13001) self.__options_6_host, self.__options_6_port = \ server_utils.split_host_port(self.__options_6["address"], 13001) group_4 = Group("GROUPID4", "4TH description.") Group.add(group_4) group_5 = Group("GROUPID5", "5TH description.") Group.add(group_5) group_6 = Group("GROUPID6", "6TH description.") Group.add(group_6) group_7 = Group("GROUPID7", "7TH description.") Group.add(group_7) group_8 = Group("GROUPID8", "8TH description.") Group.add(group_8) group_9 = Group("GROUPID9", "9TH description.") Group.add(group_9) group_10 = Group("GROUPID10", "10TH description.") Group.add(group_10) group_11 = Group("GROUPID11", "11TH description.") Group.add(group_11) group_12 = Group("GROUPID12", "12TH description.") Group.add(group_12) group_13 = Group("GROUPID13", "13TH description.") Group.add(group_13) group_14 = Group("GROUPID14", "14TH description.") Group.add(group_14) self.__shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEquals( self.__shard_mapping_list, []) self.__shard_mapping_id_1 = ShardMapping.define("RANGE", "GROUPID10") self.__shard_mapping_id_2 = ShardMapping.define("RANGE", "GROUPID11") self.__shard_mapping_id_3 = ShardMapping.define("RANGE", "GROUPID12") #Test with sharding type values in lower case self.__shard_mapping_id_4 = ShardMapping.define("range", "GROUPID13") self.__shard_mapping_id_5 = ShardMapping.define("range", "GROUPID14") self.__shard_mapping_1 = \ ShardMapping.add(self.__shard_mapping_id_1, "db1.t1", "userID1") self.__shard_mapping_2 = \ ShardMapping.add(self.__shard_mapping_id_2, "db2.t2", "userID2") self.__shard_mapping_3 = \ ShardMapping.add(self.__shard_mapping_id_3, "db3.t3", "userID3") self.__shard_mapping_4 = \ ShardMapping.add(self.__shard_mapping_id_4, "db4.t4", "userID4") self.__shard_mapping_5 = \ ShardMapping.add(self.__shard_mapping_id_5, "prune_db.prune_table", "userID") self.__shard_id_1 = Shards.add("GROUPID1", "ENABLED") self.__shard_id_2 = Shards.add("GROUPID10", "ENABLED") self.__shard_id_3 = Shards.add("GROUPID11", "DISABLED") self.__shard_id_4 = Shards.add("GROUPID4", "ENABLED") self.__shard_id_5 = Shards.add("GROUPID5", "ENABLED") self.__shard_id_6 = Shards.add("GROUPID6", "ENABLED") self.__shard_id_7 = Shards.add("GROUPID7", "ENABLED") self.__shard_id_8 = Shards.add("GROUPID8", "ENABLED") self.__shard_id_9 = Shards.add("GROUPID9", "ENABLED") self.__shard_id_10 = Shards.add("GROUPID2", "ENABLED") self.__shard_id_11 = Shards.add("GROUPID3", "ENABLED") self.__range_sharding_specification_1 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 0, self.__shard_id_1.shard_id ) self.__range_sharding_specification_2 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 1001, self.__shard_id_2.shard_id ) self.__range_sharding_specification_3 = RangeShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, 2001, self.__shard_id_3.shard_id ) self.__range_sharding_specification_4 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 3001, self.__shard_id_4.shard_id ) self.__range_sharding_specification_5 = RangeShardingSpecification.add( self.__shard_mapping_2.shard_mapping_id, 4001, self.__shard_id_5.shard_id ) self.__range_sharding_specification_6 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 6001, self.__shard_id_6.shard_id ) self.__range_sharding_specification_7 = RangeShardingSpecification.add( self.__shard_mapping_3.shard_mapping_id, 7001, self.__shard_id_7.shard_id ) self.__range_sharding_specification_8 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 8001, self.__shard_id_8.shard_id ) self.__range_sharding_specification_9 = RangeShardingSpecification.add( self.__shard_mapping_4.shard_mapping_id, 10001, self.__shard_id_9.shard_id ) self.__range_sharding_specification_10 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 100, self.__shard_id_10.shard_id) self.__range_sharding_specification_11 = RangeShardingSpecification.add( self.__shard_mapping_5.shard_mapping_id, 201, self.__shard_id_11.shard_id) READ_ONLY = MySQLServer.get_mode_idx(MySQLServer.READ_ONLY) READ_WRITE = MySQLServer.get_mode_idx(MySQLServer.READ_WRITE) SECONDARY = MySQLServer.get_status_idx(MySQLServer.SECONDARY) PRIMARY = MySQLServer.get_status_idx(MySQLServer.PRIMARY) self.__setofservers = [0, 0, 0, [[str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_3.uuid), 'GROUPID2', self.__options_3_host, self.__options_3_port, READ_WRITE, PRIMARY, 1.0], [str(self.__server_4.uuid), 'GROUPID2', self.__options_4_host, self.__options_4_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_5.uuid), 'GROUPID3', self.__options_5_host, self.__options_5_port, READ_WRITE, PRIMARY, 1.0], [str(self.__server_6.uuid), 'GROUPID3', self.__options_6_host, self.__options_6_port, READ_ONLY, SECONDARY, 1.0]]] self.__setofservers_1 = [0, 0, 0, [[str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0]]] self.__setofservers_2 = [0, 0, 0, [[str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_3.uuid), 'GROUPID2', self.__options_3_host, self.__options_3_port, READ_WRITE, PRIMARY, 1.0], [str(self.__server_4.uuid), 'GROUPID2', self.__options_4_host, self.__options_4_port, READ_ONLY, SECONDARY, 1.0]]] self.__setofservers_3 = [0, 0, 0, [[str(self.__server_1.uuid), 'GROUPID1', self.__options_1_host, self.__options_1_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_2.uuid), 'GROUPID1', self.__options_2_host, self.__options_2_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_3.uuid), 'GROUPID2', self.__options_3_host, self.__options_3_port, READ_WRITE, PRIMARY, 1.0], [str(self.__server_4.uuid), 'GROUPID2', self.__options_4_host, self.__options_4_port, READ_ONLY, SECONDARY, 1.0], [str(self.__server_5.uuid), 'GROUPID3', self.__options_5_host, self.__options_5_port, READ_WRITE, PRIMARY, 1.0], [str(self.__server_6.uuid), 'GROUPID3', self.__options_6_host, self.__options_6_port, READ_ONLY, SECONDARY, 1.0]]] self.__setoftables = [0, 0, 0, [['db1', 't1', 'userID1', '1'], ['db2', 't2', 'userID2', '2'], ['db3', 't3', 'userID3', '3'], ['db4', 't4', 'userID4', '4'], ['prune_db', 'prune_table', 'userID', '5']]] self.__setoftables_1 = [0, 0, 0, [['db1', 't1', 'userID1', '1']]] self.__setoftables_2 = [0, 0, 0, [['db1', 't1', 'userID1', '1'], ['db2', 't2', 'userID2', '2']]] self.__setoftables_3 = [0, 0, 0, [['db1', 't1', 'userID1', '1'], ['db2', 't2', 'userID2', '2'], ['db3', 't3', 'userID3', '3']]] self.__setofshardmaps = [0, 0, 0, [['1', 'RANGE', 'GROUPID10'], ['2', 'RANGE', 'GROUPID11'], ['3', 'RANGE', 'GROUPID12'], ['4', 'RANGE', 'GROUPID13'], ['5', 'RANGE', 'GROUPID14']]] self.__setofshardmaps_1 = [0, 0, 0, [['1', 'RANGE', 'GROUPID10']]] self.__setofshardmaps_2 = [0, 0, 0, [['1', 'RANGE', 'GROUPID10'], ['2', 'RANGE', 'GROUPID11']]] self.__setofshardmaps_3 = [0, 0, 0, [['1', 'RANGE', 'GROUPID10'], ['2', 'RANGE', 'GROUPID11'], ['3', 'RANGE', 'GROUPID12']]] self.__setofshardindexes = [0, 0, 0, [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10'], ['3001', '2', '4', 'GROUPID4'], ['4001', '2', '5', 'GROUPID5'], ['6001', '3', '6', 'GROUPID6'], ['7001', '3', '7', 'GROUPID7'], ['8001', '4', '8', 'GROUPID8'], ['10001', '4', '9', 'GROUPID9'], ['100', '5', '10', 'GROUPID2'], ['201', '5', '11', 'GROUPID3']]] self.__setofshardindexes_1 = [0, 0, 0, [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10']]] self.__setofshardindexes_3 = [0, 0, 0, [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10'], ['3001', '2', '4', 'GROUPID4'], ['4001', '2', '5', 'GROUPID5'], ['6001', '3', '6', 'GROUPID6'], ['7001', '3', '7', 'GROUPID7']]] self.__setofshardindexes_5 = [0, 0, 0, [['0', '1', '1', 'GROUPID1'], ['1001', '1', '2', 'GROUPID10'], ['3001', '2', '4', 'GROUPID4'], ['4001', '2', '5', 'GROUPID5'], ['6001', '3', '6', 'GROUPID6'], ['7001', '3', '7', 'GROUPID7'], ['8001', '4', '8', 'GROUPID8'], ['10001', '4', '9', 'GROUPID9'], ['100', '5', '10', 'GROUPID2'], ['201', '5', '11', 'GROUPID3']]] self.__shardinginformation_1 = [0, 0, 0, [['db1', 't1', 'userID1', '0', '1', 'RANGE', 'GROUPID1', 'GROUPID10'], ['db1', 't1', 'userID1', '1001', '2', 'RANGE', 'GROUPID10', 'GROUPID10']]] self.__shardinginformation_2 = [0, 0, 0, [['db1', 't1', 'userID1', '0', '1', 'RANGE', 'GROUPID1', 'GROUPID10'], ['db1', 't1', 'userID1', '1001', '2', 'RANGE', 'GROUPID10', 'GROUPID10'], ['db2', 't2', 'userID2', '3001', '4', 'RANGE', 'GROUPID4', 'GROUPID11'], ['db2', 't2', 'userID2', '4001', '5', 'RANGE', 'GROUPID5', 'GROUPID11']]] self.__shardinginformation_3 = [0, 0, 0, [['db1', 't1', 'userID1', '0', '1', 'RANGE', 'GROUPID1', 'GROUPID10'], ['db1', 't1', 'userID1', '1001', '2', 'RANGE', 'GROUPID10', 'GROUPID10'], ['db2', 't2', 'userID2', '3001', '4','RANGE', 'GROUPID4', 'GROUPID11'], ['db2', 't2', 'userID2', '4001', '5', 'RANGE', 'GROUPID5', 'GROUPID11'], ['db3', 't3', 'userID3', '6001', '6', 'RANGE', 'GROUPID6', 'GROUPID12'], ['db3', 't3', 'userID3', '7001', '7', 'RANGE', 'GROUPID7', 'GROUPID12']]]
def _add_shard(shard_mapping_id, groupid_lb_list, state, update_only=False): """Add the RANGE shard specification. This represents a single instance of a shard specification that maps a key RANGE to a server. :param shard_mapping_id: The unique identification for a shard mapping. :param groupid_lb_list: The list of group_id, lower_bounds pairs in the format, group_id/lower_bound, group_id/lower_bound... . :param state: Indicates whether a given shard is ENABLED or DISABLED :param update_only: Only update the state store and skip adding range checks. :return: True if the add succeeded. False otherwise. :raises: ShardingError If the group on which the shard is being created does not exist, If the shard_mapping_id is not found, If adding the shard definition fails, If the state of the shard is an invalid value, If the range definition is invalid. """ shard_mapping = ShardMapping.fetch_shard_mapping_defn(shard_mapping_id) if shard_mapping is None: raise _errors.ShardingError(SHARD_MAPPING_NOT_FOUND % \ (shard_mapping_id, )) schema_type = shard_mapping[1] if len(RangeShardingSpecification.list(shard_mapping_id)) != 0: raise _errors.ShardingError(SHARDS_ALREADY_EXIST) group_id_list, lower_bound_list = \ _utils.get_group_lower_bound_list(groupid_lb_list) if (len(group_id_list) != len(lower_bound_list)) and\ schema_type == "RANGE": raise _errors.ShardingError(LOWER_BOUND_GROUP_ID_COUNT_MISMATCH) if len(lower_bound_list) != 0 and schema_type == "HASH": raise _errors.ShardingError(LOWER_BOUND_AUTO_GENERATED) if schema_type in Shards.VALID_RANGE_SHARDING_TYPES: for lower_bound in lower_bound_list: if not SHARDING_DATATYPE_HANDLER[schema_type].\ is_valid_lower_bound(lower_bound): raise _errors.ShardingError( INVALID_LOWER_BOUND_VALUE % (lower_bound, )) state = state.upper() if state not in Shards.VALID_SHARD_STATES: raise _errors.ShardingError(INVALID_SHARD_STATE % (state, )) for index, group_id in enumerate(group_id_list): shard = Shards.add(group_id, state) shard_id = shard.shard_id if schema_type == "HASH": HashShardingSpecification.add( shard_mapping_id, shard_id ) _LOGGER.debug( "Added Shard (map id = %s, id = %s).", shard_mapping_id, shard_id ) else: range_sharding_specification = \ SHARDING_SPECIFICATION_HANDLER[schema_type].add( shard_mapping_id, lower_bound_list[index], shard_id ) _LOGGER.debug( "Added Shard (map id = %s, lower bound = %s, id = %s).", range_sharding_specification.shard_mapping_id, range_sharding_specification.lower_bound, range_sharding_specification.shard_id ) if not update_only: #If the shard is added in a DISABLED state do not setup replication #with the primary of the global group. Basically setup replication only #if the shard is ENABLED. if state == "ENABLED": _setup_shard_group_replication(shard_id) if not update_only: #Add the shard limits into the metadata present in each of the shards. _events.trigger_within_procedure( ADD_SHARD_RANGE_CHECK, shard_mapping_id, schema_type )
def test_shard_mapping_list_mappings(self): """Test the listing of all HASH shards in a shard mapping. """ shard_mappings = ShardMapping.list("HASH") self.assertTrue(ShardingUtils.compare_shard_mapping (self.__shard_mapping_1, shard_mappings[0]))
def setUp(self): self.manager, self.proxy = tests.utils.setup_xmlrpc() self.__options_1 = { "uuid" : _uuid.UUID("{aa75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(0), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server1 = MySQLServer.discover_uuid(self.__options_1["address"]) self.__options_1["uuid"] = _uuid.UUID(uuid_server1) self.__server_1 = MySQLServer(**self.__options_1) MySQLServer.add(self.__server_1) self.__group_1 = Group("GROUPID1", "First description.") Group.add(self.__group_1) self.__group_1.add_server(self.__server_1) tests.utils.configure_decoupled_master(self.__group_1, self.__server_1) self.__options_2 = { "uuid" : _uuid.UUID("{aa45b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(1), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server2 = MySQLServer.discover_uuid(self.__options_2["address"]) self.__options_2["uuid"] = _uuid.UUID(uuid_server2) self.__server_2 = MySQLServer(**self.__options_2) MySQLServer.add(self.__server_2) self.__server_2.connect() self.__server_2.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_2.exec_stmt("CREATE DATABASE db1") self.__server_2.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_2.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_2 = Group("GROUPID2", "Second description.") Group.add(self.__group_2) self.__group_2.add_server(self.__server_2) tests.utils.configure_decoupled_master(self.__group_2, self.__server_2) self.__options_3 = { "uuid" : _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(2), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server3 = MySQLServer.discover_uuid(self.__options_3["address"]) self.__options_3["uuid"] = _uuid.UUID(uuid_server3) self.__server_3 = MySQLServer(**self.__options_3) MySQLServer.add( self.__server_3) self.__server_3.connect() self.__server_3.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_3.exec_stmt("CREATE DATABASE db1") self.__server_3.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_3.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_3 = Group("GROUPID3", "Third description.") Group.add( self.__group_3) self.__group_3.add_server(self.__server_3) tests.utils.configure_decoupled_master(self.__group_3, self.__server_3) self.__options_4 = { "uuid" : _uuid.UUID("{bb45b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(3), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server4 = MySQLServer.discover_uuid(self.__options_4["address"]) self.__options_4["uuid"] = _uuid.UUID(uuid_server4) self.__server_4 = MySQLServer(**self.__options_4) MySQLServer.add(self.__server_4) self.__server_4.connect() self.__server_4.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_4.exec_stmt("CREATE DATABASE db1") self.__server_4.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_4.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_4 = Group("GROUPID4", "Fourth description.") Group.add( self.__group_4) self.__group_4.add_server(self.__server_4) tests.utils.configure_decoupled_master(self.__group_4, self.__server_4) self.__options_5 = { "uuid" : _uuid.UUID("{cc75b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(4), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server5 = MySQLServer.discover_uuid(self.__options_5["address"]) self.__options_5["uuid"] = _uuid.UUID(uuid_server5) self.__server_5 = MySQLServer(**self.__options_5) MySQLServer.add(self.__server_5) self.__server_5.connect() self.__server_5.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_5.exec_stmt("CREATE DATABASE db1") self.__server_5.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_5.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_5 = Group("GROUPID5", "Fifth description.") Group.add( self.__group_5) self.__group_5.add_server(self.__server_5) tests.utils.configure_decoupled_master(self.__group_5, self.__server_5) self.__options_6 = { "uuid" : _uuid.UUID("{cc45b12b-98d1-414c-96af-9e9d4b179678}"), "address" : MySQLInstances().get_address(5), "user" : MySQLInstances().user, "passwd" : MySQLInstances().passwd, } uuid_server6 = MySQLServer.discover_uuid(self.__options_6["address"]) self.__options_6["uuid"] = _uuid.UUID(uuid_server6) self.__server_6 = MySQLServer(**self.__options_6) MySQLServer.add(self.__server_6) self.__server_6.connect() self.__server_6.exec_stmt("DROP DATABASE IF EXISTS db1") self.__server_6.exec_stmt("CREATE DATABASE db1") self.__server_6.exec_stmt("CREATE TABLE db1.t1" "(userID INT, name VARCHAR(30))") for i in range(1, 501): self.__server_6.exec_stmt("INSERT INTO db1.t1 " "VALUES(%s, 'TEST %s')" % (i, i)) self.__group_6 = Group("GROUPID6", "Sixth description.") Group.add( self.__group_6) self.__group_6.add_server(self.__server_6) tests.utils.configure_decoupled_master(self.__group_6, self.__server_6) self.__shard_mapping_list = ShardMapping.list_shard_mapping_defn() self.assertEquals( self.__shard_mapping_list, []) self.__shard_mapping_id_1 = ShardMapping.define("HASH", "GROUPID1") self.__shard_mapping_1 = ShardMapping.add( self.__shard_mapping_id_1, "db1.t1", "userID" ) self.__shard_1 = Shards.add("GROUPID2") self.__shard_2 = Shards.add("GROUPID3") self.__shard_3 = Shards.add("GROUPID4") self.__shard_4 = Shards.add("GROUPID5") self.__shard_5 = Shards.add("GROUPID6") self.__hash_sharding_specification_1 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_1.shard_id ) self.__hash_sharding_specification_2 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_2.shard_id ) self.__hash_sharding_specification_3 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_3.shard_id ) self.__hash_sharding_specification_4 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_4.shard_id ) self.__hash_sharding_specification_5 = HashShardingSpecification.add( self.__shard_mapping_1.shard_mapping_id, self.__shard_5.shard_id )
def _add_shard(shard_mapping_id, groupid_lb_list, state): """Add the RANGE shard specification. This represents a single instance of a shard specification that maps a key RANGE to a server. :param shard_mapping_id: The unique identification for a shard mapping. :param groupid_lb_list: The list of group_id, lower_bounds pairs in the format, group_id/lower_bound, group_id/lower_bound... . :param state: Indicates whether a given shard is ENABLED or DISABLED :return: True if the add succeeded. False otherwise. :raises: ShardingError If the group on which the shard is being created does not exist, If the shard_mapping_id is not found, If adding the shard definition fails, If the state of the shard is an invalid value, If the range definition is invalid. """ shard_mapping = ShardMapping.fetch_shard_mapping_defn(shard_mapping_id) if shard_mapping is None: raise _errors.ShardingError(SHARD_MAPPING_NOT_FOUND % \ (shard_mapping_id, )) schema_type = shard_mapping[1] if len(RangeShardingSpecification.list(shard_mapping_id)) != 0: raise _errors.ShardingError(SHARDS_ALREADY_EXIST) group_id_list, lower_bound_list = \ _utils.get_group_lower_bound_list(groupid_lb_list) if (len(group_id_list) != len(lower_bound_list)) and\ schema_type == "RANGE": raise _errors.ShardingError(LOWER_BOUND_GROUP_ID_COUNT_MISMATCH) if len(lower_bound_list) != 0 and schema_type == "HASH": raise _errors.ShardingError(LOWER_BOUND_AUTO_GENERATED) if schema_type in Shards.VALID_RANGE_SHARDING_TYPES: for lower_bound in lower_bound_list: if not SHARDING_DATATYPE_HANDLER[schema_type].\ is_valid_lower_bound(lower_bound): raise _errors.ShardingError(INVALID_LOWER_BOUND_VALUE % (lower_bound, )) state = state.upper() if state not in Shards.VALID_SHARD_STATES: raise _errors.ShardingError(INVALID_SHARD_STATE % (state, )) for index, group_id in enumerate(group_id_list): shard = Shards.add(group_id, state) shard_id = shard.shard_id if schema_type == "HASH": HashShardingSpecification.add(shard_mapping_id, shard_id) _LOGGER.debug("Added Shard (map id = %s, id = %s).", shard_mapping_id, shard_id) else: range_sharding_specification = \ SHARDING_SPECIFICATION_HANDLER[schema_type].add( shard_mapping_id, lower_bound_list[index], shard_id ) _LOGGER.debug( "Added Shard (map id = %s, lower bound = %s, id = %s).", range_sharding_specification.shard_mapping_id, range_sharding_specification.lower_bound, range_sharding_specification.shard_id) #If the shard is added in a DISABLED state do not setup replication #with the primary of the global group. Basically setup replication only #if the shard is ENABLED. if state == "ENABLED": _setup_shard_group_replication(shard_id)