| 1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
| 2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: |
| 3 | #ident "$Id$" |
| 4 | /*====== |
| 5 | This file is part of TokuDB |
| 6 | |
| 7 | |
| 8 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. |
| 9 | |
| 10 | TokuDB is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License, version 2, |
| 12 | as published by the Free Software Foundation. |
| 13 | |
| 14 | TokuDB 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 for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with TokuDB. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | ======= */ |
| 23 | |
| 24 | #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." |
| 25 | |
| 26 | #ifndef _HATOKU_DEFINES_H |
| 27 | #define _HATOKU_DEFINES_H |
| 28 | |
| 29 | #define MYSQL_SERVER 1 |
| 30 | #include <my_global.h> |
| 31 | #include "mysql_version.h" |
| 32 | #include "sql_table.h" |
| 33 | #include "handler.h" |
| 34 | #include "table.h" |
| 35 | #include "log.h" |
| 36 | #include "sql_class.h" |
| 37 | #include "sql_show.h" |
| 38 | #include "discover.h" |
| 39 | //#include <binlog.h> |
| 40 | #include "debug_sync.h" |
| 41 | |
| 42 | #undef PACKAGE |
| 43 | #undef VERSION |
| 44 | #undef HAVE_DTRACE |
| 45 | #undef _DTRACE_VERSION |
| 46 | |
| 47 | /* We define DTRACE after mysql_priv.h in case it disabled dtrace in the main server */ |
| 48 | #ifdef HAVE_DTRACE |
| 49 | #define _DTRACE_VERSION 1 |
| 50 | #else |
| 51 | #endif |
| 52 | |
| 53 | #include <mysql/plugin.h> |
| 54 | |
| 55 | #include <ctype.h> |
| 56 | #include <stdint.h> |
| 57 | #define __STDC_FORMAT_MACROS |
| 58 | #include <inttypes.h> |
| 59 | #if defined(_WIN32) |
| 60 | #include "misc.h" |
| 61 | #endif |
| 62 | |
| 63 | #include "db.h" |
| 64 | #include "toku_os.h" |
| 65 | #include "toku_time.h" |
| 66 | #include "partitioned_counter.h" |
| 67 | |
| 68 | #ifdef USE_PRAGMA_INTERFACE |
| 69 | #pragma interface /* gcc class implementation */ |
| 70 | #endif |
| 71 | |
| 72 | #if 100000 <= MYSQL_VERSION_ID |
| 73 | |
| 74 | // mariadb 10.0 |
| 75 | #define TOKU_USE_DB_TYPE_TOKUDB 1 |
| 76 | #define TOKU_INCLUDE_ALTER_56 1 |
| 77 | #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0 |
| 78 | #define TOKU_INCLUDE_XA 1 |
| 79 | #define TOKU_INCLUDE_WRITE_FRM_DATA 0 |
| 80 | #define TOKU_PARTITION_WRITE_FRM_DATA 0 |
| 81 | #if defined(MARIADB_BASE_VERSION) |
| 82 | #define TOKU_INCLUDE_EXTENDED_KEYS 1 |
| 83 | #endif |
| 84 | #define TOKU_INCLUDE_OPTION_STRUCTS 1 |
| 85 | #define TOKU_OPTIMIZE_WITH_RECREATE 1 |
| 86 | #define TOKU_CLUSTERING_IS_COVERING 1 |
| 87 | |
| 88 | #elif 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 |
| 89 | // mysql 5.7 with no patches |
| 90 | #if TOKUDB_NOPATCH_CONFIG |
| 91 | #define TOKU_USE_DB_TYPE_UNKNOWN 1 |
| 92 | #define TOKU_INCLUDE_ALTER_56 1 |
| 93 | #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0 |
| 94 | #define TOKU_PARTITION_WRITE_FRM_DATA 0 |
| 95 | #else |
| 96 | #error |
| 97 | #endif |
| 98 | |
| 99 | #elif 50613 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 |
| 100 | // mysql 5.6 with no patches |
| 101 | #if TOKUDB_NOPATCH_CONFIG |
| 102 | #define TOKU_USE_DB_TYPE_UNKNOWN 1 |
| 103 | #define TOKU_INCLUDE_ALTER_56 1 |
| 104 | #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0 |
| 105 | #define TOKU_INCLUDE_XA 0 |
| 106 | #define TOKU_PARTITION_WRITE_FRM_DATA 0 |
| 107 | #else |
| 108 | // mysql 5.6 with tokutek patches |
| 109 | #define TOKU_USE_DB_TYPE_TOKUDB 1 // has DB_TYPE_TOKUDB patch |
| 110 | #define TOKU_INCLUDE_ALTER_56 1 |
| 111 | #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 // has tokudb row format compression patch |
| 112 | #define TOKU_INCLUDE_XA 1 // has patch that fixes TC_LOG_MMAP code |
| 113 | #define TOKU_PARTITION_WRITE_FRM_DATA 0 |
| 114 | #define TOKU_INCLUDE_WRITE_FRM_DATA 0 |
| 115 | #define TOKU_INCLUDE_UPSERT 1 // has tokudb upsert patch |
| 116 | #if defined(HTON_SUPPORTS_EXTENDED_KEYS) |
| 117 | #define TOKU_INCLUDE_EXTENDED_KEYS 1 |
| 118 | #endif |
| 119 | #endif |
| 120 | #define TOKU_OPTIMIZE_WITH_RECREATE 1 |
| 121 | |
| 122 | #elif 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599 |
| 123 | #define TOKU_USE_DB_TYPE_TOKUDB 1 |
| 124 | #define TOKU_INCLUDE_ALTER_56 0 /* MariaDB 5.5 */ |
| 125 | #define TOKU_INCLUDE_ALTER_55 0 /* MariaDB 5.5 */ |
| 126 | #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0 /* MariaDB 5.5 */ |
| 127 | #define TOKU_INCLUDE_XA 1 |
| 128 | #define TOKU_PARTITION_WRITE_FRM_DATA 0 /* MariaDB 5.5 */ |
| 129 | #define TOKU_INCLUDE_WRITE_FRM_DATA 0 /* MariaDB 5.5 */ |
| 130 | #define TOKU_INCLUDE_UPSERT 0 /* MariaDB 5.5 */ |
| 131 | #if defined(MARIADB_BASE_VERSION) |
| 132 | #define TOKU_INCLUDE_EXTENDED_KEYS 1 |
| 133 | #define TOKU_INCLUDE_OPTION_STRUCTS 1 |
| 134 | #define TOKU_CLUSTERING_IS_COVERING 1 |
| 135 | #define TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING 1 |
| 136 | #else |
| 137 | #define TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING 1 |
| 138 | #endif |
| 139 | #define TOKU_INCLUDE_HANDLERTON_HANDLE_FATAL_SIGNAL 0 |
| 140 | |
| 141 | #else |
| 142 | #error |
| 143 | |
| 144 | #endif |
| 145 | |
| 146 | #ifdef MARIADB_BASE_VERSION |
| 147 | // In MariaDB 5.3, thread progress reporting was introduced. |
| 148 | // Only include that functionality if we're using maria 5.3 + |
| 149 | #define HA_TOKUDB_HAS_THD_PROGRESS 1 |
| 150 | |
| 151 | // MariaDB supports thdvar memalloc correctly |
| 152 | #define TOKU_THDVAR_MEMALLOC_BUG 0 |
| 153 | #else |
| 154 | // MySQL does not support thdvar memalloc correctly |
| 155 | // see http://bugs.mysql.com/bug.php?id=71759 |
| 156 | #define TOKU_THDVAR_MEMALLOC_BUG 1 |
| 157 | #endif |
| 158 | |
| 159 | #if !defined(HA_CLUSTERING) |
| 160 | #define HA_CLUSTERING 0 |
| 161 | #endif |
| 162 | |
| 163 | #if !defined(HA_CLUSTERED_INDEX) |
| 164 | #define HA_CLUSTERED_INDEX 0 |
| 165 | #endif |
| 166 | |
| 167 | #if !defined(HA_CAN_WRITE_DURING_OPTIMIZE) |
| 168 | #define HA_CAN_WRITE_DURING_OPTIMIZE 0 |
| 169 | #endif |
| 170 | |
| 171 | #if !defined(HA_ONLINE_ANALYZE) |
| 172 | #define HA_ONLINE_ANALYZE 0 |
| 173 | #endif |
| 174 | |
| 175 | #if !defined(MY_ATTRIBUTE) |
| 176 | #define MY_ATTRIBUTE(A) __attribute__(A) |
| 177 | #endif |
| 178 | |
| 179 | #if !defined(HA_OPTION_CREATE_FROM_ENGINE) |
| 180 | #define HA_OPTION_CREATE_FROM_ENGINE 0 |
| 181 | #endif |
| 182 | |
| 183 | // In older (< 5.5) versions of MySQL and MariaDB, it is necessary to |
| 184 | // use a read/write lock on the key_file array in a table share, |
| 185 | // because table locks do not protect the race of some thread closing |
| 186 | // a table and another calling ha_tokudb::info() |
| 187 | // |
| 188 | // In version 5.5 and, a higher layer "metadata lock" was introduced |
| 189 | // to synchronize threads that open, close, call info(), etc on tables. |
| 190 | // In these versions, we don't need the key_file lock |
| 191 | #if MYSQL_VERSION_ID < 50500 |
| 192 | #define HA_TOKUDB_NEEDS_KEY_FILE_LOCK |
| 193 | #endif |
| 194 | |
| 195 | // |
| 196 | // returns maximum length of dictionary name, such as key-NAME |
| 197 | // NAME_CHAR_LEN is max length of the key name, and have upper bound of 10 for key- |
| 198 | // |
| 199 | #define MAX_DICT_NAME_LEN NAME_CHAR_LEN + 10 |
| 200 | |
| 201 | // QQQ how to tune these? |
| 202 | #define HA_TOKUDB_RANGE_COUNT 100 |
| 203 | /* extra rows for estimate_rows_upper_bound() */ |
| 204 | #define 100 |
| 205 | |
| 206 | /* Bits for share->status */ |
| 207 | #define STATUS_PRIMARY_KEY_INIT 0x1 |
| 208 | |
| 209 | #if defined(TOKUDB_VERSION_MAJOR) && defined(TOKUDB_VERSION_MINOR) |
| 210 | #define TOKUDB_PLUGIN_VERSION ((TOKUDB_VERSION_MAJOR << 8) + TOKUDB_VERSION_MINOR) |
| 211 | #else |
| 212 | #define TOKUDB_PLUGIN_VERSION 0 |
| 213 | #endif |
| 214 | |
| 215 | // Branch prediction macros. |
| 216 | // If supported by the compiler, will hint in instruction caching for likely |
| 217 | // branching. Should only be used where there is a very good idea of the correct |
| 218 | // branch heuristics as determined by profiling. Mostly copied from InnoDB. |
| 219 | // Use: |
| 220 | // "if (TOKUDB_LIKELY(x))" where the chances of "x" evaluating true are higher |
| 221 | // "if (TOKUDB_UNLIKELY(x))" where the chances of "x" evaluating false are higher |
| 222 | #if defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER) |
| 223 | |
| 224 | // Tell the compiler that 'expr' probably evaluates to 'constant'. |
| 225 | #define TOKUDB_EXPECT(expr,constant) __builtin_expect(expr, constant) |
| 226 | |
| 227 | #else |
| 228 | |
| 229 | #error "No TokuDB branch prediction operations in use!" |
| 230 | #define TOKUDB_EXPECT(expr,constant) (expr) |
| 231 | |
| 232 | #endif // defined(__GNUC__) && (__GNUC__ > 2) && ! defined(__INTEL_COMPILER) |
| 233 | |
| 234 | // Tell the compiler that cond is likely to hold |
| 235 | #define TOKUDB_LIKELY(cond) TOKUDB_EXPECT(cond, 1) |
| 236 | |
| 237 | // Tell the compiler that cond is unlikely to hold |
| 238 | #define TOKUDB_UNLIKELY(cond) TOKUDB_EXPECT(cond, 0) |
| 239 | |
| 240 | // Tell the compiler that the function/argument is unused |
| 241 | #define TOKUDB_UNUSED(_uu) _uu __attribute__((unused)) |
| 242 | // mysql 5.6.15 removed the test macro, so we define our own |
| 243 | #define tokudb_test(e) ((e) ? 1 : 0) |
| 244 | |
| 245 | inline const char* tokudb_thd_get_proc_info(const THD* thd) { |
| 246 | return thd->proc_info; |
| 247 | } |
| 248 | inline void tokudb_thd_set_proc_info(THD* thd, const char* proc_info) { |
| 249 | thd_proc_info(thd, proc_info); |
| 250 | } |
| 251 | |
| 252 | // uint3korr reads 4 bytes and valgrind reports an error, so we use this function instead |
| 253 | inline uint tokudb_uint3korr(const uchar *a) { |
| 254 | uchar b[4] = {}; |
| 255 | memcpy(b, a, 3); |
| 256 | return uint3korr(b); |
| 257 | } |
| 258 | |
| 259 | typedef unsigned int pfs_key_t; |
| 260 | |
| 261 | #if defined(HAVE_PSI_MUTEX_INTERFACE) |
| 262 | #define mutex_t_lock(M) M.lock(__FILE__, __LINE__) |
| 263 | #define mutex_t_unlock(M) M.unlock(__FILE__, __LINE__) |
| 264 | #else // HAVE_PSI_MUTEX_INTERFACE |
| 265 | #define mutex_t_lock(M) M.lock() |
| 266 | #define mutex_t_unlock(M) M.unlock() |
| 267 | #endif // HAVE_PSI_MUTEX_INTERFACE |
| 268 | |
| 269 | #if defined(HAVE_PSI_RWLOCK_INTERFACE) |
| 270 | #define rwlock_t_lock_read(M) M.lock_read(__FILE__, __LINE__) |
| 271 | #define rwlock_t_lock_write(M) M.lock_write(__FILE__, __LINE__) |
| 272 | #else // HAVE_PSI_RWLOCK_INTERFACE |
| 273 | #define rwlock_t_lock_read(M) M.lock_read() |
| 274 | #define rwlock_t_lock_write(M) M.lock_write() |
| 275 | #endif // HAVE_PSI_RWLOCK_INTERFACE |
| 276 | |
| 277 | #endif // _HATOKU_DEFINES_H |
| 278 | |