示例#1
0
文件: tablet.py 项目: qinbo/vitess
  def start_vttablet(self, port=None, auth=False, memcache=False, wait_for_state="SERVING", customrules=None, schema_override=None, cert=None, key=None, ca_cert=None, repl_extra_flags={}):
    """
    Starts a vttablet process, and returns it.
    The process is also saved in self.proc, so it's easy to kill as well.
    """
    environment.prog_compile('vtaction')
    args = [environment.binary_path('vttablet'),
            '-port', '%s' % (port or self.port),
            '-tablet-path', self.tablet_alias,
            '-log_dir', environment.vtlogroot]
    args.extend(environment.topo_server_flags())
    args.extend(environment.binlog_player_protocol_flags())

    dbconfigs = self._get_db_configs_file(repl_extra_flags)
    for key1 in dbconfigs:
      for key2 in dbconfigs[key1]:
        args.extend(["-db-config-"+key1+"-"+key2, dbconfigs[key1][key2]])

    if memcache:
      if os.path.exists(environment.vtroot + "/bin/memcached"):
        args.extend(["-rowcache-bin", environment.vtroot + "/bin/memcached"])
      else:
        args.extend(["-rowcache-bin", "memcached"])
      memcache_socket = os.path.join(self.tablet_dir, "memcache.sock")
      args.extend(["-rowcache-socket", memcache_socket])
      args.extend(["-enable-rowcache"])

    if auth:
      args.extend(['-auth-credentials', os.path.join(environment.vttop, 'test', 'test_data', 'authcredentials_test.json')])

    if customrules:
      args.extend(['-customrules', customrules])

    if schema_override:
      args.extend(['-schema-override', schema_override])

    if cert:
      self.secure_port = environment.reserve_ports(1)
      args.extend(['-secure-port', '%s' % self.secure_port,
                   '-cert', cert,
                   '-key', key])
      if ca_cert:
        args.extend(['-ca-cert', ca_cert])

    stderr_fd = open(os.path.join(self.tablet_dir, "vttablet.stderr"), "w")
    # increment count only the first time
    if not self.proc:
      Tablet.tablets_running += 1
    self.proc = utils.run_bg(args, stderr=stderr_fd)
    stderr_fd.close()

    # wait for zookeeper PID just to be sure we have it
    if environment.topo_server_implementation == 'zookeeper':
      utils.run(environment.binary_path('zk')+' wait -e ' + self.zk_pid, stdout=utils.devnull)

    # wait for query service to be in the right state
    if wait_for_state:
      self.wait_for_vttablet_state(wait_for_state, port=port)

    return self.proc
示例#2
0
  def start_vttablet(self, port=None, auth=False, memcache=False, wait_for_state="SERVING", customrules=None, schema_override=None, cert=None, key=None, ca_cert=None, repl_extra_flags={}):
    """
    Starts a vttablet process, and returns it.
    The process is also saved in self.proc, so it's easy to kill as well.
    """
    environment.prog_compile('vtaction')
    args = [environment.binary_path('vttablet'),
            '-port', '%s' % (port or self.port),
            '-tablet-path', self.tablet_alias,
            '-log_dir', environment.vtlogroot]
    args.extend(environment.topo_server_flags())
    args.extend(utils.binlog_player_protocol_flags)

    dbconfigs = self._get_db_configs_file(repl_extra_flags)
    for key1 in dbconfigs:
      for key2 in dbconfigs[key1]:
        args.extend(["-db-config-"+key1+"-"+key2, dbconfigs[key1][key2]])

    if memcache:
      if os.path.exists(environment.vtroot + "/bin/memcached"):
        args.extend(["-rowcache-bin", environment.vtroot + "/bin/memcached"])
      else:
        args.extend(["-rowcache-bin", "memcached"])
      memcache_socket = os.path.join(self.tablet_dir, "memcache.sock")
      args.extend(["-rowcache-socket", memcache_socket])
      args.extend(["-enable-rowcache"])

    if auth:
      args.extend(['-auth-credentials', os.path.join(environment.vttop, 'test', 'test_data', 'authcredentials_test.json')])

    if customrules:
      args.extend(['-customrules', customrules])

    if schema_override:
      args.extend(['-schema-override', schema_override])

    if cert:
      self.secure_port = environment.reserve_ports(1)
      args.extend(['-secure-port', '%s' % self.secure_port,
                   '-cert', cert,
                   '-key', key])
      if ca_cert:
        args.extend(['-ca-cert', ca_cert])

    stderr_fd = open(os.path.join(self.tablet_dir, "vttablet.stderr"), "w")
    # increment count only the first time
    if not self.proc:
      Tablet.tablets_running += 1
    self.proc = utils.run_bg(args, stderr=stderr_fd)
    stderr_fd.close()

    # wait for zookeeper PID just to be sure we have it
    if environment.topo_server_implementation == 'zookeeper':
      utils.run(environment.binary_path('zk')+' wait -e ' + self.zk_pid, stdout=utils.devnull)

    # wait for query service to be in the right state
    if wait_for_state:
      self.wait_for_vttablet_state(wait_for_state, port=port)

    return self.proc
示例#3
0
  def _start_prog(self, binary, port=None, auth=False, memcache=False,
                  wait_for_state='SERVING', filecustomrules=None, zkcustomrules=None,
                  schema_override=None, cert=None, key=None, ca_cert=None,
                  repl_extra_flags={}, table_acl_config=None,
                  lameduck_period=None, security_policy=None,
                  extra_args=None, extra_env=None):
    environment.prog_compile(binary)
    args = environment.binary_args(binary)
    args.extend(['-port', '%s' % (port or self.port),
                 '-log_dir', environment.vtlogroot])

    self._add_dbconfigs(args, repl_extra_flags)

    if memcache:
      args.extend(['-rowcache-bin', environment.memcached_bin()])
      memcache_socket = os.path.join(self.tablet_dir, 'memcache.sock')
      args.extend(['-rowcache-socket', memcache_socket])
      args.extend(['-enable-rowcache'])

    if auth:
      args.extend(
          ['-auth-credentials',
           os.path.join(
               environment.vttop, 'test', 'test_data',
               'authcredentials_test.json')])

    if filecustomrules:
      args.extend(['-filecustomrules', filecustomrules])
    if zkcustomrules:
      args.extend(['-zkcustomrules', zkcustomrules])

    if schema_override:
      args.extend(['-schema-override', schema_override])

    if table_acl_config:
      args.extend(['-table-acl-config', table_acl_config])
      args.extend(['-queryserver-config-strict-table-acl'])

    if cert:
      self.secure_port = environment.reserve_ports(1)
      args.extend(['-secure-port', '%s' % self.secure_port,
                   '-cert', cert,
                   '-key', key])
      if ca_cert:
        args.extend(['-ca_cert', ca_cert])
    if protocols_flavor().service_map():
      args.extend(['-service_map', ",".join(protocols_flavor().service_map())])
    if self.grpc_enabled():
      args.extend(['-grpc_port', str(self.grpc_port)])
    if lameduck_period:
      args.extend(['-lameduck-period', lameduck_period])
    if security_policy:
      args.extend(['-security_policy', security_policy])
    if extra_args:
      args.extend(extra_args)

    args.extend(['-enable-autocommit'])
    stderr_fd = open(os.path.join(environment.vtlogroot, '%s-%d.stderr' % (binary, self.tablet_uid)), 'w')
    # increment count only the first time
    if not self.proc:
      Tablet.tablets_running += 1
    self.proc = utils.run_bg(args, stderr=stderr_fd, extra_env=extra_env)
    stderr_fd.close()

    # wait for query service to be in the right state
    if wait_for_state:
      if binary == 'vttablet':
        self.wait_for_vttablet_state(wait_for_state, port=port)
      else:
        self.wait_for_vtocc_state(wait_for_state, port=port)

    return self.proc
示例#4
0
    def _start_prog(
        self,
        binary,
        port=None,
        auth=False,
        memcache=False,
        wait_for_state="SERVING",
        filecustomrules=None,
        zkcustomrules=None,
        schema_override=None,
        repl_extra_flags={},
        table_acl_config=None,
        lameduck_period=None,
        security_policy=None,
        extra_args=None,
        extra_env=None,
    ):
        environment.prog_compile(binary)
        args = environment.binary_args(binary)
        args.extend(["-port", "%s" % (port or self.port), "-log_dir", environment.vtlogroot])

        self._add_dbconfigs(args, repl_extra_flags)

        if memcache:
            args.extend(["-rowcache-bin", environment.memcached_bin()])
            memcache_socket = os.path.join(self.tablet_dir, "memcache.sock")
            args.extend(["-rowcache-socket", memcache_socket])
            args.extend(["-enable-rowcache"])

        if auth:
            args.extend(
                ["-auth-credentials", os.path.join(environment.vttop, "test", "test_data", "authcredentials_test.json")]
            )

        if filecustomrules:
            args.extend(["-filecustomrules", filecustomrules])
        if zkcustomrules:
            args.extend(["-zkcustomrules", zkcustomrules])

        if schema_override:
            args.extend(["-schema-override", schema_override])

        if table_acl_config:
            args.extend(["-table-acl-config", table_acl_config])
            args.extend(["-queryserver-config-strict-table-acl"])

        if protocols_flavor().service_map():
            args.extend(["-service_map", ",".join(protocols_flavor().service_map())])
        if self.grpc_enabled():
            args.extend(["-grpc_port", str(self.grpc_port)])
        if lameduck_period:
            args.extend(["-lameduck-period", lameduck_period])
        if security_policy:
            args.extend(["-security_policy", security_policy])
        if extra_args:
            args.extend(extra_args)

        args.extend(["-enable-autocommit"])
        stderr_fd = open(os.path.join(environment.vtlogroot, "%s-%d.stderr" % (binary, self.tablet_uid)), "w")
        # increment count only the first time
        if not self.proc:
            Tablet.tablets_running += 1
        self.proc = utils.run_bg(args, stderr=stderr_fd, extra_env=extra_env)

        log_message = (
            "Started vttablet: %s (%s) with pid: %s - Log files: %s/vttablet.*.{INFO,WARNING,ERROR,FATAL}.*.%s"
            % (self.tablet_uid, self.tablet_alias, self.proc.pid, environment.vtlogroot, self.proc.pid)
        )
        # This may race with the stderr output from the process (though that's usually empty).
        stderr_fd.write(log_message + "\n")
        stderr_fd.close()
        logging.debug(log_message)

        # wait for query service to be in the right state
        if wait_for_state:
            if binary == "vttablet":
                self.wait_for_vttablet_state(wait_for_state, port=port)
            else:
                self.wait_for_vtocc_state(wait_for_state, port=port)

        return self.proc
示例#5
0
文件: tablet.py 项目: miffa/vitess
    def _start_prog(self,
                    binary,
                    port=None,
                    auth=False,
                    memcache=False,
                    wait_for_state='SERVING',
                    customrules=None,
                    schema_override=None,
                    cert=None,
                    key=None,
                    ca_cert=None,
                    repl_extra_flags={},
                    table_acl_config=None,
                    lameduck_period=None,
                    security_policy=None,
                    extra_args=None,
                    extra_env=None):
        environment.prog_compile(binary)
        args = environment.binary_args(binary)
        args.extend([
            '-port',
            '%s' % (port or self.port), '-log_dir', environment.vtlogroot
        ])

        dbconfigs = self._get_db_configs_file(repl_extra_flags)
        for key1 in dbconfigs:
            for key2 in dbconfigs[key1]:
                args.extend(
                    ['-db-config-' + key1 + '-' + key2, dbconfigs[key1][key2]])

        if memcache:
            args.extend(['-rowcache-bin', environment.memcached_bin()])
            memcache_socket = os.path.join(self.tablet_dir, 'memcache.sock')
            args.extend(['-rowcache-socket', memcache_socket])
            args.extend(['-enable-rowcache'])

        if auth:
            args.extend([
                '-auth-credentials',
                os.path.join(environment.vttop, 'test', 'test_data',
                             'authcredentials_test.json')
            ])

        if customrules:
            args.extend(['-customrules', customrules])

        if schema_override:
            args.extend(['-schema-override', schema_override])

        if table_acl_config:
            args.extend(['-table-acl-config', table_acl_config])
            args.extend(['-queryserver-config-strict-table-acl'])

        if cert:
            self.secure_port = environment.reserve_ports(1)
            args.extend([
                '-secure-port',
                '%s' % self.secure_port, '-cert', cert, '-key', key
            ])
            if ca_cert:
                args.extend(['-ca_cert', ca_cert])
        if lameduck_period:
            args.extend(['-lameduck-period', lameduck_period])
        if security_policy:
            args.extend(['-security_policy', security_policy])
        if extra_args:
            args.extend(extra_args)

        stderr_fd = open(os.path.join(self.tablet_dir, '%s.stderr' % binary),
                         'w')
        # increment count only the first time
        if not self.proc:
            Tablet.tablets_running += 1
        self.proc = utils.run_bg(args, stderr=stderr_fd, extra_env=extra_env)
        stderr_fd.close()

        # wait for query service to be in the right state
        if wait_for_state:
            if binary == 'vttablet':
                self.wait_for_vttablet_state(wait_for_state, port=port)
            else:
                self.wait_for_vtocc_state(wait_for_state, port=port)

        return self.proc
示例#6
0
文件: tablet.py 项目: cgvarela/vitess
  def _start_prog(
      self, binary, port=None, auth=False, memcache=False,
      wait_for_state='SERVING', filecustomrules=None, zkcustomrules=None,
      schema_override=None,
      repl_extra_flags=None, table_acl_config=None,
      lameduck_period=None, security_policy=None,
      extra_args=None, extra_env=None):
    if repl_extra_flags is None:
      repl_extra_flags = {}
    environment.prog_compile(binary)
    args = environment.binary_args(binary)
    args.extend(['-port', '%s' % (port or self.port),
                 '-log_dir', environment.vtlogroot])

    self._add_dbconfigs(args, repl_extra_flags)

    if memcache:
      args.extend(['-rowcache-bin', environment.memcached_bin()])
      memcache_socket = os.path.join(self.tablet_dir, 'memcache.sock')
      args.extend(['-rowcache-socket', memcache_socket])
      args.extend(['-enable-rowcache'])

    if auth:
      args.extend(
          ['-auth-credentials',
           os.path.join(
               environment.vttop, 'test', 'test_data',
               'authcredentials_test.json')])

    if filecustomrules:
      args.extend(['-filecustomrules', filecustomrules])
    if zkcustomrules:
      args.extend(['-zkcustomrules', zkcustomrules])

    if schema_override:
      args.extend(['-schema-override', schema_override])

    if table_acl_config:
      args.extend(['-table-acl-config', table_acl_config])
      args.extend(['-queryserver-config-strict-table-acl'])

    if protocols_flavor().service_map():
      args.extend(['-service_map', ','.join(protocols_flavor().service_map())])
    if self.grpc_enabled():
      args.extend(['-grpc_port', str(self.grpc_port)])
    if lameduck_period:
      args.extend(['-lameduck-period', lameduck_period])
    if security_policy:
      args.extend(['-security_policy', security_policy])
    if extra_args:
      args.extend(extra_args)

    args.extend(['-enable-autocommit'])
    stderr_fd = open(
        os.path.join(environment.vtlogroot, '%s-%d.stderr' %
                     (binary, self.tablet_uid)), 'w')
    # increment count only the first time
    if not self.proc:
      Tablet.tablets_running += 1
    self.proc = utils.run_bg(args, stderr=stderr_fd, extra_env=extra_env)

    log_message = (
        'Started vttablet: %s (%s) with pid: %s - Log files: '
        '%s/vttablet.*.{INFO,WARNING,ERROR,FATAL}.*.%s' %
        (self.tablet_uid, self.tablet_alias, self.proc.pid,
         environment.vtlogroot, self.proc.pid))
    # This may race with the stderr output from the process (though
    # that's usually empty).
    stderr_fd.write(log_message + '\n')
    stderr_fd.close()
    logging.debug(log_message)

    # wait for query service to be in the right state
    if wait_for_state:
      if binary == 'vttablet':
        self.wait_for_vttablet_state(wait_for_state, port=port)
      else:
        self.wait_for_vtocc_state(wait_for_state, port=port)

    return self.proc
示例#7
0
    def start_vttablet(self,
                       port=None,
                       auth=False,
                       memcache=False,
                       wait_for_state="SERVING",
                       customrules=None,
                       schema_override=None,
                       cert=None,
                       key=None,
                       ca_cert=None,
                       repl_extra_flags={},
                       sensitive_mode=False,
                       target_tablet_type=None,
                       lameduck_period=None,
                       extra_args=None,
                       full_mycnf_args=False,
                       security_policy=None):
        """
    Starts a vttablet process, and returns it.
    The process is also saved in self.proc, so it's easy to kill as well.
    """
        environment.prog_compile('vtaction')
        args = [
            environment.binary_path('vttablet'), '-port',
            '%s' % (port or self.port), '-tablet-path', self.tablet_alias,
            '-log_dir', environment.vtlogroot
        ]
        args.extend(environment.topo_server_flags())
        args.extend(utils.binlog_player_protocol_flags)

        dbconfigs = self._get_db_configs_file(repl_extra_flags)
        for key1 in dbconfigs:
            for key2 in dbconfigs[key1]:
                args.extend(
                    ["-db-config-" + key1 + "-" + key2, dbconfigs[key1][key2]])

        if full_mycnf_args:
            # this flag is used to specify all the mycnf_ flags, to make
            # sure that code works and can fork actions.
            relay_log_path = os.path.join(
                self.tablet_dir, "relay-logs",
                "vt-%010d-relay-bin" % self.tablet_uid)
            args.extend([
                "-mycnf_server_id",
                str(self.tablet_uid),
                "-mycnf_mysql_port",
                str(self.mysql_port),
                "-mycnf_data_dir",
                os.path.join(self.tablet_dir, "data"),
                "-mycnf_innodb_data_home_dir",
                os.path.join(self.tablet_dir, "innodb", "data"),
                "-mycnf_innodb_log_group_home_dir",
                os.path.join(self.tablet_dir, "innodb", "logs"),
                "-mycnf_socket_file",
                os.path.join(self.tablet_dir, "mysql.sock"),
                "-mycnf_error_log_path",
                os.path.join(self.tablet_dir, "error.log"),
                "-mycnf_slow_log_path",
                os.path.join(self.tablet_dir, "slow-query.log"),
                "-mycnf_relay_log_path",
                relay_log_path,
                "-mycnf_relay_log_index_path",
                relay_log_path + ".index",
                "-mycnf_relay_log_info_path",
                os.path.join(self.tablet_dir, "relay-logs", "relay-log.info"),
                "-mycnf_bin_log_path",
                os.path.join(self.tablet_dir, "bin-logs",
                             "vt-%010d-bin" % self.tablet_uid),
                "-mycnf_master_info_file",
                os.path.join(self.tablet_dir, "master.info"),
                "-mycnf_pid_file",
                os.path.join(self.tablet_dir, "mysql.pid"),
                "-mycnf_tmp_dir",
                os.path.join(self.tablet_dir, "tmp"),
                "-mycnf_slave_load_tmp_dir",
                os.path.join(self.tablet_dir, "tmp"),
            ])

        if memcache:
            args.extend(["-rowcache-bin", environment.memcached_bin()])
            memcache_socket = os.path.join(self.tablet_dir, "memcache.sock")
            args.extend(["-rowcache-socket", memcache_socket])
            args.extend(["-enable-rowcache"])

        if auth:
            args.extend([
                '-auth-credentials',
                os.path.join(environment.vttop, 'test', 'test_data',
                             'authcredentials_test.json')
            ])

        if customrules:
            args.extend(['-customrules', customrules])

        if schema_override:
            args.extend(['-schema-override', schema_override])

        if cert:
            self.secure_port = environment.reserve_ports(1)
            args.extend([
                '-secure-port',
                '%s' % self.secure_port, '-cert', cert, '-key', key
            ])
            if ca_cert:
                args.extend(['-ca_cert', ca_cert])
        if sensitive_mode:
            args.extend(['-queryserver-config-sensitive-mode'])
        if target_tablet_type:
            args.extend([
                '-target_tablet_type', target_tablet_type,
                '-health_check_interval', '2s', '-allowed_replication_lag',
                '30'
            ])
        if lameduck_period:
            args.extend(['-lameduck-period', lameduck_period])
        if extra_args:
            args.extend(extra_args)
        if security_policy:
            args.extend(['-security_policy', security_policy])

        stderr_fd = open(os.path.join(self.tablet_dir, "vttablet.stderr"), "w")
        # increment count only the first time
        if not self.proc:
            Tablet.tablets_running += 1
        self.proc = utils.run_bg(args, stderr=stderr_fd)
        stderr_fd.close()

        # wait for zookeeper PID just to be sure we have it
        if environment.topo_server_implementation == 'zookeeper':
            utils.run(environment.binary_path('zk') + ' wait -e ' +
                      self.zk_pid,
                      stdout=utils.devnull)

        # wait for query service to be in the right state
        if wait_for_state:
            self.wait_for_vttablet_state(wait_for_state, port=port)

        return self.proc
示例#8
0
文件: tablet.py 项目: acid009/vitess
  def start_vttablet(self, port=None, auth=False, memcache=False,
                     wait_for_state="SERVING", customrules=None,
                     schema_override=None, cert=None, key=None, ca_cert=None,
                     repl_extra_flags={}, sensitive_mode=False,
                     target_tablet_type=None, lameduck_period=None,
                     extra_args=None, full_mycnf_args=False,
                     security_policy=None):
    """
    Starts a vttablet process, and returns it.
    The process is also saved in self.proc, so it's easy to kill as well.
    """
    environment.prog_compile('vtaction')
    args = [environment.binary_path('vttablet'),
            '-port', '%s' % (port or self.port),
            '-tablet-path', self.tablet_alias,
            '-log_dir', environment.vtlogroot]
    args.extend(environment.topo_server_flags())
    args.extend(utils.binlog_player_protocol_flags)

    dbconfigs = self._get_db_configs_file(repl_extra_flags)
    for key1 in dbconfigs:
      for key2 in dbconfigs[key1]:
        args.extend(["-db-config-"+key1+"-"+key2, dbconfigs[key1][key2]])

    if full_mycnf_args:
      # this flag is used to specify all the mycnf_ flags, to make
      # sure that code works and can fork actions.
      relay_log_path = os.path.join(self.tablet_dir, "relay-logs",
                                    "vt-%010d-relay-bin" % self.tablet_uid)
      args.extend([
          "-mycnf_server_id", str(self.tablet_uid),
          "-mycnf_mysql_port", str(self.mysql_port),
          "-mycnf_data_dir", os.path.join(self.tablet_dir, "data"),
          "-mycnf_innodb_data_home_dir", os.path.join(self.tablet_dir,
                                                      "innodb", "data"),
          "-mycnf_innodb_log_group_home_dir", os.path.join(self.tablet_dir,
                                                           "innodb", "logs"),
          "-mycnf_socket_file", os.path.join(self.tablet_dir, "mysql.sock"),
          "-mycnf_error_log_path", os.path.join(self.tablet_dir, "error.log"),
          "-mycnf_slow_log_path", os.path.join(self.tablet_dir,
                                               "slow-query.log"),
          "-mycnf_relay_log_path", relay_log_path,
          "-mycnf_relay_log_index_path", relay_log_path + ".index",
          "-mycnf_relay_log_info_path", os.path.join(self.tablet_dir,
                                                     "relay-logs",
                                                     "relay-log.info"),
          "-mycnf_bin_log_path", os.path.join(self.tablet_dir, "bin-logs",
                                              "vt-%010d-bin" % self.tablet_uid),
          "-mycnf_master_info_file", os.path.join(self.tablet_dir,
                                                  "master.info"),
          "-mycnf_pid_file", os.path.join(self.tablet_dir, "mysql.pid"),
          "-mycnf_tmp_dir", os.path.join(self.tablet_dir, "tmp"),
          "-mycnf_slave_load_tmp_dir", os.path.join(self.tablet_dir, "tmp"),
          ])

    if memcache:
      args.extend(["-rowcache-bin", environment.memcached_bin()])
      memcache_socket = os.path.join(self.tablet_dir, "memcache.sock")
      args.extend(["-rowcache-socket", memcache_socket])
      args.extend(["-enable-rowcache"])

    if auth:
      args.extend(['-auth-credentials', os.path.join(environment.vttop, 'test', 'test_data', 'authcredentials_test.json')])

    if customrules:
      args.extend(['-customrules', customrules])

    if schema_override:
      args.extend(['-schema-override', schema_override])

    if cert:
      self.secure_port = environment.reserve_ports(1)
      args.extend(['-secure-port', '%s' % self.secure_port,
                   '-cert', cert,
                   '-key', key])
      if ca_cert:
        args.extend(['-ca_cert', ca_cert])
    if sensitive_mode:
      args.extend(['-queryserver-config-sensitive-mode'])
    if target_tablet_type:
      args.extend(['-target_tablet_type', target_tablet_type,
                   '-health_check_interval', '2s',
                   '-allowed_replication_lag', '30'])
    if lameduck_period:
      args.extend(['-lameduck-period', lameduck_period])
    if extra_args:
      args.extend(extra_args)
    if security_policy:
      args.extend(['-security_policy', security_policy])

    stderr_fd = open(os.path.join(self.tablet_dir, "vttablet.stderr"), "w")
    # increment count only the first time
    if not self.proc:
      Tablet.tablets_running += 1
    self.proc = utils.run_bg(args, stderr=stderr_fd)
    stderr_fd.close()

    # wait for zookeeper PID just to be sure we have it
    if environment.topo_server_implementation == 'zookeeper':
      utils.run(environment.binary_path('zk')+' wait -e ' + self.zk_pid, stdout=utils.devnull)

    # wait for query service to be in the right state
    if wait_for_state:
      self.wait_for_vttablet_state(wait_for_state, port=port)

    return self.proc
示例#9
0
文件: tablet.py 项目: zhzhy917/vitess
    def _start_prog(self,
                    binary,
                    port=None,
                    auth=False,
                    memcache=False,
                    wait_for_state='SERVING',
                    filecustomrules=None,
                    zkcustomrules=None,
                    schema_override=None,
                    cert=None,
                    key=None,
                    ca_cert=None,
                    repl_extra_flags={},
                    table_acl_config=None,
                    lameduck_period=None,
                    security_policy=None,
                    extra_args=None,
                    extra_env=None):
        environment.prog_compile(binary)
        args = environment.binary_args(binary)
        args.extend([
            '-port',
            '%s' % (port or self.port), '-log_dir', environment.vtlogroot
        ])

        self._add_dbconfigs(args, repl_extra_flags)

        if memcache:
            args.extend(['-rowcache-bin', environment.memcached_bin()])
            memcache_socket = os.path.join(self.tablet_dir, 'memcache.sock')
            args.extend(['-rowcache-socket', memcache_socket])
            args.extend(['-enable-rowcache'])

        if auth:
            args.extend([
                '-auth-credentials',
                os.path.join(environment.vttop, 'test', 'test_data',
                             'authcredentials_test.json')
            ])

        if filecustomrules:
            args.extend(['-filecustomrules', filecustomrules])
        if zkcustomrules:
            args.extend(['-zkcustomrules', zkcustomrules])

        if schema_override:
            args.extend(['-schema-override', schema_override])

        if table_acl_config:
            args.extend(['-table-acl-config', table_acl_config])
            args.extend(['-queryserver-config-strict-table-acl'])

        if cert:
            self.secure_port = environment.reserve_ports(1)
            args.extend([
                '-secure-port',
                '%s' % self.secure_port, '-cert', cert, '-key', key
            ])
            if ca_cert:
                args.extend(['-ca_cert', ca_cert])
        if protocols_flavor().service_map():
            args.extend(
                ['-service_map', ",".join(protocols_flavor().service_map())])
        if self.grpc_enabled():
            args.extend(['-grpc_port', str(self.grpc_port)])
        if lameduck_period:
            args.extend(['-lameduck-period', lameduck_period])
        if security_policy:
            args.extend(['-security_policy', security_policy])
        if extra_args:
            args.extend(extra_args)

        args.extend(['-enable-autocommit'])
        stderr_fd = open(
            os.path.join(environment.vtlogroot,
                         '%s-%d.stderr' % (binary, self.tablet_uid)), 'w')
        # increment count only the first time
        if not self.proc:
            Tablet.tablets_running += 1
        self.proc = utils.run_bg(args, stderr=stderr_fd, extra_env=extra_env)

        log_message = "Started vttablet: %s (%s) with pid: %s - Log files: %s/vttablet.*.{INFO,WARNING,ERROR,FATAL}.*.%s" % \
            (self.tablet_uid, self.tablet_alias, self.proc.pid, environment.vtlogroot, self.proc.pid)
        # This may race with the stderr output from the process (though that's usually empty).
        stderr_fd.write(log_message + '\n')
        stderr_fd.close()
        logging.debug(log_message)

        # wait for query service to be in the right state
        if wait_for_state:
            if binary == 'vttablet':
                self.wait_for_vttablet_state(wait_for_state, port=port)
            else:
                self.wait_for_vtocc_state(wait_for_state, port=port)

        return self.proc
示例#10
0
    def start_vttablet(self,
                       port=None,
                       auth=False,
                       memcache=False,
                       wait_for_state='SERVING',
                       customrules=None,
                       schema_override=None,
                       cert=None,
                       key=None,
                       ca_cert=None,
                       repl_extra_flags={},
                       table_acl_config=None,
                       lameduck_period=None,
                       security_policy=None,
                       target_tablet_type=None,
                       full_mycnf_args=False,
                       extra_args=None,
                       include_mysql_port=True):
        """Starts a vttablet process, and returns it.

    The process is also saved in self.proc, so it's easy to kill as well.
    """
        environment.prog_compile('vtaction')
        args = []
        args.extend(['-tablet-path', self.tablet_alias])
        args.extend(environment.topo_server_flags())
        args.extend(utils.binlog_player_protocol_flags)
        args.extend(environment.tablet_manager_protocol_flags())

        if full_mycnf_args:
            # this flag is used to specify all the mycnf_ flags, to make
            # sure that code works and can fork actions.
            relay_log_path = os.path.join(
                self.tablet_dir, 'relay-logs',
                'vt-%010d-relay-bin' % self.tablet_uid)
            args.extend([
                '-mycnf_server_id',
                str(self.tablet_uid),
                '-mycnf_data_dir',
                os.path.join(self.tablet_dir, 'data'),
                '-mycnf_innodb_data_home_dir',
                os.path.join(self.tablet_dir, 'innodb', 'data'),
                '-mycnf_innodb_log_group_home_dir',
                os.path.join(self.tablet_dir, 'innodb', 'logs'),
                '-mycnf_socket_file',
                os.path.join(self.tablet_dir, 'mysql.sock'),
                '-mycnf_error_log_path',
                os.path.join(self.tablet_dir, 'error.log'),
                '-mycnf_slow_log_path',
                os.path.join(self.tablet_dir, 'slow-query.log'),
                '-mycnf_relay_log_path',
                relay_log_path,
                '-mycnf_relay_log_index_path',
                relay_log_path + '.index',
                '-mycnf_relay_log_info_path',
                os.path.join(self.tablet_dir, 'relay-logs', 'relay-log.info'),
                '-mycnf_bin_log_path',
                os.path.join(self.tablet_dir, 'bin-logs',
                             'vt-%010d-bin' % self.tablet_uid),
                '-mycnf_master_info_file',
                os.path.join(self.tablet_dir, 'master.info'),
                '-mycnf_pid_file',
                os.path.join(self.tablet_dir, 'mysql.pid'),
                '-mycnf_tmp_dir',
                os.path.join(self.tablet_dir, 'tmp'),
                '-mycnf_slave_load_tmp_dir',
                os.path.join(self.tablet_dir, 'tmp'),
            ])
            if include_mysql_port:
                args.extend(['-mycnf_mysql_port', str(self.mysql_port)])
        if target_tablet_type:
            args.extend([
                '-target_tablet_type', target_tablet_type,
                '-health_check_interval', '2s', '-allowed_replication_lag',
                '30'
            ])

        if extra_args:
            args.extend(extra_args)

        return self._start_prog(binary='vttablet',
                                port=port,
                                auth=auth,
                                memcache=memcache,
                                wait_for_state=wait_for_state,
                                customrules=customrules,
                                schema_override=schema_override,
                                cert=cert,
                                key=key,
                                ca_cert=ca_cert,
                                repl_extra_flags=repl_extra_flags,
                                table_acl_config=table_acl_config,
                                lameduck_period=lameduck_period,
                                extra_args=args,
                                security_policy=security_policy)
示例#11
0
  def start_vttablet(self, port=None, auth=False, memcache=False,
                     wait_for_state='SERVING', customrules=None,
                     schema_override=None, cert=None, key=None, ca_cert=None,
                     repl_extra_flags={}, table_acl_config=None,
                     lameduck_period=None, security_policy=None,
                     target_tablet_type=None, full_mycnf_args=False,
                     extra_args=None, include_mysql_port=True):
    """Starts a vttablet process, and returns it.

    The process is also saved in self.proc, so it's easy to kill as well.
    """
    environment.prog_compile('vtaction')
    args = []
    args.extend(['-tablet-path', self.tablet_alias])
    args.extend(environment.topo_server_flags())
    args.extend(utils.binlog_player_protocol_flags)
    args.extend(environment.tablet_manager_protocol_flags())

    if full_mycnf_args:
      # this flag is used to specify all the mycnf_ flags, to make
      # sure that code works and can fork actions.
      relay_log_path = os.path.join(self.tablet_dir, 'relay-logs',
                                    'vt-%010d-relay-bin' % self.tablet_uid)
      args.extend([
          '-mycnf_server_id', str(self.tablet_uid),
          '-mycnf_data_dir', os.path.join(self.tablet_dir, 'data'),
          '-mycnf_innodb_data_home_dir', os.path.join(self.tablet_dir,
                                                      'innodb', 'data'),
          '-mycnf_innodb_log_group_home_dir', os.path.join(self.tablet_dir,
                                                           'innodb', 'logs'),
          '-mycnf_socket_file', os.path.join(self.tablet_dir, 'mysql.sock'),
          '-mycnf_error_log_path', os.path.join(self.tablet_dir, 'error.log'),
          '-mycnf_slow_log_path', os.path.join(self.tablet_dir,
                                               'slow-query.log'),
          '-mycnf_relay_log_path', relay_log_path,
          '-mycnf_relay_log_index_path', relay_log_path + '.index',
          '-mycnf_relay_log_info_path', os.path.join(self.tablet_dir,
                                                     'relay-logs',
                                                     'relay-log.info'),
          '-mycnf_bin_log_path', os.path.join(self.tablet_dir, 'bin-logs',
                                              'vt-%010d-bin' % self.tablet_uid),
          '-mycnf_master_info_file', os.path.join(self.tablet_dir,
                                                  'master.info'),
          '-mycnf_pid_file', os.path.join(self.tablet_dir, 'mysql.pid'),
          '-mycnf_tmp_dir', os.path.join(self.tablet_dir, 'tmp'),
          '-mycnf_slave_load_tmp_dir', os.path.join(self.tablet_dir, 'tmp'),
      ])
      if include_mysql_port:
        args.extend(['-mycnf_mysql_port', str(self.mysql_port)])
    if target_tablet_type:
      args.extend(['-target_tablet_type', target_tablet_type,
                   '-health_check_interval', '2s',
                   '-allowed_replication_lag', '30'])

    if extra_args:
      args.extend(extra_args)

    return self._start_prog(binary='vttablet', port=port, auth=auth,
                            memcache=memcache, wait_for_state=wait_for_state,
                            customrules=customrules,
                            schema_override=schema_override,
                            cert=cert, key=key, ca_cert=ca_cert,
                            repl_extra_flags=repl_extra_flags,
                            table_acl_config=table_acl_config,
                            lameduck_period=lameduck_period, extra_args=args,
                            security_policy=security_policy)
示例#12
0
文件: tablet.py 项目: wubx/vitess
  def start_vttablet(self, port=None, auth=False, memcache=False,
                     wait_for_state='SERVING', customrules=None,
                     schema_override=None, cert=None, key=None, ca_cert=None,
                     repl_extra_flags={}, table_acl_config=None,
                     target_tablet_type=None, lameduck_period=None,
                     extra_args=None, full_mycnf_args=False,
                     security_policy=None):
    """Starts a vttablet process, and returns it.

    The process is also saved in self.proc, so it's easy to kill as well.
    """
    environment.prog_compile('vtaction')
    args = environment.binary_args('vttablet') + [
        '-port', '%s' % (port or self.port),
        '-tablet-path', self.tablet_alias,
        '-log_dir', environment.vtlogroot]
    args.extend(environment.topo_server_flags())
    args.extend(utils.binlog_player_protocol_flags)

    dbconfigs = self._get_db_configs_file(repl_extra_flags)
    for key1 in dbconfigs:
      for key2 in dbconfigs[key1]:
        args.extend(['-db-config-' + key1 + '-' + key2, dbconfigs[key1][key2]])

    if full_mycnf_args:
      # this flag is used to specify all the mycnf_ flags, to make
      # sure that code works and can fork actions.
      relay_log_path = os.path.join(self.tablet_dir, 'relay-logs',
                                    'vt-%010d-relay-bin' % self.tablet_uid)
      args.extend([
          '-mycnf_server_id', str(self.tablet_uid),
          '-mycnf_mysql_port', str(self.mysql_port),
          '-mycnf_data_dir', os.path.join(self.tablet_dir, 'data'),
          '-mycnf_innodb_data_home_dir', os.path.join(self.tablet_dir,
                                                      'innodb', 'data'),
          '-mycnf_innodb_log_group_home_dir', os.path.join(self.tablet_dir,
                                                           'innodb', 'logs'),
          '-mycnf_socket_file', os.path.join(self.tablet_dir, 'mysql.sock'),
          '-mycnf_error_log_path', os.path.join(self.tablet_dir, 'error.log'),
          '-mycnf_slow_log_path', os.path.join(self.tablet_dir,
                                               'slow-query.log'),
          '-mycnf_relay_log_path', relay_log_path,
          '-mycnf_relay_log_index_path', relay_log_path + '.index',
          '-mycnf_relay_log_info_path', os.path.join(self.tablet_dir,
                                                     'relay-logs',
                                                     'relay-log.info'),
          '-mycnf_bin_log_path', os.path.join(self.tablet_dir, 'bin-logs',
                                              'vt-%010d-bin' % self.tablet_uid),
          '-mycnf_master_info_file', os.path.join(self.tablet_dir,
                                                  'master.info'),
          '-mycnf_pid_file', os.path.join(self.tablet_dir, 'mysql.pid'),
          '-mycnf_tmp_dir', os.path.join(self.tablet_dir, 'tmp'),
          '-mycnf_slave_load_tmp_dir', os.path.join(self.tablet_dir, 'tmp'),
      ])

    if memcache:
      args.extend(['-rowcache-bin', environment.memcached_bin()])
      memcache_socket = os.path.join(self.tablet_dir, 'memcache.sock')
      args.extend(['-rowcache-socket', memcache_socket])
      args.extend(['-enable-rowcache'])

    if auth:
      args.extend(
          ['-auth-credentials',
           os.path.join(
               environment.vttop, 'test', 'test_data',
               'authcredentials_test.json')])

    if customrules:
      args.extend(['-customrules', customrules])

    if schema_override:
      args.extend(['-schema-override', schema_override])

    if table_acl_config:
      args.extend(['-table-acl-config', table_acl_config])
      args.extend(['-queryserver-config-strict-table-acl'])

    if cert:
      self.secure_port = environment.reserve_ports(1)
      args.extend(['-secure-port', '%s' % self.secure_port,
                   '-cert', cert,
                   '-key', key])
      if ca_cert:
        args.extend(['-ca_cert', ca_cert])
    if target_tablet_type:
      args.extend(['-target_tablet_type', target_tablet_type,
                   '-health_check_interval', '2s',
                   '-allowed_replication_lag', '30'])
    if lameduck_period:
      args.extend(['-lameduck-period', lameduck_period])
    if extra_args:
      args.extend(extra_args)
    if security_policy:
      args.extend(['-security_policy', security_policy])

    stderr_fd = open(os.path.join(self.tablet_dir, 'vttablet.stderr'), 'w')
    # increment count only the first time
    if not self.proc:
      Tablet.tablets_running += 1
    self.proc = utils.run_bg(args, stderr=stderr_fd)
    stderr_fd.close()

    # wait for query service to be in the right state
    if wait_for_state:
      self.wait_for_vttablet_state(wait_for_state, port=port)

    return self.proc