当前位置: 首页>>代码示例>>Python>>正文


Python server.MySQLServer类代码示例

本文整理汇总了Python中mysql.fabric.server.MySQLServer的典型用法代码示例。如果您正苦于以下问题:Python MySQLServer类的具体用法?Python MySQLServer怎么用?Python MySQLServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MySQLServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_managment

    def test_managment(self):
        """Test adding server to a group.
        """
        options_1 = {
            "uuid" :  _uuid.UUID("{bb75b12b-98d1-414c-96af-9e9d4b179678}"),
            "address"  : "server_1.mysql.com:3060",
        }
        server_1 = MySQLServer(**options_1)
        MySQLServer.add(server_1)
        options_2 = {
            "uuid" :  _uuid.UUID("{aa75a12a-98d1-414c-96af-9e9d4b179678}"),
            "address"  : "server_2.mysql.com:3060",
        }
        server_2 = MySQLServer(**options_2)
        MySQLServer.add(server_2)
        group_1 = Group("oracle.com", "First description.")
        Group.add(group_1)

        # Add servers to a group
        group_1.add_server(server_1)
        group_1.add_server(server_2)
        self.assertRaises(AssertionError, group_1.add_server, server_1)
        self.assertEqual(len(group_1.servers()), 2)

        # Remove servers to a group
        group_1.remove_server(server_1)
        group_1.remove_server(server_2)
        self.assertRaises(AssertionError, group_1.remove_server, server_1)
        self.assertEqual(len(group_1.servers()), 0)
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:29,代码来源:test_mysql_server.py

示例2: setUp

 def setUp(self):
     """Configure the existing environment
     """
     uuid = MySQLServer.discover_uuid(OPTIONS["address"])
     OPTIONS["uuid"] = _uuid.UUID(uuid)
     self.server = MySQLServer(**OPTIONS)
     MySQLServer.add(self.server)
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:7,代码来源:test_mysql_server.py

示例3: _setup_replication

def _setup_replication(shard_id, source_group_id, destn_group_id, split_value,
                                        prune_limit, 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 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()

    #Stop and reset any slave that  might be running on the slave server.
    _utils.set_offline_mode(slave, True) ### TODO: if forced offline_mode
    _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.repl_user, master.repl_pass)

    #Start the slave so that syncing of the data begins
    _replication.start_slave(slave, wait=True)
    _utils.set_offline_mode(slave, False) ### TODO: if forced offline_mode

    #Setup sync between the source and the destination groups.
    _events.trigger_within_procedure(
                                     SETUP_SYNC,
                                     shard_id,
                                     source_group_id,
                                     destn_group_id,
                                     split_value,
                                     prune_limit,
                                     cmd
                                     )
开发者ID:gmo-media,项目名称:mikasafabric,代码行数:60,代码来源:resharding.py

示例4: test_max_connections

 def test_max_connections(self):
     uuid = MySQLServer.discover_uuid(OPTIONS["address"])
     server = MySQLServer(
         _uuid.UUID(uuid), OPTIONS["address"],
     )
     server.connect()
     res = server.get_variable("max_connections")
     self.assertNotEqual(int(res), 0)
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:8,代码来源:test_mysql_server.py

示例5: test_wrong_uuid

 def test_wrong_uuid(self):
     """Test what happens when a server has a wrong uuid.
     """
     # Check wrong uuid.
     OPTIONS["uuid"] = _uuid.UUID("FD0AC9BB-1431-11E2-8137-11DEF124DCC5")
     server = MySQLServer(**OPTIONS)
     self.assertRaises(_errors.UuidError, server.connect)
     server.disconnect()
     ConnectionPool().purge_connections(OPTIONS["uuid"])
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:9,代码来源:test_mysql_server.py

示例6: setUp

 def setUp(self):
     """Configure the existing environment
     """
     uuid = MySQLServer.discover_uuid(
         tests.utils.MySQLInstances().get_address(0)
     )
     self.server = MySQLServer(_uuid.UUID(uuid),
         tests.utils.MySQLInstances().get_address(0)
     )
     MySQLServer.add(self.server)
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:10,代码来源:test_error_log.py

示例7: setUp

 def setUp(self):
     """Configure the existing environment
     """
     uuid = MySQLServer.discover_uuid(OPTIONS_MASTER["address"])
     OPTIONS_MASTER["uuid"] = _uuid.UUID(uuid)
     self.master = MySQLServer(**OPTIONS_MASTER)
     self.master.connect()
     reset_master(self.master)
     self.master.read_only = True
     self.master.read_only = False
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:10,代码来源:test_mysql_replication.py

示例8: _setup_sync

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
                                     )
开发者ID:mgsanusi,项目名称:DeepChrome,代码行数:55,代码来源:resharding.py

示例9: TestMySQLMaster

class TestMySQLMaster(unittest.TestCase):
    """Unit test for the configuration file handling.
    """
    def setUp(self):
        """Configure the existing environment
        """
        uuid = MySQLServer.discover_uuid(OPTIONS_MASTER["address"])
        OPTIONS_MASTER["uuid"] = _uuid.UUID(uuid)
        self.master = MySQLServer(**OPTIONS_MASTER)
        self.master.connect()
        reset_master(self.master)
        self.master.read_only = True
        self.master.read_only = False

    def tearDown(self):
        """Clean up the existing environment
        """
        cleanup_environment()
        self.master.disconnect()

    def test_master_binary_log(self):
        """Test the get_master_status() function.
        """
        # Note this is only being tested with the binary log.
        master = self.master

        # Get master status.
        check = re.compile('\w+-bin.000001')
        ret = get_master_status(master)
        self.assertNotEqual(check.match(ret[0][0]), None)

        # Reset Master.
        reset_master(master)
        ret = get_master_status(master)
        self.assertEqual(int(ret[0][1]), 151) # Format descriptor event.

    def test_master_health(self):
        """Test the check_master_issues() function.
        """
        # Note this is only being tested with the binary log.
        master = self.master

        # Check health as a master before calling connect.
        master.disconnect()
        ret = check_master_issues(master)
        self.assertEqual(ret, {'is_running': False})

        # Check health as a master after calling connect.
        master.connect()
        ret = check_master_issues(master)
        self.assertEqual(ret, {})
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:51,代码来源:test_mysql_replication.py

示例10: test_shard_split_fail_GTID_EXECUTED

 def test_shard_split_fail_GTID_EXECUTED(self):
     self.split_fail = True
     status = self.proxy.group.lookup_servers("GROUPID3")
     self.assertEqual(status[0], True)
     self.assertEqual(status[1], "")
     obtained_server_list = status[2]
     for obtained_server in obtained_server_list:
         if obtained_server["status"] == "PRIMARY":
             shard_uuid = obtained_server["server_uuid"]
             shard_server = MySQLServer.fetch(shard_uuid)
             shard_server.connect()
             break
     shard_server.exec_stmt("DROP DATABASE IF EXISTS Extra")
     shard_server.exec_stmt("CREATE DATABASE Extra")
     shard_server.exec_stmt("CREATE TABLE Extra.Extra_Table"
                               "(userID INT, name VARCHAR(30))")
     shard_server.exec_stmt("INSERT INTO Extra.Extra_Table "
                               "VALUES(101, 'TEST 1')")
     shard_server.exec_stmt("INSERT INTO Extra.Extra_Table "
                               "VALUES(102, 'TEST 2')")
     shard_server.exec_stmt("INSERT INTO Extra.Extra_Table "
                               "VALUES(103, 'TEST 3')")
     shard_server.exec_stmt("INSERT INTO Extra.Extra_Table "
                               "VALUES(701, 'TEST 4')")
     status = self.proxy.sharding.split_shard("1", "GROUPID3", "600")
     self.assertStatus(status, _executor.Job.ERROR)
     self.assertEqual(status[1][-1]["state"], _executor.Job.COMPLETE)
     self.assertEqual(status[1][-1]["description"],
                      "Tried to execute action (_restore_shard_backup).")
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:29,代码来源:test_shard_split.py

示例11: test_update_only

    def test_update_only(self):
        """Test the shard split but without provisioning.
        """
        # Get group information before the shard_move operation
        status = self.proxy.sharding.lookup_servers("db1.t1", 500,  "LOCAL")
        local_list_before = status[2]
        status = self.proxy.sharding.lookup_servers("1", 500,  "GLOBAL")
        global_list_before = status[2]

        # Do the shard split and compare group information.
        status = self.proxy.sharding.split_shard("1", "GROUPID3", "600", True)
        self.assertStatus(status, _executor.Job.SUCCESS)
        self.assertEqual(status[1][-1]["state"], _executor.Job.COMPLETE)
        self.assertEqual(status[1][-1]["description"],
                         "Executed action (_setup_resharding_switch).")
        status = self.proxy.sharding.lookup_servers("db1.t1", 601,  "LOCAL")
        local_list_after = status[2]
        self.assertNotEqual(local_list_before, local_list_after)
        status = self.proxy.sharding.lookup_servers("1", 601,  "GLOBAL")
        global_list_after = status[2]
        self.assertEqual(global_list_before, global_list_after)

        # The group has changed but no data was transfered.
        shard_server = MySQLServer.fetch(local_list_after[0][0])
        shard_server.connect()
        self.assertRaises(
            DatabaseError, shard_server.exec_stmt,
            "SELECT NAME FROM db1.t1", {"fetch" : True}
        )
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:29,代码来源:test_shard_split.py

示例12: drop_shard_range_trigger

    def drop_shard_range_trigger(group_id, sharding_type, table_name,
                                    column_name):
        """Drop a trigger on the shard table.

        :param group_id: The ID of the group on which the trigger definition
                         is applied. The trigger is created on the master of
                         this group.
        :param sharding_type: The datatype supported by the shards. Used to
                              name the trigger.
        :param table_name: The name of the table. This is used to name the
                           trigger being created.
        :param column_name: The name of the column in the table being sharded.
                            This is used to create the name of the trigger.
        """
        global_group = Group.fetch(group_id)
        master_server = MySQLServer.fetch(global_group.master)
        master_server.connect()

        db, table = table_name.split(".")

        #Drop the INSERT trigger on the sharded table.
        trigger_name = db + "." + _TRIGGER_PREFIX_INSERT+table
        drop_insert_trigger = _DROP_TRIGGER_DEFN.format(
            trigger_name=trigger_name
        )
        master_server.exec_stmt(drop_insert_trigger)

        #Drop the UPDATE trigger on the sharded table.
        trigger_name = db + "." + _TRIGGER_PREFIX_UPDATE + table
        drop_update_trigger = _DROP_TRIGGER_DEFN.format(
            trigger_name=trigger_name
        )
        master_server.exec_stmt(drop_update_trigger)
开发者ID:ioggstream,项目名称:mysql-utilities,代码行数:33,代码来源:shard_range_check_trigger.py

示例13: test_shard_prune

    def test_shard_prune(self):
        status = self.proxy.sharding.prune_shard("db2.t2")
        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).")

        status = self.proxy.sharding.lookup_servers("db2.t2", 1,  "LOCAL")
        self.assertEqual(status[0], True)
        self.assertEqual(status[1], "")
        obtained_server_list = status[2]
        shard_uuid = obtained_server_list[0][0]
        shard_server = MySQLServer.fetch(shard_uuid)
        shard_server.connect()
        rows = shard_server.exec_stmt(
                                    "SELECT COUNT(*) FROM db2.t2",
                                    {"fetch" : True})
        self.assertTrue(int(rows[0][0]) == 100)
        rows = shard_server.exec_stmt(
                                    "SELECT MAX(userID2) FROM db2.t2",
                                    {"fetch" : True})
        self.assertTrue(int(rows[0][0]) == 100)
        rows = shard_server.exec_stmt(
                                    "SELECT MIN(userID2) FROM db2.t2",
                                    {"fetch" : True})
        self.assertTrue(int(rows[0][0]) == 1)

        status = self.proxy.sharding.lookup_servers("db2.t2", 101,  "LOCAL")
        self.assertEqual(status[0], True)
        self.assertEqual(status[1], "")
        obtained_server_list = status[2]
        shard_uuid = obtained_server_list[0][0]
        shard_server = MySQLServer.fetch(shard_uuid)
        shard_server.connect()
        rows = shard_server.exec_stmt(
                                    "SELECT COUNT(*) FROM db2.t2",
                                    {"fetch" : True})
        self.assertTrue(int(rows[0][0]) == 100)
        rows = shard_server.exec_stmt(
                                    "SELECT MAX(userID2) FROM db2.t2",
                                    {"fetch" : True})
        self.assertTrue(int(rows[0][0]) == 200)
        rows = shard_server.exec_stmt(
                                    "SELECT MIN(userID2) FROM db2.t2",
                                    {"fetch" : True})
        self.assertTrue(int(rows[0][0]) == 101)
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:46,代码来源:test_multiple_shard_indexes.py

示例14: _fetch_master_of_group

    def _fetch_master_of_group(group_id):
        """Return a reference to the master of the group.

        :param group_id: ID of the group whose master needs to be fetched.

        :return: MySQLServer object referring to the group master.
        """
        global_group = Group.fetch(group_id)
        master_server = MySQLServer.fetch(global_group.master)
        master_server.connect()
        return master_server
开发者ID:ioggstream,项目名称:mysql-utilities,代码行数:11,代码来源:shard_meta_data.py

示例15: stop_group_slave

def stop_group_slave(group_master_id,  group_slave_id,  clear_ref):
    """Stop the slave on the slave group. This utility method is the
    completement of the setup_group_replication method and is
    used to stop the replication on the slave group. Given a master group ID
    and the slave group ID the method stops the slave on the slave
    group and updates the references on both the master and the
    slave group.

    :param group_master_id: The id of the master group.
    :param group_slave_id: The id of the slave group.
    :param clear_ref: The parameter indicates if the stop_group_slave
                                needs to clear the references to the group's
                                slaves. For example when you do a disable
                                shard the shard group still retains the
                                references to its slaves, since when enabled
                                it needs to enable the replication.
    """
    master_group = Group.fetch(group_master_id)
    slave_group = Group.fetch(group_slave_id)

    if master_group is None:
        raise _errors.GroupError \
        (GROUP_REPLICATION_GROUP_NOT_FOUND_ERROR % (group_master_id, ))

    if slave_group is None:
        raise _errors.GroupError \
        (GROUP_REPLICATION_GROUP_NOT_FOUND_ERROR % (group_slave_id, ))

    slave_group_master = MySQLServer.fetch(slave_group.master)
    if slave_group_master is None:
        raise _errors.GroupError \
        (GROUP_REPLICATION_GROUP_MASTER_NOT_FOUND_ERROR %
          (slave_group.master, ))

    if not server_running(slave_group_master):
        #The server is already down. We cannot connect to it to stop
        #replication.
        return
    try:
        slave_group_master.connect()
    except _errors.DatabaseError:
        #Server is not accessible, unable to connect to the server.
        return

    #Stop replication on the master of the group and clear the references,
    #if clear_ref has been set.
    _replication.stop_slave(slave_group_master, wait=True)
    _replication.reset_slave(slave_group_master,  clean=True)
    if clear_ref:
        slave_group.remove_master_group_id()
        master_group.remove_slave_group_id(group_slave_id)
开发者ID:dzolnierz,项目名称:mysql-utilities,代码行数:51,代码来源:group_replication.py


注:本文中的mysql.fabric.server.MySQLServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。