Skip to content

Commit 155ed2c

Browse files
mariadb-RexJohnstonOlernov
authored andcommitted
MDEV-37784 Introduce @@new_mode variable
@@new_mode is a set of flags to control introduced features. Flags are by default off. Setting a flag in @@new_mode will introduce a new different server behaviour and/or set of features. We also introduce a new option 'hidden_values' into some system variable types to hide options that we do not wish to show as options. - Don't print hidden values in mysqld --help output. - Make get_options() use the same logic as check_new_mode_value() does. - Setting @@new_mode=ALL shouldn't give warnings. (cherry picked from commit f7387cb)
1 parent bcb7759 commit 155ed2c

File tree

18 files changed

+306
-25
lines changed

18 files changed

+306
-25
lines changed

include/typelib.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ typedef struct st_typelib { /* Different types saved here */
2525
const char *name; /* Name of typelib */
2626
const char **type_names;
2727
unsigned int *type_lengths;
28+
/*
29+
An array of indexes of enum values that are no longer supported and so are
30+
hidden. One cannot specify hidden values, an attempt to do so will produce
31+
a warning (while an attempt to use a name that was never part of this set
32+
will produce an error).
33+
*/
34+
const int *hidden_values;
2835
} TYPELIB;
2936

30-
#define CREATE_TYPELIB_FOR(X) { (unsigned int)(sizeof(X)/sizeof(X[0])) - 1, "", X, NULL }
37+
#define CREATE_TYPELIB_FOR(X) { (unsigned int)(sizeof(X)/sizeof(X[0])) - 1, "", X, NULL, NULL }
3138

3239
extern my_ulonglong find_typeset(const char *x, TYPELIB *typelib,
3340
int *error_position);

mysql-test/main/mysqld--help.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ The following specify which files/extra groups are read (specified before remain
742742
--net-write-timeout=#
743743
Number of seconds to wait for a block to be written to a
744744
connection before aborting the write
745+
--new-mode=name Used to introduce new behavior to existing MariaDB
746+
versions. Any combination of: TEST_WARNING1
747+
Use 'ALL' to set all combinations.
745748
--note-verbosity=name
746749
Verbosity level for note-warnings given to the user. See
747750
also @@sql_notes.. Any combination of: basic,
@@ -1813,6 +1816,7 @@ net-buffer-length 16384
18131816
net-read-timeout 30
18141817
net-retry-count 10
18151818
net-write-timeout 60
1819+
new-mode
18161820
note-verbosity basic,explain
18171821
old FALSE
18181822
old-mode UTF8_IS_UTF8MB3
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
SET @global_start_value = @@global.new_mode;
2+
SELECT @global_start_value;
3+
@global_start_value
4+
5+
SET @session_start_value = @@session.new_mode;
6+
SELECT @session_start_value;
7+
@session_start_value
8+
9+
SET @@global.new_mode = DEFAULT;
10+
SELECT @@global.new_mode;
11+
@@global.new_mode
12+
13+
SELECT @@session.new_mode;
14+
@@session.new_mode
15+
16+
SET @@session.new_mode = "TEST_WARNING1";
17+
Warnings:
18+
Warning 4206 'TEST_WARNING1' is default and ignored
19+
SET @@session.new_mode = "TEST_WARNING1,TEST_WARNING2";
20+
Warnings:
21+
Warning 4206 'TEST_WARNING1' is default and ignored
22+
Warning 4206 'TEST_WARNING2' is default and ignored
23+
SET @@session.new_mode = "TEST_WARNING1,TEST_WARNING2,TEST_WARNING3";
24+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'TEST_WARNING3'
25+
SET @@session.new_mode = "ALL";
26+
select @@session.new_mode;
27+
@@session.new_mode
28+
29+
SET @@global.new_mode = NULL;
30+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'NULL'
31+
SET @@global.new_mode = '';
32+
SELECT @@global.new_mode;
33+
@@global.new_mode
34+
35+
SET @@global.new_mode = ' ';
36+
SELECT @@global.new_mode;
37+
@@global.new_mode
38+
39+
SET @@session.new_mode = NULL;
40+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'NULL'
41+
SET @@session.new_mode = '';
42+
SELECT @@session.new_mode;
43+
@@session.new_mode
44+
45+
SET @@session.new_mode = ' ';
46+
SELECT @@session.new_mode;
47+
@@session.new_mode
48+
49+
SET @@global.new_mode = OFF;
50+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'OFF'
51+
SET @@session.new_mode = OFF;
52+
ERROR 42000: Variable 'new_mode' can't be set to the value of 'OFF'
53+
SET @@global.new_mode = @global_start_value;
54+
SELECT @@global.new_mode;
55+
@@global.new_mode
56+
57+
SET @@session.new_mode = @session_start_value;
58+
SELECT @@session.new_mode;
59+
@@session.new_mode
60+

mysql-test/suite/sys_vars/r/sysvars_server_embedded.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,16 @@ NUMERIC_BLOCK_SIZE 1
23122312
ENUM_VALUE_LIST NULL
23132313
READ_ONLY NO
23142314
COMMAND_LINE_ARGUMENT REQUIRED
2315+
VARIABLE_NAME NEW_MODE
2316+
VARIABLE_SCOPE SESSION
2317+
VARIABLE_TYPE SET
2318+
VARIABLE_COMMENT Used to introduce new behavior to existing MariaDB versions
2319+
NUMERIC_MIN_VALUE NULL
2320+
NUMERIC_MAX_VALUE NULL
2321+
NUMERIC_BLOCK_SIZE NULL
2322+
ENUM_VALUE_LIST
2323+
READ_ONLY NO
2324+
COMMAND_LINE_ARGUMENT REQUIRED
23152325
VARIABLE_NAME NOTE_VERBOSITY
23162326
VARIABLE_SCOPE SESSION
23172327
VARIABLE_TYPE SET

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,16 @@ NUMERIC_BLOCK_SIZE 1
25222522
ENUM_VALUE_LIST NULL
25232523
READ_ONLY NO
25242524
COMMAND_LINE_ARGUMENT REQUIRED
2525+
VARIABLE_NAME NEW_MODE
2526+
VARIABLE_SCOPE SESSION
2527+
VARIABLE_TYPE SET
2528+
VARIABLE_COMMENT Used to introduce new behavior to existing MariaDB versions
2529+
NUMERIC_MIN_VALUE NULL
2530+
NUMERIC_MAX_VALUE NULL
2531+
NUMERIC_BLOCK_SIZE NULL
2532+
ENUM_VALUE_LIST
2533+
READ_ONLY NO
2534+
COMMAND_LINE_ARGUMENT REQUIRED
25252535
VARIABLE_NAME NOTE_VERBOSITY
25262536
VARIABLE_SCOPE SESSION
25272537
VARIABLE_TYPE SET
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--source include/load_sysvars.inc
2+
--source include/have_debug.inc
3+
4+
SET @global_start_value = @@global.new_mode;
5+
SELECT @global_start_value;
6+
7+
SET @session_start_value = @@session.new_mode;
8+
SELECT @session_start_value;
9+
10+
SET @@global.new_mode = DEFAULT;
11+
SELECT @@global.new_mode;
12+
SELECT @@session.new_mode;
13+
14+
SET @@session.new_mode = "TEST_WARNING1";
15+
SET @@session.new_mode = "TEST_WARNING1,TEST_WARNING2";
16+
--Error ER_WRONG_VALUE_FOR_VAR
17+
SET @@session.new_mode = "TEST_WARNING1,TEST_WARNING2,TEST_WARNING3";
18+
19+
SET @@session.new_mode = "ALL";
20+
select @@session.new_mode;
21+
22+
--Error ER_WRONG_VALUE_FOR_VAR
23+
SET @@global.new_mode = NULL;
24+
25+
SET @@global.new_mode = '';
26+
SELECT @@global.new_mode;
27+
28+
SET @@global.new_mode = ' ';
29+
SELECT @@global.new_mode;
30+
31+
--Error ER_WRONG_VALUE_FOR_VAR
32+
SET @@session.new_mode = NULL;
33+
34+
SET @@session.new_mode = '';
35+
SELECT @@session.new_mode;
36+
37+
SET @@session.new_mode = ' ';
38+
SELECT @@session.new_mode;
39+
40+
--Error ER_WRONG_VALUE_FOR_VAR
41+
SET @@global.new_mode = OFF;
42+
43+
--Error ER_WRONG_VALUE_FOR_VAR
44+
SET @@session.new_mode = OFF;
45+
46+
SET @@global.new_mode = @global_start_value;
47+
SELECT @@global.new_mode;
48+
49+
SET @@session.new_mode = @session_start_value;
50+
SELECT @@session.new_mode;

mysys/my_getopt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,22 @@ void my_print_help(const struct my_option *options)
16491649
col= print_comment(optp->typelib->type_names[0], col, name_space, comment_space);
16501650
for (i= 1; i < count; i++)
16511651
{
1652+
my_bool skip_value= 0;
1653+
/* Do not print the value if it is listed in hidden_values */
1654+
if (optp->typelib->hidden_values)
1655+
{
1656+
for (const int *value= optp->typelib->hidden_values;
1657+
*value >= 0; value++)
1658+
{
1659+
if (*value == (int)i)
1660+
{
1661+
skip_value= 1;
1662+
break;
1663+
}
1664+
}
1665+
}
1666+
if (skip_value)
1667+
continue;
16521668
col= print_comment(", ", col, name_space, comment_space);
16531669
col= print_comment(optp->typelib->type_names[i], col, name_space, comment_space);
16541670
}

sql/handler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const char *tx_isolation_names[]=
154154
NullS};
155155
TYPELIB tx_isolation_typelib= CREATE_TYPELIB_FOR(tx_isolation_names);
156156

157-
static TYPELIB known_extensions= {0,"known_exts", NULL, NULL};
157+
static TYPELIB known_extensions= {0,"known_exts", NULL, NULL, NULL};
158158
uint known_extensions_id= 0;
159159

160160

sql/mysqld.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static const char *tc_heuristic_recover_names[]=
300300
static TYPELIB tc_heuristic_recover_typelib=
301301
{
302302
array_elements(tc_heuristic_recover_names)-1,"",
303-
tc_heuristic_recover_names, NULL
303+
tc_heuristic_recover_names, NULL, NULL
304304
};
305305

306306
const char *first_keyword= "first";
@@ -8670,6 +8670,9 @@ static void option_error_reporter(enum loglevel level, const char *format, ...)
86708670

86718671
C_MODE_END
86728672

8673+
extern const char **new_mode_default_names;
8674+
8675+
86738676
/**
86748677
Get server options from the command line,
86758678
and perform related server initializations.
@@ -8730,6 +8733,8 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
87308733
"release. Please use --old-mode instead. ");
87318734
}
87328735

8736+
check_new_mode_value(NULL, &global_system_variables.new_behavior);
8737+
87338738
if (global_system_variables.net_buffer_length >
87348739
global_system_variables.max_allowed_packet)
87358740
{

sql/set_var.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,21 @@ int fill_sysvars(THD *thd, TABLE_LIST *tables, COND *cond)
12191219
strbuf.length(0);
12201220
for (i=0; i < tl->count; i++)
12211221
{
1222-
const char *name= tl->type_names[i];
1223-
strbuf.append(name, strlen(name));
1224-
strbuf.append(',');
1222+
bool show= TRUE;
1223+
if (tl->hidden_values)
1224+
{
1225+
for (uint j= 0; tl->hidden_values[j] >= 0; j++)
1226+
{
1227+
if (tl->hidden_values[j] == (int)i)
1228+
show= FALSE;
1229+
}
1230+
}
1231+
if (show)
1232+
{
1233+
const char *name= tl->type_names[i];
1234+
strbuf.append(name, strlen(name));
1235+
strbuf.append(',');
1236+
}
12251237
}
12261238
if (!strbuf.is_empty())
12271239
strbuf.chop();

0 commit comments

Comments
 (0)