mysql_legacy¶
MySQL shell module.
- exception spicerack.mysql_legacy.MysqlLegacyError[source]¶
Bases:
SpicerackError
Custom exception class for errors of this module.
- exception spicerack.mysql_legacy.MysqlLegacyReplagError[source]¶
Bases:
MysqlLegacyError
Custom exception class for errors related to replag in this module.
- class spicerack.mysql_legacy.Instance(host: spicerack.remote.RemoteHosts, *, name: str = '') None [source]¶
Bases:
object
Class to manage MariaDB single intances and multiinstances.
Initialize the instance.
- Parameters:
host (
spicerack.remote.RemoteHosts
) -- the RemoteHosts instance that contains this MariaDB SingleInstance.name (
str
, default:''
) -- the name of the instance in a multiinstance context. Leave it empty for single instances.
- clean_data_dir(*, skip_confirmation: bool = False) None [source]¶
Removes everything contained in the data directory.
- get_replication_info() spicerack.mysql_legacy.ReplicationInfo [source]¶
Get the replication information suitable to set a new node's replication.
- Return type:
- Returns:
The replication information object, useful to setup a new instance's replication to resume from the same position.
- post_clone_reset_with_slave_stopped() None [source]¶
Prepares the MySQL instance for the first pooling operation.
- Return type:
- prep_src_for_cloning() spicerack.mysql_legacy.ReplicationInfo [source]¶
Helper that prepares source instance to be cloned.
- Return type:
- Returns:
The replication information object, useful to setup a new instance's replication to resume from the same position.
- replication_lag() float [source]¶
Retrieves the current replication lag.
- Return type:
- Returns:
The replication lag in seconds.
- Raises:
spicerack.mysql_legacy.MysqlLegacyError -- if no lag information is present or unable to parse the it.
- restart_mysql() collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]] [source]¶
Restarts mariadb service.
- Return type:
collections.abc.Iterator
[tuple
[ClusterShell.NodeSet.NodeSet
,ClusterShell.MsgTree.MsgTreeElem
]]- Returns:
The results of the remote restart command.
- run_query(query: str, database: str = '', **kwargs: Any) Any [source]¶
Execute the query via Remote.
- Parameters:
query (
str
) -- the mysql query to be executed. Double quotes must be already escaped.database (
str
, default:''
) -- the optional database to use for the query execution.**kwargs (
typing.Any
) -- any additional argument is passed tospicerack.remote.RemoteHosts.run_sync()
. By default theprint_progress_bars
andprint_output
arguments are set toFalse
.
- Return type:
- Returns:
The result of the remote command execution.
- Raises:
spicerack.remote.RemoteExecutionError -- if the query execution via SSH returns a non-zero exit code.
- set_replication_parameters(*, replication_info: spicerack.mysql_legacy.ReplicationInfo, user: str, password: str) None [source]¶
Sets the replication parameters for the MySQL instance.
- Return type:
- show_slave_status() dict [source]¶
Returns the output of show slave status formatted as a dict.
- Return type:
- Returns:
the current slave status for the instance.
- start_mysql() collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]] [source]¶
Starts mariadb service.
- Return type:
collections.abc.Iterator
[tuple
[ClusterShell.NodeSet.NodeSet
,ClusterShell.MsgTree.MsgTreeElem
]]- Returns:
The results of the remote start command.
- status_mysql() collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]] [source]¶
Stops mariadb service.
- Return type:
collections.abc.Iterator
[tuple
[ClusterShell.NodeSet.NodeSet
,ClusterShell.MsgTree.MsgTreeElem
]]- Returns:
The results of the remote status command.
- stop_mysql() collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]] [source]¶
Stops mariadb service.
- Return type:
collections.abc.Iterator
[tuple
[ClusterShell.NodeSet.NodeSet
,ClusterShell.MsgTree.MsgTreeElem
]]- Returns:
The results of the remote status command.
- upgrade() collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]] [source]¶
Runs the relevant mysql_upgrade command to upgrade the instance content.
- Return type:
collections.abc.Iterator
[tuple
[ClusterShell.NodeSet.NodeSet
,ClusterShell.MsgTree.MsgTreeElem
]]- Returns:
The results of the remote upgrade command.
- wait_for_replication(threshold: float = 1.0) None [source]¶
Waits for replication to catch up.
- Parameters:
threshold (
float
, default:1.0
) -- the replication lag threshold in seconds under which the replication is considered in sync.- Raises:
spicerack.mysql_legacy.MysqlLegacyReplagError -- if the replication lag is still too high after all the retries.
- Return type:
- property primary: str¶
Retrieves the replication source of this cluster.
- Raises:
spicerack.mysql_legacy.MysqlLegacyError -- if unable to find the master host of the current instance.
- class spicerack.mysql_legacy.MysqlLegacy(remote: spicerack.remote.Remote, dry_run: bool = True) None [source]¶
Bases:
object
Class to manage MySQL servers.
Initialize the instance.
- Parameters:
remote (
spicerack.remote.Remote
) -- the Remote instance.dry_run (
bool
, default:True
) -- whether this is a DRY-RUN.
- check_core_masters_heartbeats(datacenter: str, heartbeat_dc: str, heartbeats: dict[str, datetime.datetime]) None [source]¶
Check the current heartbeat values in the core DB masters in DC are in sync with the provided heartbeats.
- Parameters:
datacenter (
str
) -- the name of the datacenter from where to get the heartbeat values.heartbeat_dc (
str
) -- the name of the datacenter for which to filter the heartbeat query.heartbeats (
dict
[str
,datetime.datetime
]) -- a dictionary with the section namestr
as keys and heartbeatdatetime.datetime
for each core section as values.
- Raises:
spicerack.mysql_legacy.MysqlLegacyError -- on failure to gather the heartbeat or convert it into a datetime.
- Return type:
- check_core_masters_in_sync(dc_from: str, dc_to: str) None [source]¶
Check that all core masters in dc_to are in sync with the core masters in dc_from.
- Parameters:
- Raises:
spicerack.remote.RemoteExecutionError -- on failure.
- Return type:
- get_core_dbs(*, datacenter: str | None = None, section: str | None = None, replication_role: str | None = None, excludes: tuple[str, ...] = ()) spicerack.mysql_legacy.MysqlLegacyRemoteHosts [source]¶
Get an instance to operated on the core databases matching the parameters.
- Parameters:
datacenter (
typing.Optional
[str
], default:None
) -- the name of the datacenter to filter for, accepted values are those specified inspicerack.constants.CORE_DATACENTERS
.replication_role (
typing.Optional
[str
], default:None
) -- the repication role to filter for, accepted values are those specified inspicerack.mysql_legacy.REPLICATION_ROLES
.section (
typing.Optional
[str
], default:None
) -- a specific section to filter for, accepted values are those specified inspicerack.mysql_legacy.CORE_SECTIONS
.excludes (
tuple
[str
,...
], default:()
) -- sections to exclude from getting.
- Raises:
spicerack.mysql_legacy.MysqlLegacyError -- on invalid data or unexpected matching hosts.
- Return type:
- get_core_masters_heartbeats(datacenter: str, heartbeat_dc: str) dict[str, datetime.datetime] [source]¶
Get the current heartbeat values from core DB masters in DC for a given heartbeat DC.
- Parameters:
- Return type:
- Returns:
A dictionary with the section name
str
as keys and their heartbeatdatetime.datetime
as values. For example:{'s1': datetime.datetime(2018, 1, 2, 11, 22, 33, 123456)}
- Raises:
spicerack.mysql_legacy.MysqlLegacyError -- on failure to gather the heartbeat or convert it into a datetime.
- get_dbs(query: str) spicerack.mysql_legacy.MysqlLegacyRemoteHosts [source]¶
Get a MysqlLegacyRemoteHosts instance for the matching hosts.
- Parameters:
query (
str
) -- the Remote query to use to fetch the DB hosts.- Return type:
- set_core_masters_readonly(datacenter: str) None [source]¶
Set the core masters in read-only.
- Parameters:
datacenter (
str
) -- the name of the datacenter to filter for.- Raises:
spicerack.remote.RemoteExecutionError -- on Remote failures.
spicerack.mysql_legacy.MysqlLegacyError -- on failing to verify the modified value.
- Return type:
- set_core_masters_readwrite(datacenter: str) None [source]¶
Set the core masters in read-write.
- Parameters:
datacenter (
str
) -- the name of the datacenter to filter for.- Raises:
spicerack.remote.RemoteExecutionError -- on Remote failures.
spicerack.mysql_legacy.MysqlLegacyError -- on failing to verify the modified value.
- Return type:
- class spicerack.mysql_legacy.MysqlLegacyRemoteHosts(remote_hosts: spicerack.remote.RemoteHosts) None [source]¶
Bases:
RemoteHostsAdapter
Custom RemoteHosts class for executing MySQL queries.
Initialize the instance.
- Parameters:
remote_hosts (
spicerack.remote.RemoteHosts
) -- the instance to act on the remote hosts.
- list_hosts_instances(*, group: bool = False) list[spicerack.mysql_legacy.Instance] [source]¶
List MariaDB instances on the host.
- Parameters:
group (
bool
, default:False
) -- not yet implemented feature to allow parallelization.- Raises:
spicerack.remote.RemoteExecutionError -- if the Cumin execution returns a non-zero exit code.
NotImplementedError -- if the replag is not fully caught on.
- Return type:
- run_query(query: str, database: str = '', **kwargs: Any) collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]] [source]¶
Execute the query via Remote.
- Parameters:
query (
str
) -- the mysql query to be executed. Double quotes must be already escaped.database (
str
, default:''
) -- an optional MySQL database to connect to before executing the query.**kwargs (
typing.Any
) -- any additional argument is passed tospicerack.remote.RemoteHosts.run_sync()
. By default theprint_progress_bars
andprint_output
arguments are set toFalse
.
- Raises:
spicerack.remote.RemoteExecutionError -- if the Cumin execution returns a non-zero exit code.
- Return type:
collections.abc.Iterator
[tuple
[ClusterShell.NodeSet.NodeSet
,ClusterShell.MsgTree.MsgTreeElem
]]
- class spicerack.mysql_legacy.ReplicationInfo(primary: str, binlog: str, position: int, port: int) None [source]¶
Bases:
object
Represent the minimum replication information needed to restore a replication from a given point.