Exemple #1
0
    def hash_sharding_specification_in_list(self, hash_sharding_spec,
                                            hash_sharding_specification_list):
        """Verify if the given hash sharding specification is present in
        the list of hash sharding specifications.

        :param hash_sharding_spec: The hash sharding specification that
            needs to be lookedup.
        :param hash_sharding_specification_list: The list of hash sharding
            specifications

        :return: True if the hash sharding specification is present.
                False otherwise.
        """
        for i in range(0, len(hash_sharding_specification_list)):
            if ShardingUtils.compare_hash_specifications(
                    hash_sharding_spec, hash_sharding_specification_list[i]):
                return True
        return False
    def hash_sharding_specification_in_list(self,
                                            hash_sharding_spec,
                                            hash_sharding_specification_list
                                            ):
        """Verify if the given hash sharding specification is present in
        the list of hash sharding specifications.

        :param hash_sharding_spec: The hash sharding specification that
            needs to be lookedup.
        :param hash_sharding_specification_list: The list of hash sharding
            specifications

        :return: True if the hash sharding specification is present.
                False otherwise.
        """
        for i in range(0, len(hash_sharding_specification_list)):
            if ShardingUtils.compare_hash_specifications(
                hash_sharding_spec,
                hash_sharding_specification_list[i]
            ):
                return True
        return False
    def test_shard_split(self):
        split_cnt_1 = 0
        split_cnt_2 = 0
        shard_server_1 = None
        shard_server_2 = None
        expected_address_list_1 = \
            [MySQLInstances().get_address(2), MySQLInstances().get_address(3)]
        expected_address_list_2 = \
            [MySQLInstances().get_address(4), MySQLInstances().get_address(5)]
        status = self.proxy.sharding.split_shard("1", "GROUPID3")
        self.assertStatus(status, _executor.Job.SUCCESS)
        self.assertEqual(status[1][-1]["state"], _executor.Job.COMPLETE)
        self.assertEqual(status[1][-1]["description"],
                         "Executed action (_prune_shard_tables_after_split).")

        for i in range(1,  100):
            status = self.proxy.sharding.lookup_servers("db1.t1", i, "LOCAL")
            self.assertEqual(status[0], True)
            self.assertEqual(status[1], "")
            obtained_server_list = status[2]
            obtained_uuid_list = [obtained_server_list[0][0],
                                  obtained_server_list[1][0]]
            obtained_address_list = [obtained_server_list[0][1],
                                    obtained_server_list[1][1]]
            try:
                self.assertEqual(
                    set(expected_address_list_1), set(obtained_address_list)
                )
                split_cnt_1 = split_cnt_1 + 1
                if shard_server_1 is None:
                    shard_server_1 = MySQLServer.fetch(obtained_uuid_list[0])
            except AssertionError:
                self.assertEqual(
                    set(expected_address_list_2), set(obtained_address_list)
                )
                split_cnt_2 = split_cnt_2 + 1
                if shard_server_2 is None:
                    shard_server_2 = MySQLServer.fetch(obtained_uuid_list[0])

        #Ensure that both the splits have been utilized.
        self.assertTrue(split_cnt_1 > 0)
        self.assertTrue(split_cnt_2 > 0)

        shard_server_1.connect()
        shard_server_2.connect()

        row_cnt_shard_1 = shard_server_1.exec_stmt(
                    "SELECT COUNT(*) FROM db1.t1",
                    {"fetch" : True}
                )

        row_cnt_shard_2 = shard_server_2.exec_stmt(
                    "SELECT COUNT(*) FROM db1.t1",
                    {"fetch" : True}
                )

        #Ensure that the split has happened, the number of values in
        #each shard should be less than the original.
        self.assertTrue(int(row_cnt_shard_1[0][0]) < 100)
        self.assertTrue(int(row_cnt_shard_2[0][0]) < 100)

        #Ensure tha two new shard_ids have been generated.
        hash_sharding_specifications = HashShardingSpecification.list(1)
        self.assertTrue(ShardingUtils.compare_hash_specifications(
            hash_sharding_specifications[1],
            HashShardingSpecification.fetch(2)))
        self.assertTrue(ShardingUtils.compare_hash_specifications(
            hash_sharding_specifications[0],
            HashShardingSpecification.fetch(3)))
Exemple #4
0
    def test_shard_split(self):
        split_cnt_1 = 0
        split_cnt_2 = 0
        shard_server_1 = None
        shard_server_2 = None
        expected_address_list_1 = \
            [MySQLInstances().get_address(2), MySQLInstances().get_address(3)]
        expected_address_list_2 = \
            [MySQLInstances().get_address(4), MySQLInstances().get_address(5)]
        status = self.proxy.sharding.split_shard("1", "GROUPID3")
        self.check_xmlrpc_command_result(status)

        for i in range(1, 100):
            status = self.proxy.sharding.lookup_servers("db1.t1", i, "LOCAL")
            obtained_uuid_list = [
                info['server_uuid'] for info in self.check_xmlrpc_iter(status)
            ]
            obtained_address_list = [
                info['address'] for info in self.check_xmlrpc_iter(status)
            ]
            try:
                self.assertEqual(set(expected_address_list_1),
                                 set(obtained_address_list))
                split_cnt_1 = split_cnt_1 + 1
                if shard_server_1 is None:
                    shard_server_1 = fetch_test_server(obtained_uuid_list[0])
            except AssertionError:
                self.assertEqual(set(expected_address_list_2),
                                 set(obtained_address_list))
                split_cnt_2 = split_cnt_2 + 1
                if shard_server_2 is None:
                    shard_server_2 = fetch_test_server(obtained_uuid_list[0])

        #Ensure that both the splits have been utilized.
        self.assertTrue(split_cnt_1 > 0)
        self.assertTrue(split_cnt_2 > 0)

        shard_server_1.connect()
        shard_server_2.connect()

        row_cnt_shard_1 = shard_server_1.exec_stmt(
            "SELECT COUNT(*) FROM db1.t1", {"fetch": True})

        row_cnt_shard_2 = shard_server_2.exec_stmt(
            "SELECT COUNT(*) FROM db1.t1", {"fetch": True})

        #Ensure that the split has happened, the number of values in
        #each shard should be less than the original.
        self.assertTrue(int(row_cnt_shard_1[0][0]) < 100)
        self.assertTrue(int(row_cnt_shard_2[0][0]) < 100)

        #Ensure tha two new shard_ids have been generated.
        hash_sharding_specifications = HashShardingSpecification.list(1)
        self.assertTrue(
            ShardingUtils.compare_hash_specifications(
                hash_sharding_specifications[1],
                HashShardingSpecification.fetch(2)))
        self.assertTrue(
            ShardingUtils.compare_hash_specifications(
                hash_sharding_specifications[0],
                HashShardingSpecification.fetch(3)))