Commit 6c76246e authored by unknown's avatar unknown

my_getopt: enforce "correctness" (min/max/block_size) of default values


client/mysqltest.c:
  fix my_option's with incorrect defaults
mysql-test/r/maria.result:
  update results
mysql-test/t/variables.test:
  update results
sql/mysqld.cc:
  fix my_option's with incorrect defaults
parent 7de6b459
...@@ -2018,9 +2018,9 @@ void var_set_query_get_value(struct st_command *command, VAR *var) ...@@ -2018,9 +2018,9 @@ void var_set_query_get_value(struct st_command *command, VAR *var)
static DYNAMIC_STRING ds_col; static DYNAMIC_STRING ds_col;
static DYNAMIC_STRING ds_row; static DYNAMIC_STRING ds_row;
const struct command_arg query_get_value_args[] = { const struct command_arg query_get_value_args[] = {
"query", ARG_STRING, TRUE, &ds_query, "Query to run", {"query", ARG_STRING, TRUE, &ds_query, "Query to run"},
"column name", ARG_STRING, TRUE, &ds_col, "Name of column", {"column name", ARG_STRING, TRUE, &ds_col, "Name of column"},
"row number", ARG_STRING, TRUE, &ds_row, "Number for row", {"row number", ARG_STRING, TRUE, &ds_row, "Number for row"},
}; };
DBUG_ENTER("var_set_query_get_value"); DBUG_ENTER("var_set_query_get_value");
...@@ -5007,7 +5007,7 @@ static struct my_option my_long_options[] = ...@@ -5007,7 +5007,7 @@ static struct my_option my_long_options[] =
"Don't use the memory allocation checking.", 0, 0, 0, GET_NO_ARG, NO_ARG, "Don't use the memory allocation checking.", 0, 0, 0, GET_NO_ARG, NO_ARG,
0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, 0, 0},
{"sleep", 'T', "Sleep always this many seconds on sleep commands.", {"sleep", 'T', "Sleep always this many seconds on sleep commands.",
(uchar**) &opt_sleep, (uchar**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, 0, 0, (uchar**) &opt_sleep, (uchar**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
0, 0, 0}, 0, 0, 0},
{"socket", 'S', "Socket file to use for connection.", {"socket", 'S', "Socket file to use for connection.",
(uchar**) &unix_sock, (uchar**) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, (uchar**) &unix_sock, (uchar**) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
......
...@@ -1977,9 +1977,9 @@ show variables like 'maria%'; ...@@ -1977,9 +1977,9 @@ show variables like 'maria%';
Variable_name Value Variable_name Value
maria_block_size 8192 maria_block_size 8192
maria_checkpoint_frequency 30 maria_checkpoint_frequency 30
maria_max_sort_file_size 9223372036854775807 maria_max_sort_file_size 9223372036853727232
maria_pagecache_age_threshold 300 maria_pagecache_age_threshold 300
maria_pagecache_buffer_size 8388572 maria_pagecache_buffer_size 8384512
maria_pagecache_division_limit 100 maria_pagecache_division_limit 100
maria_repair_threads 1 maria_repair_threads 1
maria_sort_buffer_size 8388608 maria_sort_buffer_size 8388608
......
...@@ -141,9 +141,9 @@ set GLOBAL myisam_max_sort_file_size=2000000; ...@@ -141,9 +141,9 @@ set GLOBAL myisam_max_sort_file_size=2000000;
show global variables like 'myisam_max_sort_file_size'; show global variables like 'myisam_max_sort_file_size';
select * from information_schema.global_variables where variable_name like 'myisam_max_sort_file_size'; select * from information_schema.global_variables where variable_name like 'myisam_max_sort_file_size';
set GLOBAL myisam_max_sort_file_size=default; set GLOBAL myisam_max_sort_file_size=default;
--replace_result 2147483647 FILE_SIZE 9223372036854775807 FILE_SIZE --replace_result 2147482624 FILE_SIZE 9223372036853727232 FILE_SIZE
show variables like 'myisam_max_sort_file_size'; show variables like 'myisam_max_sort_file_size';
--replace_result 2147483647 FILE_SIZE 9223372036854775807 FILE_SIZE --replace_result 2147482624 FILE_SIZE 9223372036853727232 FILE_SIZE
select * from information_schema.session_variables where variable_name like 'myisam_max_sort_file_size'; select * from information_schema.session_variables where variable_name like 'myisam_max_sort_file_size';
set global net_retry_count=10, session net_retry_count=10; set global net_retry_count=10, session net_retry_count=10;
......
...@@ -20,22 +20,25 @@ ...@@ -20,22 +20,25 @@
#include <mysys_err.h> #include <mysys_err.h>
#include <my_getopt.h> #include <my_getopt.h>
#if SIZEOF_LONG < SIZEOF_LONG_LONG
#define getopt_ul getopt_ll
#define getopt_ul_limit_value getopt_ll_limit_value
#else
#define getopt_ul getopt_ull
#define getopt_ul_limit_value getopt_ull_limit_value
#endif
static void default_reporter(enum loglevel level, const char *format, ...); static void default_reporter(enum loglevel level, const char *format, ...);
my_error_reporter my_getopt_error_reporter= &default_reporter; my_error_reporter my_getopt_error_reporter= &default_reporter;
static int findopt(char *optpat, uint length, static int findopt(char *, uint, const struct my_option **, char **);
const struct my_option **opt_res, my_bool getopt_compare_strings(const char *, const char *, uint);
char **ffname);
my_bool getopt_compare_strings(const char *s,
const char *t,
uint length);
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err); static longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
static ulonglong getopt_ull(char *arg, const struct my_option *optp, static longlong getopt_ll_limit_value(longlong, const struct my_option *);
int *err); static ulonglong getopt_ull(char *, const struct my_option *, int *);
static double getopt_double(char *arg, const struct my_option *optp, int *err); static double getopt_double(char *arg, const struct my_option *optp, int *err);
static void init_variables(const struct my_option *options); static void init_variables(const struct my_option *options);
static int setval(const struct my_option *opts, uchar* *value, char *argument, static int setval(const struct my_option *, uchar **, char *, my_bool);
my_bool set_maximum_value);
static char *check_struct_option(char *cur_arg, char *key_name); static char *check_struct_option(char *cur_arg, char *key_name);
/* /*
...@@ -603,9 +606,11 @@ static int setval(const struct my_option *opts, uchar* *value, char *argument, ...@@ -603,9 +606,11 @@ static int setval(const struct my_option *opts, uchar* *value, char *argument,
*((int*) result_pos)= (int) getopt_ll(argument, opts, &err); *((int*) result_pos)= (int) getopt_ll(argument, opts, &err);
break; break;
case GET_LONG: case GET_LONG:
case GET_ULONG: /* fall through */
*((long*) result_pos)= (long) getopt_ll(argument, opts, &err); *((long*) result_pos)= (long) getopt_ll(argument, opts, &err);
break; break;
case GET_ULONG:
*((long*) result_pos)= (long) getopt_ul(argument, opts, &err);
break;
case GET_LL: case GET_LL:
*((longlong*) result_pos)= getopt_ll(argument, opts, &err); *((longlong*) result_pos)= getopt_ll(argument, opts, &err);
break; break;
...@@ -748,7 +753,7 @@ static longlong eval_num_suffix(char *argument, int *error, char *option_name) ...@@ -748,7 +753,7 @@ static longlong eval_num_suffix(char *argument, int *error, char *option_name)
return num; return num;
} }
/* /*
function: getopt_ll function: getopt_ll
Evaluates and returns the value that user gave as an argument Evaluates and returns the value that user gave as an argument
...@@ -761,10 +766,22 @@ static longlong eval_num_suffix(char *argument, int *error, char *option_name) ...@@ -761,10 +766,22 @@ static longlong eval_num_suffix(char *argument, int *error, char *option_name)
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err) static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
{ {
longlong num; longlong num=eval_num_suffix(arg, err, (char*) optp->name);
return getopt_ll_limit_value(num, optp);
}
/*
function: getopt_ll_limit_value
Applies min/max/block_size to a numeric value of an option.
Returns "fixed" value.
*/
static longlong getopt_ll_limit_value(longlong num,
const struct my_option *optp)
{
ulonglong block_size= (optp->block_size ? (ulonglong) optp->block_size : 1L); ulonglong block_size= (optp->block_size ? (ulonglong) optp->block_size : 1L);
num= eval_num_suffix(arg, err, (char*) optp->name);
if (num > 0 && (ulonglong) num > (ulonglong) optp->max_value && if (num > 0 && (ulonglong) num > (ulonglong) optp->max_value &&
optp->max_value) /* if max value is not set -> no upper limit */ optp->max_value) /* if max value is not set -> no upper limit */
num= (ulonglong) optp->max_value; num= (ulonglong) optp->max_value;
...@@ -782,9 +799,7 @@ static longlong getopt_ll(char *arg, const struct my_option *optp, int *err) ...@@ -782,9 +799,7 @@ static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err) static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err)
{ {
ulonglong num; ulonglong num= eval_num_suffix(arg, err, (char*) optp->name);
num= eval_num_suffix(arg, err, (char*) optp->name);
return getopt_ull_limit_value(num, optp); return getopt_ull_limit_value(num, optp);
} }
...@@ -841,35 +856,39 @@ static double getopt_double(char *arg, const struct my_option *optp, int *err) ...@@ -841,35 +856,39 @@ static double getopt_double(char *arg, const struct my_option *optp, int *err)
SYNOPSIS SYNOPSIS
init_one_value() init_one_value()
option Option to initialize optp Option to initialize
value Pointer to variable value Pointer to variable
*/ */
static void init_one_value(const struct my_option *option, uchar* *variable, static void init_one_value(const struct my_option *optp, uchar* *variable,
longlong value) longlong value)
{ {
DBUG_ENTER("init_one_value"); DBUG_ENTER("init_one_value");
switch ((option->var_type & GET_TYPE_MASK)) { switch ((optp->var_type & GET_TYPE_MASK)) {
case GET_BOOL: case GET_BOOL:
*((my_bool*) variable)= (my_bool) value; *((my_bool*) variable)= (my_bool) value;
break; break;
case GET_INT: case GET_INT:
*((int*) variable)= (int) value; *((int*) variable)= (int) getopt_ll_limit_value(value, optp);
break; break;
case GET_UINT: case GET_UINT:
*((uint*) variable)= (uint) getopt_ll_limit_value(value, optp);
break;
case GET_ENUM: case GET_ENUM:
*((uint*) variable)= (uint) value; *((uint*) variable)= (uint) value;
break; break;
case GET_LONG: case GET_LONG:
*((long*) variable)= (long) value; *((long*) variable)= (long) getopt_ll_limit_value(value, optp);
break; break;
case GET_ULONG: case GET_ULONG:
*((ulong*) variable)= (ulong) value; *((ulong*) variable)= (ulong) getopt_ul_limit_value(value, optp);
break; break;
case GET_LL: case GET_LL:
*((longlong*) variable)= (longlong) value; *((longlong*) variable)= (longlong) getopt_ll_limit_value(value, optp);
break; break;
case GET_ULL: case GET_ULL:
*((ulonglong*) variable)= (ulonglong) getopt_ull_limit_value(value, optp);
break;
case GET_SET: case GET_SET:
*((ulonglong*) variable)= (ulonglong) value; *((ulonglong*) variable)= (ulonglong) value;
break; break;
...@@ -906,7 +925,7 @@ static void init_one_value(const struct my_option *option, uchar* *variable, ...@@ -906,7 +925,7 @@ static void init_one_value(const struct my_option *option, uchar* *variable,
} }
/* /*
initialize all variables to their default values initialize all variables to their default values
SYNOPSIS SYNOPSIS
......
...@@ -6018,7 +6018,7 @@ log and this option does nothing anymore.", ...@@ -6018,7 +6018,7 @@ log and this option does nothing anymore.",
"Max packetlength to send/receive from to server.", "Max packetlength to send/receive from to server.",
(uchar**) &global_system_variables.max_allowed_packet, (uchar**) &global_system_variables.max_allowed_packet,
(uchar**) &max_system_variables.max_allowed_packet, 0, GET_ULONG, (uchar**) &max_system_variables.max_allowed_packet, 0, GET_ULONG,
REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, 0, 1024, 0},
{"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE, {"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE,
"Can be used to restrict the total size used to cache a multi-transaction query.", "Can be used to restrict the total size used to cache a multi-transaction query.",
(uchar**) &max_binlog_cache_size, (uchar**) &max_binlog_cache_size, 0, (uchar**) &max_binlog_cache_size, (uchar**) &max_binlog_cache_size, 0,
...@@ -6096,7 +6096,7 @@ The minimum value for this variable is 4096.", ...@@ -6096,7 +6096,7 @@ The minimum value for this variable is 4096.",
{"max_user_connections", OPT_MAX_USER_CONNECTIONS, {"max_user_connections", OPT_MAX_USER_CONNECTIONS,
"The maximum number of active connections for a single user (0 = no limit).", "The maximum number of active connections for a single user (0 = no limit).",
(uchar**) &max_user_connections, (uchar**) &max_user_connections, 0, GET_UINT, (uchar**) &max_user_connections, (uchar**) &max_user_connections, 0, GET_UINT,
REQUIRED_ARG, 0, 1, ~0, 0, 1, 0}, REQUIRED_ARG, 0, 0, ~0, 0, 1, 0},
{"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT, {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT,
"After this many write locks, allow some read locks to run in between.", "After this many write locks, allow some read locks to run in between.",
(uchar**) &max_write_lock_count, (uchar**) &max_write_lock_count, 0, GET_ULONG, (uchar**) &max_write_lock_count, (uchar**) &max_write_lock_count, 0, GET_ULONG,
...@@ -6243,7 +6243,7 @@ The minimum value for this variable is 4096.", ...@@ -6243,7 +6243,7 @@ The minimum value for this variable is 4096.",
"Allocation block size for storing ranges during optimization", "Allocation block size for storing ranges during optimization",
(uchar**) &global_system_variables.range_alloc_block_size, (uchar**) &global_system_variables.range_alloc_block_size,
(uchar**) &max_system_variables.range_alloc_block_size, 0, GET_ULONG, (uchar**) &max_system_variables.range_alloc_block_size, 0, GET_ULONG,
REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, 4096, ~0L, 0, 1024, 0}, REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, ~0L, 0, 1024, 0},
{"read_buffer_size", OPT_RECORD_BUFFER, {"read_buffer_size", OPT_RECORD_BUFFER,
"Each thread that does a sequential scan allocates a buffer of this size for each table it scans. If you do many sequential scans, you may want to increase this value.", "Each thread that does a sequential scan allocates a buffer of this size for each table it scans. If you do many sequential scans, you may want to increase this value.",
(uchar**) &global_system_variables.read_buff_size, (uchar**) &global_system_variables.read_buff_size,
......
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