| 4468 | */ |
| 4469 | |
| 4470 | bool |
| 4471 | lock_table_names(THD *thd, const DDL_options_st &options, |
| 4472 | TABLE_LIST *tables_start, TABLE_LIST *tables_end, |
| 4473 | ulong lock_wait_timeout, uint flags) |
| 4474 | { |
| 4475 | MDL_request_list mdl_requests; |
| 4476 | TABLE_LIST *table; |
| 4477 | MDL_request global_request; |
| 4478 | MDL_savepoint mdl_savepoint; |
| 4479 | DBUG_ENTER("lock_table_names"); |
| 4480 | |
| 4481 | DBUG_ASSERT(!thd->locked_tables_mode); |
| 4482 | |
| 4483 | for (table= tables_start; table && table != tables_end; |
| 4484 | table= table->next_global) |
| 4485 | { |
| 4486 | DBUG_PRINT("info", ("mdl_request.type: %d open_type: %d", |
| 4487 | table->mdl_request.type, table->open_type)); |
| 4488 | if (table->mdl_request.type < MDL_SHARED_UPGRADABLE || |
| 4489 | table->mdl_request.type == MDL_SHARED_READ_ONLY || |
| 4490 | table->open_type == OT_TEMPORARY_ONLY || |
| 4491 | (table->open_type == OT_TEMPORARY_OR_BASE && is_temporary_table(table))) |
| 4492 | continue; |
| 4493 | |
| 4494 | /* Write lock on normal tables is not allowed in a read only transaction. */ |
| 4495 | if (thd->tx_read_only) |
| 4496 | { |
| 4497 | my_error(ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION, MYF(0)); |
| 4498 | DBUG_RETURN(true); |
| 4499 | } |
| 4500 | |
| 4501 | /* Scoped locks: Take intention exclusive locks on all involved schemas. */ |
| 4502 | if (!(flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK)) |
| 4503 | { |
| 4504 | MDL_request *schema_request= new (thd->mem_root) MDL_request; |
| 4505 | if (schema_request == NULL) |
| 4506 | DBUG_RETURN(TRUE); |
| 4507 | MDL_REQUEST_INIT(schema_request, MDL_key::SCHEMA, table->db.str, "", |
| 4508 | MDL_INTENTION_EXCLUSIVE, MDL_TRANSACTION); |
| 4509 | mdl_requests.push_front(schema_request); |
| 4510 | } |
| 4511 | |
| 4512 | mdl_requests.push_front(&table->mdl_request); |
| 4513 | } |
| 4514 | |
| 4515 | if (mdl_requests.is_empty()) |
| 4516 | DBUG_RETURN(FALSE); |
| 4517 | |
| 4518 | if (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) |
| 4519 | { |
| 4520 | DBUG_RETURN(thd->mdl_context.acquire_locks(&mdl_requests, |
| 4521 | lock_wait_timeout) || |
| 4522 | upgrade_lock_if_not_exists(thd, options, tables_start, |
| 4523 | lock_wait_timeout)); |
| 4524 | } |
| 4525 | |
| 4526 | /* Protect this statement against concurrent BACKUP STAGE or FTWRL. */ |
| 4527 | if (thd->has_read_only_protection()) |
no test coverage detected