MySQL  8.0.17
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 
81  @return Operation status.
82  @retval false Success
83  @retval true Failure
84 */
85 
86 bool acquire_exclusive_backup_lock(THD *thd, unsigned long lock_wait_timeout);
87 
88 /**
89  Acquire shared Backup Lock.
90 
91  @param[in] thd Current thread context
92  @param[in] lock_wait_timeout How many seconds to wait before timeout.
93  @param[in] for_trx true if MDL duration is MDL_TRANSACTION
94  false if MDL duration is MDL_EXPLICIT
95 
96  @return Operation status.
97  @retval false Success
98  @retval true Failure
99 */
100 
101 bool acquire_shared_backup_lock(THD *thd, unsigned long lock_wait_timeout,
102  bool for_trx = true);
103 
104 /**
105  Release Backup Lock if it was acquired.
106 
107  @param[in] thd Current thread context
108 */
109 
110 void release_backup_lock(THD *thd);
111 
112 /**
113  There are three possible results while checking if the instance is locked for
114  backup.
115 */
116 
118  NOT_LOCKED = 0,
119  LOCKED = 1,
120  OOM = 2
121 };
122 
123 /**
124  Check if this server instance is locked with Backup Lock. In fact, it checks
125  if any thread owns BACKUP_LOCK.
126 
127  @param[in] thd Current thread context
128 
129  @retval NOT_LOCKED Backup Lock is not acquired by any thread.
130  @retval LOCKED Backup Lock is acquired by a thread.
131  @retval OOM Error occurred (OOM) when checking lock ownership.
132 */
133 
135 
136 #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:69
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:115
virtual bool execute(THD *thd)
Execute LOCK INSTANCE statement once.
Definition: sql_backup_lock.cc:58
Representation of an SQL command.
bool acquire_exclusive_backup_lock(THD *thd, unsigned long lock_wait_timeout)
Acquire exclusive Backup Lock.
Definition: sql_backup_lock.cc:133
Definition: my_sqlcommand.h:201
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:138
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:145
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:117
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777