18 #if defined(__IBMC__) || defined(__IBMCPP__)
23 #pragma namemangling(v5)
27 #include "sql_plist.h"
30 #include <mysql_com.h>
49 #define ENTER_COND(C, M, S, O) enter_cond(C, M, S, O, __func__, __FILE__, __LINE__)
56 #define EXIT_COND(S) exit_cond(S, __func__, __FILE__, __LINE__)
85 const char *src_function,
const char *src_file,
99 const char *src_function,
const char *src_file,
116 bool needs_thr_lock_abort) = 0;
134 MDL_INTENTION_EXCLUSIVE= 0,
174 MDL_SHARED_HIGH_PRIO,
204 MDL_SHARED_UPGRADABLE,
230 MDL_SHARED_NO_READ_WRITE,
245 enum enum_mdl_duration {
266 #define MAX_MDLKEY_LENGTH (1 + NAME_LEN + 1 + NAME_LEN + 1)
281 #ifdef HAVE_PSI_INTERFACE
282 static void init_psi_keys();
311 const uchar *ptr()
const {
return (uchar*) m_ptr; }
312 uint length()
const {
return m_length; }
314 const char *db_name()
const {
return m_ptr + 1; }
315 uint db_name_length()
const {
return m_db_name_length; }
317 const char *name()
const {
return m_ptr + m_db_name_length + 2; }
318 uint name_length()
const {
return m_length - m_db_name_length - 3; }
335 const char *db,
const char *name)
337 m_ptr[0]= (char) mdl_namespace;
343 DBUG_ASSERT(strlen(db) <= NAME_LEN && strlen(name) <= NAME_LEN);
344 m_db_name_length=
static_cast<uint16
>(strmake(m_ptr + 1, db, NAME_LEN) -
346 m_length=
static_cast<uint16
>(strmake(m_ptr + m_db_name_length + 2, name,
347 NAME_LEN) - m_ptr + 1);
351 memcpy(m_ptr, rhs->m_ptr, rhs->m_length);
352 m_length= rhs->m_length;
353 m_db_name_length= rhs->m_db_name_length;
355 bool is_equal(
const MDL_key *rhs)
const
357 return (m_length == rhs->m_length &&
358 memcmp(m_ptr, rhs->m_ptr, m_length) == 0);
371 return memcmp(m_ptr, rhs->m_ptr, min(m_length, rhs->m_length));
379 const char *db_arg,
const char *name_arg)
391 return & m_namespace_to_wait_state_name[(int)mdl_namespace()];
396 uint16 m_db_name_length;
397 char m_ptr[MAX_MDLKEY_LENGTH];
398 static PSI_stage_info m_namespace_to_wait_state_name[NAMESPACE_END];
441 static void *
operator new(
size_t size,
MEM_ROOT *mem_root)
throw ()
442 {
return alloc_root(mem_root,
size); }
443 static void operator delete(
void *ptr,
MEM_ROOT *mem_root) {}
446 const char *db_arg,
const char *name_arg,
447 enum_mdl_type mdl_type_arg,
448 enum_mdl_duration mdl_duration_arg);
449 void init(
const MDL_key *key_arg, enum_mdl_type mdl_type_arg,
450 enum_mdl_duration mdl_duration_arg);
454 DBUG_ASSERT(
ticket == NULL);
489 typedef void (*mdl_cached_object_release_hook)(
void *);
534 enum enum_deadlock_weight
536 DEADLOCK_WEIGHT_DML= 0,
537 DEADLOCK_WEIGHT_DDL= 100
540 virtual uint get_deadlock_weight()
const = 0;
583 bool is_upgradable_or_exclusive()
const
585 return m_type == MDL_SHARED_UPGRADABLE ||
586 m_type == MDL_SHARED_NO_WRITE ||
587 m_type == MDL_SHARED_NO_READ_WRITE ||
588 m_type == MDL_EXCLUSIVE;
590 enum_mdl_type get_type()
const {
return m_type; }
591 MDL_lock *get_lock()
const {
return m_lock; }
596 bool is_incompatible_when_granted(enum_mdl_type
type)
const;
597 bool is_incompatible_when_waiting(enum_mdl_type
type)
const;
607 , enum_mdl_duration duration_arg
612 m_duration(duration_arg),
620 , enum_mdl_duration duration_arg
626 enum enum_mdl_type m_type;
632 enum_mdl_duration m_duration;
664 : m_stmt_ticket(stmt_ticket), m_trans_ticket(trans_ticket)
693 enum enum_wait_status { EMPTY = 0, GRANTED, VICTIM, TIMEOUT, KILLED };
712 enum_wait_status m_wait_status;
718 &MDL_request::prev_in_list>,
733 &MDL_ticket::prev_in_context> >
742 bool acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout);
743 bool acquire_locks(MDL_request_list *requests, ulong lock_wait_timeout);
745 enum_mdl_type new_type,
746 ulong lock_wait_timeout);
754 const char *db,
const char *
name,
755 enum_mdl_type mdl_type);
759 inline bool has_locks()
const
761 return !(m_tickets[MDL_STATEMENT].is_empty() &&
762 m_tickets[MDL_TRANSACTION].is_empty() &&
763 m_tickets[MDL_EXPLICIT].is_empty());
769 m_tickets[MDL_TRANSACTION].front());
776 void release_statement_locks();
784 {
return m_waiting_for->get_deadlock_weight(); }
795 void set_needs_thr_lock_abort(
bool needs_thr_lock_abort)
805 m_needs_thr_lock_abort= needs_thr_lock_abort;
807 bool get_needs_thr_lock_abort()
const
809 return m_needs_thr_lock_abort;
883 bool m_needs_thr_lock_abort;
902 THD *get_thd()
const {
return m_owner->
get_thd(); }
904 enum_mdl_duration *duration);
905 void release_locks_stored_before(enum_mdl_duration duration,
MDL_ticket *sentinel);
907 bool try_acquire_lock_impl(MDL_request *mdl_request,
919 m_waiting_for= waiting_for_arg;
930 void lock_deadlock_victim()
934 void unlock_deadlock_victim()
957 extern ulong mdl_locks_cache_size;
958 static const ulong MDL_LOCKS_CACHE_SIZE_DEFAULT = 1024;
965 extern ulong mdl_locks_hash_partitions;
966 static const ulong MDL_LOCKS_HASH_PARTITIONS_DEFAULT = 8;
973 extern "C" ulong max_write_lock_count;