Skip to content

Commit 18ef02b

Browse files
committed
MDEV-4774 Strangeness with max_binlog_stmt_cache_size Settings
Problem:- When setting max_binlog_stmt_cache_size=18446744073709547520 from either command line or .cnf file, server fails to start. Solution:- Added one more function eval_num_suffix_ull , which uses strtoull to get unsigned ulonglong from string. And getopt_ull calls this function instead of eval_num_suffix. Also changed previous eval_num_suffix to eval_num_suffix_ll to remain consistent.
1 parent fbcdc34 commit 18ef02b

File tree

4 files changed

+114
-12
lines changed

4 files changed

+114
-12
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
select @@max_binlog_stmt_cache_size;
2+
@@max_binlog_stmt_cache_size
3+
18446744073709547520
4+
set global max_binlog_stmt_cache_size= 18446744073709547520;
5+
select @@max_binlog_stmt_cache_size;
6+
@@max_binlog_stmt_cache_size
7+
18446744073709547520
8+
set global max_binlog_stmt_cache_size= 18446744073709547519;
9+
Warnings:
10+
Warning 1292 Truncated incorrect max_binlog_stmt_cache_size value: '18446744073709547519'
11+
select @@max_binlog_stmt_cache_size;
12+
@@max_binlog_stmt_cache_size
13+
18446744073709543424
14+
set global max_binlog_stmt_cache_size= 18446744073709551615;
15+
Warnings:
16+
Warning 1292 Truncated incorrect max_binlog_stmt_cache_size value: '18446744073709551615'
17+
select @@max_binlog_stmt_cache_size;
18+
@@max_binlog_stmt_cache_size
19+
18446744073709547520
20+
set global max_binlog_stmt_cache_size= 18446744073709551614;
21+
Warnings:
22+
Warning 1292 Truncated incorrect max_binlog_stmt_cache_size value: '18446744073709551614'
23+
select @@max_binlog_stmt_cache_size;
24+
@@max_binlog_stmt_cache_size
25+
18446744073709547520
26+
set global max_binlog_stmt_cache_size= 18446744073709551616;
27+
ERROR 42000: Incorrect argument type to variable 'max_binlog_stmt_cache_size'
28+
select @@max_binlog_stmt_cache_size;
29+
@@max_binlog_stmt_cache_size
30+
18446744073709547520
31+
set global max_binlog_stmt_cache_size= 18446744073709547520;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--max_binlog_stmt_cache_size=18446744073709547520
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
source include/have_log_bin.inc;
2+
select @@max_binlog_stmt_cache_size;
3+
4+
--let $cache_size=`select @@max_binlog_stmt_cache_size;`
5+
6+
set global max_binlog_stmt_cache_size= 18446744073709547520;
7+
select @@max_binlog_stmt_cache_size;
8+
9+
set global max_binlog_stmt_cache_size= 18446744073709547519;
10+
select @@max_binlog_stmt_cache_size;
11+
12+
set global max_binlog_stmt_cache_size= 18446744073709551615;
13+
select @@max_binlog_stmt_cache_size;
14+
15+
set global max_binlog_stmt_cache_size= 18446744073709551614;
16+
select @@max_binlog_stmt_cache_size;
17+
18+
--error ER_WRONG_TYPE_FOR_VAR
19+
set global max_binlog_stmt_cache_size= 18446744073709551616;
20+
select @@max_binlog_stmt_cache_size;
21+
22+
--eval set global max_binlog_stmt_cache_size= $cache_size

mysys/my_getopt.c

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -895,15 +895,39 @@ my_bool getopt_compare_strings(register const char *s, register const char *t,
895895
/*
896896
function: eval_num_suffix
897897
898+
Transforms suffix like k/m/g to their real value.
899+
*/
900+
901+
static inline long eval_num_suffix(char *suffix, int *error)
902+
{
903+
long num= 1;
904+
if (*suffix == 'k' || *suffix == 'K')
905+
num*= 1024L;
906+
else if (*suffix == 'm' || *suffix == 'M')
907+
num*= 1024L * 1024L;
908+
else if (*suffix == 'g' || *suffix == 'G')
909+
num*= 1024L * 1024L * 1024L;
910+
else if (*suffix)
911+
{
912+
*error= 1;
913+
return 0;
914+
}
915+
return num;
916+
}
917+
918+
/*
919+
function: eval_num_suffix_ll
920+
898921
Transforms a number with a suffix to real number. Suffix can
899922
be k|K for kilo, m|M for mega or g|G for giga.
900923
*/
901924

902-
static longlong eval_num_suffix(char *argument, int *error, char *option_name)
925+
static longlong eval_num_suffix_ll(char *argument,
926+
int *error, char *option_name)
903927
{
904928
char *endchar;
905929
longlong num;
906-
DBUG_ENTER("eval_num_suffix");
930+
DBUG_ENTER("eval_num_suffix_ll");
907931

908932

909933
*error= 0;
@@ -916,23 +940,47 @@ static longlong eval_num_suffix(char *argument, int *error, char *option_name)
916940
*error= 1;
917941
DBUG_RETURN(0);
918942
}
919-
if (*endchar == 'k' || *endchar == 'K')
920-
num*= 1024L;
921-
else if (*endchar == 'm' || *endchar == 'M')
922-
num*= 1024L * 1024L;
923-
else if (*endchar == 'g' || *endchar == 'G')
924-
num*= 1024L * 1024L * 1024L;
925-
else if (*endchar)
926-
{
943+
num*= eval_num_suffix(endchar, error);
944+
if (*error)
927945
fprintf(stderr,
928946
"Unknown suffix '%c' used for variable '%s' (value '%s')\n",
929947
*endchar, option_name, argument);
948+
DBUG_RETURN(num);
949+
}
950+
951+
/*
952+
function: eval_num_suffix_ull
953+
954+
Transforms a number with a suffix to positive Integer. Suffix can
955+
be k|K for kilo, m|M for mega or g|G for giga.
956+
*/
957+
958+
static ulonglong eval_num_suffix_ull(char *argument,
959+
int *error, char *option_name)
960+
{
961+
char *endchar;
962+
ulonglong num;
963+
DBUG_ENTER("eval_num_suffix_ull");
964+
965+
*error= 0;
966+
errno= 0;
967+
num= strtoull(argument, &endchar, 10);
968+
if (errno == ERANGE)
969+
{
970+
my_getopt_error_reporter(ERROR_LEVEL,
971+
"Incorrect integer value: '%s'", argument);
930972
*error= 1;
931973
DBUG_RETURN(0);
932974
}
975+
num*= eval_num_suffix(endchar, error);
976+
if (*error)
977+
fprintf(stderr,
978+
"Unknown suffix '%c' used for variable '%s' (value '%s')\n",
979+
*endchar, option_name, argument);
933980
DBUG_RETURN(num);
934981
}
935982

983+
936984
/*
937985
function: getopt_ll
938986
@@ -946,7 +994,7 @@ static longlong eval_num_suffix(char *argument, int *error, char *option_name)
946994

947995
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
948996
{
949-
longlong num=eval_num_suffix(arg, err, (char*) optp->name);
997+
longlong num=eval_num_suffix_ll(arg, err, (char*) optp->name);
950998
return getopt_ll_limit_value(num, optp, NULL);
951999
}
9521000

@@ -1023,7 +1071,7 @@ longlong getopt_ll_limit_value(longlong num, const struct my_option *optp,
10231071

10241072
static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err)
10251073
{
1026-
ulonglong num= eval_num_suffix(arg, err, (char*) optp->name);
1074+
ulonglong num= eval_num_suffix_ull(arg, err, (char*) optp->name);
10271075
return getopt_ull_limit_value(num, optp, NULL);
10281076
}
10291077

0 commit comments

Comments
 (0)