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): """ 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: 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']) 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
def start_vttablet( self, port=None, 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, full_mycnf_args=False, extra_args=None, extra_env=None, include_mysql_port=True, init_tablet_type=None, init_keyspace=None, init_shard=None, init_db_name_override=None, supports_backups=False, grace_period='1s', enable_semi_sync=True): """Starts a vttablet process, and returns it. The process is also saved in self.proc, so it's easy to kill as well. Returns: the process that was started. """ args = environment.binary_args('vttablet') # Use 'localhost' as hostname because Travis CI worker hostnames # are too long for MySQL replication. args.extend(['-tablet_hostname', 'localhost']) args.extend(['-tablet-path', self.tablet_alias]) args.extend(environment.topo_server().flags()) args.extend(['-binlog_player_protocol', protocols_flavor().binlog_player_protocol()]) args.extend(['-tablet_manager_protocol', protocols_flavor().tablet_manager_protocol()]) args.extend(['-tablet_protocol', protocols_flavor().tabletconn_protocol()]) args.extend(['-binlog_player_healthcheck_topology_refresh', '1s']) args.extend(['-binlog_player_healthcheck_retry_delay', '1s']) args.extend(['-binlog_player_retry_delay', '1s']) args.extend(['-pid_file', os.path.join(self.tablet_dir, 'vttablet.pid')]) # always enable_replication_lag_check with somewhat short values for tests args.extend(['-health_check_interval', '2s']) args.extend(['-enable_replication_lag_check']) args.extend(['-degraded_threshold', '5s']) if enable_semi_sync: args.append('-enable_semi_sync') if self.use_mysqlctld: args.extend( ['-mysqlctl_socket', os.path.join(self.tablet_dir, 'mysqlctl.sock')]) if full_mycnf_args: # this flag is used to specify all the mycnf_ flags, to make # sure that code works. 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)]) # this is used to run InitTablet as part of the vttablet startup if init_tablet_type: self.tablet_type = init_tablet_type args.extend(['-init_tablet_type', init_tablet_type]) if init_keyspace: self.keyspace = init_keyspace self.shard = init_shard args.extend(['-init_keyspace', init_keyspace, '-init_shard', init_shard]) if init_db_name_override: self.dbname = init_db_name_override args.extend(['-init_db_name_override', init_db_name_override]) else: self.dbname = 'vt_' + init_keyspace if supports_backups: args.extend(['-restore_from_backup'] + get_backup_storage_flags()) if extra_args: args.extend(extra_args) 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 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 grace_period: args.extend(['-serving_state_grace_period', grace_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, 'vttablet-%d.stderr' % 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: self.wait_for_vttablet_state(wait_for_state, port=port) if self.tablet_index is not None: topo_server().update_addr( 'test_'+self.cell, self.keyspace, self.shard, self.tablet_index, (port or self.port)) return self.proc
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
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
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
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
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
def start_vttablet(self, port=None, 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, target_tablet_type=None, full_mycnf_args=False, extra_args=None, extra_env=None, include_mysql_port=True, init_tablet_type=None, init_keyspace=None, init_shard=None, init_db_name_override=None, supports_backups=False, grace_period='1s', enable_semi_sync=True): """Starts a vttablet process, and returns it. The process is also saved in self.proc, so it's easy to kill as well. Returns: the process that was started. """ args = environment.binary_args('vttablet') # Use 'localhost' as hostname because Travis CI worker hostnames # are too long for MySQL replication. args.extend(['-tablet_hostname', 'localhost']) args.extend(['-tablet-path', self.tablet_alias]) args.extend(environment.topo_server().flags()) args.extend([ '-binlog_player_protocol', protocols_flavor().binlog_player_protocol() ]) args.extend([ '-tablet_manager_protocol', protocols_flavor().tablet_manager_protocol() ]) args.extend( ['-tablet_protocol', protocols_flavor().tabletconn_protocol()]) args.extend(['-binlog_player_healthcheck_topology_refresh', '1s']) args.extend(['-binlog_player_healthcheck_retry_delay', '1s']) args.extend(['-binlog_player_retry_delay', '1s']) args.extend( ['-pid_file', os.path.join(self.tablet_dir, 'vttablet.pid')]) if enable_semi_sync: args.append('-enable_semi_sync') if self.use_mysqlctld: args.extend([ '-mysqlctl_socket', os.path.join(self.tablet_dir, 'mysqlctl.sock') ]) if full_mycnf_args: # this flag is used to specify all the mycnf_ flags, to make # sure that code works. 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: self.tablet_type = target_tablet_type args.extend([ '-target_tablet_type', target_tablet_type, '-health_check_interval', '2s', '-enable_replication_lag_check', '-degraded_threshold', '5s' ]) # this is used to run InitTablet as part of the vttablet startup if init_tablet_type: self.tablet_type = init_tablet_type args.extend(['-init_tablet_type', init_tablet_type]) if init_keyspace: self.keyspace = init_keyspace self.shard = init_shard args.extend( ['-init_keyspace', init_keyspace, '-init_shard', init_shard]) if init_db_name_override: self.dbname = init_db_name_override args.extend(['-init_db_name_override', init_db_name_override]) else: self.dbname = 'vt_' + init_keyspace if supports_backups: args.extend(['-restore_from_backup'] + get_backup_storage_flags()) if extra_args: args.extend(extra_args) 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 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 grace_period: args.extend(['-serving_state_grace_period', grace_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, 'vttablet-%d.stderr' % 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: self.wait_for_vttablet_state(wait_for_state, port=port) if self.tablet_index is not None: topo_server().update_addr('test_' + self.cell, self.keyspace, self.shard, self.tablet_index, (port or self.port)) return self.proc
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
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
def setUp(self): # start mysql res = subprocess.call(environment.binary_args("mysqlctl") + [ "-tablet_uid", self.tabletuid, "-port", str(self.port), "-mysql_port", str(self.mysqlport), "init" ]) if res != 0: raise EnvironmentError("Cannot start mysql") res = subprocess.call([ environment.mysql_binary_path('mysql'), "-S", self.mysqldir+"/mysql.sock", "-u", "vt_dba", "-e", "create database vt_test_keyspace ; set global read_only = off"]) if res != 0: raise Exception("Cannot create vt_test_keyspace database") self.mysql_conn = self.mysql_connect() mcu = self.mysql_conn.cursor() self.clean_sqls = [] self.init_sqls = [] clean_mode = False with open(os.path.join(environment.vttop, "test", "test_data", "test_schema.sql")) as f: for line in f: line = line.rstrip() if line == "# clean": clean_mode = True if line=='' or line.startswith("#"): continue if clean_mode: self.clean_sqls.append(line) else: self.init_sqls.append(line) try: for line in self.init_sqls: mcu.execute(line, {}) finally: mcu.close() customrules = os.path.join(environment.tmproot, 'customrules.json') self.create_customrules(customrules) schema_override = os.path.join(environment.tmproot, 'schema_override.json') self.create_schema_override(schema_override) table_acl_config = os.path.join(environment.vttop, 'test', 'test_data', 'table_acl_config.json') occ_args = environment.binary_args('vtocc') + [ "-port", str(self.port), "-customrules", customrules, "-log_dir", environment.vtlogroot, "-schema-override", schema_override, "-table-acl-config", table_acl_config, "-queryserver-config-strict-table-acl", "-db-config-app-charset", "utf8", "-db-config-app-dbname", "vt_test_keyspace", "-db-config-app-host", "localhost", "-db-config-app-unixsocket", self.mysqldir+"/mysql.sock", "-db-config-app-uname", 'vt_dba', # use vt_dba as some tests depend on 'drop' "-db-config-app-keyspace", "test_keyspace", "-db-config-app-shard", "0", "-auth-credentials", os.path.join(environment.vttop, 'test', 'test_data', 'authcredentials_test.json'), ] if self.memcache: memcache = self.mysqldir+"/memcache.sock" occ_args.extend(["-rowcache-bin", environment.memcached_bin()]) occ_args.extend(["-rowcache-socket", memcache]) occ_args.extend(["-enable-rowcache"]) self.vtocc = subprocess.Popen(occ_args, stdout=utils.devnull, stderr=utils.devnull) for i in range(30): try: self.conn = self.connect() self.txlogger = utils.curl(self.url('/debug/txlog'), background=True, stdout=open(self.txlog_file, 'w')) self.txlog = framework.Tailer(open(self.txlog_file, 'r')) def flush(): utils.curl(self.url(environment.flush_logs_url), trap_output=True) self.log = framework.Tailer(open(os.path.join(environment.vtlogroot, 'vtocc.INFO')), flush=flush) break except (dbexceptions.OperationalError, dbexceptions.RetryError): if i == 29: raise time.sleep(1) self.postSetup()
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
def setUp(self): # start mysql res = subprocess.call( environment.binary_args("mysqlctl") + [ "-tablet_uid", self.tabletuid, "-port", str(self.port), "-mysql_port", str(self.mysqlport), "init" ]) if res != 0: raise EnvironmentError("Cannot start mysql") res = subprocess.call([ environment.mysql_binary_path('mysql'), "-S", self.mysqldir + "/mysql.sock", "-u", "vt_dba", "-e", "create database vt_test_keyspace ; set global read_only = off" ]) if res != 0: raise Exception("Cannot create vt_test_keyspace database") self.mysql_conn = self.mysql_connect() mcu = self.mysql_conn.cursor() self.clean_sqls = [] self.init_sqls = [] clean_mode = False with open( os.path.join(environment.vttop, "test", "test_data", "test_schema.sql")) as f: for line in f: line = line.rstrip() if line == "# clean": clean_mode = True if line == '' or line.startswith("#"): continue if clean_mode: self.clean_sqls.append(line) else: self.init_sqls.append(line) try: for line in self.init_sqls: mcu.execute(line, {}) finally: mcu.close() customrules = os.path.join(environment.tmproot, 'customrules.json') self.create_customrules(customrules) schema_override = os.path.join(environment.tmproot, 'schema_override.json') self.create_schema_override(schema_override) table_acl_config = os.path.join(environment.vttop, 'test', 'test_data', 'table_acl_config.json') occ_args = environment.binary_args('vtocc') + [ "-port", str(self.port), "-customrules", customrules, "-log_dir", environment.vtlogroot, "-schema-override", schema_override, "-table-acl-config", table_acl_config, "-queryserver-config-strict-table-acl", "-db-config-app-charset", "utf8", "-db-config-app-dbname", "vt_test_keyspace", "-db-config-app-host", "localhost", "-db-config-app-unixsocket", self.mysqldir + "/mysql.sock", "-db-config-app-uname", 'vt_dba', # use vt_dba as some tests depend on 'drop' "-db-config-app-keyspace", "test_keyspace", "-db-config-app-shard", "0", "-auth-credentials", os.path.join(environment.vttop, 'test', 'test_data', 'authcredentials_test.json'), ] if self.memcache: memcache = self.mysqldir + "/memcache.sock" occ_args.extend(["-rowcache-bin", environment.memcached_bin()]) occ_args.extend(["-rowcache-socket", memcache]) occ_args.extend(["-enable-rowcache"]) self.vtocc = subprocess.Popen(occ_args, stdout=utils.devnull, stderr=utils.devnull) for i in range(30): try: self.conn = self.connect() self.txlogger = utils.curl(self.url('/debug/txlog'), background=True, stdout=open(self.txlog_file, 'w')) self.txlog = framework.Tailer(open(self.txlog_file, 'r')) def flush(): utils.curl(self.url(environment.flush_logs_url), trap_output=True) self.log = framework.Tailer(open( os.path.join(environment.vtlogroot, 'vtocc.INFO')), flush=flush) break except (dbexceptions.OperationalError, dbexceptions.RetryError): if i == 29: raise time.sleep(1) self.postSetup()