1 /*
2 Copyright (c) 2010, 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, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef HA_NDBCLUSTER_GLUE_H
26 #define HA_NDBCLUSTER_GLUE_H
27
28 #include <mysql_version.h>
29
30 #ifndef MYSQL_SERVER
31 #define MYSQL_SERVER
32 #endif
33
34 #if MYSQL_VERSION_ID >= 50501
35 /* Include files for sql/ was split in 5.5, and ha_ndb* uses a few.. */
36 #include "sql_priv.h"
37 #include "unireg.h" // REQUIRED: for other includes
38 #include "sql_table.h" // build_table_filename,
39 // tablename_to_filename,
40 // filename_to_tablename
41 #include "sql_partition.h" // HA_CAN_*, partition_info, part_id_range
42 #include "sql_base.h" // close_cached_tables
43 #include "discover.h" // readfrm
44 #include "sql_acl.h" // wild_case_compare
45 #include "transaction.h"
46 #include "sql_test.h" // print_where
47 #include "key.h" // key_restore
48 #else
49 #include "mysql_priv.h"
50 #endif
51
52 #include "sql_show.h" // init_fill_schema_files_row,
53 // schema_table_store_record
54
55
56 #if MYSQL_VERSION_ID >= 50501
57
58 /* my_free has lost last argument */
59 static inline
my_free(void * ptr,myf MyFlags)60 void my_free(void* ptr, myf MyFlags)
61 {
62 my_free(ptr);
63 }
64
65
66 /* close_cached_tables has new signature, emulate old */
67 static inline
close_cached_tables(THD * thd,TABLE_LIST * tables,bool have_lock,bool wait_for_refresh,bool wait_for_placeholders)68 bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
69 bool wait_for_refresh, bool wait_for_placeholders)
70 {
71 return close_cached_tables(thd, tables, wait_for_refresh, LONG_TIMEOUT);
72 }
73
74 /* thd has no version field anymore */
75 #define NDB_THD_HAS_NO_VERSION
76
77 /* thd->binlog_query has new parameter "direct" */
78 #define NDB_THD_BINLOG_QUERY_HAS_DIRECT
79
80 /* No mysql_rm_table_part2 anymore in 5.5.8 */
81 #define NDB_NO_MYSQL_RM_TABLE_PART2
82
83 #endif
84
85 extern ulong opt_server_id_mask;
86
87 static inline
thd_unmasked_server_id(const THD * thd)88 uint32 thd_unmasked_server_id(const THD* thd)
89 {
90 #ifndef NDB_WITHOUT_SERVER_ID_BITS
91 const uint32 unmasked_server_id = thd->unmasked_server_id;
92 assert(thd->server_id == (thd->unmasked_server_id & opt_server_id_mask));
93 return unmasked_server_id;
94 #else
95 return thd->server_id;
96 #endif
97 }
98
99
100 /* extract the bitmask of options from THD */
101 static inline
thd_options(const THD * thd)102 ulonglong thd_options(const THD * thd)
103 {
104 #if MYSQL_VERSION_ID < 50500
105 return thd->options;
106 #else
107 /* "options" has moved to "variables.option_bits" */
108 return thd->variables.option_bits;
109 #endif
110 }
111
112 /* set the "command" member of thd */
113 static inline
thd_set_command(THD * thd,enum enum_server_command command)114 void thd_set_command(THD* thd, enum enum_server_command command)
115 {
116 #if MYSQL_VERSION_ID < 50600
117 thd->command = command;
118 #else
119 /* "command" renamed to "m_command", use accessor function */
120 thd->set_command(command);
121 #endif
122 }
123
124 /* get pointer to diagnostic area for statement from THD */
125 static inline
thd_stmt_da(THD * thd)126 Diagnostics_area* thd_stmt_da(THD* thd)
127 {
128 #if MYSQL_VERSION_ID < 50500
129 return &(thd->main_da);
130 #else
131 #if MYSQL_VERSION_ID < 50603
132 /* "main_da" has been made private and one should use "stmt_da*" */
133 return thd->stmt_da;
134 #else
135 /* "stmt_da*" has been made private and one should use 'get_stmt_da()' */
136 return thd->get_stmt_da();
137 #endif
138 #endif
139 }
140
141 #if MYSQL_VERSION_ID < 50500
142
143 /*
144 MySQL Server has got its own mutex type in 5.5, add backwards
145 compatibility support allowing to write code in 7.0 that works
146 in future MySQL Server
147 */
148
149 typedef pthread_mutex_t mysql_mutex_t;
150
151 static inline
mysql_mutex_lock(mysql_mutex_t * mutex)152 int mysql_mutex_lock(mysql_mutex_t* mutex)
153 {
154 return pthread_mutex_lock(mutex);
155 }
156
157 static inline
mysql_mutex_unlock(mysql_mutex_t * mutex)158 int mysql_mutex_unlock(mysql_mutex_t* mutex)
159 {
160 return pthread_mutex_unlock(mutex);
161 }
162
163 static inline
mysql_mutex_assert_owner(mysql_mutex_t * mutex)164 void mysql_mutex_assert_owner(mysql_mutex_t* mutex)
165 {
166 return safe_mutex_assert_owner(mutex);
167 }
168
169 typedef pthread_cond_t mysql_cond_t;
170
171 static inline
mysql_cond_wait(mysql_cond_t * cond,mysql_mutex_t * mutex)172 int mysql_cond_wait(mysql_cond_t* cond, mysql_mutex_t* mutex)
173 {
174 return pthread_cond_wait(cond, mutex);
175 }
176
177 static inline
mysql_cond_timedwait(mysql_cond_t * cond,mysql_mutex_t * mutex,struct timespec * abstime)178 int mysql_cond_timedwait(mysql_cond_t* cond, mysql_mutex_t* mutex,
179 struct timespec* abstime)
180 {
181 return pthread_cond_timedwait(cond, mutex, abstime);
182 }
183
184 #endif
185
186 static inline
partition_info_num_full_part_fields(const partition_info * part_info)187 uint partition_info_num_full_part_fields(const partition_info* part_info)
188 {
189 #if MYSQL_VERSION_ID < 50500
190 return part_info->no_full_part_fields;
191 #else
192 /* renamed to 'num_full_part_fields' and no accessor function*/
193 return part_info->num_full_part_fields;
194 #endif
195 }
196
197 static inline
partition_info_num_parts(const partition_info * part_info)198 uint partition_info_num_parts(const partition_info* part_info)
199 {
200 #if MYSQL_VERSION_ID < 50500
201 return part_info->no_parts;
202 #else
203 /* renamed to 'num_parts' and no accessor function */
204 return part_info->num_parts;
205 #endif
206 }
207
208 static inline
partition_info_num_list_values(const partition_info * part_info)209 uint partition_info_num_list_values(const partition_info* part_info)
210 {
211 #if MYSQL_VERSION_ID < 50500
212 return part_info->no_list_values;
213 #else
214 /* renamed to 'num_list_values' and no accessor function */
215 return part_info->num_list_values;
216 #endif
217 }
218
219 static inline
partition_info_use_default_num_partitions(const partition_info * part_info)220 bool partition_info_use_default_num_partitions(const partition_info* part_info)
221 {
222 #if MYSQL_VERSION_ID < 50500
223 return part_info->use_default_no_partitions;
224 #else
225 /* renamed to 'use_default_num_partitions' and no accessor function */
226 return part_info->use_default_num_partitions;
227 #endif
228 }
229
230 static inline
partition_info_num_subparts(const partition_info * part_info)231 uint partition_info_num_subparts(const partition_info* part_info)
232 {
233 #if MYSQL_VERSION_ID < 50500
234 return part_info->no_subparts;
235 #else
236 /* renamed to 'num_subparts' and no accessor function */
237 return part_info->num_subparts;
238 #endif
239 }
240
241 #if MYSQL_VERSION_ID >= 50600
242
243 /* New multi range read interface replaced original mrr */
244 #define NDB_WITH_NEW_MRR_INTERFACE
245
246 #endif
247
248 #endif
249