File: dd_schema.h

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (118 lines) | stat: -rw-r--r-- 4,278 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright (c) 2015, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef DD_SCHEMA_INCLUDED
#define DD_SCHEMA_INCLUDED

#include <stddef.h>

#include "sql/mdl.h"  // enum_mdl_duration

class MDL_ticket;
class THD;

struct CHARSET_INFO;

namespace dd {

/**
  Check if given schema exists.

  @param         thd         Thread context.
  @param         schema_name Schema to check for.
  @param  [out]  exists      true if schema exists, else false.
  @return        false if success, true if error.
*/
bool schema_exists(THD *thd, const char *schema_name, bool *exists);

/** Create a schema record into dd.schemata. */
bool create_schema(THD *thd, const char *schema_name,
                   const CHARSET_INFO *charset_info,
                   const bool default_encryption);

/**
  Acquire MDL on schema name.
  @param thd         Thread context.
  @param schema_name Schema to check for.
  @param duration    Duration type for MDL
  @param ticket      Where to store ticket pointer
  (default: nullptr, no ticket pointer will be stored)
  @return        false if success, true if error.
*/
bool mdl_lock_schema(THD *thd, const char *schema_name,
                     enum_mdl_duration duration, MDL_ticket **ticket = nullptr);

/**
  RAII based class to acquire and release schema meta data locks.

  When an instance of this class is created, and 'ensure_lock()' is called,
  it will acquire an IX lock on the submitted schema name, unless we already
  have one. When the instance goes out of scope or is deleted, the ticket
  registered will be released.

  @note It is vital that the order of releasing and unlocking the schema
        is correct. The Schema_MDL_locker must always be declared *before*
        the corresponding Auto_releaser to make sure that the schema locker
        is deleted *after* the auto releaser. Otherwise, there will be
        situations where we have the schema object referenced locally, but
        without a meta data lock. This may, in turn, violate asserts in the
        shared cache, and open up for improper usage.

  @todo TODO: Re-design this for a more complete long term solution of
        this problem. The current solution will mean that e.g. deadlock
        errors are propagated even when autocommit == 1.
*/

class Schema_MDL_locker {
 private:
  THD *m_thd;            // Thread context.
  MDL_ticket *m_ticket;  // MDL ticket.

 public:
  Schema_MDL_locker(THD *thd) : m_thd(thd), m_ticket(nullptr) {}

  /**
    Make sure we have an IX meta data lock on the schema name.

    If the circumstances indicate that we need a meta data lock, and
    we do not already have one, then an IX meta data lock is acquired.

    @param  schema_name   The name of the schema.

    @retval true    Failed to ensure that the schema name is locked.
            false   It is ensured that we have at least an IX lock on
                    the schema name.
  */

  bool ensure_locked(const char *schema_name);

  /**
    Release the MDL ticket, if any, when the instance of this
    class leaves scope or is deleted.
  */

  ~Schema_MDL_locker();
};

}  // namespace dd
#endif  // DD_SCHEMA_INCLUDED