Commit 21daa7b9 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin Committed by Sergei Golubchik

MDEV-6066: Merge new defaults from 5.6 and 5.7 (autoset)

--autoset- command line prefix added
parent b85a0016
......@@ -40,7 +40,8 @@ C_MODE_START
#define GET_FLAGSET 15
#define GET_ASK_ADDR 128
#define GET_TYPE_MASK 127
#define GET_AUTO 64
#define GET_TYPE_MASK 63
/**
Enumeration of the my_option::arg_type attributes.
......@@ -100,6 +101,7 @@ typedef void *(*my_getopt_value)(const char *, uint, const struct my_option *,
extern char *disabled_my_option;
extern char *autoset_my_option;
extern my_bool my_getopt_print_errors;
extern my_bool my_getopt_skip_unknown;
extern my_bool my_getopt_prefix_matching;
......
......@@ -47,14 +47,15 @@ static char *check_struct_option(char *cur_arg, char *key_name);
order of their arguments must correspond to each other.
*/
static const char *special_opt_prefix[]=
{"skip", "disable", "enable", "maximum", "loose", 0};
{"skip", "disable", "enable", "maximum", "loose", "autoset", 0};
static const uint special_opt_prefix_lengths[]=
{ 4, 7, 6, 7, 5, 0};
{ 4, 7, 6, 7, 5, 7, 0};
enum enum_special_opt
{ OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM, OPT_LOOSE};
{ OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM, OPT_LOOSE, OPT_AUTOSET};
char *disabled_my_option= (char*) "0";
char *enabled_my_option= (char*) "1";
char *autoset_my_option= (char*) "";
/*
This is a flag that can be set in client programs. 0 means that
......@@ -198,7 +199,7 @@ int handle_options(int *argc, char ***argv,
{
uint UNINIT_VAR(opt_found), argvpos= 0, length;
my_bool end_of_options= 0, must_be_var, set_maximum_value,
option_is_loose;
option_is_loose, option_is_autoset;
char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN];
const char *UNINIT_VAR(prev_found);
const struct my_option *optp;
......@@ -249,6 +250,7 @@ int handle_options(int *argc, char ***argv,
must_be_var= 0;
set_maximum_value= 0;
option_is_loose= 0;
option_is_autoset= 0;
cur_arg++; /* skip '-' */
if (*cur_arg == '-') /* check for long option, */
......@@ -297,6 +299,8 @@ int handle_options(int *argc, char ***argv,
length-= special_opt_prefix_lengths[i] + 1;
if (i == OPT_LOOSE)
option_is_loose= 1;
else if (i == OPT_AUTOSET)
option_is_autoset= 1;
if ((opt_found= findopt(opt_str, length, &optp, &prev_found)))
{
if (opt_found > 1)
......@@ -458,6 +462,36 @@ int handle_options(int *argc, char ***argv,
}
argument= optend;
}
else if (option_is_autoset)
{
if (optend)
{
my_getopt_error_reporter(ERROR_LEVEL,
"%s: automatic setup request of "
"option '--%s' cannot take an argument",
my_progname, optp->name);
DBUG_RETURN(EXIT_NO_ARGUMENT_ALLOWED);
}
/*
We support automatic setup only via get_one_option and only for
marked options.
*/
if (!get_one_option ||
!(optp->var_type & GET_AUTO))
{
my_getopt_error_reporter(option_is_loose ?
WARNING_LEVEL : ERROR_LEVEL,
"%s: automatic setup request is "
"unsupported by option '--%s'",
my_progname, optp->name);
if (!option_is_loose)
return EXIT_ARGUMENT_INVALID;
continue;
}
else
argument= autoset_my_option;
}
else if (optp->arg_type == REQUIRED_ARG && !optend)
{
/* Check if there are more arguments after this one,
......@@ -585,7 +619,8 @@ int handle_options(int *argc, char ***argv,
(*argc)--; /* option handled (short), decrease argument count */
continue;
}
if (((error= setval(optp, value, argument, set_maximum_value))) &&
if ((!option_is_autoset) &&
((error= setval(optp, value, argument, set_maximum_value))) &&
!option_is_loose)
DBUG_RETURN(error);
if (get_one_option && get_one_option(optp->id, optp, argument))
......@@ -1427,6 +1462,11 @@ void my_print_help(const struct my_option *options)
}
col= print_comment(optp->comment, col, name_space, comment_space);
if (optp->var_type & GET_AUTO)
{
col= print_comment(" (Automatically configured unless set explicitly)",
col, name_space, comment_space);
}
switch (optp->var_type & GET_TYPE_MASK) {
case GET_ENUM:
......
......@@ -2299,7 +2299,7 @@ static void set_ports()
if ((env = getenv("MYSQL_TCP_PORT")))
{
mysqld_port= (uint) atoi(env);
mark_sys_var_value_origin(&mysqld_port, sys_var::ENV);
set_sys_var_value_origin(&mysqld_port, sys_var::ENV);
}
}
if (!mysqld_unix_port)
......@@ -2312,7 +2312,7 @@ static void set_ports()
if ((env = getenv("MYSQL_UNIX_PORT")))
{
mysqld_unix_port= env;
mark_sys_var_value_origin(&mysqld_unix_port, sys_var::ENV);
set_sys_var_value_origin(&mysqld_unix_port, sys_var::ENV);
}
}
}
......@@ -4187,7 +4187,7 @@ static int init_common_variables()
strmake(pidfile_name, opt_log_basename, sizeof(pidfile_name)-5);
strmov(fn_ext(pidfile_name),".pid"); // Add proper extension
SYSVAR_AUTOSIZE(pidfile_name_ptr, pidfile_name);
mark_sys_var_value_origin(&opt_tc_log_size, sys_var::AUTO);
set_sys_var_value_origin(&opt_tc_log_size, sys_var::AUTO);
/*
The default-storage-engine entry in my_long_options should have a
......@@ -8767,7 +8767,7 @@ static int mysql_init_variables(void)
if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
tmpenv = DEFAULT_MYSQL_HOME;
strmake_buf(mysql_home, tmpenv);
mark_sys_var_value_origin(&mysql_home_ptr, sys_var::ENV);
set_sys_var_value_origin(&mysql_home_ptr, sys_var::ENV);
#endif
if (wsrep_init_vars())
......@@ -8782,6 +8782,11 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
if (opt->app_type)
{
sys_var *var= (sys_var*) opt->app_type;
if (argument == autoset_my_option)
{
var->value_origin= sys_var::AUTO;
return 0;
}
var->value_origin= sys_var::CONFIG;
}
......@@ -8894,8 +8899,8 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
make_default_log_name(&opt_bin_logname, "-bin", true);
/* Binary log index file */
make_default_log_name(&opt_binlog_index_name, "-bin.index", true);
mark_sys_var_value_origin(&opt_logname, sys_var::AUTO);
mark_sys_var_value_origin(&opt_slow_logname, sys_var::AUTO);
set_sys_var_value_origin(&opt_logname, sys_var::AUTO);
set_sys_var_value_origin(&opt_slow_logname, sys_var::AUTO);
if (!opt_logname || !opt_slow_logname || !opt_bin_logname ||
!opt_binlog_index_name)
return 1;
......@@ -8905,7 +8910,7 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
make_default_log_name(&opt_relay_logname, "-relay-bin", true);
/* Relay log index file */
make_default_log_name(&opt_relaylog_index_name, "-relay-bin.index", true);
mark_sys_var_value_origin(&opt_relay_logname, sys_var::AUTO);
set_sys_var_value_origin(&opt_relay_logname, sys_var::AUTO);
if (!opt_relay_logname || !opt_relaylog_index_name)
return 1;
#endif
......@@ -9101,6 +9106,7 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
max_long_data_size_used= true;
break;
case OPT_PFS_INSTRUMENT:
{
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
#ifndef EMBEDDED_LIBRARY
/* Parse instrument name and value from argument string */
......@@ -9170,6 +9176,7 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
#endif
break;
}
}
return 0;
}
......
......@@ -178,6 +178,7 @@ sys_var::sys_var(sys_var_chain *chain, const char *name_arg,
else
chain->first= this;
chain->last= this;
fix_auto_flag();
}
bool sys_var::update(THD *thd, set_var *var)
......@@ -1086,7 +1087,8 @@ int fill_sysvars(THD *thd, TABLE_LIST *tables, COND *cond)
{ STRING_WITH_LEN("DOUBLE") }, // GET_DOUBLE 14
{ STRING_WITH_LEN("FLAGSET") }, // GET_FLAGSET 15
};
const LEX_CSTRING *type= types + (var->option.var_type & GET_TYPE_MASK);
const ulong vartype= (var->option.var_type & GET_TYPE_MASK);
const LEX_CSTRING *type= types + vartype;
fields[6]->store(type->str, type->length, scs);
// VARIABLE_COMMENT
......@@ -1097,7 +1099,7 @@ int fill_sysvars(THD *thd, TABLE_LIST *tables, COND *cond)
// NUMERIC_MAX_VALUE
// NUMERIC_BLOCK_SIZE
bool is_unsigned= true;
switch (var->option.var_type)
switch (vartype)
{
case GET_INT:
case GET_LONG:
......@@ -1179,7 +1181,7 @@ end:
and update it directly.
*/
void mark_sys_var_value_origin(void *ptr, enum sys_var::where here)
void set_sys_var_value_origin(void *ptr, enum sys_var::where here)
{
bool found __attribute__((unused))= false;
DBUG_ASSERT(!mysqld_server_started); // only to be used during startup
......@@ -1198,3 +1200,20 @@ void mark_sys_var_value_origin(void *ptr, enum sys_var::where here)
DBUG_ASSERT(found); // variable must have been found
}
enum sys_var::where get_sys_var_value_origin(void *ptr)
{
DBUG_ASSERT(!mysqld_server_started); // only to be used during startup
for (uint i= 0; i < system_variable_hash.records; i++)
{
sys_var *var= (sys_var*) my_hash_element(&system_variable_hash, i);
if (var->option.value == ptr)
{
return var->value_origin; //first match
}
}
DBUG_ASSERT(0); // variable must have been found
return sys_var::CONFIG;
}
......@@ -62,7 +62,7 @@ public:
LEX_CSTRING name;
enum flag_enum { GLOBAL, SESSION, ONLY_SESSION, SCOPE_MASK=1023,
READONLY=1024, ALLOCATED=2048, PARSE_EARLY=4096,
NO_SET_STATEMENT=8192};
NO_SET_STATEMENT=8192, AUTO_SET=16384};
enum { NO_GETOPT=-1, GETOPT_ONLY_HELP=-2 };
enum where { CONFIG, AUTO, SQL, COMPILE_TIME, ENV };
......@@ -89,6 +89,12 @@ protected:
const char *const deprecation_substitute;
bool is_os_charset; ///< true if the value is in character_set_filesystem
inline void fix_auto_flag()
{
if (flags & AUTO_SET)
option.var_type|= GET_AUTO;
}
public:
sys_var(sys_var_chain *chain, const char *name_arg, const char *comment,
int flag_args, ptrdiff_t off, int getopt_id,
......@@ -389,10 +395,17 @@ int sql_set_variables(THD *thd, List<set_var_base> *var_list, bool free);
#define SYSVAR_AUTOSIZE(VAR,VAL) \
do { \
VAR= (VAL); \
mark_sys_var_value_origin(&VAR, sys_var::AUTO); \
set_sys_var_value_origin(&VAR, sys_var::AUTO); \
} while(0)
void mark_sys_var_value_origin(void *ptr, enum sys_var::where here);
void set_sys_var_value_origin(void *ptr, enum sys_var::where here);
enum sys_var::where get_sys_var_value_origin(void *ptr);
inline bool IS_SYSVAR_AUTOSIZE(void *ptr)
{
enum sys_var::where res= get_sys_var_value_origin(ptr);
return (res == sys_var::AUTO || res == sys_var::COMPILE_TIME);
}
bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type);
......
......@@ -54,6 +54,7 @@
#define ON_CHECK(X) X
#define ON_UPDATE(X) X
#define READ_ONLY sys_var::READONLY+
#define AUTO_SET sys_var::AUTO_SET+
// this means that Sys_var_charptr initial value was malloc()ed
#define PREALLOCATED sys_var::ALLOCATED+
#define PARSED_EARLY sys_var::PARSE_EARLY+
......@@ -138,6 +139,7 @@ public:
on_check_func, on_update_func, substitute)
{
option.var_type= ARGT;
fix_auto_flag();
option.min_value= min_val;
option.max_value= max_val;
option.block_size= block_size;
......@@ -157,9 +159,10 @@ public:
{
my_bool fixed= FALSE, unused;
longlong v= var->value->val_int();
ulong vartype= (ARGT & GET_TYPE_MASK);
if ((ARGT == GET_HA_ROWS) || (ARGT == GET_UINT) ||
(ARGT == GET_ULONG) || (ARGT == GET_ULL))
if ((vartype == GET_HA_ROWS) || (vartype == GET_UINT) ||
(vartype == GET_ULONG) || (vartype == GET_ULL))
{
ulonglong uv;
......@@ -343,6 +346,7 @@ public:
substitute)
{
option.var_type= GET_ENUM;
fix_auto_flag();
global_var(ulong)= def_val;
SYSVAR_ASSERT(def_val < typelib.count);
SYSVAR_ASSERT(size == sizeof(ulong));
......@@ -394,6 +398,7 @@ public:
substitute)
{
option.var_type= GET_BOOL;
fix_auto_flag();
global_var(my_bool)= def_val;
SYSVAR_ASSERT(def_val < 2);
SYSVAR_ASSERT(getopt.arg_type == OPT_ARG || getopt.id < 0);
......@@ -460,6 +465,7 @@ public:
(think of an exit because of an error right after my_getopt)
*/
option.var_type= (flags & ALLOCATED) ? GET_STR_ALLOC : GET_STR;
fix_auto_flag();
global_var(const char*)= def_val;
SYSVAR_ASSERT(scope() == GLOBAL);
SYSVAR_ASSERT(size == sizeof(char *));
......@@ -547,6 +553,7 @@ public:
{
is_os_charset= is_os_charset_arg == IN_FS_CHARSET;
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var)
{
......@@ -603,6 +610,7 @@ public:
NULL, NULL, NULL), opt_id(getopt_id)
{
option.var_type= GET_STR | GET_ASK_ADDR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var)
......@@ -692,6 +700,7 @@ public:
0),max_length(max_length_arg)
{
option.var_type= GET_STR;
fix_auto_flag();
SYSVAR_ASSERT(scope() == ONLY_SESSION)
*const_cast<SHOW_TYPE*>(&show_val_type)= SHOW_LEX_STRING;
}
......@@ -778,7 +787,7 @@ public:
getopt.arg_type, SHOW_CHAR, (intptr)def_val,
lock, binlog_status_arg, on_check_func, on_update_func,
substitute)
{ option.var_type= GET_STR; }
{ option.var_type= GET_STR; fix_auto_flag(); }
bool do_check(THD *thd, set_var *var)
{
char buff[STRING_BUFFER_USUAL_SIZE];
......@@ -1026,6 +1035,7 @@ public:
substitute)
{
option.var_type= GET_DOUBLE;
fix_auto_flag();
option.min_value= (longlong) getopt_double2ulonglong(min_val);
option.max_value= (longlong) getopt_double2ulonglong(max_val);
global_var(double)= (double)option.def_value;
......@@ -1127,6 +1137,7 @@ public:
substitute)
{
option.var_type= GET_FLAGSET;
fix_auto_flag();
global_var(ulonglong)= def_val;
SYSVAR_ASSERT(typelib.count > 1);
SYSVAR_ASSERT(typelib.count <= 65);
......@@ -1236,6 +1247,7 @@ public:
substitute)
{
option.var_type= GET_SET;
fix_auto_flag();
global_var(ulonglong)= def_val;
SYSVAR_ASSERT(typelib.count > 0);
SYSVAR_ASSERT(typelib.count <= 64);
......@@ -1341,6 +1353,7 @@ public:
plugin_type(plugin_type_arg)
{
option.var_type= GET_STR;
fix_auto_flag();
SYSVAR_ASSERT(size == sizeof(plugin_ref));
SYSVAR_ASSERT(getopt.id < 0); // force NO_CMD_LINE
}
......@@ -1457,6 +1470,7 @@ public:
{
SYSVAR_ASSERT(scope() == ONLY_SESSION);
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var)
{
......@@ -1549,6 +1563,7 @@ public:
substitute)
{
option.var_type= GET_BOOL;
fix_auto_flag();
reverse_semantics= my_count_bits(bitmask_arg) > 1;
bitmask= reverse_semantics ? ~bitmask_arg : bitmask_arg;
set(global_var_ptr(), def_val);
......@@ -1757,6 +1772,7 @@ public:
SYSVAR_ASSERT(on_update == 0);
SYSVAR_ASSERT(size == sizeof(enum SHOW_COMP_OPTION));
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var) {
DBUG_ASSERT(FALSE);
......@@ -1819,6 +1835,7 @@ public:
name_offset(name_off)
{
option.var_type= GET_ENUM; // because we accept INT and STRING here
fix_auto_flag();
/*
struct variables are special on the command line - often (e.g. for
charsets) the name cannot be immediately resolved, but only after all
......@@ -1888,6 +1905,7 @@ public:
SYSVAR_ASSERT(getopt.id < 0);
SYSVAR_ASSERT(size == sizeof(Time_zone *));
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var)
{
......@@ -2107,6 +2125,7 @@ public:
SYSVAR_ASSERT(getopt.id < 0);
SYSVAR_ASSERT(is_readonly());
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var)
{
......@@ -2156,6 +2175,7 @@ public:
SYSVAR_ASSERT(getopt.id < 0);
SYSVAR_ASSERT(is_readonly());
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var)
{
......@@ -2203,6 +2223,7 @@ public:
NULL, NULL, NULL)
{
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var);
bool session_update(THD *thd, set_var *var)
......@@ -2245,6 +2266,7 @@ public:
NULL, NULL, NULL)
{
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var);
bool session_update(THD *thd, set_var *var)
......@@ -2288,6 +2310,7 @@ public:
SYSVAR_ASSERT(getopt.id < 0);
SYSVAR_ASSERT(is_readonly());
option.var_type= GET_STR;
fix_auto_flag();
}
bool do_check(THD *thd, set_var *var)
{
......
......@@ -34,7 +34,11 @@ void compute_digest_md5(const sql_digest_storage *, unsigned char *)
}
class sys_var { public: enum where { AUTO }; };
void mark_sys_var_value_origin(void *ptr, enum sys_var::where here)
void set_sys_var_value_origin(void *ptr, enum sys_var::where here)
{
}
enum sys_var::where get_sys_var_value_origin(void *ptr)
{
return sys_var::AUTO;
}
......@@ -14,6 +14,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
MY_ADD_TESTS(bitmap base64 my_vsnprintf my_atomic my_rdtsc lf my_malloc aes
my_getopt
LINK_LIBRARIES mysys)
ADD_DEFINITIONS(${SSL_DEFINES})
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment