Skip to content

Commit 7a8834b

Browse files
committed
Silly but deadly mistakes caught by MTR!
I don’t mind highlighting them; but for records’ sake, TODO: squash
1 parent 9722e56 commit 7a8834b

File tree

3 files changed

+55
-54
lines changed

3 files changed

+55
-54
lines changed

sql/rpl_info_file.hh

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct InfoFile
158158
/// @param other not `nullptr`
159159
auto &operator=(const char *other)
160160
{
161-
strmake_buf(this->buf, other);
161+
strmake(buf, other, size-1);
162162
return *this;
163163
}
164164
virtual bool load_from(IO_CACHE *file) override
@@ -245,35 +245,38 @@ protected:
245245
std::from_chars_result result= std::from_chars(
246246
field1.buf, &field1.buf[sizeof(field1.buf)], lines);
247247
// Skip the first field in the for loop if that line was not a line count.
248-
size_t i= result.ec != IntIOCache::ERRC_OK || *(result.ptr) != '\n';
248+
size_t i= result.ec != IntIOCache::ERRC_OK || *(result.ptr) != '\0';
249249
/**
250250
Set the default after parsing: While std::from_chars() does not replace
251251
the output if it failed, it does replace if the line is not fully spent.
252252
*/
253253
if (i)
254254
lines= default_lines;
255-
size_t fields_count= MY_MIN(lines, fields.size());
256-
for (; i < fields_count; ++i)
255+
for (; i < lines; ++i)
257256
{
258-
const mem_fn &pm= fields.begin()[i];
259-
if (static_cast<bool>(pm) && pm(this).load_from(&file))
260-
return true;
261-
}
262-
/*
263-
Count and discard remaining lines if the line count runs beyond `fields`.
264-
This is especially to prepare for @ref MasterInfoFile for MariaDB 10.0+,
265-
which reserves a bunch of lines before its unique `key=value` section
266-
to accomodate any future line-based (old-style) additions in MySQL.
267-
(This will make moving from MariaDB to MySQL easier by not
268-
requiring MySQL to recognize MariaDB `key=value` lines.)
269-
*/
270-
while (i < lines)
271-
switch (my_b_get(&file)) {
272-
case my_b_EOF:
273-
return true; // EOF already?
274-
case '\n':
275-
++i;
257+
char c;
258+
if (i < fields.size()) // line known in the ` list
259+
{
260+
const mem_fn &pm= fields.begin()[i];
261+
if (static_cast<bool>(pm))
262+
{
263+
if (pm(this).load_from(&file))
264+
return true;
265+
continue;
266+
}
276267
}
268+
/*
269+
Count and discard unrecognized lines.
270+
This is especially to prepare for @ref MasterInfoFile for MariaDB 10.0+,
271+
which reserves a bunch of lines before its unique `key=value` section
272+
to accomodate any future line-based (old-style) additions in MySQL.
273+
(This will make moving from MariaDB to MySQL easier by not
274+
requiring MySQL to recognize MariaDB `key=value` lines.)
275+
*/
276+
while ((c= my_b_get(&file)) != '\n')
277+
if (c == my_b_EOF)
278+
return true; // EOF already?
279+
}
277280
return false;
278281
}
279282

@@ -298,9 +301,13 @@ protected:
298301
of effective lines in the first line of the file.
299302
*/
300303
IntIOCache::to_chars(&file, lines);
304+
my_b_write_byte(&file, '\n');
301305
for (const mem_fn &pm: fields)
306+
{
302307
if (static_cast<bool>(pm))
303308
pm(this).save_to(&file);
309+
my_b_write_byte(&file, '\n');
310+
}
304311
/*
305312
Pad additional reserved lines:
306313
(1 for the line count line + field count) inclusive -> max line inclusive

sql/rpl_master_info_file.hh

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct MasterInfoFile: InfoFile
8484
optional.emplace(value);
8585
return *this;
8686
}
87-
bool is_default() override { return optional.has_value(); }
87+
bool is_default() override { return !optional.has_value(); }
8888
bool set_default() override
8989
{
9090
optional.reset();
@@ -214,25 +214,21 @@ struct MasterInfoFile: InfoFile
214214
/// +1 for the terminating delimiter
215215
char buf[IntIOCache::BUF_SIZE<uint32_t> + 1];
216216
for (i=0; i < sizeof(buf); ++i)
217-
switch (int c= my_b_get(file)) {
218-
case my_b_EOF:
217+
{
218+
int c= my_b_get(file);
219+
if (c == my_b_EOF)
219220
return true;
220-
case ' ': // End of Field
221-
case '\n': // End of Line
222-
goto break_for1;
223-
default:
224-
buf[i]= c;
225-
}
226-
break_for1:
221+
buf[i]= c;
222+
if (c == /* End of Line */ '\n' || c == /* End of Count */ ' ')
223+
break;
224+
}
227225
/*
228226
* std::from_chars() fails if `count` will overflow in any way.
229227
* exclusive end index of the string = size
230228
*/
231229
std::from_chars_result result= std::from_chars(buf, &buf[i], count);
232-
if (result.ec != IntIOCache::ERRC_OK)
233-
return true;
234230
// Reserve enough elements ahead of time.
235-
if (allocate_dynamic(&array, count))
231+
if (result.ec != IntIOCache::ERRC_OK || allocate_dynamic(&array, count))
236232
return true;
237233
while (count--)
238234
{
@@ -244,20 +240,18 @@ struct MasterInfoFile: InfoFile
244240
if (*(result.ptr) != ' ')
245241
return true;
246242
for (i=0; i < sizeof(buf); ++i)
243+
{
247244
/*
248245
Bottlenecks from repeated IO does not affect the
249246
performance of reading char by char thanks to the cache.
250247
*/
251-
switch (int c= my_b_get(file)) {
252-
case my_b_EOF:
248+
int c= my_b_get(file);
249+
if (c == my_b_EOF)
253250
return true;
254-
case ' ': // End of Field
255-
case '\n': // End of Line
256-
goto break_for2;
257-
default:
258-
buf[i]= c;
259-
}
260-
break_for2:
251+
buf[i]= c;
252+
if (c == /* End of Count */ ' ' || c == /* End of Line */ '\n')
253+
break;
254+
}
261255
result= std::from_chars(buf, &buf[i], value);
262256
if (result.ec != IntIOCache::ERRC_OK)
263257
return true;
@@ -359,7 +353,7 @@ struct MasterInfoFile: InfoFile
359353
return *this;
360354
}
361355
bool is_default() override
362-
{ return mode <= enum_master_use_gtid::DEFAULT; }
356+
{ return mode >= enum_master_use_gtid::DEFAULT; }
363357
bool set_default() override
364358
{
365359
mode= enum_master_use_gtid::DEFAULT;
@@ -446,7 +440,7 @@ struct MasterInfoFile: InfoFile
446440
{
447441
my_b_write(file, (const uchar *)buf, size - 3);
448442
my_b_write_byte(file, '.');
449-
my_b_write(file, &(const uchar &)result.ptr[-3], 3);
443+
my_b_write(file, (const uchar *)(&result.ptr[-3]), 3);
450444
}
451445
else
452446
{
@@ -480,7 +474,7 @@ struct MasterInfoFile: InfoFile
480474
&MasterInfoFile::master_ssl_key,
481475
&MasterInfoFile::master_ssl_verify_server_cert,
482476
&MasterInfoFile::master_heartbeat_period,
483-
// &MasterInfoFile::master_bind, // MDEV-19248
477+
nullptr, // &MasterInfoFile::master_bind, // MDEV-19248
484478
&MasterInfoFile::ignore_server_ids,
485479
nullptr, // MySQL field `master_uuid`, which MariaDB ignores.
486480
&MasterInfoFile::master_retry_count,

sql/sql_repl.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,13 +4103,13 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added)
41034103
mi->master_ssl_verify_server_cert=
41044104
(lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::LEX_MI_ENABLE);
41054105

4106-
mi->master_ssl_ca = lex_mi->ssl_ca;
4107-
mi->master_ssl_capath = lex_mi->ssl_capath;
4108-
mi->master_ssl_cert = lex_mi->ssl_cert;
4109-
mi->master_ssl_cipher = lex_mi->ssl_cipher;
4110-
mi->master_ssl_key = lex_mi->ssl_key;
4111-
mi->master_ssl_crl = lex_mi->ssl_crl;
4112-
mi->master_ssl_crlpath= lex_mi->ssl_crlpath;
4106+
if (lex_mi->ssl_ca) mi->master_ssl_ca = lex_mi->ssl_ca;
4107+
if (lex_mi->ssl_capath) mi->master_ssl_capath = lex_mi->ssl_capath;
4108+
if (lex_mi->ssl_cert) mi->master_ssl_cert = lex_mi->ssl_cert;
4109+
if (lex_mi->ssl_cipher) mi->master_ssl_cipher = lex_mi->ssl_cipher;
4110+
if (lex_mi->ssl_key) mi->master_ssl_key = lex_mi->ssl_key;
4111+
if (lex_mi->ssl_crl) mi->master_ssl_crl = lex_mi->ssl_crl;
4112+
if (lex_mi->ssl_crlpath) mi->master_ssl_crlpath= lex_mi->ssl_crlpath;
41134113

41144114
#ifndef HAVE_OPENSSL
41154115
if (lex_mi->ssl || lex_mi->ssl_ca || lex_mi->ssl_capath ||

0 commit comments

Comments
 (0)