1 /*
2 Copyright (c) 2010, 2015, 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 #include "sql_table.h" // build_table_filename,
35 // tablename_to_filename,
36 // filename_to_tablename
37 #include "sql_partition.h" // HA_CAN_*, part_id_range
38 #include "partition_info.h" // partition_info
39 #include "sql_base.h" // close_cached_tables
40 #include "discover.h" // readfrm
41 #include "auth_common.h" // wild_case_compare
42 #include "transaction.h"
43 #include "item_cmpfunc.h" // Item_func_like
44 #include "sql_test.h" // print_where
45 #include "key.h" // key_restore
46 #include "rpl_constants.h" // Transid in Binlog
47 #include "rpl_slave.h" // Silent retry definition
48 #include "log_event.h" // my_strmov_quoted_identifier
49 #include "log.h" // sql_print_error
50
51 #include "sql_show.h" // init_fill_schema_files_row,
52 // schema_table_store_record
53
54
55 #if MYSQL_VERSION_ID >= 50501
56
57 /* my_free has lost last argument */
58 static inline
my_free(void * ptr,myf MyFlags)59 void my_free(void* ptr, myf MyFlags)
60 {
61 my_free(ptr);
62 }
63
64 /* thd has no version field anymore */
65 #define NDB_THD_HAS_NO_VERSION
66
67 /* No mysql_rm_table_part2 anymore in 5.5.8 */
68 #define NDB_NO_MYSQL_RM_TABLE_PART2
69
70 #endif
71
72 static inline
thd_unmasked_server_id(const THD * thd)73 uint32 thd_unmasked_server_id(const THD* thd)
74 {
75 const uint32 unmasked_server_id = thd->unmasked_server_id;
76 assert(thd->server_id == (thd->unmasked_server_id & opt_server_id_mask));
77 return unmasked_server_id;
78 }
79
80
81 /* extract the bitmask of options from THD */
82 static inline
thd_options(const THD * thd)83 ulonglong thd_options(const THD * thd)
84 {
85 #if MYSQL_VERSION_ID < 50500
86 return thd->options;
87 #else
88 /* "options" has moved to "variables.option_bits" */
89 return thd->variables.option_bits;
90 #endif
91 }
92
93 /* set the "command" member of thd */
94 static inline
thd_set_command(THD * thd,enum enum_server_command command)95 void thd_set_command(THD* thd, enum enum_server_command command)
96 {
97 #if MYSQL_VERSION_ID < 50600
98 thd->command = command;
99 #else
100 /* "command" renamed to "m_command", use accessor function */
101 thd->set_command(command);
102 #endif
103 }
104
105 /* get pointer to Diagnostics Area for statement from THD */
106 static inline
thd_stmt_da(THD * thd)107 Diagnostics_area* thd_stmt_da(THD* thd)
108 {
109 #if MYSQL_VERSION_ID < 50500
110 return &(thd->main_da);
111 #else
112 #if MYSQL_VERSION_ID < 50603
113 /* "main_da" has been made private and one should use "stmt_da*" */
114 return thd->stmt_da;
115 #else
116 /* "stmt_da*" has been made private and one should use 'get_stmt_da()' */
117 return thd->get_stmt_da();
118 #endif
119 #endif
120 }
121
122 #if MYSQL_VERSION_ID < 50500
123
124 /*
125 MySQL Server has got its own mutex type in 5.5, add backwards
126 compatibility support allowing to write code in 7.0 that works
127 in future MySQL Server
128 */
129
130 typedef pthread_mutex_t mysql_mutex_t;
131
132 static inline
mysql_mutex_lock(mysql_mutex_t * mutex)133 int mysql_mutex_lock(mysql_mutex_t* mutex)
134 {
135 return pthread_mutex_lock(mutex);
136 }
137
138 static inline
mysql_mutex_unlock(mysql_mutex_t * mutex)139 int mysql_mutex_unlock(mysql_mutex_t* mutex)
140 {
141 return pthread_mutex_unlock(mutex);
142 }
143
144 static inline
mysql_mutex_assert_owner(mysql_mutex_t * mutex)145 void mysql_mutex_assert_owner(mysql_mutex_t* mutex)
146 {
147 return safe_mutex_assert_owner(mutex);
148 }
149
150 typedef pthread_cond_t mysql_cond_t;
151
152 static inline
mysql_cond_wait(mysql_cond_t * cond,mysql_mutex_t * mutex)153 int mysql_cond_wait(mysql_cond_t* cond, mysql_mutex_t* mutex)
154 {
155 return pthread_cond_wait(cond, mutex);
156 }
157
158 static inline
mysql_cond_timedwait(mysql_cond_t * cond,mysql_mutex_t * mutex,struct timespec * abstime)159 int mysql_cond_timedwait(mysql_cond_t* cond, mysql_mutex_t* mutex,
160 struct timespec* abstime)
161 {
162 return pthread_cond_timedwait(cond, mutex, abstime);
163 }
164
165 #endif
166
167 #endif
168