Skip to content

Commit

Permalink
MDEV-33145 support for old-mode=OLD_FLUSH_STATUS
Browse files Browse the repository at this point in the history
add old-mode that restores inconsistent legacy behavior for FLUSH STATUS.
It doesn't affect FLUSH { SESSION | GLOBAL } STATUS.
  • Loading branch information
vuvova committed May 27, 2024
1 parent 9ecec1f commit 9293d40
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/mysql_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ enum enum_indicator_type
#define REFRESH_LOG (1ULL << 1) /* Start on new log file */
#define REFRESH_TABLES (1ULL << 2) /* close all tables */
#define REFRESH_HOSTS (1ULL << 3) /* Flush host cache */
#define REFRESH_SESSION_STATUS (1ULL << 4) /* Flush status variables */
#define REFRESH_STATUS REFRESH_SESSION_STATUS
#define REFRESH_STATUS (1ULL << 4) /* Flush status variables */
#define REFRESH_THREADS (1ULL << 5) /* Flush thread cache */
#define REFRESH_SLAVE (1ULL << 6) /* Reset master info and restart
slave thread */
Expand All @@ -220,6 +219,7 @@ enum enum_indicator_type
#define REFRESH_FOR_EXPORT (1ULL << 20) /* FLUSH TABLES ... FOR EXPORT */
#define REFRESH_SSL (1ULL << 21)
#define REFRESH_GLOBAL_STATUS (1ULL << 22) /* Flush global status */
#define REFRESH_SESSION_STATUS (1ULL << 23) /* Flush session status */

#define REFRESH_GENERIC (1ULL << 30)
#define REFRESH_FAST (1ULL << 31) /* Intern flag */
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/main/mysqld--help.result
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,8 @@ The following specify which files/extra groups are read (specified before remain
NO_DUP_KEY_WARNINGS_WITH_IGNORE, NO_PROGRESS_INFO,
ZERO_DATE_TIME_CAST, UTF8_IS_UTF8MB3,
IGNORE_INDEX_ONLY_FOR_JOIN, COMPAT_5_1_CHECKSUM,
NO_NULL_COLLATION_IDS, LOCK_ALTER_TABLE_COPY, or ALL to
set all combinations
NO_NULL_COLLATION_IDS, LOCK_ALTER_TABLE_COPY,
OLD_FLUSH_STATUS, or ALL to set all combinations
--old-passwords Use old password encryption method (needed for 4.0 and
older clients)
--old-style-user-limits
Expand Down
25 changes: 25 additions & 0 deletions mysql-test/main/status.result
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,29 @@ select $new_local_flush_status >= $local_flush_status as "1";
select $new_global_flush_status < $new_local_flush_status as "1";
1
1
create or replace table t1 (a int, key(a)) engine=MyISAM;
insert into t1 values (1),(2);
connect con1,localhost,root;
set old_mode=OLD_FLUSH_STATUS;
Warnings:
Warning 1287 'OLD_FLUSH_STATUS' is deprecated and will be removed in a future release
insert into t1 values (3),(4);
drop table t1;
select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
from information_schema.global_status t1 join information_schema.session_status t2
on t1.variable_name = t2.variable_name
where t1.variable_name in ('Key_writes','Com_insert');
variable_name global_value session_value
COM_INSERT 2 1
KEY_WRITES 2 2
flush status;
select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
from information_schema.global_status t1 join information_schema.session_status t2
on t1.variable_name = t2.variable_name
where t1.variable_name in ('Key_writes','Com_insert');
variable_name global_value session_value
COM_INSERT 2 0
KEY_WRITES 0 0
disconnect con1;
connection default;
# end of 11.5 tests
28 changes: 28 additions & 0 deletions mysql-test/main/status.test
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,32 @@ let $new_local_flush_status= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.SESS
--evalp select $new_local_flush_status >= $local_flush_status as "1"
--evalp select $new_global_flush_status < $new_local_flush_status as "1"

#
# Test OLD_FLUSH_STATUS
#

create or replace table t1 (a int, key(a)) engine=MyISAM;
insert into t1 values (1),(2);

--connect con1,localhost,root
set old_mode=OLD_FLUSH_STATUS;

insert into t1 values (3),(4);
drop table t1;

select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
from information_schema.global_status t1 join information_schema.session_status t2
on t1.variable_name = t2.variable_name
where t1.variable_name in ('Key_writes','Com_insert');

flush status;

select t1.variable_name, t1.variable_value as global_value, t2.variable_value as session_value
from information_schema.global_status t1 join information_schema.session_status t2
on t1.variable_name = t2.variable_name
where t1.variable_name in ('Key_writes','Com_insert');

disconnect con1;
connection default;

--echo # end of 11.5 tests
4 changes: 2 additions & 2 deletions mysql-test/suite/sys_vars/r/old_mode_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Warning 1287 'ZERO_DATE_TIME_CAST' is deprecated and will be removed in a future
SELECT @@global.old_mode;
@@global.old_mode
ZERO_DATE_TIME_CAST
SET @@global.old_mode = 256;
ERROR 42000: Variable 'old_mode' can't be set to the value of '256'
SET @@global.old_mode = 6536;
ERROR 42000: Variable 'old_mode' can't be set to the value of '6536'
SELECT @@global.old_mode;
@@global.old_mode
ZERO_DATE_TIME_CAST
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/sys_vars/r/sysvars_server_embedded.result
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ VARIABLE_COMMENT Used to emulate old behavior from earlier MariaDB or MySQL vers
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY,OLD_FLUSH_STATUS
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME OLD_PASSWORDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ VARIABLE_COMMENT Used to emulate old behavior from earlier MariaDB or MySQL vers
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY
ENUM_VALUE_LIST NO_DUP_KEY_WARNINGS_WITH_IGNORE,NO_PROGRESS_INFO,ZERO_DATE_TIME_CAST,UTF8_IS_UTF8MB3,IGNORE_INDEX_ONLY_FOR_JOIN,COMPAT_5_1_CHECKSUM,NO_NULL_COLLATION_IDS,LOCK_ALTER_TABLE_COPY,OLD_FLUSH_STATUS
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME OLD_PASSWORDS
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/sys_vars/t/old_mode_basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ SET @@global.old_mode = 4;
SELECT @@global.old_mode;

--Error ER_WRONG_VALUE_FOR_VAR
SET @@global.old_mode = 256;
SET @@global.old_mode = 6536;
SELECT @@global.old_mode;

# use of decimal values
Expand Down
46 changes: 46 additions & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9227,6 +9227,52 @@ void refresh_global_status()
max_used_connections_time= time(nullptr);
}

/** Emulate the legacy FLUSH STATUS inconsistent behavior

* additive session variables are added to global and set to 0 in session
* non-additive global variables are set to 0
*/
void refresh_status_legacy(THD *thd)
{
mysql_mutex_lock(&LOCK_status);

#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
/* Reset aggregated status counters. */
reset_pfs_status_stats();
#endif

/* Add thread's status variabes to global status */
add_to_status(&global_status_var, &thd->status_var);

/* Reset thread's status variables */
thd->set_status_var_init();
thd->status_var.global_memory_used= 0;
bzero((uchar*) &thd->org_status_var, sizeof(thd->org_status_var));
thd->start_bytes_received= 0;

/* Reset some global variables */
reset_status_vars();
#ifdef WITH_WSREP
if (WSREP_ON)
{
Wsrep_server_state::instance().provider().reset_status();
}
#endif /* WITH_WSREP */

/* Reset the counters of all key caches (default and named). */
process_key_caches(reset_key_cache_counters, 0);
global_status_var.flush_status_time= my_time(0);
mysql_mutex_unlock(&LOCK_status);

/*
Set max_used_connections to the number of currently open
connections. This is not perfect, but status data is not exact anyway.
*/
max_used_connections= connection_count + extra_connection_count;
max_used_connections_time= time(nullptr);
}



#ifdef HAVE_PSI_INTERFACE
static PSI_file_info all_server_files[]=
Expand Down
1 change: 1 addition & 0 deletions sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void close_connection(THD *thd, uint sql_errno= 0);
void handle_connection_in_main_thread(CONNECT *thd);
void create_thread_to_handle_connection(CONNECT *connect);
void unlink_thd(THD *thd);
void refresh_status_legacy(THD *thd);
void refresh_session_status(THD *thd);
void refresh_global_status();
bool is_secure_file_path(char *path);
Expand Down
1 change: 1 addition & 0 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ enum enum_binlog_row_image {
#define OLD_MODE_COMPAT_5_1_CHECKSUM (1 << 5)
#define OLD_MODE_NO_NULL_COLLATION_IDS (1 << 6)
#define OLD_MODE_LOCK_ALTER_TABLE_COPY (1 << 7)
#define OLD_MODE_OLD_FLUSH_STATUS (1 << 8)

#define OLD_MODE_DEFAULT_VALUE OLD_MODE_UTF8_IS_UTF8MB3

Expand Down
4 changes: 4 additions & 0 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,9 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
if (trans_commit_implicit(thd))
break;
thd->release_transactional_locks();
if (options & REFRESH_STATUS &&
!(thd->variables.old_behavior & OLD_MODE_OLD_FLUSH_STATUS))
options= (options & ~REFRESH_STATUS) | REFRESH_SESSION_STATUS;
if ((options & ~REFRESH_SESSION_STATUS) &&
check_global_access(thd,RELOAD_ACL))
break;
Expand Down Expand Up @@ -5277,6 +5280,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
#ifdef HAVE_QUERY_CACHE
REFRESH_QUERY_CACHE_FREE |
#endif /* HAVE_QUERY_CACHE */
REFRESH_STATUS |
REFRESH_SESSION_STATUS |
REFRESH_GLOBAL_STATUS |
REFRESH_USER_RESOURCES))
Expand Down
2 changes: 2 additions & 0 deletions sql/sql_reload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options,
#endif
if (options & REFRESH_HOSTS)
hostname_cache_refresh();
if (thd && (options & REFRESH_STATUS))
refresh_status_legacy(thd);
if (thd && (options & REFRESH_SESSION_STATUS))
refresh_session_status(thd);
if ((options & REFRESH_GLOBAL_STATUS))
Expand Down
7 changes: 6 additions & 1 deletion sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -14673,7 +14673,12 @@ flush_option:
Lex->relay_log_connection_name= empty_clex_str;
}
| STATUS_SYM
{ Lex->type|= REFRESH_SESSION_STATUS; }
{
if (thd->variables.old_behavior & OLD_MODE_OLD_FLUSH_STATUS)
Lex->type|= REFRESH_STATUS;
else
Lex->type|= REFRESH_SESSION_STATUS;
}
| SESSION_SYM STATUS_SYM
{ Lex->type|= REFRESH_SESSION_STATUS; }
| GLOBAL_SYM STATUS_SYM
Expand Down
4 changes: 4 additions & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3955,6 +3955,7 @@ static const char *old_mode_names[]=
"COMPAT_5_1_CHECKSUM", // 5: deprecated since 11.3
"NO_NULL_COLLATION_IDS", // 6: deprecated since 11.3
"LOCK_ALTER_TABLE_COPY", // 7: deprecated since 11.3
"OLD_FLUSH_STATUS", // 8: deprecated since 11.5
0
};

Expand All @@ -3974,6 +3975,9 @@ static bool old_mode_deprecated(sys_var *self, THD *thd, set_var *var)
for (; i <= 7; i++)
if ((1ULL<<i) & v)
warn_deprecated<1103>(thd, old_mode_names[i]);
for (; i <= 8; i++)
if ((1ULL<<i) & v)
warn_deprecated<1105>(thd, old_mode_names[i]);
return false;
}

Expand Down

0 comments on commit 9293d40

Please sign in to comment.