1 #ifndef VERS_UTILS_INCLUDED 2 #define VERS_UTILS_INCLUDED 3 4 #include "table.h" 5 #include "sql_class.h" 6 #include "vers_string.h" 7 8 class MDL_auto_lock 9 { 10 THD *thd; 11 TABLE_LIST &table; 12 bool error; 13 14 public: MDL_auto_lock(THD * _thd,TABLE_LIST & _table)15 MDL_auto_lock(THD *_thd, TABLE_LIST &_table) : 16 thd(_thd), table(_table) 17 { 18 DBUG_ASSERT(thd); 19 MDL_request protection_request; 20 if (thd->global_read_lock.can_acquire_protection()) 21 { 22 error= true; 23 return; 24 } 25 protection_request.init(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE, 26 MDL_EXPLICIT); 27 error= thd->mdl_context.acquire_lock(&protection_request, thd->variables.lock_wait_timeout); 28 if (error) 29 return; 30 31 table.mdl_request.init(MDL_key::TABLE, table.db.str, table.table_name.str, MDL_EXCLUSIVE, MDL_EXPLICIT); 32 error= thd->mdl_context.acquire_lock(&table.mdl_request, thd->variables.lock_wait_timeout); 33 thd->mdl_context.release_lock(protection_request.ticket); 34 } ~MDL_auto_lock()35 ~MDL_auto_lock() 36 { 37 if (!error) 38 { 39 DBUG_ASSERT(table.mdl_request.ticket); 40 thd->mdl_context.release_lock(table.mdl_request.ticket); 41 table.mdl_request.ticket= NULL; 42 } 43 } acquire_error()44 bool acquire_error() const { return error; } 45 }; 46 47 #endif // VERS_UTILS_INCLUDED 48