MySQL 8.0.39
Source Code Documentation
sql_backup_lock.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 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 SQL_LOCK_INCLUDED
25#define SQL_LOCK_INCLUDED
26
27#include <sys/types.h>
28
29#include "my_sqlcommand.h" // SQLCOM_LOCK_INSTANCE, SQLCOM_UNLOCK_INSTANCE
30#include "sql/sql_cmd.h" // Sql_cmd
31
32class THD;
33
34/**
35 Sql_cmd_lock_instance represents statement LOCK INSTANCE FOR BACKUP.
36*/
37
39 public:
40 /**
41 Execute LOCK INSTANCE statement once.
42
43 @param thd Thread handler
44
45 @returns false on success, true on error
46 */
47
48 bool execute(THD *thd) override;
49
52 }
53};
54
55/**
56 Sql_cmd_unlock_instance represents statement UNLOCK INSTANCE.
57*/
58
60 public:
61 /**
62 Execute UNLOCK INSTANCE statement once.
63
64 @param thd Thread handler
65
66 @returns false on success, true on error
67 */
68
69 bool execute(THD *thd) override;
70
73 }
74};
75
76/**
77 MDL_key::BACKUP_LOCK RAII.
78 */
80 public:
81 /**
82 There are three possible results while checking if the instance is locked
83 for backup.
84 */
85 enum class Lock_result { not_locked = 0, locked = 1, oom = 2 };
86
91 delete;
93
95
96 operator Lock_result() const;
97
98 private:
99 /**
100 Try to acquire shared backup lock.
101
102 @param[in] thd Current thread context
103 @param[in] for_trx true if MDL duration is MDL_TRANSACTION
104 false if MDL duration is MDL_EXPLICIT
105
106 @return Operation status.
107 @retval Shared_backup_lock_guard::Lock_result::locked Locked shared
108 BACKUP lock.
109 @retval Shared_backup_lock_guard::Lock_result::not_locked Could not lock
110 shared BACKUP lock. Conflicting lock exists.
111 @retval Shared_backup_lock_guard::Lock_result::oom Error. Could
112 not lock shared BACKUP lock.
113 */
115 THD *thd, bool for_trx);
118};
119
120/**
121 Acquire exclusive Backup Lock.
122
123 @param[in] thd Current thread context
124 @param[in] lock_wait_timeout How many seconds to wait before timeout.
125 @param[in] for_trx true if MDL duration is MDL_TRANSACTION
126 false if MDL duration is MDL_EXPLICIT
127
128 @return Operation status.
129 @retval false Success
130 @retval true Failure
131*/
132
133bool acquire_exclusive_backup_lock(THD *thd, unsigned long lock_wait_timeout,
134 bool for_trx);
135
136/**
137 Acquire shared Backup Lock.
138
139 @param[in] thd Current thread context
140 @param[in] lock_wait_timeout How many seconds to wait before timeout.
141 @param[in] for_trx true if MDL duration is MDL_TRANSACTION
142 false if MDL duration is MDL_EXPLICIT
143
144 @return Operation status.
145 @retval false Success
146 @retval true Failure
147*/
148
149bool acquire_shared_backup_lock(THD *thd, unsigned long lock_wait_timeout,
150 bool for_trx = true);
151
152/**
153 Release Backup Lock if it was acquired.
154
155 @param[in] thd Current thread context
156*/
157
158void release_backup_lock(THD *thd);
159
160#endif /* SQL_LOCK_INCLUDED */
MDL_key::BACKUP_LOCK RAII.
Definition: sql_backup_lock.h:79
Shared_backup_lock_guard::Lock_result try_acquire_shared_backup_lock(THD *thd, bool for_trx)
Try to acquire shared backup lock.
Definition: sql_backup_lock.cc:105
THD * m_thd
Definition: sql_backup_lock.h:117
Shared_backup_lock_guard & operator=(Shared_backup_lock_guard &&o)=default
Shared_backup_lock_guard(const Shared_backup_lock_guard &o)=delete
Shared_backup_lock_guard::Lock_result m_lock_state
Definition: sql_backup_lock.h:116
Shared_backup_lock_guard(THD *thd)
Definition: sql_backup_lock.cc:81
~Shared_backup_lock_guard()
Definition: sql_backup_lock.cc:93
Lock_result
There are three possible results while checking if the instance is locked for backup.
Definition: sql_backup_lock.h:85
Shared_backup_lock_guard & operator=(const Shared_backup_lock_guard &o)=delete
Shared_backup_lock_guard(Shared_backup_lock_guard &&o)=default
Sql_cmd_lock_instance represents statement LOCK INSTANCE FOR BACKUP.
Definition: sql_backup_lock.h:38
bool execute(THD *thd) override
Execute LOCK INSTANCE statement once.
Definition: sql_backup_lock.cc:59
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_backup_lock.h:50
Sql_cmd_unlock_instance represents statement UNLOCK INSTANCE.
Definition: sql_backup_lock.h:59
bool execute(THD *thd) override
Execute UNLOCK INSTANCE statement once.
Definition: sql_backup_lock.cc:72
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_backup_lock.h:71
Representation of an SQL command.
Definition: sql_cmd.h:65
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_LOCK_INSTANCE
Definition: my_sqlcommand.h:201
@ SQLCOM_UNLOCK_INSTANCE
Definition: my_sqlcommand.h:202
bool acquire_shared_backup_lock(THD *thd, unsigned long lock_wait_timeout, bool for_trx=true)
Acquire shared Backup Lock.
bool acquire_exclusive_backup_lock(THD *thd, unsigned long lock_wait_timeout, bool for_trx)
Acquire exclusive Backup Lock.
void release_backup_lock(THD *thd)
Release Backup Lock if it was acquired.
Definition: sql_backup_lock.cc:159
Representation of an SQL command.