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