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