mysql:
c:底层
C++:相对上层
主备复制:主库通知备库来取
MYSQL复制源代码代码:SQL文件夹intstart_slave_thread(
#ifdef HAVE_PSI_INTERFACE
PSI_thread_key thread_key,#endifpthread_handler h_func, mysql_mutex_t*start_lock,
mysql_mutex_t*cond_lock,
mysql_cond_t*start_cond,volatile uint *slave_running,volatile ulong *slave_run_id,
Master_info*mi)
{
pthread_t th;ulongstart_id;interror;
DBUG_ENTER("start_slave_thread");if(start_lock)
mysql_mutex_lock(start_lock);if (!server_id)
{if(start_cond)
mysql_cond_broadcast(start_cond);if(start_lock)
mysql_mutex_unlock(start_lock);
sql_print_error("Server id not set, will not start slave");
DBUG_RETURN(ER_BAD_SLAVE);
}if (*slave_running)
{if(start_cond)
mysql_cond_broadcast(start_cond);if(start_lock)
mysql_mutex_unlock(start_lock);
DBUG_RETURN(ER_SLAVE_MUST_STOP);
}
start_id= *slave_run_id;
DBUG_PRINT("info",("Creating new slave thread"));if ((error=mysql_thread_create(thread_key,&th, &connection_attrib, h_func, (void*)mi)))
{
sql_print_error("Can't create slave thread (errno= %d).", error);if(start_lock)
mysql_mutex_unlock(start_lock);
DBUG_RETURN(ER_SLAVE_THREAD);
}if (start_cond && cond_lock) //caller has cond_lock
{
THD* thd =current_thd;while (start_id == *slave_run_id && thd !=NULL)
{
DBUG_PRINT("sleep",("Waiting for slave thread to start"));
PSI_stage_info saved_st