diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-04-27 11:18:11 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-04-27 11:18:11 +0300 |
commit | edbdfc2f995eb47ba49235195aca00888aeacbc4 (patch) | |
tree | 144c2e26bdd69e40b5ab9f1ff3c9d9958807201d /storage/xtradb/handler/ha_innodb.cc | |
parent | dd4124c22430dd2f245afbf9a20cfea303de3320 (diff) | |
download | mariadb-git-edbdfc2f995eb47ba49235195aca00888aeacbc4.tar.gz |
MDEV-7962 wsrep_on() takes 0.14% in OLTP RO
The function wsrep_on() was being called rather frequently
in InnoDB and XtraDB. Let us cache it in trx_t and invoke
trx_t::is_wsrep() instead.
innobase_trx_init(): Cache trx->wsrep = wsrep_on(thd).
ha_innobase::write_row(): Replace many repeated calls to current_thd,
and test the cheapest condition first.
Diffstat (limited to 'storage/xtradb/handler/ha_innodb.cc')
-rw-r--r-- | storage/xtradb/handler/ha_innodb.cc | 126 |
1 files changed, 52 insertions, 74 deletions
diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 2aafb1a44ee..2ec16280eb6 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -5,7 +5,7 @@ Copyright (c) 2013, 2018, MariaDB Corporation. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -1934,8 +1934,7 @@ innobase_srv_conc_enter_innodb( trx_t* trx) /*!< in: transaction handle */ { #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; #endif /* WITH_WSREP */ if (srv_thread_concurrency) { if (trx->n_tickets_to_enter_innodb > 0) { @@ -1973,8 +1972,7 @@ innobase_srv_conc_exit_innodb( ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch)); #endif /* UNIV_SYNC_DEBUG */ #ifdef WITH_WSREP - if (wsrep_on(trx->mysql_thd) && - wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; + if (trx->is_wsrep() && wsrep_thd_is_BF(trx->mysql_thd, FALSE)) return; #endif /* WITH_WSREP */ /* This is to avoid making an unnecessary function call. */ @@ -2950,6 +2948,9 @@ innobase_trx_init( trx->check_unique_secondary = !thd_test_options( thd, OPTION_RELAXED_UNIQUE_CHECKS); +#ifdef WITH_WSREP + trx->wsrep = wsrep_on(thd); +#endif /* Transaction on start caches the fake_changes state and uses it for complete transaction lifetime. @@ -4676,19 +4677,17 @@ innobase_commit_low( trx_t* trx) /*!< in: transaction handle */ { #ifdef WITH_WSREP - THD* thd = (THD*)trx->mysql_thd; const char* tmp = 0; - if (thd && wsrep_on(thd)) { + if (trx->is_wsrep()) { #ifdef WSREP_PROC_INFO char info[64]; info[sizeof(info) - 1] = '\0'; snprintf(info, sizeof(info) - 1, "innobase_commit_low():trx_commit_for_mysql(%lld)", - (long long) wsrep_thd_trx_seqno(thd)); - tmp = thd_proc_info(thd, info); - + (long long) wsrep_thd_trx_seqno(trx->mysql_thd)); + tmp = thd_proc_info(trx->mysql_thd, info); #else - tmp = thd_proc_info(thd, "innobase_commit_low()"); + tmp = thd_proc_info(trx->mysql_thd, "innobase_commit_low()"); #endif /* WSREP_PROC_INFO */ } #endif /* WITH_WSREP */ @@ -4697,7 +4696,7 @@ innobase_commit_low( trx_commit_for_mysql(trx); } #ifdef WITH_WSREP - if (thd && wsrep_on(thd)) { thd_proc_info(thd, tmp); } + if (trx->is_wsrep()) { thd_proc_info(trx->mysql_thd, tmp); } #endif /* WITH_WSREP */ } @@ -8713,19 +8712,19 @@ ha_innobase::write_row( sql_command = thd_sql_command(user_thd); - if ((sql_command == SQLCOM_ALTER_TABLE - || sql_command == SQLCOM_OPTIMIZE - || sql_command == SQLCOM_CREATE_INDEX + if (num_write_row >= 10000 + && (sql_command == SQLCOM_ALTER_TABLE + || sql_command == SQLCOM_OPTIMIZE + || sql_command == SQLCOM_CREATE_INDEX #ifdef WITH_WSREP - || (wsrep_on(user_thd) && wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && - !thd_test_options( - user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + || (sql_command == SQLCOM_LOAD && + trx->is_wsrep() && wsrep_load_data_splitting && + !thd_test_options( + user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) #endif /* WITH_WSREP */ - || sql_command == SQLCOM_DROP_INDEX) - && num_write_row >= 10000) { + || sql_command == SQLCOM_DROP_INDEX)) { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && sql_command == SQLCOM_LOAD) { + if (sql_command == SQLCOM_LOAD && trx->is_wsrep()) { WSREP_DEBUG("forced trx split for LOAD: %s", wsrep_thd_query(user_thd)); } @@ -8764,9 +8763,8 @@ no_commit: ; } else if (src_table == prebuilt->table) { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && - wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && + if (sql_command == SQLCOM_LOAD && trx->is_wsrep() && + wsrep_load_data_splitting && !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { @@ -8796,9 +8794,8 @@ no_commit: prebuilt->sql_stat_start = TRUE; } else { #ifdef WITH_WSREP - if (wsrep_on(user_thd) && - wsrep_load_data_splitting && - sql_command == SQLCOM_LOAD && + if (sql_command == SQLCOM_LOAD && trx->is_wsrep() && + wsrep_load_data_splitting && !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { @@ -8943,21 +8940,19 @@ no_commit: prebuilt->autoinc_offset, prebuilt->autoinc_increment); - if (wsrep_on(current_thd) && + if (trx->is_wsrep() && auto_inc_inserted && wsrep_drupal_282555_workaround && - wsrep_thd_retry_counter(current_thd) == 0 && - !thd_test_options(current_thd, + wsrep_thd_retry_counter(user_thd) == 0 && + !thd_test_options(user_thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) { WSREP_DEBUG( "retrying insert: %s", - (*wsrep_thd_query(current_thd)) ? - wsrep_thd_query(current_thd) : - (char *)"void"); + wsrep_thd_query(user_thd)); error= DB_SUCCESS; wsrep_thd_set_conflict_state( - current_thd, MUST_ABORT); + user_thd, MUST_ABORT); innobase_srv_conc_exit_innodb(prebuilt->trx); /* jump straight to func exit over * later wsrep hooks */ @@ -8995,7 +8990,7 @@ set_max_autoinc: prebuilt autoinc values don't get properly assigned. Fetch values from server side. */ - if (wsrep_on(user_thd) && + if (trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == REPL_RECV) { wsrep_thd_auto_increment_variables( @@ -9044,18 +9039,16 @@ report_error: user_thd); #ifdef WITH_WSREP - if (!error_result - && wsrep_on(user_thd) - && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE + if (!error_result && trx->is_wsrep() + && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && !wsrep_consistency_check(user_thd) && !wsrep_thd_ignore_table(user_thd)) { if (wsrep_append_keys(user_thd, WSREP_KEY_EXCLUSIVE, record, NULL)) { DBUG_PRINT("wsrep", ("row key failed")); error_result = HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + goto func_exit; } } -wsrep_error: #endif /* WITH_WSREP */ if (error_result == HA_FTS_INVALID_DOCID) { @@ -9536,7 +9529,7 @@ ha_innobase::update_row( prebuilt autoinc values don't get properly assigned. Fetch values from server side. */ - if (wsrep_on(user_thd) && + if (trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == REPL_RECV) { wsrep_thd_auto_increment_variables( @@ -9581,9 +9574,8 @@ func_exit: innobase_active_small(); #ifdef WITH_WSREP - if (error == DB_SUCCESS && + if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && - wsrep_on(user_thd) && !wsrep_thd_ignore_table(user_thd)) { DBUG_PRINT("wsrep", ("update row key")); @@ -9592,11 +9584,9 @@ func_exit: new_row)) { WSREP_DEBUG("WSREP: UPDATE_ROW_KEY FAILED"); DBUG_PRINT("wsrep", ("row key failed")); - err = HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } } -wsrep_error: #endif /* WITH_WSREP */ DBUG_RETURN(err); @@ -9643,25 +9633,20 @@ ha_innobase::delete_row( /* Tell the InnoDB server that there might be work for utility threads: */ - innobase_active_small(); #ifdef WITH_WSREP - if (error == DB_SUCCESS && + if (error == DB_SUCCESS && trx->is_wsrep() && wsrep_thd_exec_mode(user_thd) == LOCAL_STATE && - wsrep_on(user_thd) && !wsrep_thd_ignore_table(user_thd)) { if (wsrep_append_keys(user_thd, WSREP_KEY_EXCLUSIVE, record, - NULL)) { + NULL)) { DBUG_PRINT("wsrep", ("delete fail")); - error = (dberr_t) HA_ERR_INTERNAL_ERROR; - goto wsrep_error; + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } } -wsrep_error: #endif /* WITH_WSREP */ - DBUG_RETURN(convert_error_code_to_mysql( error, prebuilt->table->flags, user_thd)); } @@ -10917,8 +10902,7 @@ wsrep_append_foreign_key( int cache_key_len; bool const copy = true; - if (!wsrep_on(trx->mysql_thd) || - wsrep_thd_exec_mode(thd) != LOCAL_STATE) + if (!trx->is_wsrep() || wsrep_thd_exec_mode(thd) != LOCAL_STATE) return DB_SUCCESS; if (!thd || !foreign || @@ -15541,12 +15525,11 @@ ha_innobase::external_lock( THD* thd, /*!< in: handle to the user thread */ int lock_type) /*!< in: lock type */ { - trx_t* trx; - DBUG_ENTER("ha_innobase::external_lock"); DBUG_PRINT("enter",("lock_type: %d", lock_type)); update_thd(thd); + trx_t* trx = prebuilt->trx; /* Statement based binlogging does not work in isolation level READ UNCOMMITTED and READ COMMITTED since the necessary @@ -15560,22 +15543,19 @@ ha_innobase::external_lock( && thd_binlog_format(thd) == BINLOG_FORMAT_STMT && thd_binlog_filter_ok(thd) && thd_sqlcom_can_generate_row_events(thd)) { - bool skip = 0; + bool skip = false; +#ifdef WITH_WSREP + skip = trx->is_wsrep() + && wsrep_thd_exec_mode(thd) != LOCAL_STATE; +#endif /* WITH_WSREP */ /* used by test case */ DBUG_EXECUTE_IF("no_innodb_binlog_errors", skip = true;); if (!skip) { -#ifdef WITH_WSREP - if (!wsrep_on(thd) || wsrep_thd_exec_mode(thd) == LOCAL_STATE) - { -#endif /* WITH_WSREP */ - my_error(ER_BINLOG_STMT_MODE_AND_ROW_ENGINE, MYF(0), - " InnoDB is limited to row-logging when " - "transaction isolation level is " - "READ COMMITTED or READ UNCOMMITTED."); - DBUG_RETURN(HA_ERR_LOGGING_IMPOSSIBLE); -#ifdef WITH_WSREP - } -#endif /* WITH_WSREP */ + my_error(ER_BINLOG_STMT_MODE_AND_ROW_ENGINE, MYF(0), + " InnoDB is limited to row-logging when " + "transaction isolation level is " + "READ COMMITTED or READ UNCOMMITTED."); + DBUG_RETURN(HA_ERR_LOGGING_IMPOSSIBLE); } } @@ -15606,8 +15586,6 @@ ha_innobase::external_lock( } - trx = prebuilt->trx; - prebuilt->sql_stat_start = TRUE; prebuilt->hint_need_to_fetch_extra_cols = 0; |