MySQL  8.0.18
Source Code Documentation
sql_backup_lock.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
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_cmd.h" // Sql_cmd
30 
31 class 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  virtual bool execute(THD *thd);
48 
50  return SQLCOM_LOCK_INSTANCE;
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  virtual bool execute(THD *thd);
69 
72  }
73 };
74 
75 /**
76  Acquire exclusive Backup Lock.
77 
78  @param[in] thd Current thread context
79  @param[in] lock_wait_timeout How many seconds to wait before timeout.
80  @param[in] for_trx true if MDL duration is MDL_TRANSACTION
81  false if MDL duration is MDL_EXPLICIT
82 
83  @return Operation status.
84  @retval false Success
85  @retval true Failure
86 */
87 
88 bool acquire_exclusive_backup_lock(THD *thd, unsigned long lock_wait_timeout,
89  bool for_trx);
90 
91 /**
92  Acquire shared Backup Lock.
93 
94  @param[in] thd Current thread context
95  @param[in] lock_wait_timeout How many seconds to wait before timeout.
96  @param[in] for_trx true if MDL duration is MDL_TRANSACTION
97  false if MDL duration is MDL_EXPLICIT
98 
99  @return Operation status.
100  @retval false Success
101  @retval true Failure
102 */
103 
104 bool acquire_shared_backup_lock(THD *thd, unsigned long lock_wait_timeout,
105  bool for_trx = true);
106 
107 /**
108  Release Backup Lock if it was acquired.
109 
110  @param[in] thd Current thread context
111 */
112 
113 void release_backup_lock(THD *thd);
114 
115 /**
116  There are three possible results while checking if the instance is locked for
117  backup.
118 */
119 
121  NOT_LOCKED = 0,
122  LOCKED = 1,
123  OOM = 2
124 };
125 
126 /**
127  Check if this server instance is locked with Backup Lock. In fact, it checks
128  if any thread owns BACKUP_LOCK.
129 
130  @param[in] thd Current thread context
131 
132  @retval NOT_LOCKED Backup Lock is not acquired by any thread.
133  @retval LOCKED Backup Lock is acquired by a thread.
134  @retval OOM Error occurred (OOM) when checking lock ownership.
135 */
136 
138 
139 #endif /* SQL_LOCK_INCLUDED */
Representation of an SQL command.
Definition: sql_cmd.h:63
virtual bool execute(THD *thd)
Execute UNLOCK INSTANCE statement once.
Definition: sql_backup_lock.cc:71
enum_sql_command
Definition: my_sqlcommand.h:45
void release_backup_lock(THD *thd)
Release Backup Lock if it was acquired.
Definition: sql_backup_lock.cc:117
virtual bool execute(THD *thd)
Execute LOCK INSTANCE statement once.
Definition: sql_backup_lock.cc:58
Representation of an SQL command.
Definition: my_sqlcommand.h:201
bool acquire_exclusive_backup_lock(THD *thd, unsigned long lock_wait_timeout, bool for_trx)
Acquire exclusive Backup Lock.
Definition: sql_backup_lock.cc:135
virtual enum_sql_command sql_command_code() const
Return the command code for this statement.
Definition: sql_backup_lock.h:70
bool acquire_shared_backup_lock(THD *thd, unsigned long lock_wait_timeout, bool for_trx=true)
Acquire shared Backup Lock.
Definition: sql_backup_lock.cc:141
Sql_cmd_lock_instance represents statement LOCK INSTANCE FOR BACKUP.
Definition: sql_backup_lock.h:37
virtual enum_sql_command sql_command_code() const
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
Is_instance_backup_locked_result is_instance_backup_locked(THD *thd)
Check if this server instance is locked with Backup Lock.
Definition: sql_backup_lock.cc:148
Definition: my_sqlcommand.h:200
Is_instance_backup_locked_result
There are three possible results while checking if the instance is locked for backup.
Definition: sql_backup_lock.h:120
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778