MySQL 8.0.31
Source Code Documentation
dd_schema.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef DD_SCHEMA_INCLUDED
24#define DD_SCHEMA_INCLUDED
25
26#include <stddef.h>
27
28#include "sql/mdl.h" // enum_mdl_duration
29
30class MDL_ticket;
31class THD;
32
33struct CHARSET_INFO;
34
35namespace dd {
36
37/**
38 Check if given schema exists.
39
40 @param thd Thread context.
41 @param schema_name Schema to check for.
42 @param [out] exists true if schema exists, else false.
43 @return false if success, true if error.
44*/
45bool schema_exists(THD *thd, const char *schema_name, bool *exists);
46
47/** Create a schema record into dd.schemata. */
48bool create_schema(THD *thd, const char *schema_name,
50 const bool default_encryption);
51
52/**
53 Acquire MDL on schema name.
54 @param thd Thread context.
55 @param schema_name Schema to check for.
56 @param duration Duration type for MDL
57 @param ticket Where to store ticket pointer
58 (default: nullptr, no ticket pointer will be stored)
59 @return false if success, true if error.
60*/
61bool mdl_lock_schema(THD *thd, const char *schema_name,
62 enum_mdl_duration duration, MDL_ticket **ticket = nullptr);
63
64/**
65 RAII based class to acquire and release schema meta data locks.
66
67 When an instance of this class is created, and 'ensure_lock()' is called,
68 it will acquire an IX lock on the submitted schema name, unless we already
69 have one. When the instance goes out of scope or is deleted, the ticket
70 registered will be released.
71
72 @note It is vital that the order of releasing and unlocking the schema
73 is correct. The Schema_MDL_locker must always be declared *before*
74 the corresponding Auto_releaser to make sure that the schema locker
75 is deleted *after* the auto releaser. Otherwise, there will be
76 situations where we have the schema object referenced locally, but
77 without a meta data lock. This may, in turn, violate asserts in the
78 shared cache, and open up for improper usage.
79
80 @todo TODO: Re-design this for a more complete long term solution of
81 this problem. The current solution will mean that e.g. deadlock
82 errors are propagated even when autocommit == 1.
83*/
84
86 private:
87 THD *m_thd; // Thread context.
88 MDL_ticket *m_ticket; // MDL ticket.
89
90 public:
92
93 /**
94 Make sure we have an IX meta data lock on the schema name.
95
96 If the circumstances indicate that we need a meta data lock, and
97 we do not already have one, then an IX meta data lock is acquired.
98
99 @param schema_name The name of the schema.
100
101 @retval true Failed to ensure that the schema name is locked.
102 false It is ensured that we have at least an IX lock on
103 the schema name.
104 */
105
106 bool ensure_locked(const char *schema_name);
107
108 /**
109 Release the MDL ticket, if any, when the instance of this
110 class leaves scope or is deleted.
111 */
112
114};
115
116} // namespace dd
117#endif // DD_SCHEMA_INCLUDED
A granted metadata lock.
Definition: mdl.h:984
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
RAII based class to acquire and release schema meta data locks.
Definition: dd_schema.h:85
Schema_MDL_locker(THD *thd)
Definition: dd_schema.h:91
bool ensure_locked(const char *schema_name)
Make sure we have an IX meta data lock on the schema name.
Definition: dd_schema.cc:125
~Schema_MDL_locker()
Release the MDL ticket, if any, when the instance of this class leaves scope or is deleted.
Definition: dd_schema.cc:129
THD * m_thd
Definition: dd_schema.h:87
MDL_ticket * m_ticket
Definition: dd_schema.h:88
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
enum_mdl_duration
Duration of metadata lock.
Definition: mdl.h:332
static const CHARSET_INFO * charset_info
Definition: mysql.cc:232
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
bool schema_exists(THD *thd, const char *schema_name, bool *exists)
Check if given schema exists.
Definition: dd_schema.cc:46
bool mdl_lock_schema(THD *thd, const char *schema_name, enum_mdl_duration duration, MDL_ticket **ticket)
Acquire MDL on schema name.
Definition: dd_schema.cc:82
bool create_schema(THD *thd, const char *schema_name, const CHARSET_INFO *charset_info, bool default_encryption)
Create a schema record into dd.schemata.
Definition: dd_schema.cc:61
static int exists(node_address *name, node_list const *nodes, u_int with_uid)
Definition: node_list.cc:105
Definition: m_ctype.h:382