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


Python MySQLServer.fetch方法代码示例

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


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

示例1: _setup_replication

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
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,代码行数:62,代码来源:resharding.py

示例2: _setup_sync

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
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,代码行数:57,代码来源:resharding.py

示例3: test_update_only

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
    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,代码行数:31,代码来源:test_shard_split.py

示例4: drop_shard_range_trigger

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
    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,代码行数:35,代码来源:shard_range_check_trigger.py

示例5: test_shard_split_fail_GTID_EXECUTED

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
 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,代码行数:31,代码来源:test_shard_split.py

示例6: test_shard_prune

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
    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,代码行数:48,代码来源:test_multiple_shard_indexes.py

示例7: _fetch_master_of_group

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
    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,代码行数:13,代码来源:shard_meta_data.py

示例8: stop_group_slave

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
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,代码行数:53,代码来源:group_replication.py

示例9: stop_group_slaves

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
def stop_group_slaves(master_group_id):
    """Stop the group slaves for the given master group. This will be used
    for use cases that required all the slaves replicating from this group to
    be stopped. An example use case would be disabling a shard.

    :param master_group_id: The master group ID.
    """
    master_group = Group.fetch(master_group_id)
    if master_group is None:
        raise _errors.GroupError \
        (GROUP_REPLICATION_GROUP_NOT_FOUND_ERROR % \
        (master_group_id, ))

    # Stop the replication on all of the registered slaves for the group.
    for slave_group_id in master_group.slave_group_ids:

        slave_group = Group.fetch(slave_group_id)
        # Fetch the Slave Group and the master of the Slave Group
        slave_group_master = MySQLServer.fetch(slave_group.master)
        if slave_group_master is None:
            _LOGGER.warning(
                GROUP_REPLICATION_GROUP_MASTER_NOT_FOUND_ERROR % \
                (slave_group.master, )
            )
            continue

        if not server_running(slave_group_master):
            # The server is already down. we cannot connect to it to stop
            # replication.
            continue

        try:
            slave_group_master.connect()
            _replication.stop_slave(slave_group_master, wait=True)
            # Reset the slave to remove the reference of the master so
            # that when the server is used as a slave next it does not
            # complaint about having a different master.
            _replication.reset_slave(slave_group_master, clean=True)
        except _errors.DatabaseError as error:
            # Server is not accessible, unable to connect to the server.
            _LOGGER.warning(
                "Error while unconfiguring group replication between "
                "(%s) and (%s): (%s).", master_group_id, slave_group.group_id,
                error
            )
            continue
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:48,代码来源:group_replication.py

示例10: add_shard_range_trigger

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
    def add_shard_range_trigger(group_id, sharding_type, table_name,
                                column_name):
        """Add a trigger on the shard table to ensure that values
        inserted fall within the valid shard ranges.

        :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()

        #Create an INSERT trigger on the sharded table.
        db, table = table_name.split(".")
        trigger_tmpl = _TRIGGER_DEFN[sharding_type]
        trigger_name = db + "." + _TRIGGER_PREFIX_INSERT + table
 
        create_insert_trigger = trigger_tmpl.format(
            trigger_name=trigger_name,
            operation="INSERT",
            table_name=table_name,
            column_name="NEW"+"."+column_name
        )
        master_server.exec_stmt(create_insert_trigger)

        #Create an UPDATE trigger on the sharded table.
        trigger_tmpl = _TRIGGER_DEFN[sharding_type]
        trigger_name = db + "." + _TRIGGER_PREFIX_UPDATE + table
        create_update_trigger =trigger_tmpl.format(
                trigger_name=trigger_name,
                operation="UPDATE",
                table_name=table_name,
                column_name="NEW"+"."+column_name
            )
        master_server.exec_stmt(create_update_trigger)
开发者ID:ioggstream,项目名称:mysql-utilities,代码行数:44,代码来源:shard_range_check_trigger.py

示例11: _setup_shard_switch_move

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
def _setup_shard_switch_move(shard_id,  source_group_id, destination_group_id,
                             update_only):
    """Setup the moved shard to map to the new group.

    :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 destination_group_id: The ID of the group to which the shard
                                needs to be moved.
    :update_only: Only update the state store and skip provisioning.
    """
    #Fetch the Range sharding specification. When we start implementing
    #heterogenous sharding schemes, we need to find out the type of
    #sharding scheme and we should use that to find out the sharding
    #implementation.
    _, source_shard,  _,  shard_mapping_defn = \
        _services_sharding._verify_and_fetch_shard(shard_id)

    #Setup replication between the shard group and the global group.
    _group_replication.setup_group_replication \
            (shard_mapping_defn[2],  destination_group_id)
    #set the shard to point to the new group.
    source_shard.group_id = destination_group_id
    #Stop the replication between the global server and the original
    #group associated with the shard.
    _group_replication.stop_group_slave\
            (shard_mapping_defn[2],  source_group_id,  True)

    #Reset the read only flag on the source server.
    source_group = Group.fetch(source_group_id)
    if source_group is None:
        raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND %
                                    (source_group_id, ))

    master = MySQLServer.fetch(source_group.master)
    if master is None:
        raise _errors.ShardingError(
            _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND)

    if not update_only:
        master.connect()
        master.read_only = False
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:43,代码来源:resharding.py

示例12: test_sync_readonly_servers

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
 def test_sync_readonly_servers(self):
     status = self.proxy.group.lookup_servers("GROUPID3")
     self.assertEqual(status[0], True)
     self.assertEqual(status[1], "")
     obtained_server_list = status[2]
     for idx in range(0, 2):
         if obtained_server_list[idx]["status"] == MySQLServer.SECONDARY:
             slave_uuid = obtained_server_list[idx]["server_uuid"]
             slave_server = MySQLServer.fetch(slave_uuid)
             slave_server.connect()
     _group_replication.setup_group_replication("GROUPID2", "GROUPID3")
     _replication.synchronize_with_read_only(
         slave_server, self.shard_server, 3, 5
     )
     _group_replication.stop_group_slave("GROUPID2", "GROUPID3", True)
     try:
         rows = self.shard_server.exec_stmt(
                             "SELECT NAME FROM db1.t1",
                             {"fetch" : True})
     except _errors.DatabaseError:
         raise Exception("Enable Shard failed to enable shard.")
     self.assertEqual(len(rows), 15)
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:24,代码来源:test_sync_read_only.py

示例13: _setup_move_sync

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
def _setup_move_sync(shard_id, source_group_id, destn_group_id, split_value,
                                        cmd):
    """Setup replication between the source and the destination groups and
    ensure that they are in sync.

    :param shard_id: The shard ID of the shard that needs to be moved.
    :param source_group_id: The group_id of the source shard.
    :param destn_group_id: The ID of the group to which the shard needs to
                           be moved.
    :param split_value: Indicates the value at which the range for the
                        particular shard will be split. Will be set only
                        for shard split operations.
    :param cmd: Indicates the type of re-sharding operation
    """
    source_group = Group.fetch(source_group_id)
    if source_group is None:
        raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND %
                                    (source_group_id, ))

    destination_group = Group.fetch(destn_group_id)
    if destination_group is None:
        raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND %
                                    (destination_group_id, ))

    master = MySQLServer.fetch(source_group.master)
    if master is None:
        raise _errors.ShardingError(
            _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND)
    master.connect()

    slave = MySQLServer.fetch(destination_group.master)
    if slave is None:
        raise _errors.ShardingError(
            _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND)
    slave.connect()

    #Stop and reset any slave that  might be running on the slave server.
    _replication.stop_slave(slave, wait=True)
    _replication.reset_slave(slave, clean=True)

    #Change the master to the shard group master.
    _replication.switch_master(slave,  master,  master. user,  master.passwd)

    #Start the slave so that syncing of the data begins
    _replication.start_slave(slave, wait=True)

    #Synchronize until the slave catches up with the master.
    _replication.synchronize_with_read_only(slave, master)

    #Reset replication once the syncing is done.
    _replication.stop_slave(slave, wait=True)
    _replication.reset_slave(slave, clean=True)

    #Trigger changing the mappings for the shard that was copied
    _events.trigger_within_procedure(
                                     SETUP_RESHARDING_SWITCH,
                                     shard_id,
                                     source_group_id,
                                     destn_group_id,
                                     split_value,
                                     cmd
                                     )
开发者ID:rockiebond,项目名称:mysql-fabric,代码行数:64,代码来源:resharding.py

示例14: _setup_shard_switch_move

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
def _setup_shard_switch_move(shard_id, source_group_id, destination_group_id,
                             update_only):
    """Setup the moved shard to map to the new group.

    :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 destination_group_id: The ID of the group to which the shard
                                needs to be moved.
    :update_only: Only update the state store and skip provisioning.
    """
    #Fetch the Range sharding specification. When we start implementing
    #heterogenous sharding schemes, we need to find out the type of
    #sharding scheme and we should use that to find out the sharding
    #implementation.
    _, source_shard, _, shard_mapping_defn = \
        _services_sharding.verify_and_fetch_shard(shard_id)

    destination_group = Group.fetch(destination_group_id)
    if destination_group is None:
        raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND %
                                    (destination_group_id, ))
    destn_group_master = MySQLServer.fetch(destination_group.master)
    if destn_group_master is None:
        raise _errors.ShardingError(
            _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND)
    destn_group_master.connect()
    #Set the destination group master to read_only
    destn_group_master.read_only = True

    #Setup replication between the shard group and the global group.
    _group_replication.setup_group_replication \
            (shard_mapping_defn[2], destination_group_id)
    #set the shard to point to the new group.
    source_shard.group_id = destination_group_id
    #Stop the replication between the global server and the original
    #group associated with the shard.
    _group_replication.stop_group_slave\
            (shard_mapping_defn[2], source_group_id,  True)

    #The sleep ensures that the connector have refreshed their caches with the
    #new shards that have been added as a result of the split.
    time.sleep(_utils.TTL)

    #Reset the read only flag on the source server.
    source_group = Group.fetch(source_group_id)
    if source_group is None:
        raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND %
                                    (source_group_id, ))

    master = MySQLServer.fetch(source_group.master)
    if master is None:
        raise _errors.ShardingError(
            _services_sharding.SHARD_GROUP_MASTER_NOT_FOUND)

    if not update_only:
        master.connect()
        master.read_only = False
        #Kill all the existing connections on the servers
        source_group.kill_connections_on_servers()
        #allow updates in the destination group master
        destn_group_master.read_only = False
开发者ID:mgsanusi,项目名称:DeepChrome,代码行数:63,代码来源:resharding.py

示例15: _check_shard_information

# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import fetch [as 别名]
def _check_shard_information(shard_id, destn_group_id,
                             split_value, prune_limit, cmd, update_only):
    """Verify the sharding information before starting a re-sharding operation.

    :param shard_id: The destination shard ID.
    :param destn_group_id: The Destination group ID.
    :param split_value: The point at which the sharding definition
                        should be split.
    :param prune_limit: The number of DELETEs that should be
                        done in one batch.
    :param cmd: Indicates if it is a split or a move being executed.
    :param update_only: If the operation is a update only operation.
    """
    backup_user = _services_utils.read_config_value(
                            _config.global_config,
                            'servers',
                            'backup_user'
                        )
    backup_passwd = _services_utils.read_config_value(
                            _config.global_config,
                            'servers',
                            'backup_password'
                        )
    restore_user = _services_utils.read_config_value(
                            _config.global_config,
                            'servers',
                            'restore_user'
                        )
    restore_passwd = _services_utils.read_config_value(
                            _config.global_config,
                            'servers',
                            'restore_password'
                        )
    mysqldump_binary = _services_utils.read_config_value(
                            _config.global_config,
                            'sharding',
                            'mysqldump_program'
                        )
    mysqlclient_binary = _services_utils.read_config_value(
                            _config.global_config,
                            'sharding',
                            'mysqlclient_program'
                        )

    if not _services_utils.is_valid_binary(mysqldump_binary):
        raise _errors.ShardingError(
                _services_sharding.MYSQLDUMP_NOT_FOUND % mysqldump_binary)

    if not _services_utils.is_valid_binary(mysqlclient_binary):
        raise _errors.ShardingError(
                _services_sharding.MYSQLCLIENT_NOT_FOUND % mysqlclient_binary)

    if cmd == "SPLIT":
        range_sharding_spec, _, shard_mappings, _ = \
            _services_sharding.verify_and_fetch_shard(shard_id)
        upper_bound = \
            SHARDING_SPECIFICATION_HANDLER[shard_mappings[0].type_name].\
                        get_upper_bound(
                            range_sharding_spec.lower_bound,
                            range_sharding_spec.shard_mapping_id,
                            shard_mappings[0].type_name
                          )
        #If the underlying sharding scheme is a HASH. When a shard is split,
        #all the tables that are part of the shard, have the same sharding
        #scheme. All the shard mappings associated with this shard_id will be
        #of the same sharding type. Hence it is safe to use one of the shard
        #mappings.
        if shard_mappings[0].type_name == "HASH":
            if split_value is not None:
                raise _errors.ShardingError(
                    _services_sharding.NO_LOWER_BOUND_FOR_HASH_SHARDING
                )
            if  upper_bound is None:
                #While splitting a range, retrieve the next upper bound and
                #find the mid-point, in the case where the next upper_bound
                #is unavailable pick the maximum value in the set of values in
                #the shard.
                upper_bound = HashShardingSpecification.fetch_max_key(shard_id)

            #Calculate the split value.
            split_value = \
                SHARDING_DATATYPE_HANDLER[shard_mappings[0].type_name].\
                split_value(
                    range_sharding_spec.lower_bound,
                    upper_bound
                )
        elif split_value is not None:
            if not (SHARDING_DATATYPE_HANDLER[shard_mappings[0].type_name].\
                    is_valid_split_value(
                        split_value, range_sharding_spec.lower_bound,
                        upper_bound
                    )
                ):
                raise _errors.ShardingError(
                    _services_sharding.INVALID_LOWER_BOUND_VALUE %
                    (split_value, )
                )
        elif split_value is None:
            raise _errors.ShardingError(
                _services_sharding.SPLIT_VALUE_NOT_DEFINED
#.........这里部分代码省略.........
开发者ID:dzolnierz,项目名称:mysql-utilities,代码行数:103,代码来源:resharding.py


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