MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ha_ndbcluster_binlog.h
1 /*
2  Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 // Typedefs for long names
25 
26 #define IS_TMP_PREFIX(A) (is_prefix(A, tmp_file_prefix))
27 
28 #define INJECTOR_EVENT_LEN 200
29 
30 #define NDB_INVALID_SCHEMA_OBJECT 241
31 
32 extern handlerton *ndbcluster_hton;
33 
35 {
36 public:
37  Ndb_event_data(NDB_SHARE *the_share) :
38  shadow_table(0),
39  share(the_share)
40  {
41  ndb_value[0]= 0;
42  ndb_value[1]= 0;
43  }
45  {
46  if (shadow_table)
47  closefrm(shadow_table, 1);
48  shadow_table= 0;
49  free_root(&mem_root, MYF(0));
50  share= 0;
51  /*
52  ndbvalue[] allocated with my_multi_malloc
53  so only first pointer should be freed
54  */
55  my_free(ndb_value[0], MYF(MY_WME|MY_ALLOW_ZERO_PTR));
56  }
57  MEM_ROOT mem_root;
58  TABLE *shadow_table;
59  NDB_SHARE *share;
60  NdbValue *ndb_value[2];
61 };
62 
63 /*
64  The numbers below must not change as they
65  are passed between mysql servers, and if changed
66  would break compatablility. Add new numbers to
67  the end.
68 */
69 enum SCHEMA_OP_TYPE
70 {
71  SOT_DROP_TABLE= 0,
72  SOT_CREATE_TABLE= 1,
73  SOT_RENAME_TABLE_NEW= 2,
74  SOT_ALTER_TABLE_COMMIT= 3,
75  SOT_DROP_DB= 4,
76  SOT_CREATE_DB= 5,
77  SOT_ALTER_DB= 6,
78  SOT_CLEAR_SLOCK= 7,
79  SOT_TABLESPACE= 8,
80  SOT_LOGFILE_GROUP= 9,
81  SOT_RENAME_TABLE= 10,
82  SOT_TRUNCATE_TABLE= 11,
83  SOT_RENAME_TABLE_PREPARE= 12,
84  SOT_ONLINE_ALTER_TABLE_PREPARE= 13,
85  SOT_ONLINE_ALTER_TABLE_COMMIT= 14,
86  SOT_CREATE_USER= 15,
87  SOT_DROP_USER= 16,
88  SOT_RENAME_USER= 17,
89  SOT_GRANT= 18,
90  SOT_REVOKE= 19
91 };
92 
93 const uint max_ndb_nodes= 256; /* multiple of 32 */
94 
95 static const char *ha_ndb_ext=".ndb";
96 
97 #ifdef HAVE_NDB_BINLOG
98 #define NDB_EXCEPTIONS_TABLE_SUFFIX "$EX"
99 #define NDB_EXCEPTIONS_TABLE_SUFFIX_LOWER "$ex"
100 
101 const uint error_conflict_fn_violation= 9999;
102 #endif /* HAVE_NDB_BINLOG */
103 
104 
106 {
107 public:
108  Mutex_guard(pthread_mutex_t &mutex) : m_mutex(mutex)
109  {
110  pthread_mutex_lock(&m_mutex);
111  };
112  ~Mutex_guard()
113  {
114  pthread_mutex_unlock(&m_mutex);
115  };
116 private:
117  pthread_mutex_t &m_mutex;
118 };
119 
120 
121 extern Ndb_cluster_connection* g_ndb_cluster_connection;
122 
123 extern unsigned char g_node_id_map[max_ndb_nodes];
124 extern pthread_mutex_t LOCK_ndb_util_thread;
125 extern pthread_cond_t COND_ndb_util_thread;
126 extern pthread_mutex_t LOCK_ndb_index_stat_thread;
127 extern pthread_cond_t COND_ndb_index_stat_thread;
128 extern pthread_mutex_t ndbcluster_mutex;
129 extern HASH ndbcluster_open_tables;
130 
131 /*
132  Initialize the binlog part of the ndb handlerton
133 */
134 void ndbcluster_binlog_init_handlerton();
135 /*
136  Initialize the binlog part of the NDB_SHARE
137 */
138 int ndbcluster_binlog_init_share(THD *thd, NDB_SHARE *share, TABLE *table);
139 int ndbcluster_create_binlog_setup(THD *thd, Ndb *ndb, const char *key,
140  uint key_len,
141  const char *db,
142  const char *table_name,
143  TABLE * table);
144 int ndbcluster_create_event(THD *thd, Ndb *ndb, const NDBTAB *table,
145  const char *event_name, NDB_SHARE *share,
146  int push_warning= 0);
147 int ndbcluster_create_event_ops(THD *thd,
148  NDB_SHARE *share,
149  const NDBTAB *ndbtab,
150  const char *event_name);
151 int ndbcluster_log_schema_op(THD *thd,
152  const char *query, int query_length,
153  const char *db, const char *table_name,
154  uint32 ndb_table_id,
155  uint32 ndb_table_version,
156  enum SCHEMA_OP_TYPE type,
157  const char *new_db,
158  const char *new_table_name);
159 int ndbcluster_drop_event(THD *thd, Ndb *ndb, NDB_SHARE *share,
160  const char *type_str,
161  const char * dbname, const char * tabname);
162 int ndbcluster_handle_drop_table(THD *thd, Ndb *ndb, NDB_SHARE *share,
163  const char *type_str,
164  const char * db, const char * tabname);
165 void ndb_rep_event_name(String *event_name,
166  const char *db, const char *tbl, my_bool full);
167 #ifdef HAVE_NDB_BINLOG
168 int
169 ndbcluster_get_binlog_replication_info(THD *thd, Ndb *ndb,
170  const char* db,
171  const char* table_name,
172  uint server_id,
173  const TABLE *table,
174  Uint32* binlog_flags,
175  const st_conflict_fn_def** conflict_fn,
176  st_conflict_fn_arg* args,
177  Uint32* num_args);
178 int
179 ndbcluster_apply_binlog_replication_info(THD *thd,
180  NDB_SHARE *share,
181  const NDBTAB* ndbtab,
182  TABLE* table,
183  const st_conflict_fn_def* conflict_fn,
184  const st_conflict_fn_arg* args,
185  Uint32 num_args,
186  bool do_set_binlog_flags,
187  Uint32 binlog_flags);
188 int
189 ndbcluster_read_binlog_replication(THD *thd, Ndb *ndb,
190  NDB_SHARE *share,
191  const NDBTAB *ndbtab,
192  uint server_id,
193  TABLE *table,
194  bool do_set_binlog_flags);
195 #endif
196 int ndb_create_table_from_engine(THD *thd, const char *db,
197  const char *table_name);
198 int ndbcluster_binlog_start();
199 
200 
201 /*
202  Setup function for the ndb binlog component. The function should be
203  called on startup until it succeeds(to allow initial setup) and with
204  regular intervals afterwards to reconnect after a lost cluster
205  connection
206 */
207 bool ndb_binlog_setup(THD *thd);
208 
209 /*
210  Will return true when the ndb binlog component is properly setup
211  and ready to receive events from the cluster. As long as function
212  returns false, all tables in this MySQL Server are opened in read only
213  mode to avoid writes before the binlog is ready to record them.
214  */
215 bool ndb_binlog_is_read_only(void);
216 
217 extern NDB_SHARE *ndb_apply_status_share;
218 extern NDB_SHARE *ndb_schema_share;
219 
220 extern my_bool ndb_binlog_running;
221 
222 bool
223 ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print,
224  enum ha_stat_type stat_type);
225 
226 /*
227  prototypes for ndb handler utility function also needed by
228  the ndb binlog code
229 */
230 int cmp_frm(const NDBTAB *ndbtab, const void *pack_data,
231  uint pack_length);
232 int ndbcluster_find_all_files(THD *thd);
233 
234 char *ndb_pack_varchar(const NDBCOL *col, char *buf,
235  const char *str, int sz);
236 
237 NDB_SHARE *ndbcluster_get_share(const char *key,
238  TABLE *table,
239  bool create_if_not_exists,
240  bool have_lock);
241 NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share);
242 void ndbcluster_free_share(NDB_SHARE **share, bool have_lock);
243 void ndbcluster_real_free_share(NDB_SHARE **share);
244 int handle_trailing_share(THD *thd, NDB_SHARE *share);
245 int ndbcluster_prepare_rename_share(NDB_SHARE *share, const char *new_key);
246 int ndbcluster_rename_share(THD *thd, NDB_SHARE *share);
247 int ndbcluster_undo_rename_share(THD *thd, NDB_SHARE *share);
248 inline NDB_SHARE *get_share(const char *key,
249  TABLE *table,
250  bool create_if_not_exists= TRUE,
251  bool have_lock= FALSE)
252 {
253  return ndbcluster_get_share(key, table, create_if_not_exists, have_lock);
254 }
255 
256 inline NDB_SHARE *get_share(NDB_SHARE *share)
257 {
258  return ndbcluster_get_share(share);
259 }
260 
261 inline void free_share(NDB_SHARE **share, bool have_lock= FALSE)
262 {
263  ndbcluster_free_share(share, have_lock);
264 }
265 
266 void set_binlog_flags(NDB_SHARE *share);
267 
268 /*
269  Helper functions
270 */
271 bool
272 ndbcluster_check_if_local_table(const char *dbname, const char *tabname);
273 bool
274 ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname);
275 
276 bool ndbcluster_anyvalue_is_reserved(Uint32 anyValue);
277 bool ndbcluster_anyvalue_is_nologging(Uint32 anyValue);
278 void ndbcluster_anyvalue_set_nologging(Uint32& anyValue);
279 bool ndbcluster_anyvalue_is_serverid_in_range(Uint32 serverId);
280 void ndbcluster_anyvalue_set_normal(Uint32& anyValue);
281 Uint32 ndbcluster_anyvalue_get_serverid(Uint32 anyValue);
282 void ndbcluster_anyvalue_set_serverid(Uint32& anyValue, Uint32 serverId);
283 
284 #ifndef DBUG_OFF
285 void dbug_ndbcluster_anyvalue_set_userbits(Uint32& anyValue);
286 #endif