Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1.   def _execute_via_pt_osc(self, alter_statement, task,
  2.       action=OnlineSchemaChangeActions.EXECUTE):
  3.     """Executes an ALTER TABLE statement via pt-osc.
  4.    """
  5.  
  6.     table, alter = _get_pt_osc_table_and_alter(alter_statement)
  7.     username, password = task.credentials
  8.  
  9.     pt_osc_command = [
  10.       'pt-online-schema-change',
  11.       '--{}'.format(action),
  12.       '--ask-pass',
  13.       '--alter={}'.format(alter),
  14.       '--user={}'.format(username),
  15.     ] + PT_OSC_DEFAULT_FLAGS + [
  16.       'h={0},D={1},t={2}'.format(task.database.cluster.get_master_hostname(),
  17.           task.database.name, table),
  18.     ]
  19.     log.info('Executing online schema change: %s', alter_statement)
  20.  
  21.     pt_osc_process = None
  22.     log_writer = LogWriter(log.info)
  23.     try:
  24.       log.info('Running command: %s', pt_osc_command)
  25.       pt_osc_env = os.environ.copy()
  26.  
  27.       # If we're using a Packer-provided percona-toolkit, we should annotate our env's
  28.       # paths to allow all Perl wrappers to link appropriately at runtime.
  29.       if config.USE_PERCONA_TOOLKIT_FROM_PACKER:
  30.         pt_library_paths = ':'.join(['./percona-toolkit/{}'.format(directory)
  31.           for directory in ['lib', 'lib64', 'usr/lib', 'usr/lib64']])
  32.         if 'LD_LIBRARY_PATH' not in pt_osc_env:
  33.           pt_osc_env['LD_LIBRARY_PATH'] = pt_library_paths
  34.         else:
  35.           pt_osc_env['LD_LIBRARY_PATH'] = ':'.join(
  36.               [pt_osc_env['LD_LIBRARY_PATH'], pt_library_paths])
  37.         pt_osc_env['PATH'] = ':'.join(['./percona-toolkit/usr/bin', pt_osc_env['PATH']])
  38.  
  39.       pt_osc_process = pexpect.pty_spawn.spawn(command='/usr/bin/env',
  40.           args=pt_osc_command, env=pt_osc_env)
  41.       pt_osc_process.logfile_read = log_writer
  42.       pt_osc_process.expect('Enter MySQL password: ')
  43.       pt_osc_process.sendline(password)
  44.       pt_osc_process.expect(pexpect.EOF)
  45.     finally:
  46.       if pt_osc_process is not None:
  47.         pt_osc_process.close()
  48.  
  49.     if pt_osc_process.exitstatus != 0:
  50.       self._add_result(task.id, text(alter_statement), (log_writer.all_output,))
  51.       raise OnlineSchemaChangeError(log_writer.all_output)
  52.     else:
  53.       log.info('Successfully executed online schema change: %s', alter_statement)
  54.       self._add_result(task.id, text(alter_statement), ('Statement completed successfully',))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement