diff options
Diffstat (limited to 'storage/tokudb/hatoku_defines.h')
-rw-r--r-- | storage/tokudb/hatoku_defines.h | 279 |
1 files changed, 203 insertions, 76 deletions
diff --git a/storage/tokudb/hatoku_defines.h b/storage/tokudb/hatoku_defines.h index 10350d6791f..650fd0257a3 100644 --- a/storage/tokudb/hatoku_defines.h +++ b/storage/tokudb/hatoku_defines.h @@ -88,70 +88,47 @@ PATENT RIGHTS GRANT: #ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved." #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." -#ifndef _HATOKU_DEF -#define _HATOKU_DEF -#include "mysql_version.h" -#if MYSQL_VERSION_ID < 50506 -#include "mysql_priv.h" -#else -#include "sql_table.h" -#include "handler.h" -#include "table.h" -#include "log.h" -#include "sql_class.h" -#include "sql_show.h" -#include "discover.h" -#endif - -#include "db.h" -#include "toku_os.h" +#ifndef _TOKUDB_CONFIG_H +#define _TOKUDB_CONFIG_H #ifdef USE_PRAGMA_INTERFACE #pragma interface /* gcc class implementation */ #endif -// In MariaDB 5.3, thread progress reporting was introduced. -// Only include that functionality if we're using maria 5.3 + -#ifdef MARIADB_BASE_VERSION -#if MYSQL_VERSION_ID >= 50300 -#define HA_TOKUDB_HAS_THD_PROGRESS -#endif -#endif - -#if defined(TOKUDB_PATCHES) && TOKUDB_PATCHES == 0 - -#elif 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099 +#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099 +// mariadb 10 +#define TOKU_USE_DB_TYPE_TOKUDB 1 #define TOKU_INCLUDE_ALTER_56 1 -#define TOKU_INCLUDE_ALTER_55 0 #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 #define TOKU_INCLUDE_XA 1 -#define TOKU_PARTITION_WRITE_FRM_DATA 0 #define TOKU_INCLUDE_WRITE_FRM_DATA 0 -#define TOKU_INCLUDE_UPSERT 0 +#define TOKU_PARTITION_WRITE_FRM_DATA 0 +#if defined(MARIADB_BASE_VERSION) #define TOKU_INCLUDE_EXTENDED_KEYS 1 -#define TOKU_INCLUDE_OTHER_DB_TYPE 0 +#endif -#elif 50613 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 +#elif 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 +// mysql 5.7 with no patches +#define TOKU_USE_DB_TYPE_UNKNOWN 1 #define TOKU_INCLUDE_ALTER_56 1 -#define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 -#define TOKU_INCLUDE_XA 1 #define TOKU_PARTITION_WRITE_FRM_DATA 0 -#define TOKU_INCLUDE_WRITE_FRM_DATA 0 -#define TOKU_INCLUDE_UPSERT 1 -#define TOKU_INCLUDE_EXTENDED_KEYS 0 -#elif 50610 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50610 +#elif 50613 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 +// mysql 5.6 +#define TOKU_USE_DB_TYPE_TOKUDB 1 #define TOKU_INCLUDE_ALTER_56 1 #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 #define TOKU_INCLUDE_XA 1 -#define TOKU_PARTITION_WRITE_FRM_DATA 1 -#define TOKU_INCLUDE_WRITE_FRM_DATA 1 +#define TOKU_PARTITION_WRITE_FRM_DATA 0 +#define TOKU_INCLUDE_WRITE_FRM_DATA 0 #define TOKU_INCLUDE_UPSERT 1 +#if defined(HTON_SUPPORTS_EXTENDED_KEYS) #define TOKU_INCLUDE_EXTENDED_KEYS 1 -#define TOKU_INCLUDE_OTHER_DB_TYPE 0 +#endif #elif 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599 +#define TOKU_USE_DB_TYPE_TOKUDB 1 #define TOKU_INCLUDE_ALTER_56 0 /* MariaDB 5.5 */ #define TOKU_INCLUDE_ALTER_55 0 /* MariaDB 5.5 */ #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 @@ -162,14 +139,26 @@ PATENT RIGHTS GRANT: #if defined(MARIADB_BASE_VERSION) #define TOKU_INCLUDE_EXTENDED_KEYS 1 #endif -#define TOKU_INCLUDE_OTHER_DB_TYPE 0 /* MariaDB 5.5 */ #define TOKU_INCLUDE_HANDLERTON_HANDLE_FATAL_SIGNAL 0 /* MariaDB 5.5 */ -#else +#else #error #endif +#ifdef MARIADB_BASE_VERSION +// In MariaDB 5.3, thread progress reporting was introduced. +// Only include that functionality if we're using maria 5.3 + +#define HA_TOKUDB_HAS_THD_PROGRESS 1 + +// MariaDB supports thdvar memalloc correctly +#define TOKU_THDVAR_MEMALLOC_BUG 0 +#else +// MySQL does not support thdvar memalloc correctly +// see http://bugs.mysql.com/bug.php?id=71759 +#define TOKU_THDVAR_MEMALLOC_BUG 1 +#endif + #if !defined(HA_CLUSTERING) #define HA_CLUSTERING 0 #endif @@ -182,10 +171,6 @@ PATENT RIGHTS GRANT: #define HA_CAN_WRITE_DURING_OPTIMIZE 0 #endif -#if !defined(HA_OPTION_CREATE_FROM_ENGINE) -#define HA_OPTION_CREATE_FROM_ENGINE 0 -#endif - // In older (< 5.5) versions of MySQL and MariaDB, it is necessary to // use a read/write lock on the key_file array in a table share, // because table locks do not protect the race of some thread closing @@ -198,8 +183,6 @@ PATENT RIGHTS GRANT: #define HA_TOKUDB_NEEDS_KEY_FILE_LOCK #endif -extern ulong tokudb_debug; - // // returns maximum length of dictionary name, such as key-NAME // NAME_CHAR_LEN is max length of the key name, and have upper bound of 10 for key- @@ -214,6 +197,13 @@ extern ulong tokudb_debug; /* Bits for share->status */ #define STATUS_PRIMARY_KEY_INIT 0x1 +#endif // _TOKUDB_CONFIG_H + +#ifndef _TOKUDB_DEBUG_H +#define _TOKUDB_DEBUG_H + +extern ulong tokudb_debug; + // tokudb debug tracing #define TOKUDB_DEBUG_INIT 1 #define TOKUDB_DEBUG_OPEN 2 @@ -225,40 +215,62 @@ extern ulong tokudb_debug; #define TOKUDB_DEBUG_LOCK 256 #define TOKUDB_DEBUG_CHECK_KEY 1024 #define TOKUDB_DEBUG_HIDE_DDL_LOCK_ERRORS 2048 -#define TOKUDB_DEBUG_ALTER_TABLE_INFO 4096 +#define TOKUDB_DEBUG_ALTER_TABLE 4096 #define TOKUDB_DEBUG_UPSERT 8192 #define TOKUDB_DEBUG_CHECK (1<<14) #define TOKUDB_DEBUG_ANALYZE (1<<15) -#define TOKUDB_TRACE(f, ...) \ - fprintf(stderr, "%d:%s:%d:" f, my_tid(), __FILE__, __LINE__, ##__VA_ARGS__); - +#define TOKUDB_TRACE(f, ...) { \ + fprintf(stderr, "%u %s:%u %s " f "\n", my_tid(), __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ +} static inline unsigned int my_tid() { return (unsigned int)toku_os_gettid(); } -#define TOKUDB_DBUG_ENTER(f, ...) \ -{ \ +#define TOKUDB_DBUG_ENTER(f, ...) { \ if (tokudb_debug & TOKUDB_DEBUG_ENTER) { \ - TOKUDB_TRACE(f "\n", ##__VA_ARGS__); \ + TOKUDB_TRACE(f, ##__VA_ARGS__); \ } \ } \ DBUG_ENTER(__FUNCTION__); +#define TOKUDB_DBUG_RETURN(r) { \ + int rr = (r); \ + if ((tokudb_debug & TOKUDB_DEBUG_RETURN) || (rr != 0 && (tokudb_debug & TOKUDB_DEBUG_ERROR))) { \ + TOKUDB_TRACE("return %d", rr); \ + } \ + DBUG_RETURN(rr); \ +} + +#define TOKUDB_HANDLER_TRACE(f, ...) \ + fprintf(stderr, "%u %p %s:%u ha_tokudb::%s " f "\n", my_tid(), this, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); -#define TOKUDB_DBUG_RETURN(r) \ -{ \ +#define TOKUDB_HANDLER_DBUG_ENTER(f, ...) { \ + if (tokudb_debug & TOKUDB_DEBUG_ENTER) { \ + TOKUDB_HANDLER_TRACE(f, ##__VA_ARGS__); \ + } \ +} \ + DBUG_ENTER(__FUNCTION__); + +#define TOKUDB_HANDLER_DBUG_RETURN(r) { \ int rr = (r); \ if ((tokudb_debug & TOKUDB_DEBUG_RETURN) || (rr != 0 && (tokudb_debug & TOKUDB_DEBUG_ERROR))) { \ - TOKUDB_TRACE("%s:return %d\n", __FUNCTION__, rr); \ + TOKUDB_HANDLER_TRACE("return %d", rr); \ } \ DBUG_RETURN(rr); \ } +#define TOKUDB_HANDLER_DBUG_VOID_RETURN { \ + if (tokudb_debug & TOKUDB_DEBUG_RETURN) { \ + TOKUDB_HANDLER_TRACE("return"); \ + } \ + DBUG_VOID_RETURN; \ +} + #define TOKUDB_DBUG_DUMP(s, p, len) \ { \ - TOKUDB_TRACE("%s:%s", __FUNCTION__, s); \ + TOKUDB_TRACE("%s", s); \ uint i; \ for (i=0; i<len; i++) { \ fprintf(stderr, "%2.2x", ((uchar*)p)[i]); \ @@ -266,6 +278,20 @@ static inline unsigned int my_tid() { fprintf(stderr, "\n"); \ } +/* The purpose of this file is to define assert() for use by the handlerton. + * The intention is for a failed handlerton assert to invoke a failed assert + * in the fractal tree layer, which dumps engine status to the error log. + */ + +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__)); + +#undef assert +#define assert(expr) ((expr) ? (void)0 : toku_hton_assert_fail(#expr, __FUNCTION__, __FILE__, __LINE__, errno)) + +#endif // _TOKUDB_DEBUG_H + +#ifndef _TOKUDB_TXN_H +#define _TOKUDB_TXN_H typedef enum { hatoku_iso_not_set = 0, @@ -294,6 +320,7 @@ typedef struct st_tokudb_trx_data { uint tokudb_lock_count; tokudb_stmt_progress stmt_progress; bool checkpoint_lock_taken; + LIST *handlers; } tokudb_trx_data; struct ha_table_option_struct @@ -301,11 +328,6 @@ struct ha_table_option_struct uint row_format; }; -struct ha_index_option_struct -{ - bool clustering; -}; - extern char *tokudb_data_dir; extern const char *ha_tokudb_ext; @@ -352,14 +374,14 @@ static inline int txn_begin(DB_ENV *env, DB_TXN *parent, DB_TXN **txn, uint32_t this_txn->set_client_id(this_txn, thd_get_thread_id(thd)); } if ((tokudb_debug & TOKUDB_DEBUG_TXN)) { - TOKUDB_TRACE("begin txn %p %p %u r=%d\n", parent, *txn, flags, r); + TOKUDB_TRACE("begin txn %p %p %u r=%d", parent, *txn, flags, r); } return r; } static inline void commit_txn(DB_TXN* txn, uint32_t flags) { if (tokudb_debug & TOKUDB_DEBUG_TXN) - TOKUDB_TRACE("commit txn %p\n", txn); + TOKUDB_TRACE("commit txn %p", txn); int r = txn->commit(txn, flags); if (r != 0) { sql_print_error("tried committing transaction %p and got error code %d", txn, r); @@ -369,7 +391,7 @@ static inline void commit_txn(DB_TXN* txn, uint32_t flags) { static inline void abort_txn(DB_TXN* txn) { if (tokudb_debug & TOKUDB_DEBUG_TXN) - TOKUDB_TRACE("abort txn %p\n", txn); + TOKUDB_TRACE("abort txn %p", txn); int r = txn->abort(txn); if (r != 0) { sql_print_error("tried aborting transaction %p and got error code %d", txn, r); @@ -377,14 +399,119 @@ static inline void abort_txn(DB_TXN* txn) { assert(r == 0); } -/* The purpose of this file is to define assert() for use by the handlerton. - * The intention is for a failed handlerton assert to invoke a failed assert - * in the fractal tree layer, which dumps engine status to the error log. - */ +#endif // _TOKUDB_TXN_H -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__)); +#ifndef _TOKUDB_PORTABILITY_H +#define _TOKUDB_PORTABILITY_H -#undef assert -#define assert(expr) ((expr) ? (void)0 : toku_hton_assert_fail(#expr, __FUNCTION__, __FILE__, __LINE__, errno)) +static inline void *tokudb_my_malloc(size_t s, myf flags) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + return my_malloc(0, s, flags); +#else + return my_malloc(s, flags); +#endif +} +static inline void *tokudb_my_realloc(void *p, size_t s, myf flags) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + return my_realloc(0, p, s, flags); +#else + return my_realloc(p, s, flags); #endif +} + +static inline void tokudb_my_free(void *ptr) { + my_free(ptr); +} + +static inline char *tokudb_my_strdup(const char *p, myf flags) { +#if 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799 + return my_strdup(0, p, flags); +#else + return my_strdup(p, flags); +#endif +} + +static inline void* tokudb_my_multi_malloc(myf myFlags, ...) { + va_list args; + char **ptr,*start,*res; + size_t tot_length,length; + + va_start(args,myFlags); + tot_length=0; + while ((ptr=va_arg(args, char **))) { + length=va_arg(args,uint); + tot_length+=ALIGN_SIZE(length); + } + va_end(args); + + if (!(start=(char *) tokudb_my_malloc(tot_length,myFlags))) { + return 0; + } + + va_start(args,myFlags); + res=start; + while ((ptr=va_arg(args, char **))) { + *ptr=res; + length=va_arg(args,uint); + res+=ALIGN_SIZE(length); + } + va_end(args); + return start; +} + +static inline void tokudb_pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { + int r = pthread_mutex_init(mutex, attr); + assert(r == 0); +} + +static inline void tokudb_pthread_mutex_destroy(pthread_mutex_t *mutex) { + int r = pthread_mutex_destroy(mutex); + assert(r == 0); +} + +static inline void tokudb_pthread_mutex_lock(pthread_mutex_t *mutex) { + int r = pthread_mutex_lock(mutex); + assert(r == 0); +} + +static inline void tokudb_pthread_mutex_unlock(pthread_mutex_t *mutex) { + int r = pthread_mutex_unlock(mutex); + assert(r == 0); +} + +static inline void tokudb_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { + int r = pthread_cond_init(cond, attr); + assert(r == 0); +} + +static inline void tokudb_pthread_cond_destroy(pthread_cond_t *cond) { + int r = pthread_cond_destroy(cond); + assert(r == 0); +} + +static inline void tokudb_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { + int r = pthread_cond_wait(cond, mutex); + assert(r == 0); +} + +static inline void tokudb_pthread_cond_broadcast(pthread_cond_t *cond) { + int r = pthread_cond_broadcast(cond); + assert(r == 0); +} + +// mysql 5.6.15 removed the test macro, so we define our own +#define tokudb_test(e) ((e) ? 1 : 0) + +static const char *tokudb_thd_get_proc_info(THD *thd) { + return thd->proc_info; +} + +// uint3korr reads 4 bytes and valgrind reports an error, so we use this function instead +static uint tokudb_uint3korr(const uchar *a) { + uchar b[4] = {}; + memcpy(b, a, 3); + return uint3korr(b); +} + +#endif // _TOKUDB_PORTABILITY_H |