MySQL 8.0.32
Source Code Documentation
sql_backup_lock.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2022, 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 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
88bool 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
104bool 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
113void 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 */
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:64
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
enum_sql_command
Definition: my_sqlcommand.h:45
@ SQLCOM_LOCK_INSTANCE
Definition: my_sqlcommand.h:200
@ SQLCOM_UNLOCK_INSTANCE
Definition: my_sqlcommand.h:201
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
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:117
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
Representation of an SQL command.