#At file:///home/sven/bzr/w5393-rpl_locks/simplifications/ based on revid:sven.sandberg@stripped
3202 Sven Sandberg 2010-09-28
WL#5582: encapsulate replication locks
This is a step to change functions that operate on RLI and MI structures
to member functions, so that we can encapsulate things.
In this commit, we change the static functions connect_to_master() and
try_to_reconnect() so that they become member functions of Master_info.
The functions is now called Master_info::connect() and Master_info::try_to_reconnect(),
respectively.
We also remove safe_connect() and safe_reconnect(), which were only
aliases to connect_to_master().
We also change the static const variable reconnect_messages,
and the associated types enum_slave_reconnect_actions and
enum_slave_reconnect_messages, so that they become members of Master_info.
@ sql/rpl_mi.h
Moved connect_to_master and try_to_reconnect so that they became members of Master_info.
Moved reconnect_messages and associated enum types so that they are members of Master_info.
@ sql/rpl_slave.cc
Moved connect_to_master and try_to_reconnect so that they became members of Master_info.
Moved reconnect_messages and associated enum types so that they are members of Master_info.
Removed safe_connect() and safe_reconnect() and call mi->connect directly instead.
modified:
sql/rpl_mi.h
sql/rpl_slave.cc
=== modified file 'sql/rpl_mi.h'
--- a/sql/rpl_mi.h 2010-09-28 18:17:33 +0000
+++ b/sql/rpl_mi.h 2010-09-28 19:02:24 +0000
@@ -109,8 +109,31 @@ class Master_info : public Slave_thread
char master_uuid[UUID_LENGTH+1];
char info_file_name[FN_REFLEN + 128];
+ enum enum_slave_reconnect_messages
+ {
+ SLAVE_RECON_MSG_WAIT= 0,
+ SLAVE_RECON_MSG_KILLED_WAITING= 1,
+ SLAVE_RECON_MSG_AFTER= 2,
+ SLAVE_RECON_MSG_FAILED= 3,
+ SLAVE_RECON_MSG_COMMAND= 4,
+ SLAVE_RECON_MSG_KILLED_AFTER= 5,
+ SLAVE_RECON_MSG_MAX
+ };
+ enum enum_slave_reconnect_actions
+ {
+ SLAVE_RECON_ACT_REG= 0,
+ SLAVE_RECON_ACT_DUMP= 1,
+ SLAVE_RECON_ACT_EVENT= 2,
+ SLAVE_RECON_ACT_MAX
+ };
+
+ static const char *const reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX];
+
int process_rotate(Rotate_log_event* rev);
int process_create_file(Create_file_log_event* cev);
+ int connect(bool reconnect, bool suppress_warnings);
+ int try_to_reconnect(uint *retry_count, bool suppress_warnings,
+ enum_slave_reconnect_actions action);
};
void init_master_log_pos(Master_info* mi);
int init_master_info(Master_info* mi, const char* master_info_fname,
=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc 2010-09-28 18:23:50 +0000
+++ b/sql/rpl_slave.cc 2010-09-28 19:02:24 +0000
@@ -84,26 +84,7 @@ int disconnect_slave_event_count = 0, ab
static pthread_key(Master_info*, RPL_MASTER_INFO);
-enum enum_slave_reconnect_actions
-{
- SLAVE_RECON_ACT_REG= 0,
- SLAVE_RECON_ACT_DUMP= 1,
- SLAVE_RECON_ACT_EVENT= 2,
- SLAVE_RECON_ACT_MAX
-};
-
-enum enum_slave_reconnect_messages
-{
- SLAVE_RECON_MSG_WAIT= 0,
- SLAVE_RECON_MSG_KILLED_WAITING= 1,
- SLAVE_RECON_MSG_AFTER= 2,
- SLAVE_RECON_MSG_FAILED= 3,
- SLAVE_RECON_MSG_COMMAND= 4,
- SLAVE_RECON_MSG_KILLED_AFTER= 5,
- SLAVE_RECON_MSG_MAX
-};
-
-static const char *reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX]=
+const char *const Master_info::reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX]=
{
{
"Waiting to reconnect after a failed registration on master",
@@ -142,11 +123,6 @@ static inline bool io_slave_killed(THD*
static inline bool sql_slave_killed(THD* thd,Relay_log_info* rli);
static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type);
static void print_slave_skip_errors(void);
-static int safe_connect(THD* thd, MYSQL* mysql, Master_info* mi);
-static int safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
- bool suppress_warnings);
-static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
- bool reconnect, bool suppress_warnings);
static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed,
void* thread_killed_arg);
static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi);
@@ -2897,7 +2873,7 @@ static bool check_io_slave_killed(THD *t
@details Terminates current connection to master, sleeps for
@c mi->connect_retry msecs and initiates new connection with
- @c safe_reconnect(). Variable pointed by @c retry_count is increased -
+ @c connect(). Variable pointed by @c retry_count is increased -
if it exceeds @c mi->retry_count then connection is not re-established
and function signals error.
Unless @c suppres_warnings is TRUE, a warning is put in the server error log
@@ -2905,9 +2881,6 @@ static bool check_io_slave_killed(THD *t
are taken from @c messages array. In case @c mi->retry_count is exceeded,
no messages are added to the log.
- @param[in] thd Thread context.
- @param[in] mysql MySQL connection.
- @param[in] mi Master connection information.
@param[in,out] retry_count Number of attempts to reconnect.
@param[in] suppress_warnings TRUE when a normal net read timeout
has caused to reconnecting.
@@ -2916,12 +2889,15 @@ static bool check_io_slave_killed(THD *t
@retval 0 OK.
@retval 1 There was an error.
-*/
-static int try_to_reconnect(THD *thd, MYSQL *mysql, Master_info *mi,
- uint *retry_count, bool suppress_warnings,
- const char *messages[SLAVE_RECON_MSG_MAX])
+ This was previously a static function.
+*/
+int Master_info::try_to_reconnect(uint *retry_count, bool suppress_warnings,
+ enum_slave_reconnect_actions action)
{
+ Master_info *mi= this;
+ const char * const *messages= mi->reconnect_messages[action];
+
mi->slave_running= MYSQL_SLAVE_RUN_NOT_CONNECT;
thd->proc_info= messages[SLAVE_RECON_MSG_WAIT];
#ifdef SIGNAL_WITH_VIO_CLOSE
@@ -2958,7 +2934,7 @@ static int try_to_reconnect(THD *thd, MY
sql_print_information("%s", buf);
}
}
- if (safe_reconnect(thd, mysql, mi, 1) || io_slave_killed(thd, mi))
+ if (mi->connect(1, 1) || io_slave_killed(thd, mi))
{
if (global_system_variables.log_warnings)
sql_print_information("%s", messages[SLAVE_RECON_MSG_KILLED_AFTER]);
@@ -3047,8 +3023,8 @@ pthread_handler_t handle_slave_io(void *
}
thd_proc_info(thd, "Connecting to master");
- // we can get killed during safe_connect
- if (!safe_connect(thd, mysql, mi))
+ // we can get killed during connect
+ if (!mi->connect(0, 0))
{
sql_print_information("Slave I/O thread: connected to master '%s@%s:%d',"
"replication started in log '%s' at position %s",
@@ -3107,8 +3083,8 @@ connected:
goto err;
suppress_warnings= FALSE;
/* Try to reconnect because the error was caused by a transient network problem */
- if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
- reconnect_messages[SLAVE_RECON_ACT_REG]))
+ if (mi->try_to_reconnect(&retry_count, suppress_warnings,
+ Master_info::SLAVE_RECON_ACT_REG))
goto err;
goto connected;
}
@@ -3125,8 +3101,8 @@ connected:
"while registering slave on master"))
{
sql_print_error("Slave I/O thread couldn't register on master");
- if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
- reconnect_messages[SLAVE_RECON_ACT_REG]))
+ if (mi->try_to_reconnect(&retry_count, suppress_warnings,
+ Master_info::SLAVE_RECON_ACT_REG))
goto err;
}
else
@@ -3138,8 +3114,8 @@ connected:
{
retry_count_reg++;
sql_print_information("Forcing to reconnect slave I/O thread");
- if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
- reconnect_messages[SLAVE_RECON_ACT_REG]))
+ if (mi->try_to_reconnect(&retry_count, suppress_warnings,
+ Master_info::SLAVE_RECON_ACT_REG))
goto err;
goto connected;
});
@@ -3154,8 +3130,8 @@ connected:
sql_print_error("Failed on request_dump()");
if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
requesting master dump") ||
- try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
- reconnect_messages[SLAVE_RECON_ACT_DUMP]))
+ mi->try_to_reconnect(&retry_count, suppress_warnings,
+ Master_info::SLAVE_RECON_ACT_DUMP))
goto err;
goto connected;
}
@@ -3164,8 +3140,8 @@ requesting master dump") ||
{
retry_count_dump++;
sql_print_information("Forcing to reconnect slave I/O thread");
- if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
- reconnect_messages[SLAVE_RECON_ACT_DUMP]))
+ if (mi->try_to_reconnect(&retry_count, suppress_warnings,
+ Master_info::SLAVE_RECON_ACT_DUMP))
goto err;
goto connected;
});
@@ -3191,8 +3167,8 @@ reading event"))
{
retry_count_event++;
sql_print_information("Forcing to reconnect slave I/O thread");
- if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
- reconnect_messages[SLAVE_RECON_ACT_EVENT]))
+ if (mi->try_to_reconnect(&retry_count, suppress_warnings,
+ Master_info::SLAVE_RECON_ACT_EVENT))
goto err;
goto connected;
});
@@ -3222,8 +3198,8 @@ Stopping slave I/O thread due to out-of-
"%s", ER(ER_OUT_OF_RESOURCES));
goto err;
}
- if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings,
- reconnect_messages[SLAVE_RECON_ACT_EVENT]))
+ if (mi->try_to_reconnect(&retry_count, suppress_warnings,
+ Master_info::SLAVE_RECON_ACT_EVENT))
goto err;
goto connected;
} // if (event_len == packet_error)
@@ -4426,40 +4402,21 @@ extern "C" void slave_io_thread_detach_v
}
-/*
- Try to connect until successful or slave killed
-
- SYNPOSIS
- safe_connect()
- thd Thread handler for slave
- mysql MySQL connection handle
- mi Replication handle
-
- RETURN
- 0 ok
- # Error
-*/
-
-static int safe_connect(THD* thd, MYSQL* mysql, Master_info* mi)
-{
- DBUG_ENTER("safe_connect");
-
- DBUG_RETURN(connect_to_master(thd, mysql, mi, 0, 0));
-}
+/**
+ Try to connect to master until successful or slave killed or we have
+ retried mi->retry_count times.
+ @param reconnect Set to true if this is not the first time we try to
+ connect. This affects if we call mysql_reconnect(mysql) or
+ mysql_real_connect(mysql, <login options>).
-/*
- SYNPOSIS
- connect_to_master()
+ @param suppress_warnings Set to true if warnings should be suppressed.
- IMPLEMENTATION
- Try to connect until successful or slave killed or we have retried
- mi->retry_count times
+ @return nonzero if slave was killed, 0 otherwise.
*/
-
-static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi,
- bool reconnect, bool suppress_warnings)
+int Master_info::connect(bool reconnect, bool suppress_warnings)
{
+ Master_info *mi= this;
int slave_was_killed;
int last_errno= -2; // impossible error
ulong err_count= 0;
@@ -4568,22 +4525,6 @@ replication resumed in log '%s' at posit
}
-/*
- safe_reconnect()
-
- IMPLEMENTATION
- Try to connect until successful or slave killed or we have retried
- mi->retry_count times
-*/
-
-static int safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
- bool suppress_warnings)
-{
- DBUG_ENTER("safe_reconnect");
- DBUG_RETURN(connect_to_master(thd, mysql, mi, 1, suppress_warnings));
-}
-
-
MYSQL *rpl_connect_master(MYSQL *mysql)
{
THD *thd= current_thd;
Attachment: [text/bzr-bundle] bzr/sven.sandberg@oracle.com-20100928190224-lnbpc1bpvix78owy.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr branch (sven.sandberg:3202) WL#5582 | Sven Sandberg | 28 Sep |