diff options
Diffstat (limited to 'sql/slave.cc')
-rw-r--r-- | sql/slave.cc | 234 |
1 files changed, 3 insertions, 231 deletions
diff --git a/sql/slave.cc b/sql/slave.cc index c35f0641729..5dbbaac195f 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -144,9 +144,6 @@ 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 request_table_dump(MYSQL* mysql, const char* db, const char* table); -static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, - const char* table_name, bool overwrite); static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi); static Log_event* next_event(Relay_log_info* rli); static int queue_event(Master_info* mi,const char* buf,ulong event_len); @@ -266,19 +263,16 @@ int init_slave() } if (init_master_info(active_mi,master_info_file,relay_log_info_file, - !master_host, (SLAVE_IO | SLAVE_SQL))) + 1, (SLAVE_IO | SLAVE_SQL))) { sql_print_error("Failed to initialize the master info structure"); error= 1; goto err; } - if (server_id && !master_host && active_mi->host[0]) - master_host= active_mi->host; - /* If server id is not set, start_slave_thread() will say it */ - if (master_host && !opt_skip_slave_start) + if (active_mi->host[0] && !opt_skip_slave_start) { if (start_slave_threads(1 /* need mutex */, 0 /* no wait for start*/, @@ -1460,198 +1454,6 @@ network_err: DBUG_RETURN(2); } -/* - Used by fetch_master_table (used by LOAD TABLE tblname FROM MASTER and LOAD - DATA FROM MASTER). Drops the table (if 'overwrite' is true) and recreates it - from the dump. Honours replication inclusion/exclusion rules. - db must be non-zero (guarded by assertion). - - RETURN VALUES - 0 success - 1 error -*/ - -static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, - const char* table_name, bool overwrite) -{ - ulong packet_len; - char *query, *save_db; - uint32 save_db_length; - Vio* save_vio; - HA_CHECK_OPT check_opt; - TABLE_LIST tables; - int error= 1; - handler *file; - ulonglong save_options; - NET *net= &mysql->net; - const char *found_semicolon= NULL; - DBUG_ENTER("create_table_from_dump"); - - packet_len= my_net_read(net); // read create table statement - if (packet_len == packet_error) - { - my_message(ER_MASTER_NET_READ, ER(ER_MASTER_NET_READ), MYF(0)); - DBUG_RETURN(1); - } - if (net->read_pos[0] == 255) // error from master - { - char *err_msg; - err_msg= (char*) net->read_pos + ((mysql->server_capabilities & - CLIENT_PROTOCOL_41) ? - 3+SQLSTATE_LENGTH+1 : 3); - my_error(ER_MASTER, MYF(0), err_msg); - DBUG_RETURN(1); - } - thd->command = COM_TABLE_DUMP; - if (!(query = thd->strmake((char*) net->read_pos, packet_len))) - { - sql_print_error("create_table_from_dump: out of memory"); - my_message(ER_GET_ERRNO, "Out of memory", MYF(0)); - DBUG_RETURN(1); - } - thd->set_query(query, packet_len); - thd->is_slave_error = 0; - - bzero((char*) &tables,sizeof(tables)); - tables.db = (char*)db; - tables.alias= tables.table_name= (char*)table_name; - - /* Drop the table if 'overwrite' is true */ - if (overwrite) - { - if (mysql_rm_table(thd,&tables,1,0)) /* drop if exists */ - { - sql_print_error("create_table_from_dump: failed to drop the table"); - goto err; - } - else - { - /* Clear the OK result of mysql_rm_table(). */ - thd->main_da.reset_diagnostics_area(); - } - } - - /* Create the table. We do not want to log the "create table" statement */ - save_options = thd->options; - thd->options &= ~ (OPTION_BIN_LOG); - thd_proc_info(thd, "Creating table from master dump"); - // save old db in case we are creating in a different database - save_db = thd->db; - save_db_length= thd->db_length; - thd->db = (char*)db; - DBUG_ASSERT(thd->db != 0); - thd->db_length= strlen(thd->db); - mysql_parse(thd, thd->query, packet_len, &found_semicolon); // run create table - thd->db = save_db; // leave things the way the were before - thd->db_length= save_db_length; - thd->options = save_options; - - if (thd->is_slave_error) - goto err; // mysql_parse took care of the error send - - thd_proc_info(thd, "Opening master dump table"); - thd->main_da.reset_diagnostics_area(); /* cleanup from CREATE_TABLE */ - /* - Note: If this function starts to fail for MERGE tables, - change the next two lines to these: - tables.table= NULL; // was set by mysql_rm_table() - if (!open_n_lock_single_table(thd, &tables, TL_WRITE)) - */ - tables.lock_type = TL_WRITE; - if (!open_ltable(thd, &tables, TL_WRITE, 0)) - { - sql_print_error("create_table_from_dump: could not open created table"); - goto err; - } - - file = tables.table->file; - thd_proc_info(thd, "Reading master dump table data"); - /* Copy the data file */ - if (file->net_read_dump(net)) - { - my_message(ER_MASTER_NET_READ, ER(ER_MASTER_NET_READ), MYF(0)); - sql_print_error("create_table_from_dump: failed in\ - handler::net_read_dump()"); - goto err; - } - - check_opt.init(); - check_opt.flags|= T_VERY_SILENT | T_CALC_CHECKSUM | T_QUICK; - thd_proc_info(thd, "Rebuilding the index on master dump table"); - /* - We do not want repair() to spam us with messages - just send them to the error log, and report the failure in case of - problems. - */ - save_vio = thd->net.vio; - thd->net.vio = 0; - /* Rebuild the index file from the copied data file (with REPAIR) */ - error=file->ha_repair(thd,&check_opt) != 0; - thd->net.vio = save_vio; - if (error) - my_error(ER_INDEX_REBUILD, MYF(0), tables.table->s->table_name.str); - -err: - close_thread_tables(thd); - DBUG_RETURN(error); -} - - -int fetch_master_table(THD *thd, const char *db_name, const char *table_name, - Master_info *mi, MYSQL *mysql, bool overwrite) -{ - int error= 1; - const char *errmsg=0; - bool called_connected= (mysql != NULL); - DBUG_ENTER("fetch_master_table"); - DBUG_PRINT("enter", ("db_name: '%s' table_name: '%s'", - db_name,table_name)); - - if (!called_connected) - { - if (!(mysql = mysql_init(NULL))) - { - DBUG_RETURN(1); - } - if (connect_to_master(thd, mysql, mi)) - { - my_error(ER_CONNECT_TO_MASTER, MYF(0), mysql_error(mysql)); - /* - We need to clear the active VIO since, theoretically, somebody - might issue an awake() on this thread. If we are then in the - middle of closing and destroying the VIO inside the - mysql_close(), we will have a problem. - */ -#ifdef SIGNAL_WITH_VIO_CLOSE - thd->clear_active_vio(); -#endif - mysql_close(mysql); - DBUG_RETURN(1); - } - if (thd->killed) - goto err; - } - - if (request_table_dump(mysql, db_name, table_name)) - { - error= ER_UNKNOWN_ERROR; - errmsg= "Failed on table dump request"; - goto err; - } - if (create_table_from_dump(thd, mysql, db_name, - table_name, overwrite)) - goto err; // create_table_from_dump have sent the error already - error = 0; - - err: - if (!called_connected) - mysql_close(mysql); - if (errmsg && thd->vio_ok()) - my_message(error, errmsg, MYF(0)); - DBUG_RETURN(test(error)); // Return 1 on error -} - - static bool wait_for_relay_log_space(Relay_log_info* rli) { bool slave_killed=0; @@ -2206,37 +2008,7 @@ static int request_dump(THD *thd, MYSQL* mysql, Master_info* mi, else sql_print_error("Error on COM_BINLOG_DUMP: %d %s, will retry in %d secs", mysql_errno(mysql), mysql_error(mysql), - master_connect_retry); - DBUG_RETURN(1); - } - - DBUG_RETURN(0); -} - - -static int request_table_dump(MYSQL* mysql, const char* db, const char* table) -{ - uchar buf[1024], *p = buf; - DBUG_ENTER("request_table_dump"); - - uint table_len = (uint) strlen(table); - uint db_len = (uint) strlen(db); - if (table_len + db_len > sizeof(buf) - 2) - { - sql_print_error("request_table_dump: Buffer overrun"); - DBUG_RETURN(1); - } - - *p++ = db_len; - memcpy(p, db, db_len); - p += db_len; - *p++ = table_len; - memcpy(p, table, table_len); - - if (simple_command(mysql, COM_TABLE_DUMP, buf, p - buf + table_len, 1)) - { - sql_print_error("request_table_dump: Error sending the table dump \ -command"); + mi->connect_retry); DBUG_RETURN(1); } |