| 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 | TokuDBis 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_HTON_H |
| 27 | #define _HATOKU_HTON_H |
| 28 | |
| 29 | #include "hatoku_defines.h" |
| 30 | #include "tokudb_debug.h" |
| 31 | #include "tokudb_information_schema.h" |
| 32 | #include "tokudb_memory.h" |
| 33 | #include "tokudb_thread.h" |
| 34 | #include "tokudb_time.h" |
| 35 | #include "tokudb_txn.h" |
| 36 | #include "tokudb_sysvars.h" |
| 37 | |
| 38 | extern handlerton* tokudb_hton; |
| 39 | |
| 40 | extern DB_ENV* db_env; |
| 41 | |
| 42 | extern pfs_key_t ha_tokudb_mutex_key; |
| 43 | extern pfs_key_t num_DBs_lock_key; |
| 44 | |
| 45 | inline tokudb::sysvars::row_format_t toku_compression_method_to_row_format( |
| 46 | toku_compression_method method) { |
| 47 | |
| 48 | switch (method) { |
| 49 | case TOKU_NO_COMPRESSION: |
| 50 | return tokudb::sysvars::SRV_ROW_FORMAT_UNCOMPRESSED; |
| 51 | case TOKU_ZLIB_WITHOUT_CHECKSUM_METHOD: |
| 52 | case TOKU_ZLIB_METHOD: |
| 53 | return tokudb::sysvars::SRV_ROW_FORMAT_ZLIB; |
| 54 | case TOKU_SNAPPY_METHOD: |
| 55 | return tokudb::sysvars::SRV_ROW_FORMAT_SNAPPY; |
| 56 | case TOKU_QUICKLZ_METHOD: |
| 57 | return tokudb::sysvars::SRV_ROW_FORMAT_QUICKLZ; |
| 58 | case TOKU_LZMA_METHOD: |
| 59 | return tokudb::sysvars::SRV_ROW_FORMAT_LZMA; |
| 60 | case TOKU_DEFAULT_COMPRESSION_METHOD: |
| 61 | return tokudb::sysvars::SRV_ROW_FORMAT_DEFAULT; |
| 62 | case TOKU_FAST_COMPRESSION_METHOD: |
| 63 | return tokudb::sysvars::SRV_ROW_FORMAT_FAST; |
| 64 | case TOKU_SMALL_COMPRESSION_METHOD: |
| 65 | return tokudb::sysvars::SRV_ROW_FORMAT_SMALL; |
| 66 | default: |
| 67 | assert_unreachable(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | inline toku_compression_method row_format_to_toku_compression_method( |
| 72 | tokudb::sysvars::row_format_t row_format) { |
| 73 | |
| 74 | switch (row_format) { |
| 75 | case tokudb::sysvars::SRV_ROW_FORMAT_UNCOMPRESSED: |
| 76 | return TOKU_NO_COMPRESSION; |
| 77 | case tokudb::sysvars::SRV_ROW_FORMAT_QUICKLZ: |
| 78 | case tokudb::sysvars::SRV_ROW_FORMAT_FAST: |
| 79 | return TOKU_QUICKLZ_METHOD; |
| 80 | case tokudb::sysvars::SRV_ROW_FORMAT_SNAPPY: |
| 81 | return TOKU_SNAPPY_METHOD; |
| 82 | case tokudb::sysvars::SRV_ROW_FORMAT_ZLIB: |
| 83 | case tokudb::sysvars::SRV_ROW_FORMAT_DEFAULT: |
| 84 | return TOKU_ZLIB_WITHOUT_CHECKSUM_METHOD; |
| 85 | case tokudb::sysvars::SRV_ROW_FORMAT_LZMA: |
| 86 | case tokudb::sysvars::SRV_ROW_FORMAT_SMALL: |
| 87 | return TOKU_LZMA_METHOD; |
| 88 | default: |
| 89 | assert_unreachable(); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | inline enum row_type row_format_to_row_type( |
| 94 | tokudb::sysvars::row_format_t row_format) { |
| 95 | #if TOKU_INCLUDE_ROW_TYPE_COMPRESSION |
| 96 | switch (row_format) { |
| 97 | case tokudb::sysvars::SRV_ROW_FORMAT_UNCOMPRESSED: |
| 98 | return ROW_TYPE_TOKU_UNCOMPRESSED; |
| 99 | case tokudb::sysvars::SRV_ROW_FORMAT_ZLIB: |
| 100 | return ROW_TYPE_TOKU_ZLIB; |
| 101 | case tokudb::sysvars::SRV_ROW_FORMAT_SNAPPY: |
| 102 | return ROW_TYPE_TOKU_SNAPPY; |
| 103 | case tokudb::sysvars::SRV_ROW_FORMAT_QUICKLZ: |
| 104 | return ROW_TYPE_TOKU_QUICKLZ; |
| 105 | case tokudb::sysvars::SRV_ROW_FORMAT_LZMA: |
| 106 | return ROW_TYPE_TOKU_LZMA; |
| 107 | case tokudb::sysvars::SRV_ROW_FORMAT_SMALL: |
| 108 | return ROW_TYPE_TOKU_SMALL; |
| 109 | case tokudb::sysvars::SRV_ROW_FORMAT_FAST: |
| 110 | return ROW_TYPE_TOKU_FAST; |
| 111 | case tokudb::sysvars::SRV_ROW_FORMAT_DEFAULT: |
| 112 | return ROW_TYPE_DEFAULT; |
| 113 | } |
| 114 | #endif |
| 115 | return ROW_TYPE_DEFAULT; |
| 116 | } |
| 117 | |
| 118 | inline tokudb::sysvars::row_format_t row_type_to_row_format( |
| 119 | enum row_type type) { |
| 120 | #if TOKU_INCLUDE_ROW_TYPE_COMPRESSION |
| 121 | switch (type) { |
| 122 | case ROW_TYPE_TOKU_UNCOMPRESSED: |
| 123 | return tokudb::sysvars::SRV_ROW_FORMAT_UNCOMPRESSED; |
| 124 | case ROW_TYPE_TOKU_ZLIB: |
| 125 | return tokudb::sysvars::SRV_ROW_FORMAT_ZLIB; |
| 126 | case ROW_TYPE_TOKU_SNAPPY: |
| 127 | return tokudb::sysvars::SRV_ROW_FORMAT_SNAPPY; |
| 128 | case ROW_TYPE_TOKU_QUICKLZ: |
| 129 | return tokudb::sysvars::SRV_ROW_FORMAT_QUICKLZ; |
| 130 | case ROW_TYPE_TOKU_LZMA: |
| 131 | return tokudb::sysvars::SRV_ROW_FORMAT_LZMA; |
| 132 | case ROW_TYPE_TOKU_SMALL: |
| 133 | return tokudb::sysvars::SRV_ROW_FORMAT_SMALL; |
| 134 | case ROW_TYPE_TOKU_FAST: |
| 135 | return tokudb::sysvars::SRV_ROW_FORMAT_FAST; |
| 136 | case ROW_TYPE_DEFAULT: |
| 137 | return tokudb::sysvars::SRV_ROW_FORMAT_DEFAULT; |
| 138 | default: |
| 139 | return tokudb::sysvars::SRV_ROW_FORMAT_DEFAULT; |
| 140 | } |
| 141 | #endif |
| 142 | return tokudb::sysvars::SRV_ROW_FORMAT_DEFAULT; |
| 143 | } |
| 144 | |
| 145 | inline enum row_type toku_compression_method_to_row_type( |
| 146 | toku_compression_method method) { |
| 147 | |
| 148 | return row_format_to_row_type( |
| 149 | toku_compression_method_to_row_format(method)); |
| 150 | } |
| 151 | |
| 152 | inline toku_compression_method row_type_to_toku_compression_method( |
| 153 | enum row_type type) { |
| 154 | |
| 155 | return row_format_to_toku_compression_method(row_type_to_row_format(type)); |
| 156 | } |
| 157 | |
| 158 | void tokudb_checkpoint_lock(THD * thd); |
| 159 | void tokudb_checkpoint_unlock(THD * thd); |
| 160 | |
| 161 | inline uint64_t tokudb_get_lock_wait_time_callback(uint64_t default_wait_time) { |
| 162 | THD *thd = current_thd; |
| 163 | return tokudb::sysvars::lock_timeout(thd); |
| 164 | } |
| 165 | |
| 166 | inline uint64_t tokudb_get_loader_memory_size_callback(void) { |
| 167 | THD *thd = current_thd; |
| 168 | return tokudb::sysvars::loader_memory_size(thd); |
| 169 | } |
| 170 | |
| 171 | inline uint64_t tokudb_get_killed_time_callback(uint64_t default_killed_time) { |
| 172 | THD *thd = current_thd; |
| 173 | return tokudb::sysvars::killed_time(thd); |
| 174 | } |
| 175 | |
| 176 | inline int tokudb_killed_callback(void) { |
| 177 | THD *thd = current_thd; |
| 178 | return thd_kill_level(thd); |
| 179 | } |
| 180 | |
| 181 | inline bool tokudb_killed_thd_callback(void *, uint64_t deleted_rows) { |
| 182 | THD *thd = static_cast<THD *>(extra); |
| 183 | return thd_kill_level(thd) != 0; |
| 184 | } |
| 185 | |
| 186 | extern HASH tokudb_open_tables; |
| 187 | extern const char* tokudb_hton_name; |
| 188 | extern int tokudb_hton_initialized; |
| 189 | extern tokudb::thread::rwlock_t tokudb_hton_initialized_lock; |
| 190 | |
| 191 | void toku_hton_update_primary_key_bytes_inserted(uint64_t row_size); |
| 192 | |
| 193 | void tokudb_split_dname( |
| 194 | const char* dname, |
| 195 | String& database_name, |
| 196 | String& table_name, |
| 197 | String& dictionary_name); |
| 198 | |
| 199 | void tokudb_pretty_left_key(const DB* db, const DBT* key, String* out); |
| 200 | void tokudb_pretty_right_key(const DB* db, const DBT* key, String* out); |
| 201 | const char *tokudb_get_index_name(DB* db); |
| 202 | |
| 203 | #endif //#ifdef _HATOKU_HTON |
| 204 | |