1. 程式人生 > >MySQL複製--slave設定讀取binlog的位置

MySQL複製--slave設定讀取binlog的位置

change_master->global_init_info->Master_info::mi_init_info->Rpl_info_handler::init_info->Rpl_info_file::do_init_info 
                               ->mi->rli->rli_init_info()->初始化./relay-bin.000001,4如果relay-log.info不存在的話,否則讀取

//初始化master_info結構
int Master_info::mi_init_info()
{
    if (inited)
        DBUG_RETURN(0);//如果已經建立master_info檔案,直接退出
    handler->init_info();//建立/開啟master_info檔案
    if (check_return == REPOSITORY_DOES_NOT_EXIST){//如果master_info檔案是剛建立的,設定需讀取的log位置是4
        init_master_log_pos();
        |--master_log_name[0]= 0;
        |--master_log_pos= BIN_LOG_HEADER_SIZE;
        |--ssl_verify_server_cert= 0;
        |-- heartbeat_period= min<float>(SLAVE_MAX_HEARTBEAT_PERIOD,(slave_net_timeout/2.0));
    }else{
        read_info(handler);//讀取檔案
    }
	inited= 1;
    flush_info(TRUE);
    |--handler->set_sync_period(sync_masterinfo_period);//預設10000
	|--flush_io_cache(&info_file);
    |--my_sync(info_fd, MYF(MY_WME));
    DBUG_RETURN(0);

int Rpl_info_file::do_init_info()
{
    if (ret_check == REPOSITORY_DOES_NOT_EXIST){
        info_fd = my_open(info_fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME));
        init_io_cache(&info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,MYF(MY_WME));
    }else if (ret_check == REPOSITORY_EXISTS){
        info_fd = my_open(info_fname, O_RDWR|O_BINARY, MYF(MY_WME));
        init_io_cache(&info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0, MYF(MY_WME))
    }
}


如果master.info不存在,就建立並初始化對應的IO_CACHE
如果存在,就開啟,並初始化對應的IO_CACHE