本文整理汇总了Python中mysql.fabric.server.Group类的典型用法代码示例。如果您正苦于以下问题:Python Group类的具体用法?Python Group怎么用?Python Group使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Group类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _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
)
示例2: start_group_slaves
def start_group_slaves(master_group_id):
"""Start the slave groups for the given master group. The
method will be used in the events that requires, a group, that
has registered slaves to start them. An example would be
enable shard, enable shard requires that a group start all
the slaves that are registered with it.
:param master_group_id: The master group ID. The ID belongs to the master
whose slaves need to be started.
"""
# Fetch the master group corresponding to 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, ))
# Setup replication with masters of the groups registered as master
# groups. master_group.slave_group_ids contains the list of the group
# IDs that are slaves to this master. Iterate through this list and start
# replication with the registered slaves.
for slave_group_id in master_group.slave_group_ids:
slave_group = Group.fetch(slave_group_id)
# Setup replication with the slave group.
try:
setup_group_replication(master_group_id, slave_group.group_id)
except (_errors.GroupError, _errors.DatabaseError) as error:
_LOGGER.warning(
"Error while configuring group replication between "
"(%s) and (%s): (%s).", master_group_id, slave_group.group_id,
error
)
示例3: _lookup
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
示例4: _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
)
示例5: 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)
示例6: 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)
示例7: 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)
示例8: register_groups
def register_groups():
"""Upon startup initializes a failure detector for each group.
"""
from mysql.fabric.server import Group
_LOGGER.info("Starting failure detector.")
for row in Group.groups_by_status(Group.ACTIVE):
FailureDetector.register_group(row[0])
示例9: _restore_shard_backup
def _restore_shard_backup(shard_id, source_group_id, destn_group_id,
backup_image, split_value, prune_limit, cmd):
"""Restore the backup on the destination 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 destn_group_id: The ID of the group to which the shard needs to
be moved.
:param backup_image: The destination file that contains the backup
of the source shard.
: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
"""
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'
)
mysqlclient_binary = _services_utils.read_config_value(
_config.global_config,
'sharding',
'mysqlclient_program'
)
destn_group = Group.fetch(destn_group_id)
if destn_group is None:
raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND %
(destn_group_id, ))
#Build a backup image that will be used for restoring
bk_img = _backup.BackupImage(backup_image)
for destn_group_server in destn_group.servers():
destn_group_server.connect()
_backup.MySQLDump.restore_fabric_server(
destn_group_server,
restore_user, restore_passwd,
bk_img,
mysqlclient_binary
)
#Setup sync between the source and the destination groups.
_events.trigger_within_procedure(
SETUP_REPLICATION,
shard_id,
source_group_id,
destn_group_id,
split_value,
prune_limit,
cmd
)
示例10: stop_group_slaves
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
示例11: test_clone_from_group
def test_clone_from_group(self):
"""Verify the clone operation from a group.
"""
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.__group_1.master = self.__server_2.uuid
try:
status = self.proxy.server.clone("GROUPID1", self.__server_2.address,
str(self.__server_1.uuid))
raise Exception("Cloning to a server inside Fabric should "
"throw a fault")
except:
pass
try:
status = self.proxy.server.clone("GROUPID1", self.__server_2.address,
uuid_server3)
raise Exception("Cloning from a server outside the "
"source group should throw a fault")
except:
pass
status = self.proxy.server.clone("GROUPID1", self.__server_3.address,
None)
self.assertStatus(status, _executor.Job.SUCCESS)
self.assertEqual(status[1][-1]["state"], _executor.Job.COMPLETE)
self.assertEqual(status[1][-1]["description"],
"Executed action (_restore_server).")
rows = self.__server_3.exec_stmt(
"SELECT NAME FROM db1.t1",
{"fetch" : True})
self.assertEqual(len(rows), 2)
self.assertEqual(rows[0][0], 'TEST 1')
self.assertEqual(rows[1][0], 'TEST 2')
rows = self.__server_3.exec_stmt(
"SELECT NAME FROM db2.t1",
{"fetch" : True})
self.assertEqual(len(rows), 2)
self.assertEqual(rows[0][0], 'TEST 1')
self.assertEqual(rows[1][0], 'TEST 2')
示例12: _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
示例13: _backup_source_shard
def _backup_source_shard(shard_id, source_group_id, destn_group_id,
split_value, prune_limit, cmd, update_only):
"""Backup the source shard.
: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 (move, split)
:update_only: Only update the state store and skip provisioning.
"""
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'
)
mysqldump_binary = _services_utils.read_config_value(
_config.global_config,
'sharding',
'mysqldump_program'
)
source_group = Group.fetch(source_group_id)
move_source_server = _services_utils.fetch_backup_server(source_group)
#Do the backup of the group hosting the source shard.
backup_image = _backup.MySQLDump.backup(
move_source_server,
backup_user, backup_passwd,
mysqldump_binary
)
#Change the master for the server that is master of the group which hosts
#the destination shard.
_events.trigger_within_procedure(
RESTORE_SHARD_BACKUP,
shard_id,
source_group_id,
destn_group_id,
backup_image.path,
split_value,
prune_limit,
cmd
)
示例14: _backup_source_shard
def _backup_source_shard(shard_id, source_group_id, destn_group_id,
mysqldump_binary, mysqlclient_binary, split_value,
config_file, prune_limit, cmd, update_only):
"""Backup the source shard.
: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 mysqldump_binary: The fully qualified mysqldump binary.
:param mysqlclient_binary: The fully qualified mysql client binary.
: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 config_file: The complete path to the fabric configuration file.
:param prune_limit: The number of DELETEs that should be
done in one batch.
:param cmd: Indicates the type of re-sharding operation (move, split)
:update_only: Only update the state store and skip provisioning.
"""
source_group = Group.fetch(source_group_id)
move_source_server = _services_utils.fetch_backup_server(source_group)
#Do the backup of the group hosting the source shard.
backup_image = _backup.MySQLDump.backup(
move_source_server,
config_file,
mysqldump_binary
)
#Change the master for the server that is master of the group which hosts
#the destination shard.
_events.trigger_within_procedure(
RESTORE_SHARD_BACKUP,
shard_id,
source_group_id,
destn_group_id,
mysqlclient_binary,
backup_image.path,
split_value,
config_file,
prune_limit,
cmd
)
示例15: _restore_shard_backup
def _restore_shard_backup(shard_id, source_group_id, destn_group_id,
mysqlclient_binary, backup_image,
split_value, config_file, cmd):
"""Restore the backup on the destination 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 destn_group_id: The ID of the group to which the shard needs to
be moved.
:param mysqlclient_binary: The fully qualified mysqlclient binary.
:param backup_image: The destination file that contains the backup
of the source shard.
: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 config_file: The complete path to the fabric configuration file.
:param cmd: Indicates the type of re-sharding operation
"""
destn_group = Group.fetch(destn_group_id)
if destn_group is None:
raise _errors.ShardingError(_services_sharding.SHARD_GROUP_NOT_FOUND %
(destn_group_id, ))
#Build a backup image that will be used for restoring
bk_img = _backup.BackupImage(backup_image)
for destn_group_server in destn_group.servers():
destn_group_server.connect()
_backup.MySQLDump.restore_fabric_server(
destn_group_server,
bk_img,
config_file,
mysqlclient_binary
)
#Setup sync between the source and the destination groups.
_events.trigger_within_procedure(
SETUP_MOVE_SYNC,
shard_id,
source_group_id,
destn_group_id,
split_value,
cmd
)