1 /* Copyright (c) 2010, 2011, 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 RPL_INFO_H
24 #define RPL_INFO_H
25 
26 #include "sql_priv.h"
27 #include "sql_class.h"
28 #include "rpl_info_handler.h"
29 #include "rpl_reporting.h"
30 
31 class Rpl_info : public Slave_reporting_capability
32 {
33 public:
34   virtual ~Rpl_info();
35 
36   /*
37     standard lock acquisition order to avoid deadlocks:
38     run_lock, data_lock, relay_log.LOCK_log, relay_log.LOCK_index
39     run_lock, sleep_lock
40   */
41   mysql_mutex_t data_lock, run_lock, sleep_lock;
42   /*
43     start_cond is broadcast when SQL thread is started
44     stop_cond  - when stopped
45     data_cond  - when data protected by data_lock changes
46     sleep_cond - when killed
47   */
48   mysql_cond_t data_cond, start_cond, stop_cond, sleep_cond;
49 
50 #ifdef HAVE_PSI_INTERFACE
51   PSI_mutex_key *key_info_run_lock, *key_info_data_lock, *key_info_sleep_lock;
52 
53   PSI_mutex_key *key_info_data_cond, *key_info_start_cond, *key_info_stop_cond,
54                 *key_info_sleep_cond;
55 #endif
56 
57   THD *info_thd;
58 
59   bool inited;
60   volatile bool abort_slave;
61   volatile uint slave_running;
62   volatile ulong slave_run_id;
63 
64 #ifndef DBUG_OFF
65   int events_until_exit;
66 #endif
67 
68   /**
69     Sets the persistency component/handler.
70 
71     @param[in] hanlder Pointer to the handler.
72   */
set_rpl_info_handler(Rpl_info_handler * param_handler)73   void set_rpl_info_handler(Rpl_info_handler * param_handler)
74   {
75     handler= param_handler;
76   }
77 
78   /**
79     Gets the persistency component/handler.
80 
81     @return the handler if there is one.
82   */
get_rpl_info_handler()83   Rpl_info_handler *get_rpl_info_handler()
84   {
85     return (handler);
86   }
87 
check_info()88   enum_return_check check_info()
89   {
90     return (handler->check_info());
91   }
92 
remove_info()93   int remove_info()
94   {
95     return (handler->remove_info());
96   }
97 
clean_info()98   int clean_info()
99   {
100     return (handler->clean_info());
101   }
102 
is_transactional()103   bool is_transactional()
104   {
105     return (handler->is_transactional());
106   }
107 
update_is_transactional()108   bool update_is_transactional()
109   {
110     return (handler->update_is_transactional());
111   }
112 
get_description_info()113   char *get_description_info()
114   {
115     return (handler->get_description_info());
116   }
117 
copy_info(Rpl_info_handler * from,Rpl_info_handler * to)118   bool copy_info(Rpl_info_handler *from, Rpl_info_handler *to)
119   {
120     if (read_info(from) || write_info(to))
121       return(TRUE);
122 
123     return(FALSE);
124   }
125 
get_internal_id()126   uint get_internal_id()
127   {
128     return internal_id;
129   }
130 
131 protected:
132   /**
133     Pointer to the repository's handler.
134   */
135   Rpl_info_handler *handler;
136 
137   /**
138     Uniquely and internaly identifies an info entry (.e.g. a row or
139     file). This information is completely transparent to users and
140     is used only during startup to retrieve information from the
141     repositories.
142   */
143   uint internal_id;
144 
145   Rpl_info(const char* type
146 #ifdef HAVE_PSI_INTERFACE
147            ,PSI_mutex_key *param_key_info_run_lock,
148            PSI_mutex_key *param_key_info_data_lock,
149            PSI_mutex_key *param_key_info_sleep_lock,
150            PSI_mutex_key *param_key_info_data_cond,
151            PSI_mutex_key *param_key_info_start_cond,
152            PSI_mutex_key *param_key_info_stop_cond,
153            PSI_mutex_key *param_key_info_sleep_cond
154 #endif
155            ,uint param_id
156           );
157 
158 private:
159   virtual bool read_info(Rpl_info_handler *from)= 0;
160   virtual bool write_info(Rpl_info_handler *to)= 0;
161 
162   Rpl_info(const Rpl_info& info);
163   Rpl_info& operator=(const Rpl_info& info);
164 };
165 #endif /* RPL_INFO_H */
166