diff --git a/plugin/handler_socket/handlersocket/database.cpp b/plugin/handler_socket/handlersocket/database.cpp index 8f172a95151..001981e3baa 100644 --- a/plugin/handler_socket/handlersocket/database.cpp +++ b/plugin/handler_socket/handlersocket/database.cpp @@ -1006,7 +1006,7 @@ dbcontext::cmd_open(dbcallback_i& cb, const cmd_open_args& arg) LEX_CSTRING db_name= { arg.dbn, strlen(arg.dbn) }; LEX_CSTRING tbl_name= { arg.tbl, strlen(arg.tbl) }; tables.init_one_table(&db_name, &tbl_name, 0, lock_type); - tables.mdl_request.init(MDL_key::TABLE, arg.dbn, arg.tbl, + MDL_REQUEST_INIT(&tables.mdl_request, MDL_key::TABLE, arg.dbn, arg.tbl, for_write_flag ? MDL_SHARED_WRITE : MDL_SHARED_READ, MDL_TRANSACTION); Open_table_context ot_act(thd, 0); if (!open_table(thd, &tables, &ot_act)) { diff --git a/sql/backup.cc b/sql/backup.cc index 1a0341ad9a4..40791e27416 100644 --- a/sql/backup.cc +++ b/sql/backup.cc @@ -161,7 +161,8 @@ static bool backup_start(THD *thd) DBUG_RETURN(1); } - mdl_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_START, MDL_EXPLICIT); + MDL_REQUEST_INIT(&mdl_request, MDL_key::BACKUP, "", "", MDL_BACKUP_START, + MDL_EXPLICIT); if (thd->mdl_context.acquire_lock(&mdl_request, thd->variables.lock_wait_timeout)) DBUG_RETURN(1); diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc index 759e28b8589..fdca2c47dbc 100644 --- a/sql/debug_sync.cc +++ b/sql/debug_sync.cc @@ -121,6 +121,25 @@ static void init_debug_sync_psi_keys(void) #endif /* HAVE_PSI_INTERFACE */ +/** + Set the THD::proc_info without instrumentation. + This method is private to DEBUG_SYNC, + and on purpose avoid any use of: + - the SHOW PROFILE instrumentation + - the PERFORMANCE_SCHEMA instrumentation + so that using DEBUG_SYNC() in the server code + does not cause the instrumentations to record + spurious data. +*/ +static const char* +debug_sync_thd_proc_info(THD *thd, const char* info) +{ + const char* old_proc_info= thd->proc_info; + thd->proc_info= info; + return old_proc_info; +} + + /** Initialize the debug sync facility at server start. @@ -1365,7 +1384,7 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action) strxnmov(ds_control->ds_proc_info, sizeof(ds_control->ds_proc_info)-1, "debug sync point: ", action->sync_point.c_ptr(), NullS); old_proc_info= thd->proc_info; - thd_proc_info(thd, ds_control->ds_proc_info); + debug_sync_thd_proc_info(thd, ds_control->ds_proc_info); } /* @@ -1483,11 +1502,11 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action) mysql_mutex_lock(&thd->mysys_var->mutex); thd->mysys_var->current_mutex= old_mutex; thd->mysys_var->current_cond= old_cond; - thd_proc_info(thd, old_proc_info); + debug_sync_thd_proc_info(thd, old_proc_info); mysql_mutex_unlock(&thd->mysys_var->mutex); } else - thd_proc_info(thd, old_proc_info); + debug_sync_thd_proc_info(thd, old_proc_info); } else { diff --git a/sql/handler.cc b/sql/handler.cc index 7f79ce98eec..efcccc9f0c6 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1489,7 +1489,8 @@ int ha_commit_trans(THD *thd, bool all) We allow the owner of FTWRL to COMMIT; we assume that it knows what it does. */ - mdl_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_COMMIT, MDL_EXPLICIT); + MDL_REQUEST_INIT(&mdl_request, MDL_key::BACKUP, "", "", MDL_BACKUP_COMMIT, + MDL_EXPLICIT); if (!WSREP(thd) && thd->mdl_context.acquire_lock(&mdl_request, diff --git a/sql/item_func.cc b/sql/item_func.cc index da7b523d830..fe89938260c 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4027,7 +4027,7 @@ longlong Item_func_get_lock::val_int() } MDL_request ull_request; - ull_request.init(MDL_key::USER_LOCK, res->c_ptr_safe(), "", + MDL_REQUEST_INIT(&ull_request, MDL_key::USER_LOCK, res->c_ptr_safe(), "", MDL_SHARED_NO_WRITE, MDL_EXPLICIT); MDL_key *ull_key= &ull_request.key; diff --git a/sql/lock.cc b/sql/lock.cc index 92f4ea0c279..db205efd643 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -859,8 +859,10 @@ bool lock_schema_name(THD *thd, const char *db) if (thd->has_read_only_protection()) return TRUE; - global_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_DDL, MDL_STATEMENT); - mdl_request.init(MDL_key::SCHEMA, db, "", MDL_EXCLUSIVE, MDL_TRANSACTION); + MDL_REQUEST_INIT(&global_request, MDL_key::BACKUP, "", "", MDL_BACKUP_DDL, + MDL_STATEMENT); + MDL_REQUEST_INIT(&mdl_request, MDL_key::SCHEMA, db, "", MDL_EXCLUSIVE, + MDL_TRANSACTION); mdl_requests.push_front(&mdl_request); mdl_requests.push_front(&global_request); @@ -917,10 +919,12 @@ bool lock_object_name(THD *thd, MDL_key::enum_mdl_namespace mdl_type, if (thd->has_read_only_protection()) return TRUE; - global_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_DDL, MDL_STATEMENT); - schema_request.init(MDL_key::SCHEMA, db, "", MDL_INTENTION_EXCLUSIVE, - MDL_TRANSACTION); - mdl_request.init(mdl_type, db, name, MDL_EXCLUSIVE, MDL_TRANSACTION); + MDL_REQUEST_INIT(&global_request, MDL_key::BACKUP, "", "", MDL_BACKUP_DDL, + MDL_STATEMENT); + MDL_REQUEST_INIT(&schema_request, MDL_key::SCHEMA, db, "", + MDL_INTENTION_EXCLUSIVE, MDL_TRANSACTION); + MDL_REQUEST_INIT(&mdl_request, mdl_type, db, name, MDL_EXCLUSIVE, + MDL_TRANSACTION); mdl_requests.push_front(&mdl_request); mdl_requests.push_front(&schema_request); @@ -1041,7 +1045,7 @@ bool Global_read_lock::lock_global_read_lock(THD *thd) MDL_BACKUP_FTWRL1)); DBUG_ASSERT(! thd->mdl_context.is_lock_owner(MDL_key::BACKUP, "", "", MDL_BACKUP_FTWRL2)); - mdl_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_FTWRL1, + MDL_REQUEST_INIT(&mdl_request, MDL_key::BACKUP, "", "", MDL_BACKUP_FTWRL1, MDL_EXPLICIT); do diff --git a/sql/mdl.cc b/sql/mdl.cc index 0d6588cd6a4..ee20c89c3cb 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -25,6 +25,8 @@ #include #include #include +#include +#include static PSI_memory_key key_memory_MDL_context_acquire_locks; @@ -965,16 +967,20 @@ bool MDL_context::fix_pins() @param mdl_type The MDL lock type for the request. */ -void MDL_request::init(MDL_key::enum_mdl_namespace mdl_namespace, +void MDL_request::init_with_source(MDL_key::enum_mdl_namespace mdl_namespace, const char *db_arg, const char *name_arg, enum_mdl_type mdl_type_arg, - enum_mdl_duration mdl_duration_arg) + enum_mdl_duration mdl_duration_arg, + const char *src_file, + uint src_line) { key.mdl_key_init(mdl_namespace, db_arg, name_arg); type= mdl_type_arg; duration= mdl_duration_arg; ticket= NULL; + m_src_file= src_file; + m_src_line= src_line; } @@ -987,14 +993,18 @@ void MDL_request::init(MDL_key::enum_mdl_namespace mdl_namespace, @param mdl_type_arg The MDL lock type for the request. */ -void MDL_request::init(const MDL_key *key_arg, +void MDL_request::init_by_key_with_source(const MDL_key *key_arg, enum_mdl_type mdl_type_arg, - enum_mdl_duration mdl_duration_arg) + enum_mdl_duration mdl_duration_arg, + const char *src_file, + uint src_line) { key.mdl_key_init(key_arg); type= mdl_type_arg; duration= mdl_duration_arg; ticket= NULL; + m_src_file= src_file; + m_src_line= src_line; } @@ -1023,6 +1033,9 @@ MDL_ticket *MDL_ticket::create(MDL_context *ctx_arg, enum_mdl_type type_arg void MDL_ticket::destroy(MDL_ticket *ticket) { + mysql_mdl_destroy(ticket->m_psi); + ticket->m_psi= NULL; + delete ticket; } @@ -2109,6 +2122,15 @@ MDL_context::try_acquire_lock_impl(MDL_request *mdl_request, return TRUE; } + DBUG_ASSERT(ticket->m_psi == NULL); + ticket->m_psi= mysql_mdl_create(ticket, + &mdl_request->key, + mdl_request->type, + mdl_request->duration, + MDL_ticket::PENDING, + mdl_request->m_src_file, + mdl_request->m_src_line); + ticket->m_lock= lock; if (lock->can_grant_lock(mdl_request->type, this, false)) @@ -2120,6 +2142,8 @@ MDL_context::try_acquire_lock_impl(MDL_request *mdl_request, m_tickets[mdl_request->duration].push_front(ticket); mdl_request->ticket= ticket; + + mysql_mdl_set_status(ticket->m_psi, MDL_ticket::GRANTED); } else *out_ticket= ticket; @@ -2169,6 +2193,15 @@ MDL_context::clone_ticket(MDL_request *mdl_request) ))) return TRUE; + DBUG_ASSERT(ticket->m_psi == NULL); + ticket->m_psi= mysql_mdl_create(ticket, + &mdl_request->key, + mdl_request->type, + mdl_request->duration, + MDL_ticket::PENDING, + mdl_request->m_src_file, + mdl_request->m_src_line); + /* clone() is not supposed to be used to get a stronger lock. */ DBUG_ASSERT(mdl_request->ticket->has_stronger_or_equal_type(ticket->m_type)); @@ -2181,6 +2214,8 @@ MDL_context::clone_ticket(MDL_request *mdl_request) m_tickets[mdl_request->duration].push_front(ticket); + mysql_mdl_set_status(ticket->m_psi, MDL_ticket::GRANTED); + return FALSE; } @@ -2320,6 +2355,12 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout) mysql_prlock_unlock(&lock->m_rwlock); + PSI_metadata_locker_state state; + PSI_metadata_locker *locker= NULL; + + if (ticket->m_psi != NULL) + locker= PSI_CALL_start_metadata_wait(&state, ticket->m_psi, __FILE__, __LINE__); + will_wait_for(ticket); /* There is a shared or exclusive lock on the object. */ @@ -2365,6 +2406,9 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout) done_waiting_for(); + if (locker != NULL) + PSI_CALL_end_metadata_wait(locker, 0); + if (wait_status != MDL_wait::GRANTED) { lock->remove_ticket(m_pins, &MDL_lock::m_waiting, ticket); @@ -2400,6 +2444,8 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout) mdl_request->ticket= ticket; + mysql_mdl_set_status(ticket->m_psi, MDL_ticket::GRANTED); + DBUG_RETURN(FALSE); } @@ -2531,8 +2577,8 @@ MDL_context::upgrade_shared_lock(MDL_ticket *mdl_ticket, mdl_ticket->get_key()->mdl_namespace() != MDL_key::BACKUP) DBUG_RETURN(FALSE); - mdl_xlock_request.init(&mdl_ticket->m_lock->key, new_type, - MDL_TRANSACTION); + MDL_REQUEST_INIT_BY_KEY(&mdl_xlock_request, &mdl_ticket->m_lock->key, + new_type, MDL_TRANSACTION); if (acquire_lock(&mdl_xlock_request, lock_wait_timeout)) DBUG_RETURN(TRUE); @@ -2972,7 +3018,8 @@ MDL_context::is_lock_owner(MDL_key::enum_mdl_namespace mdl_namespace, MDL_request mdl_request; enum_mdl_duration not_unused; /* We don't care about exact duration of lock here. */ - mdl_request.init(mdl_namespace, db, name, mdl_type, MDL_TRANSACTION); + MDL_REQUEST_INIT(&mdl_request, mdl_namespace, db, name, mdl_type, + MDL_TRANSACTION); MDL_ticket *ticket= find_ticket(&mdl_request, ¬_unused); DBUG_ASSERT(ticket == NULL || ticket->m_lock); diff --git a/sql/mdl.h b/sql/mdl.h index b084670e5c6..4659238e9f2 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -353,7 +353,7 @@ enum enum_mdl_duration { or "name". */ -class MDL_key +struct MDL_key { public: #ifdef HAVE_PSI_INTERFACE @@ -535,18 +535,23 @@ public: /** A lock is requested based on a fully qualified name and type. */ MDL_key key; + const char *m_src_file; + uint m_src_line; + public: static void *operator new(size_t size, MEM_ROOT *mem_root) throw () { return alloc_root(mem_root, size); } static void operator delete(void *, MEM_ROOT *) {} - void init(MDL_key::enum_mdl_namespace namespace_arg, + void init_with_source(MDL_key::enum_mdl_namespace namespace_arg, const char *db_arg, const char *name_arg, enum_mdl_type mdl_type_arg, - enum_mdl_duration mdl_duration_arg); - void init(const MDL_key *key_arg, enum_mdl_type mdl_type_arg, - enum_mdl_duration mdl_duration_arg); + enum_mdl_duration mdl_duration_arg, + const char *src_file, uint src_line); + void init_by_key_with_source(const MDL_key *key_arg, enum_mdl_type mdl_type_arg, + enum_mdl_duration mdl_duration_arg, + const char *src_file, uint src_line); /** Set type of lock request. Can be only applied to pending locks. */ inline void set_type(enum_mdl_type type_arg) { @@ -610,6 +615,12 @@ public: typedef void (*mdl_cached_object_release_hook)(void *); +#define MDL_REQUEST_INIT(R, P1, P2, P3, P4, P5) \ + (*R).init_with_source(P1, P2, P3, P4, P5, __FILE__, __LINE__) + +#define MDL_REQUEST_INIT_BY_KEY(R, P1, P2, P3) \ + (*R).init_by_key_with_source(P1, P2, P3, __FILE__, __LINE__) + /** An abstract class for inspection of a connected @@ -718,6 +729,11 @@ public: /** Implement MDL_wait_for_subgraph interface. */ virtual bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor); virtual uint get_deadlock_weight() const; + /** + Status of lock request represented by the ticket as reflected in P_S. + */ + enum enum_psi_status { PENDING = 0, GRANTED, + PRE_ACQUIRE_NOTIFY, POST_RELEASE_NOTIFY }; private: friend class MDL_context; @@ -731,9 +747,15 @@ private: m_duration(duration_arg), #endif m_ctx(ctx_arg), - m_lock(NULL) + m_lock(NULL), + m_psi(NULL) {} + virtual ~MDL_ticket() + { + DBUG_ASSERT(m_psi == NULL); + } + static MDL_ticket *create(MDL_context *ctx_arg, enum_mdl_type type_arg #ifndef DBUG_OFF , enum_mdl_duration duration_arg @@ -760,6 +782,8 @@ private: */ MDL_lock *m_lock; + PSI_metadata_lock *m_psi; + private: MDL_ticket(const MDL_ticket &); /* not implemented */ MDL_ticket &operator=(const MDL_ticket &); /* not implemented */ diff --git a/sql/sp.cc b/sql/sp.cc index 4cfbdde7228..103f72b3089 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1774,7 +1774,7 @@ bool lock_db_routines(THD *thd, const char *db) sp_type); if (!sph) sph= &sp_handler_procedure; - mdl_request->init(sph->get_mdl_type(), db, sp_name, + MDL_REQUEST_INIT(mdl_request, sph->get_mdl_type(), db, sp_name, MDL_EXCLUSIVE, MDL_TRANSACTION); mdl_requests.push_front(mdl_request); } while (! (nxtres= table->file->ha_index_next_same(table->record[0], keybuf, key_len))); @@ -2291,7 +2291,7 @@ bool sp_add_used_routine(Query_tables_list *prelocking_ctx, Query_arena *arena, (Sroutine_hash_entry *)arena->alloc(sizeof(Sroutine_hash_entry)); if (unlikely(!rn)) // OOM. Error will be reported using fatal_error(). return FALSE; - rn->mdl_request.init(key, MDL_SHARED, MDL_TRANSACTION); + MDL_REQUEST_INIT_BY_KEY(&rn->mdl_request, key, MDL_SHARED, MDL_TRANSACTION); if (my_hash_insert(&prelocking_ctx->sroutines, (uchar *)rn)) return FALSE; prelocking_ctx->sroutines_list.link_in_list(rn, &rn->next); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index da02b0e680a..fb99ad11552 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -4977,8 +4977,8 @@ sp_add_to_query_tables(THD *thd, LEX *lex, table->lock_type= locktype; table->select_lex= lex->current_select; table->cacheable_table= 1; - table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, - mdl_type, MDL_TRANSACTION); + MDL_REQUEST_INIT(&table->mdl_request, MDL_key::TABLE, table->db.str, + table->table_name.str, mdl_type, MDL_TRANSACTION); lex->add_to_query_tables(table); return table; diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index e5347f2fda4..3982f453bd2 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -122,9 +122,9 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, Let us try to open at least a .FRM for this table. */ - table_list->mdl_request.init(MDL_key::TABLE, - table_list->db.str, table_list->table_name.str, - MDL_EXCLUSIVE, MDL_TRANSACTION); + MDL_REQUEST_INIT(&table_list->mdl_request, MDL_key::TABLE, + table_list->db.str, table_list->table_name.str, + MDL_EXCLUSIVE, MDL_TRANSACTION); if (lock_table_names(thd, table_list, table_list->next_global, thd->variables.lock_wait_timeout, 0)) @@ -547,8 +547,9 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, close_thread_tables(thd); table->table= NULL; thd->mdl_context.release_transactional_locks(); - table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, - MDL_SHARED_NO_READ_WRITE, MDL_TRANSACTION); + MDL_REQUEST_INIT(&table->mdl_request, MDL_key::TABLE, table->db.str, + table->table_name.str, MDL_SHARED_NO_READ_WRITE, + MDL_TRANSACTION); } #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -822,8 +823,9 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, close_thread_tables(thd); table->table= NULL; thd->mdl_context.release_transactional_locks(); - table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, - MDL_SHARED_NO_READ_WRITE, MDL_TRANSACTION); + MDL_REQUEST_INIT(&table->mdl_request, MDL_key::TABLE, table->db.str, + table->table_name.str, MDL_SHARED_NO_READ_WRITE, + MDL_TRANSACTION); table->mdl_request.set_type(MDL_SHARED_READ); table->lock_type= TL_READ; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6a59202609d..7fbd4fb3af1 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -437,7 +437,8 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, MDL_request *mdl_request= new (thd->mem_root) MDL_request; if (mdl_request == NULL) DBUG_RETURN(true); - mdl_request->init(&table->mdl_request.key, MDL_EXCLUSIVE, MDL_STATEMENT); + MDL_REQUEST_INIT_BY_KEY(mdl_request, &table->mdl_request.key, + MDL_EXCLUSIVE, MDL_STATEMENT); mdl_requests.push_front(mdl_request); } @@ -1577,10 +1578,9 @@ open_table_get_mdl_lock(THD *thd, Open_table_context *ot_ctx, DBUG_ASSERT(!(flags & MYSQL_OPEN_FORCE_SHARED_MDL) || !(flags & MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL)); - mdl_request_shared.init(&mdl_request->key, - (flags & MYSQL_OPEN_FORCE_SHARED_MDL) ? - MDL_SHARED : MDL_SHARED_HIGH_PRIO, - MDL_TRANSACTION); + MDL_REQUEST_INIT_BY_KEY(&mdl_request_shared, &mdl_request->key, + flags & MYSQL_OPEN_FORCE_SHARED_MDL ? MDL_SHARED : MDL_SHARED_HIGH_PRIO, + MDL_TRANSACTION); mdl_request= &mdl_request_shared; } @@ -2151,8 +2151,8 @@ retry_share: DBUG_RETURN(TRUE); } - protection_request.init(MDL_key::BACKUP, "", "", mdl_type, - MDL_STATEMENT); + MDL_REQUEST_INIT(&protection_request, MDL_key::BACKUP, "", "", mdl_type, + MDL_STATEMENT); /* Install error handler which if possible will convert deadlock error @@ -4044,9 +4044,8 @@ lock_table_names(THD *thd, const DDL_options_st &options, MDL_request *schema_request= new (thd->mem_root) MDL_request; if (schema_request == NULL) DBUG_RETURN(TRUE); - schema_request->init(MDL_key::SCHEMA, table->db.str, "", - MDL_INTENTION_EXCLUSIVE, - MDL_TRANSACTION); + MDL_REQUEST_INIT(schema_request, MDL_key::SCHEMA, table->db.str, "", + MDL_INTENTION_EXCLUSIVE, MDL_TRANSACTION); mdl_requests.push_front(schema_request); } @@ -4068,7 +4067,8 @@ lock_table_names(THD *thd, const DDL_options_st &options, if (thd->has_read_only_protection()) DBUG_RETURN(true); - global_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_DDL, MDL_STATEMENT); + MDL_REQUEST_INIT(&global_request, MDL_key::BACKUP, "", "", MDL_BACKUP_DDL, + MDL_STATEMENT); mdl_savepoint= thd->mdl_context.mdl_savepoint(); while (!thd->mdl_context.acquire_locks(&mdl_requests, lock_wait_timeout) && diff --git a/sql/sql_db.cc b/sql/sql_db.cc index b4d96b83dbe..2698b29d787 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1148,9 +1148,9 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp, (char*) table_list->table_name.str); table_list->alias= table_list->table_name; // If lower_case_table_names=2 - table_list->mdl_request.init(MDL_key::TABLE, table_list->db.str, - table_list->table_name.str, MDL_EXCLUSIVE, - MDL_TRANSACTION); + MDL_REQUEST_INIT(&table_list->mdl_request, MDL_key::TABLE, + table_list->db.str, table_list->table_name.str, + MDL_EXCLUSIVE, MDL_TRANSACTION); /* Link into list */ (*tot_list_next_local)= table_list; (*tot_list_next_global)= table_list; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 6292631ea7d..1427d3a17b6 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -333,8 +333,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) right from the start as open_tables() can't handle properly back-off for such locks. */ - tables->mdl_request.init(MDL_key::TABLE, tables->db.str, tables->table_name.str, - MDL_SHARED_READ, MDL_TRANSACTION); + MDL_REQUEST_INIT(&tables->mdl_request, MDL_key::TABLE, tables->db.str, + tables->table_name.str, MDL_SHARED_READ, MDL_TRANSACTION); mdl_savepoint= thd->mdl_context.mdl_savepoint(); /* for now HANDLER can be used only for real TABLES */ diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 8b1b27c67bf..71c09159f1c 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -554,8 +554,8 @@ bool open_and_lock_for_insert_delayed(THD *thd, TABLE_LIST *table_list) if (thd->has_read_only_protection()) DBUG_RETURN(TRUE); - protection_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_DML, - MDL_STATEMENT); + MDL_REQUEST_INIT(&protection_request, MDL_key::BACKUP, "", "", + MDL_BACKUP_DML, MDL_STATEMENT); if (thd->mdl_context.acquire_lock(&protection_request, thd->variables.lock_wait_timeout)) @@ -2422,8 +2422,8 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request, We need the tickets so that they can be cloned in handle_delayed_insert */ - di->grl_protection.init(MDL_key::BACKUP, "", "", - MDL_BACKUP_DML, MDL_STATEMENT); + MDL_REQUEST_INIT(&di->grl_protection, MDL_key::BACKUP, "", "", + MDL_BACKUP_DML, MDL_STATEMENT); di->grl_protection.ticket= grl_protection_request->ticket; init_mdl_requests(&di->table_list); di->table_list.mdl_request.ticket= table_list->mdl_request.ticket; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 055f2bc736d..03116a03d22 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -8221,9 +8221,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, // Pure table aliases do not need to be locked: if (ptr->db.str && !(table_options & TL_OPTION_ALIAS)) { - ptr->mdl_request.init(MDL_key::TABLE, ptr->db.str, ptr->table_name.str, - mdl_type, - MDL_TRANSACTION); + MDL_REQUEST_INIT(&ptr->mdl_request, MDL_key::TABLE, ptr->db.str, + ptr->table_name.str, mdl_type, MDL_TRANSACTION); } DBUG_RETURN(ptr); } diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc index 8b2f49a5910..a5676b8989a 100644 --- a/sql/sql_sequence.cc +++ b/sql/sql_sequence.cc @@ -452,10 +452,9 @@ int SEQUENCE::read_initial_values(TABLE *table) where we don't have a mdl lock on the table */ - mdl_request.init(MDL_key::TABLE, - table->s->db.str, - table->s->table_name.str, - MDL_SHARED_READ, MDL_EXPLICIT); + MDL_REQUEST_INIT(&mdl_request, MDL_key::TABLE, table->s->db.str, + table->s->table_name.str, MDL_SHARED_READ, + MDL_EXPLICIT); mdl_requests.push_front(&mdl_request); if (thd->mdl_context.acquire_locks(&mdl_requests, thd->variables.lock_wait_timeout)) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index cc08dadf2b8..90b3efe3655 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -4769,8 +4769,9 @@ try_acquire_high_prio_shared_mdl_lock(THD *thd, TABLE_LIST *table, bool can_deadlock) { bool error; - table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, - MDL_SHARED_HIGH_PRIO, MDL_TRANSACTION); + MDL_REQUEST_INIT(&table->mdl_request, MDL_key::TABLE, table->db.str, + table->table_name.str, MDL_SHARED_HIGH_PRIO, + MDL_TRANSACTION); if (can_deadlock) { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 4239fcc8de7..32aa1e50b43 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9205,8 +9205,8 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table, ref_table= tbuf; } - mdl_request.init(MDL_key::TABLE, ref_db, ref_table, MDL_SHARED_NO_WRITE, - MDL_TRANSACTION); + MDL_REQUEST_INIT(&mdl_request, MDL_key::TABLE, ref_db, ref_table, + MDL_SHARED_NO_WRITE, MDL_TRANSACTION); if (thd->mdl_context.acquire_lock(&mdl_request, thd->variables.lock_wait_timeout)) DBUG_RETURN(true); @@ -9631,9 +9631,9 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, MDL_request_list mdl_requests; MDL_request target_db_mdl_request; - target_mdl_request.init(MDL_key::TABLE, - alter_ctx.new_db.str, alter_ctx.new_name.str, - MDL_EXCLUSIVE, MDL_TRANSACTION); + MDL_REQUEST_INIT(&target_mdl_request, MDL_key::TABLE, + alter_ctx.new_db.str, alter_ctx.new_name.str, + MDL_EXCLUSIVE, MDL_TRANSACTION); mdl_requests.push_front(&target_mdl_request); /* @@ -9643,9 +9643,9 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, */ if (alter_ctx.is_database_changed()) { - target_db_mdl_request.init(MDL_key::SCHEMA, alter_ctx.new_db.str, "", - MDL_INTENTION_EXCLUSIVE, - MDL_TRANSACTION); + MDL_REQUEST_INIT(&target_db_mdl_request, MDL_key::SCHEMA, + alter_ctx.new_db.str, "", MDL_INTENTION_EXCLUSIVE, + MDL_TRANSACTION); mdl_requests.push_front(&target_db_mdl_request); } diff --git a/sql/table.cc b/sql/table.cc index 7c982584d52..cfd2358cd20 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -8222,11 +8222,10 @@ size_t max_row_length(TABLE *table, MY_BITMAP const *cols, const uchar *data) void init_mdl_requests(TABLE_LIST *table_list) { for ( ; table_list ; table_list= table_list->next_global) - table_list->mdl_request.init(MDL_key::TABLE, - table_list->db.str, table_list->table_name.str, - table_list->lock_type >= TL_WRITE_ALLOW_WRITE ? - MDL_SHARED_WRITE : MDL_SHARED_READ, - MDL_TRANSACTION); + MDL_REQUEST_INIT(&table_list->mdl_request, MDL_key::TABLE, + table_list->db.str, table_list->table_name.str, + table_list->lock_type >= TL_WRITE_ALLOW_WRITE + ? MDL_SHARED_WRITE : MDL_SHARED_READ, MDL_TRANSACTION); } diff --git a/sql/table.h b/sql/table.h index 0a91df9c04c..ad3336b9bd9 100644 --- a/sql/table.h +++ b/sql/table.h @@ -2012,8 +2012,8 @@ struct TABLE_LIST alias= (alias_arg ? *alias_arg : *table_name_arg); lock_type= lock_type_arg; updating= lock_type >= TL_WRITE_ALLOW_WRITE; - mdl_request.init(MDL_key::TABLE, db.str, table_name.str, mdl_type, - MDL_TRANSACTION); + MDL_REQUEST_INIT(&mdl_request, MDL_key::TABLE, db.str, table_name.str, + mdl_type, MDL_TRANSACTION); } TABLE_LIST(TABLE *table_arg, thr_lock_type lock_type) diff --git a/sql/xa.cc b/sql/xa.cc index efcb3ea5c00..020af8cb784 100644 --- a/sql/xa.cc +++ b/sql/xa.cc @@ -592,7 +592,7 @@ bool trans_xa_commit(THD *thd) We allow FLUSHer to COMMIT; we assume FLUSHer knows what it does. */ - mdl_request.init(MDL_key::BACKUP, "", "", MDL_BACKUP_COMMIT, + MDL_REQUEST_INIT(&mdl_request, MDL_key::BACKUP, "", "", MDL_BACKUP_COMMIT, MDL_TRANSACTION); if (thd->mdl_context.acquire_lock(&mdl_request, diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 710edb59764..0747a571504 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -844,7 +844,7 @@ is_unaccessible: mutex_exit(&dict_sys.mutex); { MDL_request request; - request.init(MDL_key::TABLE, db_buf, tbl_buf, MDL_SHARED, MDL_EXPLICIT); + MDL_REQUEST_INIT(&request,MDL_key::TABLE, db_buf, tbl_buf, MDL_SHARED, MDL_EXPLICIT); if (trylock ? mdl_context->try_acquire_lock(&request) : mdl_context->acquire_lock(&request, diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index 1a472e2c12b..19023a00da3 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -997,7 +997,7 @@ long long spider_copy_tables_body( #if MYSQL_VERSION_ID < 50500 if (open_and_lock_tables(thd, table_list)) #else - table_list->mdl_request.init( + MDL_REQUEST_INIT(&table_list->mdl_request, MDL_key::TABLE, SPIDER_TABLE_LIST_db_str(table_list), SPIDER_TABLE_LIST_table_name_str(table_list), diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc index 7bf0b91a4a7..406d189fcc9 100644 --- a/storage/spider/spd_direct_sql.cc +++ b/storage/spider/spd_direct_sql.cc @@ -1751,7 +1751,7 @@ long long spider_direct_sql_body( SPIDER_TABLE_LIST_table_name_length(&table_list), SPIDER_TABLE_LIST_table_name_str(&table_list), TL_WRITE); #endif - tables->mdl_request.init(MDL_key::TABLE, + MDL_REQUEST_INIT(&tables->mdl_request, MDL_key::TABLE, SPIDER_TABLE_LIST_db_str(&table_list), SPIDER_TABLE_LIST_table_name_str(&table_list), MDL_SHARED_WRITE, MDL_TRANSACTION);