[MySQL Bug] 在RBR複製模式下使用Merge引擎導致備庫Crash的bug

來源:互聯網
上載者:User

最近碰到一個很蛋疼的BUG,使用merge引擎,row模式下複製,極大的機率crash備庫。

我的測試環境是5.1的主庫,5.5的備庫

test case:

  1. create table m1 (a int primary key, b int) engine=myisam;  
  2. create table m2 (a int primary key, b int) engine=myisam;  
  3. create table mm (a int primary key , b int) engine=mrg_myisam  INSERT_METHOD=LAST UNION=(m1,m2);  
  4. insert into mm values (1,2);  
crash的原因非常簡單,實際上在很早之前這個bug就fix了(MySQL Bug#47103), 可能是官方疏忽,又或者是Merge儲存引擎用的人少,沒有將這個patch backport到5.5中。

以下是個簡單的介紹。


我們知道每個Binlog的行事件都有一個table_map_event。

在函數Table_map_log_event::do_apply_event中,會根據table map event的內容初始化table_list結構體,並構建table_list->m_tabledef。

這裡的table_list->m_tabledef.m_field_metadata是被分配記憶體的。然後將該table_list掛到rli->tables_to_lock上


而在函數Rows_log_event::do_apply_event中,當調用open_and_lock_tables實際開啟表時,還會開啟相依賴的子表,並將這些table_list掛到rli->tables_to_lock之後(連結指標為next_global),但要注意,這裡開啟的依賴字表時,其table_list->m_tabledef.m_field_metadata實0x0,並沒有分配空間


隨後,在開啟表後,要檢查table map裡的定義和實際開啟表的定義是否相容。

  1. 7663       RPL_TABLE_LIST *ptr= rli->tables_to_lock;  
  2. 7664       for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global))  
  3. 7665       {  
  4. 7666         TABLE *conv_table;  
  5. 7667         if (!ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli),  
  6. 7668                                              ptr->table, &conv_table))  
而在table_def::compatible_with中:

can_convert_field_to(field, type(col), field_metadata(col), rli, m_flags, &order)

其中type和field_metadata都會涉及到對m_field_metadata的引用,因此直接產生段錯誤,導致crash。

官方的fix見http://lists.mysql.com/commits/86326

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.