Example #1
0
REPLICA_ROLE_SLAVE = 'slave'
REPLICA_TYPES = [REPLICA_ROLE_MASTER,
                 REPLICA_ROLE_SLAVE,
                 REPLICA_ROLE_DR_SLAVE]
TESTING_DATA_DIR = '/tmp/'
TESTING_PINFO_CLOUD = 'vagrant'

# /raid0 and /mnt are interchangable; use whichever one we have.
REQUIRED_MOUNTS = ['/raid0:/mnt']
SUPERVISOR_CMD = '/usr/local/bin/supervisorctl {action} mysql:mysqld-{port}'
INIT_CMD = '/etc/init.d/mysqld_multi {options} {action} {port}'
PTKILL_CMD = '/usr/sbin/service pt-kill-{port} {action}'
PTHEARTBEAT_CMD = '/usr/sbin/service pt-heartbeat-{port} {action}'
ZK_CACHE = [MYSQL_DS_ZK, MYSQL_DR_ZK, MYSQL_GEN_ZK]

log = environment_specific.setup_logging_defaults(__name__)


def take_flock_lock(file_name):
    """ Take a flock for throw an exception

    Args:
    file_name - The name of the file to flock

    Returns:
    file_handle - This will be passed to release_flock_lock for relase
    """
    success = False
    try:
        with timeout.timeout(1):
            file_handle = open(file_name, 'w')
Example #2
0
# Run pt-table-sync in read-only (print, verbose) mode to find the
# actual number of rows which differ between master and slave.
#
def checksum_tbl_via_sync(instance, db, tbl):
    username, password = mysql_lib.get_mysql_user_for_role('ptchecksum')
    cmd = (' '.join(('/usr/bin/pt-table-sync',
                     CHECKSUM_SYNC_DEFAULTS,
                     '--tables={db}.{tbl}',
                     '--user={username}',
                     '--password={password}',
                     'h={host},P={port}')).format(db=db,
                                                  tbl=tbl,
                                                  username=username,
                                                  password=password,
                                                  host=instance.hostname,
                                                  port=instance.port))

    out, err, ret = host_utils.shell_exec(cmd)

    diff_count = 0
    for line in out.split("\n"):
        diff_count += parse_sync_row(line)

    # strip out the password in case we are storing it in the DB.
    return cmd.replace(password, 'REDACTED'), out, err, ret, diff_count


if __name__ == "__main__":
    log = environment_specific.setup_logging_defaults(__name__)
    main()