MySQL  8.0.16
Source Code Documentation
dd_kill_immunizer.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2017, 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 DD_KILL_IMMUNIZER_INCLUDED
24 #define DD_KILL_IMMUNIZER_INCLUDED
25 
26 #include "mutex_lock.h" // MUTEX_LOCK
27 #include "sql/sql_class.h" // THD
28 
29 namespace dd {
30 
31 /**
32  RAII class for immunizing the THD from kill operations.
33 
34  Interruptions to operations on new Data Dictionary tables due to KILL QUERY,
35  KILL CONNECTION or statement execution timeout would leave DD in inconsistent
36  state. So the operations on the New Data Dictionary tables are made immune to
37  these operations using DD_kill_immunizer.
38 
39  Note:
40  DD operations are made immune to KILL operations till WL#7743 and WL#7016
41  are implemented. So as part of these WL's DD_kill_immunizer should be
42  removed.
43 */
44 
46  public:
48  : m_thd(thd), m_killed_state(THD::NOT_KILLED), m_is_active(true) {
49  MUTEX_LOCK(thd_data_lock, &thd->LOCK_thd_data);
50 
51  // If DD_kill_immunizer is initialized as part of nested Transaction_ro's
52  // then store reference to parent kill_immunizer else NULL value is saved in
53  // m_saved_kill_immunizer.
55 
56  // Save either thd->killed value or parent kill_immunizer's m_killed_state
57  // value.
60  : thd->killed.load();
61 
62  // Set current DD_kill_immunizer object to THD.
63  thd->kill_immunizer = this;
64 
65  // Set killed state of THD as NOT_KILLED.
66  thd->killed = THD::NOT_KILLED;
67  }
68 
70  MUTEX_LOCK(thd_data_lock, &m_thd->LOCK_thd_data);
71 
72  /*
73  Current instance is of top level kill immunizer, set kill immune mode to
74  inactive(or exiting).
75  */
76  if (m_saved_kill_immunizer == NULL) m_is_active = false;
77 
78  // If there were any concurrent kill operations in kill immune mode, call
79  // THD::awake() with the m_killed_state. This will either propagate the
80  // m_killed_state to the parent kill_immunizer and return or assign state to
81  // the THD::killed and complete the THD::awake(). Otherwise, if it is a top
82  // level kill immunizer just reset THD::killed state else we need not have
83  // to do anything.
84  if (m_killed_state)
86  else if (m_saved_kill_immunizer == NULL)
88 
89  // Reset kill_immunizer of THD.
91  }
92 
93  /*
94  Check if thread is in the kill immune mode.
95  */
96  bool is_active() { return m_is_active; }
97 
98  // Save kill state set while kill immune mode is active.
101 
103  }
104 
105  private:
107 
108  // When kill_immunizer is set(i.e. operation on DD tables is in progress) to
109  // THD then there might be some concurrent KILL operations. The KILL state
110  // from those operations is stored in the m_killed_state. While exiting from
111  // the kill immune mode THD::awake() is called with this value.
113 
114  // In case of nested Transaction_ro, m_saved_kill_immunizer is used to refer
115  // the parent Transaction_ro's kill_immunizer. This is used to propogate the
116  // m_killed_state to the parent kill_immunizer.
118 
119  // THD::killed value is saved before entering the kill immune mode.
120  // If kill_immunizer is of some Transaction_ro in the nested Transaction_ro
121  // then parent kill_immunizer's m_killed_state is saved in the
122  // m_saved_killed_state for reference.
124 
125  /*
126  kill immunizer state (active or exiting). The state is set to active when
127  kill immunizer is invoked. Kill_immunizer state is set to inactive(or
128  exiting) while exiting from the kill immune mode (current instance is of top
129  level kill immunizer at this point).
130  */
132 };
133 
134 } // namespace dd
135 #endif // DD_KILL_IMMUNIZER_INCLUDED
~DD_kill_immunizer()
Definition: dd_kill_immunizer.h:69
DD_kill_immunizer * m_saved_kill_immunizer
Definition: dd_kill_immunizer.h:117
bool m_is_active
Definition: dd_kill_immunizer.h:131
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
THD::killed_state m_killed_state
Definition: dd_kill_immunizer.h:112
std::atomic< killed_state > killed
Definition: sql_class.h:2282
THD::killed_state m_saved_killed_state
Definition: dd_kill_immunizer.h:123
void awake(THD::killed_state state_to_set)
Awake a thread.
Definition: sql_class.cc:1126
#define MUTEX_LOCK(NAME, X)
Definition: mutex_lock.h:60
dd::DD_kill_immunizer * kill_immunizer
When operation on DD tables is in progress then THD is set to kill immune mode.
Definition: sql_class.h:2291
killed_state
Definition: sql_class.h:2275
#define true
Definition: config_static.h:44
void save_killed_state(THD::killed_state state)
Definition: dd_kill_immunizer.h:99
Definition: sql_class.h:2276
#define mysql_mutex_assert_owner(M)
Wrapper, to use safe_mutex_assert_owner with instrumented mutexes.
Definition: mysql_mutex.h:109
THD * m_thd
Definition: dd_kill_immunizer.h:106
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
mysql_mutex_t LOCK_thd_data
Protects THD data accessed from other threads.
Definition: sql_class.h:1004
DD_kill_immunizer(THD *thd)
Definition: dd_kill_immunizer.h:47
bool is_active()
Definition: dd_kill_immunizer.h:96
RAII class for immunizing the THD from kill operations.
Definition: dd_kill_immunizer.h:45
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776