global_lib api documentation

class global_lib.replica_engine(args)[source]

Bases: object

This class is wraps the the mysql and postgresql engines in order to perform the various activities required for the replica. The constructor inits the global configuration class and setup the mysql and postgresql engines as class objects. The class sets the logging using the configuration parameter.


The method adds a new replication source. A pre existence check is performed


The method calls init_replica adding a flag for skipping the data copy. Useful if we want to test for schema issues or to populate the schema preventively.


The method creates the replica schema in the destination database.


The method terminates the replica process. The source is removed from the table t_sources with all the associated data. The schema sequences in are reset to the max values in the corresponding tables, leaving the postgresql database as a standalone snapshot. The method creates the foreign keys existing in MySQL as well. Is compulsory to specify a source name when running this method.


The method removes the replica schema from the destination database.


The method removes a replication source from the catalogue.


The method resets the source status to stopped and disables any leftover maintenance mode


The method initialise a replica for a given source and configuration. It is compulsory to specify a source name when running this method. The method checks the source type and calls the corresponding initialisation’s method.


The method loads the configuration from the file specified in the args.config parameter.

read_replica(queue, log_read)[source]

The method reads the replica stream for the given source and stores the row images in the target postgresql database.


The method reload the data from a source and only for a specified schema. Is compulsory to specify a source name and an origin’s schema name. The schema mappings are honoured by the procedure automatically.

replay_replica(queue, log_replay)[source]

The method replays the row images stored in the target postgresql database.


The method runs a maintenance process on the target postgresql database specified in the given source.


The method loops the list self.conf_dirs creating them only if they are missing.

The method checks the freshness of the config-example.yaml and connection-example.yml copies the new version from the python library determined in the class constructor with get_python_lib().

If the configuration file is missing the method copies the file with a different message.


The method loads the current configuration and displays the status in tabular output


displays the error log entries if any. If the source the error log is filtered for this source only.


The method shows the sources available in the configuration file.


list the replica status from the replica catalogue. If the source is specified gives some extra details on the source status.


The method starts a new replica process. Is compulsory to specify a source name when running this method.


The method stops all the active replicas within the target database


The method calls the private method __stop_replica to stop the replica process.


The method reload the data from a source only for specified tables. Is compulsory to specify a source name and at least one table name when running this method. Multiple tables are allowed if comma separated.

terminate_replica(signal, frame)[source]

Stops gracefully the replica.


The method updates the schema mappings for the given source. The schema mappings is a configuration parameter but is stored in the replica catalogue when the source is added. If any change is made on the configuration file this method should be called to update the system catalogue as well. The pg_engine method checks for any conflict before running the update on the tables t_sources and t_replica_tables. Is compulsory to specify a source name when running this method.


The method upgrades an existing replica catalogue to the newer version. If the catalogue is from the previous version

class global_lib.rollbar_notifier(rollbar_key, rollbar_env, rollbar_level, logger)[source]

Bases: object

This class is used to send messages to rollbar whether the key and environment variables are set

send_message(message, level)[source]

The method sends a message to rollbar. If it fails it just logs an error without causing the process to crash.