You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
7.1 KiB

  1. #ifndef _HATOKU_DEF
  2. #define _HATOKU_DEF
  3. #include "mysql_version.h"
  4. #if MYSQL_VERSION_ID < 50506
  5. #include "mysql_priv.h"
  6. #else
  7. #include "sql_table.h"
  8. #include "handler.h"
  9. #include "table.h"
  10. #include "log.h"
  11. #include "sql_class.h"
  12. #include "sql_show.h"
  13. #include "discover.h"
  14. #endif
  15. #include "db.h"
  16. #include "toku_os.h"
  17. #ifdef USE_PRAGMA_INTERFACE
  18. #pragma interface /* gcc class implementation */
  19. #endif
  20. // In MariaDB 5.3, thread progress reporting was introduced.
  21. // Only include that functionality if we're using maria 5.3 +
  22. #ifdef MARIADB_BASE_VERSION
  23. #if MYSQL_VERSION_ID >= 50300
  24. #define HA_TOKUDB_HAS_THD_PROGRESS
  25. #endif
  26. #endif
  27. #if defined(TOKUDB_PATCHES) && TOKUDB_PATCHES == 0
  28. #elif 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099
  29. #define TOKU_INCLUDE_ALTER_56 0
  30. #define TOKU_INCLUDE_ALTER_55 0
  31. #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0
  32. #define TOKU_INCLUDE_XA 1
  33. #define TOKU_PARTITION_WRITE_FRM_DATA 0
  34. #define TOKU_INCLUDE_WRITE_FRM_DATA 0
  35. #elif 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699
  36. #define TOKU_INCLUDE_ALTER_56 1
  37. #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1
  38. #define TOKU_INCLUDE_XA 1
  39. #define TOKU_PARTITION_WRITE_FRM_DATA 1
  40. #define TOKU_INCLUDE_WRITE_FRM_DATA 1
  41. #define TOKU_INCLUDE_UPSERT 1
  42. #if DB_TYPE_TOKUDB_DEFINED
  43. #define TOKU_INCLUDE_EXTENDED_KEYS 1
  44. #endif
  45. #elif 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599
  46. #define TOKU_INCLUDE_ALTER_56 1
  47. #define TOKU_INCLUDE_ALTER_55 1
  48. #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1
  49. #define TOKU_INCLUDE_XA 1
  50. #define TOKU_PARTITION_WRITE_FRM_DATA 1
  51. #define TOKU_INCLUDE_WRITE_FRM_DATA 1
  52. #define TOKU_INCLUDE_UPSERT 1
  53. #if defined(MARIADB_BASE_VERSION) && DB_TYPE_TOKUDB_DEFINED
  54. #define TOKU_INCLUDE_EXTENDED_KEYS 1
  55. #endif
  56. #else
  57. #error
  58. #endif
  59. #if !defined(HA_CLUSTERING)
  60. #define HA_CLUSTERING 0
  61. #endif
  62. #if !defined(HA_CLUSTERED_INDEX)
  63. #define HA_CLUSTERED_INDEX 0
  64. #endif
  65. #if !defined(HA_CAN_WRITE_DURING_OPTIMIZE)
  66. #define HA_CAN_WRITE_DURING_OPTIMIZE 0
  67. #endif
  68. // In older (< 5.5) versions of MySQL and MariaDB, it is necessary to
  69. // use a read/write lock on the key_file array in a table share,
  70. // because table locks do not protect the race of some thread closing
  71. // a table and another calling ha_tokudb::info()
  72. //
  73. // In version 5.5 and, a higher layer "metadata lock" was introduced
  74. // to synchronize threads that open, close, call info(), etc on tables.
  75. // In these versions, we don't need the key_file lock
  76. #if MYSQL_VERSION_ID < 50500
  77. #define HA_TOKUDB_NEEDS_KEY_FILE_LOCK
  78. #endif
  79. extern ulong tokudb_debug;
  80. //
  81. // returns maximum length of dictionary name, such as key-NAME
  82. // NAME_CHAR_LEN is max length of the key name, and have upper bound of 10 for key-
  83. //
  84. #define MAX_DICT_NAME_LEN NAME_CHAR_LEN + 10
  85. // QQQ how to tune these?
  86. #define HA_TOKUDB_RANGE_COUNT 100
  87. /* extra rows for estimate_rows_upper_bound() */
  88. #define HA_TOKUDB_EXTRA_ROWS 100
  89. /* Bits for share->status */
  90. #define STATUS_PRIMARY_KEY_INIT 0x1
  91. // tokudb debug tracing
  92. #define TOKUDB_DEBUG_INIT 1
  93. #define TOKUDB_DEBUG_OPEN 2
  94. #define TOKUDB_DEBUG_ENTER 4
  95. #define TOKUDB_DEBUG_RETURN 8
  96. #define TOKUDB_DEBUG_ERROR 16
  97. #define TOKUDB_DEBUG_TXN 32
  98. #define TOKUDB_DEBUG_AUTO_INCREMENT 64
  99. #define TOKUDB_DEBUG_LOCK 256
  100. #define TOKUDB_DEBUG_LOCKRETRY 512
  101. #define TOKUDB_DEBUG_CHECK_KEY 1024
  102. #define TOKUDB_DEBUG_HIDE_DDL_LOCK_ERRORS 2048
  103. #define TOKUDB_DEBUG_ALTER_TABLE_INFO 4096
  104. #define TOKUDB_DEBUG_UPSERT 8192
  105. #define TOKUDB_DEBUG_CHECK (1<<14)
  106. #define TOKUDB_DEBUG_ANALYZE (1<<15)
  107. #define TOKUDB_TRACE(f, ...) \
  108. printf("%d:%s:%d:" f, my_tid(), __FILE__, __LINE__, ##__VA_ARGS__);
  109. static inline unsigned int my_tid() {
  110. return (unsigned int)toku_os_gettid();
  111. }
  112. #define TOKUDB_DBUG_ENTER(f, ...) \
  113. { \
  114. if (tokudb_debug & TOKUDB_DEBUG_ENTER) { \
  115. TOKUDB_TRACE(f "\n", ##__VA_ARGS__); \
  116. } \
  117. } \
  118. DBUG_ENTER(__FUNCTION__);
  119. #define TOKUDB_DBUG_RETURN(r) \
  120. { \
  121. int rr = (r); \
  122. if ((tokudb_debug & TOKUDB_DEBUG_RETURN) || (rr != 0 && (tokudb_debug & TOKUDB_DEBUG_ERROR))) { \
  123. TOKUDB_TRACE("%s:return %d\n", __FUNCTION__, rr); \
  124. } \
  125. DBUG_RETURN(rr); \
  126. }
  127. #define TOKUDB_DBUG_DUMP(s, p, len) \
  128. { \
  129. TOKUDB_TRACE("%s:%s", __FUNCTION__, s); \
  130. uint i; \
  131. for (i=0; i<len; i++) { \
  132. printf("%2.2x", ((uchar*)p)[i]); \
  133. } \
  134. printf("\n"); \
  135. }
  136. typedef enum {
  137. hatoku_iso_not_set = 0,
  138. hatoku_iso_read_uncommitted,
  139. hatoku_iso_read_committed,
  140. hatoku_iso_repeatable_read,
  141. hatoku_iso_serializable
  142. } HA_TOKU_ISO_LEVEL;
  143. typedef struct st_tokudb_stmt_progress {
  144. ulonglong inserted;
  145. ulonglong updated;
  146. ulonglong deleted;
  147. ulonglong queried;
  148. bool using_loader;
  149. } tokudb_stmt_progress;
  150. typedef struct st_tokudb_trx_data {
  151. DB_TXN *all;
  152. DB_TXN *stmt;
  153. DB_TXN *sp_level;
  154. DB_TXN *sub_sp_level;
  155. uint tokudb_lock_count;
  156. tokudb_stmt_progress stmt_progress;
  157. bool checkpoint_lock_taken;
  158. } tokudb_trx_data;
  159. extern char *tokudb_data_dir;
  160. extern const char *ha_tokudb_ext;
  161. static inline void reset_stmt_progress (tokudb_stmt_progress* val) {
  162. val->deleted = 0;
  163. val->inserted = 0;
  164. val->updated = 0;
  165. val->queried = 0;
  166. }
  167. static inline int get_name_length(const char *name) {
  168. int n = 0;
  169. const char *newname = name;
  170. n += strlen(newname);
  171. n += strlen(ha_tokudb_ext);
  172. return n;
  173. }
  174. //
  175. // returns maximum length of path to a dictionary
  176. //
  177. static inline int get_max_dict_name_path_length(const char *tablename) {
  178. int n = 0;
  179. n += get_name_length(tablename);
  180. n += 1; //for the '-'
  181. n += MAX_DICT_NAME_LEN;
  182. return n;
  183. }
  184. static inline void make_name(char *newname, const char *tablename, const char *dictname) {
  185. const char *newtablename = tablename;
  186. char *nn = newname;
  187. assert(tablename);
  188. assert(dictname);
  189. nn += sprintf(nn, "%s", newtablename);
  190. nn += sprintf(nn, "-%s", dictname);
  191. }
  192. static inline void commit_txn(DB_TXN* txn, uint32_t flags) {
  193. if (tokudb_debug & TOKUDB_DEBUG_TXN)
  194. TOKUDB_TRACE("commit_txn %p\n", txn);
  195. int r = txn->commit(txn, flags);
  196. if (r != 0) {
  197. sql_print_error("tried committing transaction %p and got error code %d", txn, r);
  198. }
  199. assert(r == 0);
  200. }
  201. static inline void abort_txn(DB_TXN* txn) {
  202. if (tokudb_debug & TOKUDB_DEBUG_TXN)
  203. TOKUDB_TRACE("abort_txn %p\n", txn);
  204. int r = txn->abort(txn);
  205. if (r != 0) {
  206. sql_print_error("tried aborting transaction %p and got error code %d", txn, r);
  207. }
  208. assert(r == 0);
  209. }
  210. /* The purpose of this file is to define assert() for use by the handlerton.
  211. * The intention is for a failed handlerton assert to invoke a failed assert
  212. * in the fractal tree layer, which dumps engine status to the error log.
  213. */
  214. void toku_hton_assert_fail(const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default"))) __attribute__((__noreturn__));
  215. #undef assert
  216. #define assert(expr) ((expr) ? (void)0 : toku_hton_assert_fail(#expr, __FUNCTION__, __FILE__, __LINE__, errno))
  217. #endif