Skip to content

Commit 4bad74e

Browse files
montywivuvova
authored andcommitted
Added error checking for all calls to flush_relay_log_info() and stmt_done()
1 parent a2de378 commit 4bad74e

File tree

7 files changed

+40
-21
lines changed

7 files changed

+40
-21
lines changed

sql/log.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,7 +4129,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd, bool create_new_log,
41294129

41304130
int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
41314131
{
4132-
int error;
4132+
int error, errcode;
41334133
char *to_purge_if_included= NULL;
41344134
inuse_relaylog *ir;
41354135
ulonglong log_space_reclaimed= 0;
@@ -4200,7 +4200,8 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
42004200
}
42014201

42024202
/* Store where we are in the new file for the execution thread */
4203-
flush_relay_log_info(rli);
4203+
if (flush_relay_log_info(rli))
4204+
error= LOG_INFO_IO;
42044205

42054206
DBUG_EXECUTE_IF("crash_before_purge_logs", DBUG_SUICIDE(););
42064207

@@ -4216,11 +4217,13 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
42164217
* Need to update the log pos because purge logs has been called
42174218
* after fetching initially the log pos at the begining of the method.
42184219
*/
4219-
if((error=find_log_pos(&rli->linfo, rli->event_relay_log_name, 0)))
4220+
if ((errcode= find_log_pos(&rli->linfo, rli->event_relay_log_name, 0)))
42204221
{
42214222
char buff[22];
4223+
if (!error)
4224+
error= errcode;
42224225
sql_print_error("next log error: %d offset: %s log: %s included: %d",
4223-
error,
4226+
errcode,
42244227
llstr(rli->linfo.index_file_offset,buff),
42254228
rli->group_relay_log_name,
42264229
included);

sql/log_event.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6244,9 +6244,11 @@ bool Rotate_log_event::write(IO_CACHE* file)
62446244
62456245
@retval
62466246
0 ok
6247+
1 error
62476248
*/
62486249
int Rotate_log_event::do_update_pos(rpl_group_info *rgi)
62496250
{
6251+
int error= 0;
62506252
Relay_log_info *rli= rgi->rli;
62516253
DBUG_ENTER("Rotate_log_event::do_update_pos");
62526254
#ifndef DBUG_OFF
@@ -6298,7 +6300,7 @@ int Rotate_log_event::do_update_pos(rpl_group_info *rgi)
62986300
(ulong) rli->group_master_log_pos));
62996301
mysql_mutex_unlock(&rli->data_lock);
63006302
rpl_global_gtid_slave_state->record_and_update_gtid(thd, rgi);
6301-
flush_relay_log_info(rli);
6303+
error= flush_relay_log_info(rli);
63026304

63036305
/*
63046306
Reset thd->variables.option_bits and sql_mode etc, because this could
@@ -6316,8 +6318,7 @@ int Rotate_log_event::do_update_pos(rpl_group_info *rgi)
63166318
else
63176319
rgi->inc_event_relay_log_pos();
63186320

6319-
6320-
DBUG_RETURN(0);
6321+
DBUG_RETURN(error);
63216322
}
63226323

63236324

@@ -8174,6 +8175,7 @@ void Stop_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
81748175

81758176
int Stop_log_event::do_update_pos(rpl_group_info *rgi)
81768177
{
8178+
int error= 0;
81778179
Relay_log_info *rli= rgi->rli;
81788180
DBUG_ENTER("Stop_log_event::do_update_pos");
81798181
/*
@@ -8189,9 +8191,10 @@ int Stop_log_event::do_update_pos(rpl_group_info *rgi)
81898191
{
81908192
rpl_global_gtid_slave_state->record_and_update_gtid(thd, rgi);
81918193
rli->inc_group_relay_log_pos(0, rgi);
8192-
flush_relay_log_info(rli);
8194+
if (flush_relay_log_info(rli))
8195+
error= 1;
81938196
}
8194-
DBUG_RETURN(0);
8197+
DBUG_RETURN(error);
81958198
}
81968199

81978200
#endif /* !MYSQL_CLIENT */
@@ -10178,8 +10181,8 @@ int
1017810181
Rows_log_event::do_update_pos(rpl_group_info *rgi)
1017910182
{
1018010183
Relay_log_info *rli= rgi->rli;
10181-
DBUG_ENTER("Rows_log_event::do_update_pos");
1018210184
int error= 0;
10185+
DBUG_ENTER("Rows_log_event::do_update_pos");
1018310186

1018410187
DBUG_PRINT("info", ("flags: %s",
1018510188
get_flags(STMT_END_F) ? "STMT_END_F " : ""));
@@ -10191,7 +10194,7 @@ Rows_log_event::do_update_pos(rpl_group_info *rgi)
1019110194
Step the group log position if we are not in a transaction,
1019210195
otherwise increase the event log position.
1019310196
*/
10194-
rli->stmt_done(log_pos, thd, rgi);
10197+
error= rli->stmt_done(log_pos, thd, rgi);
1019510198
/*
1019610199
Clear any errors in thd->net.last_err*. It is not known if this is
1019710200
needed or not. It is believed that any errors that may exist in

sql/log_event_old.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,8 +1843,8 @@ int
18431843
Old_rows_log_event::do_update_pos(rpl_group_info *rgi)
18441844
{
18451845
Relay_log_info *rli= rgi->rli;
1846-
DBUG_ENTER("Old_rows_log_event::do_update_pos");
18471846
int error= 0;
1847+
DBUG_ENTER("Old_rows_log_event::do_update_pos");
18481848

18491849
DBUG_PRINT("info", ("flags: %s",
18501850
get_flags(STMT_END_F) ? "STMT_END_F " : ""));
@@ -1856,7 +1856,7 @@ Old_rows_log_event::do_update_pos(rpl_group_info *rgi)
18561856
Step the group log position if we are not in a transaction,
18571857
otherwise increase the event log position.
18581858
*/
1859-
rli->stmt_done(log_pos, thd, rgi);
1859+
error= rli->stmt_done(log_pos, thd, rgi);
18601860
/*
18611861
Clear any errors in thd->net.last_err*. It is not known if this is
18621862
needed or not. It is believed that any errors that may exist in

sql/rpl_rli.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Failed to open the existing relay log info file '%s' (errno %d)",
432432
}
433433
rli->inited= 1;
434434
mysql_mutex_unlock(&rli->data_lock);
435-
DBUG_RETURN(error);
435+
DBUG_RETURN(0);
436436

437437
err:
438438
sql_print_error("%s", msg);
@@ -1304,9 +1304,10 @@ bool Relay_log_info::is_until_satisfied(THD *thd, Log_event *ev)
13041304
}
13051305

13061306

1307-
void Relay_log_info::stmt_done(my_off_t event_master_log_pos, THD *thd,
1307+
bool Relay_log_info::stmt_done(my_off_t event_master_log_pos, THD *thd,
13081308
rpl_group_info *rgi)
13091309
{
1310+
int error= 0;
13101311
DBUG_ENTER("Relay_log_info::stmt_done");
13111312

13121313
DBUG_ASSERT(rgi->rli == this);
@@ -1358,10 +1359,11 @@ void Relay_log_info::stmt_done(my_off_t event_master_log_pos, THD *thd,
13581359
}
13591360
DBUG_EXECUTE_IF("inject_crash_before_flush_rli", DBUG_SUICIDE(););
13601361
if (mi->using_gtid == Master_info::USE_GTID_NO)
1361-
flush_relay_log_info(this);
1362+
if (flush_relay_log_info(this))
1363+
error= 1;
13621364
DBUG_EXECUTE_IF("inject_crash_after_flush_rli", DBUG_SUICIDE(););
13631365
}
1364-
DBUG_VOID_RETURN;
1366+
DBUG_RETURN(error);
13651367
}
13661368

13671369

sql/rpl_rli.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class Relay_log_info : public Slave_reporting_capability
416416
relay log info and used to produce information for <code>SHOW
417417
SLAVE STATUS</code>.
418418
*/
419-
void stmt_done(my_off_t event_log_pos, THD *thd, rpl_group_info *rgi);
419+
bool stmt_done(my_off_t event_log_pos, THD *thd, rpl_group_info *rgi);
420420
int alloc_inuse_relaylog(const char *name);
421421
void free_inuse_relaylog(inuse_relaylog *ir);
422422
void reset_inuse_relaylog();

sql/slave.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,8 +4788,15 @@ log '%s' at position %s, relay log '%s' position: %s%s", RPL_LOG_NAME,
47884788
if (rli->mi->using_gtid != Master_info::USE_GTID_NO)
47894789
{
47904790
ulong domain_count;
4791+
my_bool save_log_all_errors= thd->log_all_errors;
47914792

4793+
/*
4794+
We don't need to check return value for flush_relay_log_info()
4795+
as any errors should be logged to stderr
4796+
*/
4797+
thd->log_all_errors= 1;
47924798
flush_relay_log_info(rli);
4799+
thd->log_all_errors= save_log_all_errors;
47934800
if (mi->using_parallel())
47944801
{
47954802
/*
@@ -6715,9 +6722,12 @@ static Log_event* next_event(rpl_group_info *rgi, ulonglong *event_size)
67156722
}
67166723
rli->event_relay_log_pos = BIN_LOG_HEADER_SIZE;
67176724
strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name);
6718-
flush_relay_log_info(rli);
6725+
if (flush_relay_log_info(rli))
6726+
{
6727+
errmsg= "error flushing relay log";
6728+
goto err;
6729+
}
67196730
}
6720-
67216731
/*
67226732
Now we want to open this next log. To know if it's a hot log (the one
67236733
being written by the I/O thread now) or a cold log, we can use

sql/sql_repl.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3619,7 +3619,8 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added)
36193619
in-memory value at restart (thus causing errors, as the old relay log does
36203620
not exist anymore).
36213621
*/
3622-
flush_relay_log_info(&mi->rli);
3622+
if (flush_relay_log_info(&mi->rli))
3623+
ret= 1;
36233624
mysql_cond_broadcast(&mi->data_cond);
36243625
mysql_mutex_unlock(&mi->rli.data_lock);
36253626

0 commit comments

Comments
 (0)