Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/mariadb-test-data.lintian-overrides
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-te
package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-test/std_data/mariadb-conv/file01.utf8.txt]
package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-test/std_data/mariadb-conv/file02.latin1.txt]
package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-test/std_data/mysql5613mysql/README]
package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-test/std_data/new-format-master.info]
package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-test/std_data/new-format-relay-log-win.info]
package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-test/std_data/new-format-relay-log.info]
package-contains-documentation-outside-usr-share-doc [usr/share/mysql/mariadb-test/std_data/numbers.txt]
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/main/rpl_read_new_info.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CHANGE MASTER TO master_host='127.0.0.1';
# restart: --skip-slave-start
Master_Log_File = 'mysqld-bin.000002'
Read_Master_Log_Pos = '2147483648'
Master_SSL_Key = ''
Using_Gtid = 'Current_Pos'
Relay_Master_Log_File = 'mysqld-bin.000001'
Exec_Master_Log_Pos = '2147483648'
SQL_Delay = '5'
RESET SLAVE ALL;
41 changes: 41 additions & 0 deletions mysql-test/main/rpl_read_new_info.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Verify that the post-WL#344 format of `*.info` can be parsed.
# * Verify that the line count includes the line-count line in
# `@@master_info_file` while excludes it in `@@relay_log_info_file`
# (Reference: MDEV-39788 master.info is read and
# written one line too many compared to before)
# * Verify that position values > 2^31 can be read
# (MDEV-38020: Master & relay log info files read 2^31 and above incorrectly)

--source include/have_binlog_format_mixed.inc # format-agnostic
CHANGE MASTER TO master_host='127.0.0.1'; # have_info_files

--let $MYSQLD_DATADIR= `SELECT @@datadir`

# the new version of relay_log.info comes in two versions: with path
# separator '/' (most systems) and with path separator '\' (windows)
if ($SYSTEM_PATH_SEPARATOR != /) {
--let $file_suffix= -win
}


--source include/shutdown_mysqld.inc

--remove_file $MYSQLD_DATADIR/master.info
# `Using_Gtid` is the key-value section, not the 33rd option.
--copy_file $MYSQL_TEST_DIR/std_data/new-format-master.info $MYSQLD_DATADIR/master.info

# Check that the 5th option (`SQL_Delay`) is included.
--remove_file $MYSQLD_DATADIR/relay-log.info
--copy_file $MYSQL_TEST_DIR/std_data/new-format-relay-log$file_suffix.info $MYSQLD_DATADIR/relay-log.info

--let $restart_parameters= --skip-slave-start
--source include/start_mysqld.inc

--let $status_items= Master_Log_File, Read_Master_Log_Pos, Master_SSL_Key, Using_Gtid, Relay_Master_Log_File, Exec_Master_Log_Pos, SQL_Delay
--source include/show_slave_status.inc


# Reset
--disable_warnings
RESET SLAVE ALL;
--enable_warnings
34 changes: 34 additions & 0 deletions mysql-test/std_data/new-format-master.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
33
mysqld-bin.000002
2147483648
127.0.0.1
root

3306
60
1





1
60.000

0

100000













using_gtid=1
8 changes: 4 additions & 4 deletions mysql-test/std_data/new-format-relay-log-win.info
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
5
.\slave-relay-bin.000001
.\mysqld-relay-bin.000001
4

0
0
mysqld-bin.000001
2147483648
5
8 changes: 4 additions & 4 deletions mysql-test/std_data/new-format-relay-log.info
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
5
./slave-relay-bin.000001
./mysqld-relay-bin.000001
4

0
0
mysqld-bin.000001
2147483648
5
15 changes: 0 additions & 15 deletions mysql-test/suite/rpl/r/rpl_read_new_relay_log_info.result

This file was deleted.

48 changes: 0 additions & 48 deletions mysql-test/suite/rpl/t/rpl_read_new_relay_log_info.test

This file was deleted.

26 changes: 11 additions & 15 deletions sql/rpl_info_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ struct Info_file
(Re)load the MySQL line-based section from the @ref file
@param value_list
List of wrapped member pointers to values. The first element must be a
file name @ref String_value to be unambiguous with the line count line.
file name @ref String_value to be unambiguous with the line-count line.
@param default_line_count
We cannot simply read lines until EOF as all versions
of MySQL/MariaDB may generate more lines than needed.
Therefore, starting with MySQL/MariaDB 4.1.x for @ref Master_info_file and
5.6.x for @ref Relay_log_info_file, the first line of the file is number
of one-line-per-value lines in the file, including this line count itself.
5.6.x/10.0.x for @ref Relay_log_info_file, the first line of the file is
the number of one-line-per-value lines in the file.
This parameter specifies the number of effective lines before those
versions (i.e., not counting the line count line if it was to have one),
versions (i.e., not counting the line-count line if it was to have one),
where the first line is a filename with extension
(either contains a `.` or is entirely empty) rather than an integer.
@return `false` if the file has parsed successfully or `true` if error
Expand All @@ -273,13 +273,13 @@ struct Info_file
@param total_line_count
The number of lines to describe the file as on the first line of the file.
If this is larger than `value_list.size()`, suffix the file with empty
lines until the line count (including the line count line) is this many.
This reservation provides compatibility with MySQL,
who has added more old-style lines while MariaDB innovated.
lines until the line count (*excluding* the line-count line) is this many.
This reservation provides compatibility
with older versions of MySQL and MariaDB.
*/
template<size_t size> void save_to_file(
const Mem_fn (&value_list)[size],
size_t total_line_count= size + /* line count line */ 1
size_t total_line_count= size
) { return save_to_file(value_list, size, total_line_count); }

private:
Expand Down Expand Up @@ -336,7 +336,7 @@ struct Info_file

void save_to_file(const Mem_fn *values, size_t size, size_t total_line_count)
{
DBUG_ASSERT(total_line_count > size);
DBUG_ASSERT(total_line_count >= size);
my_b_seek(&file, 0);
/*
If the new contents take less space than the previous file contents,
Expand All @@ -353,12 +353,8 @@ struct Info_file
pm(this).save_to(&file);
my_b_write_byte(&file, '\n');
}
/*
Pad additional reserved lines:
(1 for the line count line + line count) inclusive -> max line inclusive
= line count exclusive <- max line inclusive
*/
for (; total_line_count > size; --total_line_count)
// Pad additional reserved lines
for (; size < total_line_count; ++size)
my_b_write_byte(&file, '\n');
}

Expand Down
23 changes: 22 additions & 1 deletion sql/rpl_master_info_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,25 @@ struct Master_info_file: Info_file
/// }@


protected:
/**
@ref Master_info_file has been inconsistent that its line count included
the line-count "value", while @ref Relay_log_info_file's excludes it.
Although the use common code now makes @ref Master_info_file match,
files from older versions are now off-by-one to Info_file::load_from_file().
The presence of this non-reading pseudo-value restores
compatibility with files generated by MariaDB 10.0+,
as the driver loop will increment the line counter for it,
thus emulating counting the line-count "value".
@deprecated This is not needed after all pre-12.3 versions go EoL.
*/
struct: Persistent
{
bool load_from(IO_CACHE *file) override { return false; } ///< No-op
void save_to(IO_CACHE *file) override {} ///< No-op
} LINE_COUNT_FIX;
Comment on lines +543 to +559

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Naming the unnamed struct Line_count_fix_t improves code readability and avoids potential compiler-specific issues with unnamed classes overriding virtual functions or being used in template-based pointer-to-member wrappers. Additionally, there is a minor typo in the comment: 'use common code' should be 'use of common code'.

protected:
  /**
    @ref Master_info_file has been inconsistent that its line count included
    the line-count "value", while @ref Relay_log_info_file's excludes it.
    Although the use of common code now makes @ref Master_info_file match,
    files from older versions are now off-by-one to Info_file::load_from_file().
    The presence of this non-reading pseudo-value restores
    compatibility with files generated by MariaDB 10.0+,
    as the driver loop will increment the line counter for it,
    thus emulating counting the line-count "value".
    @deprecated This is not needed after all pre-12.3 versions go EoL.
  */
  struct Line_count_fix_t : Persistent
  {
    bool load_from(IO_CACHE *file) override { return false; } ///< No-op
    void save_to(IO_CACHE *file) override {} ///< No-op
  } LINE_COUNT_FIX;

public:

inline static const Mem_fn VALUE_LIST[] {
&Master_info_file::master_log_file,
&Master_info_file::master_log_pos,
Expand All @@ -561,7 +580,9 @@ struct Master_info_file: Info_file
nullptr, // MySQL `master_uuid`, which MariaDB ignores.
&Master_info_file::master_retry_count,
&Master_info_file::master_ssl_crl,
&Master_info_file::master_ssl_crlpath
&Master_info_file::master_ssl_crlpath,
// This must be last, so its blank line blend into trailing blank line(s).
&Master_info_file::LINE_COUNT_FIX
};

/**
Expand Down