Commit 8ca5935a authored by Yuchen Pei's avatar Yuchen Pei

MDEV-34915 [debug] Sort output of session track info in mysqltest

The new test is for debugging only and should be removed
parent fe3432b3
......@@ -8022,6 +8022,22 @@ static const char *trking_info_desc[SESSION_TRACK_END + 1]=
/**
@brief Append state change information (received through Ok packet) to the output.
@details The appended string is lines prefixed with "-- ". Only
tracking types with info sent from the server are displayed. For
each tracking type, the first line is the type name e.g.
"-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES".
The subsequent lines are the actual tracking info. When type is
SESSION_TRACK_SYSTEM_VARIABLES, the actual tracking info is a list
of name-value pairs of lines, sorted by name, e.g. if the info
received from the server is "autocommit=ON;time_zone=SYSTEM", the
corresponding string is
-- autocommit
-- ON
-- time_zone
-- SYSTEM
@param [in,out] ds Dynamic string to hold the content to be printed.
@param [in] mysql Connection handle.
*/
......@@ -8031,11 +8047,16 @@ static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql)
if (!(mysql->server_status & SERVER_SESSION_STATE_CHANGED))
return;
#ifndef EMBEDDED_LIBRARY
DYNAMIC_STRING ds_sort, *ds_type= NULL;
for (unsigned int type= SESSION_TRACK_BEGIN; type <= SESSION_TRACK_END; type++)
{
const char *data;
size_t data_length;
/*
Append the tracking type line, if any corresponding tracking
info is received.
*/
if (!mysql_session_track_get_first(mysql,
(enum_session_state_type) type,
&data, &data_length))
......@@ -8051,26 +8072,60 @@ static void append_session_track_info(DYNAMIC_STRING *ds, MYSQL *mysql)
DBUG_ASSERT(0);
dynstr_append_mem(ds, STRING_WITH_LEN("Tracker???\n"));
}
dynstr_append_mem(ds, STRING_WITH_LEN("-- "));
dynstr_append_mem(ds, data, data_length);
}
else
continue;
/*
The remaining of this function: format and append the actual
tracking info.
*/
if (type == SESSION_TRACK_SYSTEM_VARIABLES)
{
/* Prepare a string to be sorted before being appended. */
if (init_dynamic_string(&ds_sort, "", 1024, 1024))
die("Out of memory");
ds_type= &ds_sort;
}
else
ds_type= ds;
/* Append the first piece of info */
dynstr_append_mem(ds_type, STRING_WITH_LEN("-- "));
dynstr_append_mem(ds_type, data, data_length);
/* Whether we are appending the value of a variable */
bool appending_value= type == SESSION_TRACK_SYSTEM_VARIABLES;
/* Append remaining pieces */
while (!mysql_session_track_get_next(mysql,
(enum_session_state_type) type,
&data, &data_length))
{
dynstr_append_mem(ds, STRING_WITH_LEN("\n-- "));
if (appending_value)
dynstr_append_mem(ds_type, STRING_WITH_LEN(" -- "));
else
dynstr_append_mem(ds_type, STRING_WITH_LEN("\n-- "));
appending_value= !appending_value && type == SESSION_TRACK_SYSTEM_VARIABLES;
if (data == NULL)
{
DBUG_ASSERT(data_length == 0);
dynstr_append_mem(ds, STRING_WITH_LEN("<NULL>"));
dynstr_append_mem(ds_type, STRING_WITH_LEN("<NULL>"));
}
else
dynstr_append_mem(ds, data, data_length);
dynstr_append_mem(ds_type, data, data_length);
}
DBUG_ASSERT(!appending_value);
if (type == SESSION_TRACK_SYSTEM_VARIABLES)
{
dynstr_append_mem(ds_type, STRING_WITH_LEN("\n"));
dynstr_append_sorted(ds, ds_type, false);
dynstr_append_mem(ds, STRING_WITH_LEN("\n"));
char *find_replace= ds->str;
while ((find_replace= strstr(find_replace, " -- ")) &&
find_replace < ds->str + ds->length)
*find_replace= '\n';
dynstr_free(&ds_sort);
}
dynstr_append_mem(ds, STRING_WITH_LEN("\n\n"));
else
dynstr_append_mem(ds, STRING_WITH_LEN("\n\n"));
}
#endif /* EMBEDDED_LIBRARY */
}
......@@ -12173,7 +12228,8 @@ void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val)
/*
Build a list of pointer to each line in ds_input, sort
the list and use the sorted list to append the strings
sorted to the output ds
sorted to the output ds. The string ds_input needs to
end with a newline.
SYNOPSIS
dynstr_append_sorted()
......
set @old_session_track_system_variables=@@global.session_track_system_variables;
set global session_track_system_variables="autocommit,character_set_client,character_set_connection,redirect_url,time_zone";
connect foo,localhost,root;
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- autocommit
-- ON
-- character_set_client
-- latin1
-- character_set_connection
-- latin1
-- redirect_url
--
-- time_zone
-- SYSTEM
connection default;
disconnect foo;
set global session_track_system_variables=@old_session_track_system_variables;
......@@ -160,14 +160,14 @@ connect foo,localhost,root;
-- Tracker : SESSION_TRACK_SYSTEM_VARIABLES
-- autocommit
-- ON
-- time_zone
-- SYSTEM
-- character_set_client
-- latin1
-- character_set_connection
-- latin1
-- redirect_url
--
-- time_zone
-- SYSTEM
connection default;
disconnect foo;
......
--source include/not_embedded.inc
set @old_session_track_system_variables=@@global.session_track_system_variables;
# We set the session_track_system_variables to exclude
# character_set_results as it can appear out of order in the CI
# builder x86-debian-sid.
set global session_track_system_variables="autocommit,character_set_client,character_set_connection,redirect_url,time_zone";
enable_session_track_info;
connect foo,localhost,root;
disable_session_track_info;
connection default;
disconnect foo;
set global session_track_system_variables=@old_session_track_system_variables;
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