diff options
Diffstat (limited to 'sql/log_event.cc')
-rw-r--r-- | sql/log_event.cc | 292 |
1 files changed, 202 insertions, 90 deletions
diff --git a/sql/log_event.cc b/sql/log_event.cc index cd47cbba9bd..7a6d0a1821b 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. - Copyright (c) 2009, 2016, MariaDB + Copyright (c) 2000, 2018, Oracle and/or its affiliates. + Copyright (c) 2009, 2018, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -53,6 +53,7 @@ #include "rpl_constants.h" #include "sql_digest.h" #include "zlib.h" +#include "my_atomic.h" #define my_b_write_string(A, B) my_b_write((A), (uchar*)(B), (uint) (sizeof(B) - 1)) @@ -394,7 +395,7 @@ static bool pretty_print_str(IO_CACHE* cache, const char* str, int len) error= my_b_write_byte(cache, c); break; } - if (error) + if (unlikely(error)) goto err; } return my_b_write_byte(cache, '\''); @@ -1924,7 +1925,7 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, res->register_temp_buf(event.release(), true); err: - if (error) + if (unlikely(error)) { DBUG_ASSERT(!res); #ifdef MYSQL_CLIENT @@ -3120,7 +3121,7 @@ Rows_log_event::print_verbose_one_row(IO_CACHE *file, table_def *td, typestr, sizeof(typestr)); error= copy_event_cache_to_string_and_reinit(&tmp_cache, &review_str); close_cached_file(&tmp_cache); - if (error) + if (unlikely(error)) return 0; switch (td->type(i)) // Converting a string to HEX format @@ -3740,15 +3741,15 @@ bool Log_event::print_base64(IO_CACHE* file, } if (my_b_tell(file) == 0) - if (my_b_write_string(file, "\nBINLOG '\n")) + if (unlikely(my_b_write_string(file, "\nBINLOG '\n"))) error= 1; - if (!error && my_b_printf(file, "%s\n", tmp_str)) + if (likely(!error) && unlikely(my_b_printf(file, "%s\n", tmp_str))) error= 1; - if (!more && !error) - if (my_b_printf(file, "'%s\n", print_event_info->delimiter)) + if (!more && likely(!error)) + if (unlikely(my_b_printf(file, "'%s\n", print_event_info->delimiter))) error= 1; my_free(tmp_str); - if (error) + if (unlikely(error)) goto err; } @@ -3855,7 +3856,7 @@ bool Log_event::print_base64(IO_CACHE* file, error= ev->print_verbose(&tmp_cache, print_event_info); close_cached_file(&tmp_cache); - if (error) + if (unlikely(error)) { delete ev; goto err; @@ -3868,7 +3869,7 @@ bool Log_event::print_base64(IO_CACHE* file, ev->count_row_events(print_event_info); #endif delete ev; - if (error) + if (unlikely(error)) goto err; } } @@ -4830,6 +4831,24 @@ Query_log_event::Query_log_event(const char* buf, uint event_len, db= (char *)start; query= (char *)(start + db_len + 1); q_len= data_len - db_len -1; + + if (data_len && (data_len < db_len || + data_len < q_len || + data_len != (db_len + q_len + 1))) + { + q_len= 0; + query= NULL; + DBUG_VOID_RETURN; + } + + uint32 max_length= uint32(event_len - ((const char*)(end + db_len + 1) - + (buf - common_header_len))); + if (q_len != max_length) + { + q_len= 0; + query= NULL; + DBUG_VOID_RETURN; + } /** Append the db length at the end of the buffer. This will be used by Query_cache::send_result_to_client() in case the query cache is On. @@ -5376,6 +5395,19 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, you. */ thd->catalog= catalog_len ? (char *) catalog : (char *)""; + + size_t valid_len= Well_formed_prefix(system_charset_info, + db, db_len, NAME_LEN).length(); + + if (valid_len != db_len) + { + rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid database name in Query event."); + thd->is_slave_error= true; + goto end; + } + new_db.length= db_len; new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length); thd->set_db(&new_db); /* allocates a copy of 'db' */ @@ -5415,7 +5447,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, thd->variables.pseudo_thread_id= thread_id; // for temp tables DBUG_PRINT("query",("%s", thd->query())); - if (!(expected_error= error_code) || + if (unlikely(!(expected_error= error_code)) || ignored_error_code(expected_error) || !unexpected_error_code(expected_error)) { @@ -5517,7 +5549,23 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, } else thd->variables.collation_database= thd->db_charset; - + + { + const CHARSET_INFO *cs= thd->charset(); + /* + We cannot ask for parsing a statement using a character set + without state_maps (parser internal data). + */ + if (!cs->state_map) + { + rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "character_set cannot be parsed"); + thd->is_slave_error= true; + goto end; + } + } + /* Record any GTID in the same transaction, so slave state is transactionally consistent. @@ -5531,8 +5579,10 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, rgi->gtid_pending= false; gtid= rgi->current_gtid; - if (rpl_global_gtid_slave_state->record_gtid(thd, >id, sub_id, - true, false, &hton)) + if (unlikely(rpl_global_gtid_slave_state->record_gtid(thd, >id, + sub_id, + true, false, + &hton))) { int errcode= thd->get_stmt_da()->sql_errno(); if (!is_parallel_retry_error(rgi, errcode)) @@ -5559,7 +5609,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, it is a concurrency issue or ignorable issue, effects of the statement should be rolled back. */ - if (expected_error && + if (unlikely(expected_error) && (ignored_error_code(expected_error) || concurrency_error_code(expected_error))) { @@ -5628,7 +5678,7 @@ START SLAVE; . Query: '%s'", expected_error, thd->query()); } /* If the query was not ignored, it is printed to the general log */ - if (!thd->is_error() || + if (likely(!thd->is_error()) || thd->get_stmt_da()->sql_errno() != ER_SLAVE_IGNORED_TABLE) general_log_write(thd, COM_QUERY, thd->query(), thd->query_length()); else @@ -5667,7 +5717,7 @@ compare_errors: DBUG_PRINT("info",("expected_error: %d sql_errno: %d", expected_error, actual_error)); - if ((expected_error && + if ((unlikely(expected_error) && !test_if_equal_repl_errors(expected_error, actual_error) && !concurrency_error_code(expected_error)) && !ignored_error_code(actual_error) && @@ -5702,7 +5752,7 @@ compare_errors: /* Other cases: mostly we expected no error and get one. */ - else if (thd->is_slave_error || thd->is_fatal_error) + else if (unlikely(thd->is_slave_error || thd->is_fatal_error)) { if (!is_parallel_retry_error(rgi, actual_error)) rli->report(ERROR_LEVEL, actual_error, rgi->gtid_info(), @@ -5752,7 +5802,7 @@ compare_errors: } end: - if (sub_id && !thd->is_slave_error) + if (unlikely(sub_id && !thd->is_slave_error)) rpl_global_gtid_slave_state->update_state_hash(sub_id, >id, hton, rgi); /* @@ -6073,7 +6123,13 @@ int Start_log_event_v3::do_apply_event(rpl_group_info *rgi) */ break; default: - /* this case is impossible */ + /* + This case is not expected. It can be either an event corruption or an + unsupported binary log version. + */ + rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Binlog version not supported"); DBUG_RETURN(1); } DBUG_RETURN(error); @@ -6992,6 +7048,9 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, fields = (char*)field_lens + num_fields; table_name = fields + field_block_len; + if (strlen(table_name) > NAME_LEN) + goto err; + db = table_name + table_name_len + 1; DBUG_EXECUTE_IF ("simulate_invalid_address", db_len = data_len;); @@ -7419,7 +7478,7 @@ error: DBUG_EXECUTE_IF("LOAD_DATA_INFILE_has_fatal_error", thd->is_slave_error= 0; thd->is_fatal_error= 1;); - if (thd->is_slave_error) + if (unlikely(thd->is_slave_error)) { /* this err/sql_errno code is copy-paste from net_send_error() */ const char *err; @@ -7442,7 +7501,7 @@ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'", } free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); - if (thd->is_fatal_error) + if (unlikely(thd->is_fatal_error)) { char buf[256]; my_snprintf(buf, sizeof(buf), @@ -7973,6 +8032,23 @@ Gtid_log_event::do_apply_event(rpl_group_info *rgi) } DBUG_ASSERT((bits & OPTION_GTID_BEGIN) == 0); + + Master_info *mi=rgi->rli->mi; + switch (flags2 & (FL_DDL | FL_TRANSACTIONAL)) + { + case FL_TRANSACTIONAL: + my_atomic_add64_explicit((volatile int64 *)&mi->total_trans_groups, 1, + MY_MEMORY_ORDER_RELAXED); + break; + case FL_DDL: + my_atomic_add64_explicit((volatile int64 *)&mi->total_ddl_groups, 1, + MY_MEMORY_ORDER_RELAXED); + break; + default: + my_atomic_add64_explicit((volatile int64 *)&mi->total_non_trans_groups, 1, + MY_MEMORY_ORDER_RELAXED); + } + if (flags2 & FL_STANDALONE) return 0; @@ -8841,7 +8917,7 @@ int Xid_log_event::do_apply_event(rpl_group_info *rgi) gtid= rgi->current_gtid; err= rpl_global_gtid_slave_state->record_gtid(thd, >id, sub_id, true, false, &hton); - if (err) + if (unlikely(err)) { int ec= thd->get_stmt_da()->sql_errno(); /* @@ -8872,7 +8948,7 @@ int Xid_log_event::do_apply_event(rpl_group_info *rgi) res= trans_commit(thd); /* Automatically rolls back on error. */ thd->mdl_context.release_transactional_locks(); - if (!res && sub_id) + if (likely(!res) && sub_id) rpl_global_gtid_slave_state->update_state_hash(sub_id, >id, hton, rgi); /* @@ -9048,6 +9124,13 @@ User_var_log_event(const char* buf, uint event_len, buf+= description_event->common_header_len + description_event->post_header_len[USER_VAR_EVENT-1]; name_len= uint4korr(buf); + /* Avoid reading out of buffer */ + if ((buf - buf_start) + UV_NAME_LEN_SIZE + name_len > event_len) + { + error= true; + goto err; + } + name= (char *) buf + UV_NAME_LEN_SIZE; /* @@ -9104,7 +9187,12 @@ User_var_log_event(const char* buf, uint event_len, Old events will not have this extra byte, thence, we keep the flags set to UNDEF_F. */ - size_t bytes_read= ((val + val_len) - buf_start); + size_t bytes_read= (val + val_len) - buf_start; + if (bytes_read > size_t(event_len)) + { + error= true; + goto err; + } if ((data_written - bytes_read) > 0) { flags= (uint) *(buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + @@ -9114,7 +9202,7 @@ User_var_log_event(const char* buf, uint event_len, } err: - if (error) + if (unlikely(error)) name= 0; } @@ -9294,7 +9382,7 @@ bool User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info) cs->csname, hex_str, cs->name, print_event_info->delimiter); my_free(hex_str); - if (error) + if (unlikely(error)) goto err; break; } @@ -9336,7 +9424,12 @@ int User_var_log_event::do_apply_event(rpl_group_info *rgi) } if (!(charset= get_charset(charset_number, MYF(MY_WME)))) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid character set for User var event"); DBUG_RETURN(1); + } LEX_CSTRING user_var_name; user_var_name.str= name; user_var_name.length= name_len; @@ -9351,12 +9444,26 @@ int User_var_log_event::do_apply_event(rpl_group_info *rgi) { switch (type) { case REAL_RESULT: + if (val_len != 8) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid variable length at User var event"); + return 1; + } float8get(real_val, val); it= new (thd->mem_root) Item_float(thd, real_val, 0); val= (char*) &real_val; // Pointer to value in native format val_len= 8; break; case INT_RESULT: + if (val_len != 8) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid variable length at User var event"); + return 1; + } int_val= (longlong) uint8korr(val); it= new (thd->mem_root) Item_int(thd, int_val); val= (char*) &int_val; // Pointer to value in native format @@ -9364,6 +9471,13 @@ int User_var_log_event::do_apply_event(rpl_group_info *rgi) break; case DECIMAL_RESULT: { + if (val_len < 3) + { + rgi->rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, + ER_THD(thd, ER_SLAVE_FATAL_ERROR), + "Invalid variable length at User var event"); + return 1; + } Item_decimal *dec= new (thd->mem_root) Item_decimal(thd, (uchar*) val+2, val[0], val[1]); it= dec; val= (char *)dec->val_decimal(NULL); @@ -9806,9 +9920,9 @@ int Create_file_log_event::do_apply_event(rpl_group_info *rgi) error=0; // Everything is ok err: - if (error) + if (unlikely(error)) end_io_cache(&file); - if (fd >= 0) + if (likely(fd >= 0)) mysql_file_close(fd, MYF(0)); return error != 0; } @@ -10519,7 +10633,7 @@ Execute_load_query_log_event::do_apply_event(rpl_group_info *rgi) If there was an error the slave is going to stop, leave the file so that we can re-execute this event at START SLAVE. */ - if (!error) + if (unlikely(!error)) mysql_file_delete(key_file_log_event_data, fname, MYF(MY_WME)); my_free(buf); @@ -10779,6 +10893,14 @@ Rows_log_event::Rows_log_event(const char *buf, uint event_len, DBUG_PRINT("debug", ("Reading from %p", ptr_after_width)); m_width = net_field_length(&ptr_after_width); DBUG_PRINT("debug", ("m_width=%lu", m_width)); + + /* Avoid reading out of buffer */ + if (ptr_after_width + (m_width + 7) / 8 > (uchar*)buf + event_len) + { + m_cols.bitmap= NULL; + DBUG_VOID_RETURN; + } + /* if my_bitmap_init fails, catched in is_valid() */ if (likely(!my_bitmap_init(&m_cols, m_width <= sizeof(m_bitbuf)*8 ? m_bitbuf : NULL, @@ -10827,7 +10949,12 @@ Rows_log_event::Rows_log_event(const char *buf, uint event_len, const uchar* const ptr_rows_data= (const uchar*) ptr_after_width; - size_t const data_size= event_len - (ptr_rows_data - (const uchar *) buf); + size_t const read_size= ptr_rows_data - (const unsigned char *) buf; + if (read_size > event_len) + { + DBUG_VOID_RETURN; + } + size_t const data_size= event_len - read_size; DBUG_PRINT("info",("m_table_id: %lu m_flags: %d m_width: %lu data_size: %lu", m_table_id, m_flags, m_width, (ulong) data_size)); @@ -11146,7 +11273,7 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) lex->query_tables_last= &tables->next_global; } } - if (open_and_lock_tables(thd, rgi->tables_to_lock, FALSE, 0)) + if (unlikely(open_and_lock_tables(thd, rgi->tables_to_lock, FALSE, 0))) { uint actual_error= thd->get_stmt_da()->sql_errno(); #ifdef WITH_WSREP @@ -11399,13 +11526,13 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) error= do_exec_row(rgi); - if (error) + if (unlikely(error)) DBUG_PRINT("info", ("error: %s", HA_ERR(error))); DBUG_ASSERT(error != HA_ERR_RECORD_DELETED); table->in_use = old_thd; - if (error) + if (unlikely(error)) { int actual_error= convert_handler_error(error, thd, table); bool idempotent_error= (idempotent_error_code(error) && @@ -11436,12 +11563,12 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) DBUG_PRINT("info", ("curr_row: %p; curr_row_end: %p; rows_end:%p", m_curr_row, m_curr_row_end, m_rows_end)); - if (!m_curr_row_end && !error) + if (!m_curr_row_end && likely(!error)) error= unpack_current_row(rgi); m_curr_row= m_curr_row_end; - if (error == 0 && !transactional_table) + if (likely(error == 0) && !transactional_table) thd->transaction.all.modified_non_trans_table= thd->transaction.stmt.modified_non_trans_table= TRUE; } // row processing loop @@ -11463,7 +11590,7 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) const_cast<Relay_log_info*>(rli)->abort_slave= 1;); } - if ((error= do_after_row_operations(rli, error)) && + if (unlikely(error= do_after_row_operations(rli, error)) && ignored_error_code(convert_handler_error(error, thd, table))) { @@ -11477,7 +11604,7 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) } // if (table) - if (error) + if (unlikely(error)) { slave_rows_error_report(ERROR_LEVEL, error, rgi, thd, table, get_type_str(), @@ -11506,7 +11633,8 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) } #endif /* WITH_WSREP && HAVE_QUERY_CACHE */ - if (get_flags(STMT_END_F) && (error= rows_event_stmt_cleanup(rgi, thd))) + if (unlikely(get_flags(STMT_END_F) && + (error= rows_event_stmt_cleanup(rgi, thd)))) slave_rows_error_report(ERROR_LEVEL, thd->is_error() ? 0 : error, rgi, thd, table, @@ -12863,7 +12991,7 @@ Write_rows_log_event::do_after_row_operations(const Slave_reporting_capability * ultimately. Still todo: fix */ } - if ((local_error= m_table->file->ha_end_bulk_insert())) + if (unlikely((local_error= m_table->file->ha_end_bulk_insert()))) { m_table->file->print_error(local_error, MYF(0)); } @@ -12981,7 +13109,7 @@ Rows_log_event::write_row(rpl_group_info *rgi, prepare_record(table, m_width, true); /* unpack row into table->record[0] */ - if ((error= unpack_current_row(rgi))) + if (unlikely((error= unpack_current_row(rgi)))) { table->file->print_error(error, MYF(0)); DBUG_RETURN(error); @@ -13021,9 +13149,9 @@ Rows_log_event::write_row(rpl_group_info *rgi, DBUG_PRINT_BITSET("debug", "read_set: %s", table->read_set); if (invoke_triggers && - process_triggers(TRG_EVENT_INSERT, TRG_ACTION_BEFORE, TRUE)) + unlikely(process_triggers(TRG_EVENT_INSERT, TRG_ACTION_BEFORE, TRUE))) { - DBUG_RETURN(HA_ERR_GENERIC); // in case if error is not set yet + DBUG_RETURN(HA_ERR_GENERIC); // in case if error is not set yet } // Handle INSERT. @@ -13047,7 +13175,7 @@ Rows_log_event::write_row(rpl_group_info *rgi, if (table->s->sequence) error= update_sequence(); - else while ((error= table->file->ha_write_row(table->record[0]))) + else while (unlikely(error= table->file->ha_write_row(table->record[0]))) { if (error == HA_ERR_LOCK_DEADLOCK || error == HA_ERR_LOCK_WAIT_TIMEOUT || @@ -13079,11 +13207,9 @@ Rows_log_event::write_row(rpl_group_info *rgi, { DBUG_PRINT("info",("Locating offending record using rnd_pos()")); error= table->file->ha_rnd_pos(table->record[1], table->file->dup_ref); - if (error) + if (unlikely(error)) { DBUG_PRINT("info",("rnd_pos() returns error %d",error)); - if (error == HA_ERR_RECORD_DELETED) - error= HA_ERR_KEY_NOT_FOUND; table->file->print_error(error, MYF(0)); DBUG_RETURN(error); } @@ -13114,11 +13240,9 @@ Rows_log_event::write_row(rpl_group_info *rgi, (const uchar*)key.get(), HA_WHOLE_KEY, HA_READ_KEY_EXACT); - if (error) + if (unlikely(error)) { DBUG_PRINT("info",("index_read_idx() returns %s", HA_ERR(error))); - if (error == HA_ERR_RECORD_DELETED) - error= HA_ERR_KEY_NOT_FOUND; table->file->print_error(error, MYF(0)); DBUG_RETURN(error); } @@ -13189,18 +13313,20 @@ Rows_log_event::write_row(rpl_group_info *rgi, { DBUG_PRINT("info",("Deleting offending row and trying to write new one again")); if (invoke_triggers && - process_triggers(TRG_EVENT_DELETE, TRG_ACTION_BEFORE, TRUE)) + unlikely(process_triggers(TRG_EVENT_DELETE, TRG_ACTION_BEFORE, + TRUE))) error= HA_ERR_GENERIC; // in case if error is not set yet else { - if ((error= table->file->ha_delete_row(table->record[1]))) + if (unlikely((error= table->file->ha_delete_row(table->record[1])))) { DBUG_PRINT("info",("ha_delete_row() returns error %d",error)); table->file->print_error(error, MYF(0)); DBUG_RETURN(error); } if (invoke_triggers && - process_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER, TRUE)) + unlikely(process_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER, + TRUE))) DBUG_RETURN(HA_ERR_GENERIC); // in case if error is not set yet } /* Will retry ha_write_row() with the offending row removed. */ @@ -13208,7 +13334,7 @@ Rows_log_event::write_row(rpl_group_info *rgi, } if (invoke_triggers && - process_triggers(TRG_EVENT_INSERT, TRG_ACTION_AFTER, TRUE)) + unlikely(process_triggers(TRG_EVENT_INSERT, TRG_ACTION_AFTER, TRUE))) error= HA_ERR_GENERIC; // in case if error is not set yet DBUG_RETURN(error); @@ -13262,7 +13388,7 @@ Write_rows_log_event::do_exec_row(rpl_group_info *rgi) error= write_row(rgi, slave_exec_mode == SLAVE_EXEC_MODE_IDEMPOTENT); thd_proc_info(thd, tmp); - if (error && !thd->is_error()) + if (unlikely(error) && unlikely(!thd->is_error())) { DBUG_ASSERT(0); my_error(ER_UNKNOWN_ERROR, MYF(0)); @@ -13613,11 +13739,9 @@ int Rows_log_event::find_row(rpl_group_info *rgi) DBUG_RETURN(error); error= table->file->ha_rnd_pos_by_record(table->record[0]); - if (error) + if (unlikely(error)) { DBUG_PRINT("info",("rnd_pos returns error %d",error)); - if (error == HA_ERR_RECORD_DELETED) - error= HA_ERR_KEY_NOT_FOUND; table->file->print_error(error, MYF(0)); } DBUG_RETURN(error); @@ -13677,13 +13801,12 @@ int Rows_log_event::find_row(rpl_group_info *rgi) table->record[0][table->s->null_bytes - 1]|= 256U - (1U << table->s->last_null_bit_pos); - if ((error= table->file->ha_index_read_map(table->record[0], m_key, - HA_WHOLE_KEY, - HA_READ_KEY_EXACT))) + if (unlikely((error= table->file->ha_index_read_map(table->record[0], + m_key, + HA_WHOLE_KEY, + HA_READ_KEY_EXACT)))) { DBUG_PRINT("info",("no record matching the key found in the table")); - if (error == HA_ERR_RECORD_DELETED) - error= HA_ERR_KEY_NOT_FOUND; table->file->print_error(error, MYF(0)); table->file->ha_index_end(); goto end; @@ -13759,9 +13882,6 @@ int Rows_log_event::find_row(rpl_group_info *rgi) { while ((error= table->file->ha_index_next(table->record[0]))) { - /* We just skip records that has already been deleted */ - if (error == HA_ERR_RECORD_DELETED) - continue; DBUG_PRINT("info",("no record matching the given row found")); table->file->print_error(error, MYF(0)); table->file->ha_index_end(); @@ -13776,7 +13896,7 @@ int Rows_log_event::find_row(rpl_group_info *rgi) DBUG_EXECUTE_IF("slave_crash_if_table_scan", abort();); /* We don't have a key: search the table using rnd_next() */ - if ((error= table->file->ha_rnd_init_with_error(1))) + if (unlikely((error= table->file->ha_rnd_init_with_error(1)))) { DBUG_PRINT("info",("error initializing table scan" " (ha_rnd_init returns %d)",error)); @@ -13788,10 +13908,9 @@ int Rows_log_event::find_row(rpl_group_info *rgi) /* Continue until we find the right record or have made a full loop */ do { - restart_rnd_next: error= table->file->ha_rnd_next(table->record[0]); - if (error) + if (unlikely(error)) DBUG_PRINT("info", ("error: %s", HA_ERR(error))); switch (error) { @@ -13804,13 +13923,6 @@ int Rows_log_event::find_row(rpl_group_info *rgi) table->file->ha_rnd_end(); goto end; - /* - If the record was deleted, we pick the next one without doing - any comparisons. - */ - case HA_ERR_RECORD_DELETED: - goto restart_rnd_next; - default: DBUG_PRINT("info", ("Failed to get next record" " (rnd_next returns %d)",error)); @@ -13941,7 +14053,7 @@ int Delete_rows_log_event::do_exec_row(rpl_group_info *rgi) #endif /* WSREP_PROC_INFO */ thd_proc_info(thd, message); - if (!(error= find_row(rgi))) + if (likely(!(error= find_row(rgi)))) { /* Delete the record found, located in record[0] @@ -13956,9 +14068,9 @@ int Delete_rows_log_event::do_exec_row(rpl_group_info *rgi) thd_proc_info(thd, message); if (invoke_triggers && - process_triggers(TRG_EVENT_DELETE, TRG_ACTION_BEFORE, FALSE)) + unlikely(process_triggers(TRG_EVENT_DELETE, TRG_ACTION_BEFORE, FALSE))) error= HA_ERR_GENERIC; // in case if error is not set yet - if (!error) + if (likely(!error)) { m_table->mark_columns_per_binlog_row_image(); if (m_vers_from_plain && m_table->versioned(VERS_TIMESTAMP)) @@ -13976,8 +14088,8 @@ int Delete_rows_log_event::do_exec_row(rpl_group_info *rgi) } m_table->default_column_bitmaps(); } - if (invoke_triggers && !error && - process_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER, FALSE)) + if (invoke_triggers && likely(!error) && + unlikely(process_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER, FALSE))) error= HA_ERR_GENERIC; // in case if error is not set yet m_table->file->ha_index_or_rnd_end(); } @@ -14162,7 +14274,7 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi) thd_proc_info(thd, message); int error= find_row(rgi); - if (error) + if (unlikely(error)) { /* We need to read the second image in the event of error to be @@ -14198,7 +14310,7 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi) /* this also updates m_curr_row_end */ thd_proc_info(thd, message); - if ((error= unpack_current_row(rgi, &m_cols_ai))) + if (unlikely((error= unpack_current_row(rgi, &m_cols_ai)))) goto err; /* @@ -14225,7 +14337,7 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi) thd_proc_info(thd, message); if (invoke_triggers && - process_triggers(TRG_EVENT_UPDATE, TRG_ACTION_BEFORE, TRUE)) + unlikely(process_triggers(TRG_EVENT_UPDATE, TRG_ACTION_BEFORE, TRUE))) { error= HA_ERR_GENERIC; // in case if error is not set yet goto err; @@ -14239,7 +14351,7 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi) if (m_vers_from_plain && m_table->versioned(VERS_TIMESTAMP)) m_table->vers_update_fields(); error= m_table->file->ha_update_row(m_table->record[1], m_table->record[0]); - if (error == HA_ERR_RECORD_IS_THE_SAME) + if (unlikely(error == HA_ERR_RECORD_IS_THE_SAME)) error= 0; if (m_vers_from_plain && m_table->versioned(VERS_TIMESTAMP)) { @@ -14249,8 +14361,8 @@ Update_rows_log_event::do_exec_row(rpl_group_info *rgi) } m_table->default_column_bitmaps(); - if (invoke_triggers && !error && - process_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER, TRUE)) + if (invoke_triggers && likely(!error) && + unlikely(process_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER, TRUE))) error= HA_ERR_GENERIC; // in case if error is not set yet thd_proc_info(thd, tmp); @@ -14391,7 +14503,7 @@ void Incident_log_event::pack_info(Protocol *protocol) #endif /* MYSQL_CLIENT */ -#if WITH_WSREP && !defined(MYSQL_CLIENT) +#if defined(WITH_WSREP) && !defined(MYSQL_CLIENT) /* read the first event from (*buf). The size of the (*buf) is (*buf_len). At the end (*buf) is shitfed to point to the following event or NULL and |