Skip to content

Commit 5b1dd31

Browse files
MrRobertYuanoleksandr-kachan
authored andcommitted
PS-8057: Fix initialization of general and slow log file names
https://perconadev.atlassian.net/browse/PS-8057 In case general and slow log file names are provided in config and slow log rotation is enabled, slow_query_log_file system variable gets initialized with general log name. The reason of the issue is that code responsible for slow and general logs handling have many in common and during initial log names initialization code responsible for slow log rotation was ivoked while initializing general log name. To fix the issue there was a checkup added to make sure code related to slow log rotation is not invoked while general log file name is being processed.
1 parent 646a7cf commit 5b1dd31

4 files changed

+32
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
select @@global.slow_query_log_file;
2+
@@global.slow_query_log_file
3+
mysqld.slowlog
4+
select @@global.general_log_file;
5+
@@global.general_log_file
6+
mysqld.general
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--slow_query_log=ON
2+
--general_log=ON
3+
--slow_query_log_file=mysqld.slowlog
4+
--general_log_file=mysqld.general
5+
--max_slowlog_files=10
6+
--max_slowlog_size=5000
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--replace_regex /\.\d+//
2+
select @@global.slow_query_log_file;
3+
select @@global.general_log_file;

sql/log.cc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,18 @@ bool File_query_log::set_file(const char *new_name) {
505505
if (name != nullptr) my_free(name);
506506

507507
name = nn;
508+
bool res = false;
508509

509-
mysql_mutex_lock(&LOCK_log);
510-
cur_log_ext = 0;
511-
last_removed_ext = 0;
512-
bool res = set_rotated_name(false) || purge_logs();
513-
mysql_mutex_unlock(&LOCK_log);
510+
if (m_log_type == QUERY_LOG_SLOW) {
511+
mysql_mutex_lock(&LOCK_log);
512+
cur_log_ext = 0;
513+
last_removed_ext = 0;
514+
res = set_rotated_name(false) || purge_logs();
515+
mysql_mutex_unlock(&LOCK_log);
516+
} else {
517+
// We can do this here since we're not actually resolving symlinks etc.
518+
fn_format(log_file_name, name, mysql_data_home, "", MY_UNPACK_FILENAME);
519+
}
514520

515521
return res;
516522
}
@@ -2138,6 +2144,8 @@ static size_t get_last_extension(const char *const name) {
21382144
*/
21392145
bool File_query_log::set_rotated_name(const bool need_lock) {
21402146
DBUG_ENTER("File_query_log::set_rotated_name");
2147+
assert(m_log_type == QUERY_LOG_SLOW);
2148+
21412149
if (need_lock) mysql_mutex_assert_owner(&LOCK_log);
21422150

21432151
if (!max_slowlog_size) {
@@ -2189,6 +2197,8 @@ bool File_query_log::set_rotated_name(const bool need_lock) {
21892197
*/
21902198
bool File_query_log::rotate(const ulong max_size) {
21912199
DBUG_ENTER("File_query_log::rotate");
2200+
assert(m_log_type == QUERY_LOG_SLOW);
2201+
21922202
mysql_mutex_assert_owner(&LOCK_log);
21932203

21942204
if (my_b_tell(&log_file) > max_size) {
@@ -2207,6 +2217,8 @@ bool File_query_log::rotate(const ulong max_size) {
22072217
*/
22082218
bool File_query_log::purge_logs() {
22092219
DBUG_ENTER("File_query_log::purge_logs");
2220+
assert(m_log_type == QUERY_LOG_SLOW);
2221+
22102222
mysql_mutex_assert_owner(&LOCK_log);
22112223

22122224
if (max_slowlog_files == 0 || cur_log_ext < 1 ||

0 commit comments

Comments
 (0)