diff options
Diffstat (limited to 'storage/tokudb/hatoku_hton.cc')
-rw-r--r-- | storage/tokudb/hatoku_hton.cc | 295 |
1 files changed, 153 insertions, 142 deletions
diff --git a/storage/tokudb/hatoku_hton.cc b/storage/tokudb/hatoku_hton.cc index 538f6c936d2..2291f2345bb 100644 --- a/storage/tokudb/hatoku_hton.cc +++ b/storage/tokudb/hatoku_hton.cc @@ -126,7 +126,12 @@ typedef struct savepoint_info { bool in_sub_stmt; } *SP_INFO, SP_INFO_T; -#if defined(MARIADB_BASE_VERSION) +#if TOKU_INCLUDE_OPTION_STRUCTS +ha_create_table_option tokudb_table_options[] = { + HA_TOPTION_SYSVAR("compression", row_format, row_format), + HA_TOPTION_END +}; + ha_create_table_option tokudb_index_options[] = { HA_IOPTION_BOOL("clustering", clustering, 0), HA_IOPTION_END @@ -162,10 +167,12 @@ static int tokudb_rollback_by_xid(handlerton* hton, XID* xid); static int tokudb_rollback_to_savepoint(handlerton * hton, THD * thd, void *savepoint); static int tokudb_savepoint(handlerton * hton, THD * thd, void *savepoint); static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoint); +#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099 static int tokudb_discover_table(handlerton *hton, THD* thd, TABLE_SHARE *ts); static int tokudb_discover_table_existence(handlerton *hton, const char *db, const char *name); +#endif static int tokudb_discover(handlerton *hton, THD* thd, const char *db, const char *name, uchar **frmblob, size_t *frmlen); -static int tokudb_discover2(handlerton *hton, THD* thd, const char *db, const char *name, bool translate_name,uchar **frmblob, size_t *frmlen); +static int tokudb_discover2(handlerton *hton, THD* thd, const char *db, const char *name, bool translate_name, uchar **frmblob, size_t *frmlen); static int tokudb_discover3(handlerton *hton, THD* thd, const char *db, const char *name, char *path, uchar **frmblob, size_t *frmlen); handlerton *tokudb_hton; @@ -269,12 +276,6 @@ extern "C" { } #endif -ha_create_table_option tokudb_table_options[]= -{ - HA_TOPTION_SYSVAR("compression", row_format, row_format), - HA_TOPTION_END -}; - // A flag set if the handlerton is in an initialized, usable state, // plus a reader-write lock to protect it without serializing reads. // Since we don't have static initializers for the opaque rwlock type, @@ -300,49 +301,46 @@ static TOKU_ENGINE_STATUS_ROW_S* toku_global_status_rows = NULL; static void handle_ydb_error(int error) { switch (error) { case TOKUDB_HUGE_PAGES_ENABLED: - fprintf(stderr, "************************************************************\n"); - fprintf(stderr, " \n"); - fprintf(stderr, " @@@@@@@@@@@ \n"); - fprintf(stderr, " @@' '@@ \n"); - fprintf(stderr, " @@ _ _ @@ \n"); - fprintf(stderr, " | (.) (.) | \n"); - fprintf(stderr, " | ` | \n"); - fprintf(stderr, " | > ' | \n"); - fprintf(stderr, " | .----. | \n"); - fprintf(stderr, " .. |.----.| .. \n"); - fprintf(stderr, " .. ' ' .. \n"); - fprintf(stderr, " .._______,. \n"); - fprintf(stderr, " \n"); - fprintf(stderr, " %s will not run with transparent huge pages enabled. \n", tokudb_hton_name); - fprintf(stderr, " Please disable them to continue. \n"); - fprintf(stderr, " (echo never > /sys/kernel/mm/transparent_hugepage/enabled) \n"); - fprintf(stderr, " \n"); - fprintf(stderr, "************************************************************\n"); - fflush(stderr); + sql_print_error("************************************************************"); + sql_print_error(" "); + sql_print_error(" @@@@@@@@@@@ "); + sql_print_error(" @@' '@@ "); + sql_print_error(" @@ _ _ @@ "); + sql_print_error(" | (.) (.) | "); + sql_print_error(" | ` | "); + sql_print_error(" | > ' | "); + sql_print_error(" | .----. | "); + sql_print_error(" .. |.----.| .. "); + sql_print_error(" .. ' ' .. "); + sql_print_error(" .._______,. "); + sql_print_error(" "); + sql_print_error("%s will not run with transparent huge pages enabled. ", tokudb_hton_name); + sql_print_error("Please disable them to continue. "); + sql_print_error("(echo never > /sys/kernel/mm/transparent_hugepage/enabled) "); + sql_print_error(" "); + sql_print_error("************************************************************"); break; } } static int tokudb_init_func(void *p) { - TOKUDB_DBUG_ENTER(""); + TOKUDB_DBUG_ENTER("%p", p); int r; -#if defined(_WIN64) - r = toku_ydb_init(); - if (r) { - fprintf(stderr, "got error %d\n", r); - goto error; - } -#endif - // 3938: lock the handlerton's initialized status flag for writing r = rw_wrlock(&tokudb_hton_initialized_lock); assert(r == 0); db_env = NULL; - tokudb_hton = (handlerton *) p; +#if TOKUDB_CHECK_JEMALLOC + if (tokudb_check_jemalloc && dlsym(RTLD_DEFAULT, "mallctl") == NULL) { + sql_print_error("%s not initialized because jemalloc is not loaded", tokudb_hton_name); + goto error; + } +#endif + tokudb_pthread_mutex_init(&tokudb_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(&tokudb_open_tables, table_alias_charset, 32, 0, 0, (my_hash_get_key) tokudb_get_key, 0, 0); @@ -378,11 +376,15 @@ static int tokudb_init_func(void *p) { tokudb_hton->savepoint_rollback = tokudb_rollback_to_savepoint; tokudb_hton->savepoint_release = tokudb_release_savepoint; +#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099 tokudb_hton->discover_table = tokudb_discover_table; tokudb_hton->discover_table_existence = tokudb_discover_table_existence; +#else + tokudb_hton->discover = tokudb_discover; #if defined(MYSQL_HANDLERTON_INCLUDE_DISCOVER2) tokudb_hton->discover2 = tokudb_discover2; #endif +#endif tokudb_hton->commit = tokudb_commit; tokudb_hton->rollback = tokudb_rollback; #if TOKU_INCLUDE_XA @@ -402,7 +404,8 @@ static int tokudb_init_func(void *p) { tokudb_hton->handle_fatal_signal = tokudb_handle_fatal_signal; #endif -#if defined(MARIADB_BASE_VERSION) +#if TOKU_INCLUDE_OPTION_STRUCTS + tokudb_hton->table_options = tokudb_table_options; tokudb_hton->index_options = tokudb_index_options; #endif @@ -438,19 +441,18 @@ static int tokudb_init_func(void *p) { } { - char *tmp_dir = tokudb_tmp_dir; - char *data_dir = tokudb_data_dir; - if (data_dir == 0) { - data_dir = mysql_data_home; - } - if (tmp_dir == 0) { - tmp_dir = data_dir; - } - DBUG_PRINT("info", ("tokudb_data_dir: %s\n", data_dir)); - db_env->set_data_dir(db_env, data_dir); - - DBUG_PRINT("info", ("tokudb_tmp_dir: %s\n", tmp_dir)); - db_env->set_tmp_dir(db_env, tmp_dir); + char *tmp_dir = tokudb_tmp_dir; + char *data_dir = tokudb_data_dir; + if (data_dir == 0) { + data_dir = mysql_data_home; + } + if (tmp_dir == 0) { + tmp_dir = data_dir; + } + DBUG_PRINT("info", ("tokudb_data_dir: %s\n", data_dir)); + db_env->set_data_dir(db_env, data_dir); + DBUG_PRINT("info", ("tokudb_tmp_dir: %s\n", tmp_dir)); + db_env->set_tmp_dir(db_env, tmp_dir); } if (tokudb_log_dir) { @@ -627,9 +629,6 @@ static int tokudb_close_connection(handlerton * hton, THD * thd) { int error = 0; tokudb_trx_data* trx = NULL; trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot); - if (tokudb_debug & TOKUDB_DEBUG_TXN) { - TOKUDB_TRACE("trx %p", trx); - } if (trx && trx->checkpoint_lock_taken) { error = db_env->checkpointing_resume(db_env); } @@ -639,7 +638,6 @@ static int tokudb_close_connection(handlerton * hton, THD * thd) { struct tokudb_map_pair key = { thd, NULL }; struct tokudb_map_pair *found_key = (struct tokudb_map_pair *) tree_search(&tokudb_map, &key, NULL); if (found_key) { - if (0) TOKUDB_TRACE("thd %p %p", thd, found_key->last_lock_timeout); tokudb_my_free(found_key->last_lock_timeout); tree_delete(&tokudb_map, found_key, sizeof *found_key, NULL); } @@ -733,7 +731,7 @@ static int tokudb_commit(handlerton * hton, THD * thd, bool all) { DB_TXN *this_txn = *txn; if (this_txn) { if (tokudb_debug & TOKUDB_DEBUG_TXN) { - TOKUDB_TRACE("commit trx %u trx %p txn %p", all, trx, this_txn); + TOKUDB_TRACE("commit trx %u txn %p", all, this_txn); } // test hook to induce a crash on a debug build DBUG_EXECUTE_IF("tokudb_crash_commit_before", DBUG_SUICIDE();); @@ -762,7 +760,7 @@ static int tokudb_rollback(handlerton * hton, THD * thd, bool all) { DB_TXN *this_txn = *txn; if (this_txn) { if (tokudb_debug & TOKUDB_DEBUG_TXN) { - TOKUDB_TRACE("rollback %u trx %p txn %p", all, trx, this_txn); + TOKUDB_TRACE("rollback %u txn %p", all, this_txn); } tokudb_cleanup_handlers(trx, this_txn); abort_txn_with_progress(this_txn, thd); @@ -933,26 +931,28 @@ static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoin TOKUDB_DBUG_RETURN(error); } +#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099 static int tokudb_discover_table(handlerton *hton, THD* thd, TABLE_SHARE *ts) { - uchar *frmblob = 0; - size_t frmlen; - int res= tokudb_discover3(hton, thd, ts->db.str, ts->table_name.str, - ts->normalized_path.str, &frmblob, &frmlen); - if (!res) - res= ts->init_from_binary_frm_image(thd, true, frmblob, frmlen); - - my_free(frmblob); - // discover_table should returns HA_ERR_NO_SUCH_TABLE for "not exists" - return res == ENOENT ? HA_ERR_NO_SUCH_TABLE : res; + uchar *frmblob = 0; + size_t frmlen; + int res= tokudb_discover3(hton, thd, ts->db.str, ts->table_name.str, + ts->normalized_path.str, &frmblob, &frmlen); + if (!res) + res= ts->init_from_binary_frm_image(thd, true, frmblob, frmlen); + + my_free(frmblob); + // discover_table should returns HA_ERR_NO_SUCH_TABLE for "not exists" + return res == ENOENT ? HA_ERR_NO_SUCH_TABLE : res; } static int tokudb_discover_table_existence(handlerton *hton, const char *db, const char *name) { - uchar *frmblob = 0; - size_t frmlen; - int res= tokudb_discover(hton, current_thd, db, name, &frmblob, &frmlen); - my_free(frmblob); - return res != ENOENT; + uchar *frmblob = 0; + size_t frmlen; + int res= tokudb_discover(hton, current_thd, db, name, &frmblob, &frmlen); + my_free(frmblob); + return res != ENOENT; } +#endif static int tokudb_discover(handlerton *hton, THD* thd, const char *db, const char *name, uchar **frmblob, size_t *frmlen) { return tokudb_discover2(hton, thd, db, name, true, frmblob, frmlen); @@ -967,28 +967,30 @@ static int tokudb_discover2(handlerton *hton, THD* thd, const char *db, const ch static int tokudb_discover3(handlerton *hton, THD* thd, const char *db, const char *name, char *path, uchar **frmblob, size_t *frmlen) { - TOKUDB_DBUG_ENTER("%s %s", db, name); + TOKUDB_DBUG_ENTER("%s %s %s", db, name, path); int error; DB* status_db = NULL; DB_TXN* txn = NULL; HA_METADATA_KEY curr_key = hatoku_frm_data; - DBT key, value; - tokudb_trx_data *trx = NULL; - bool do_commit = false; + DBT key = {}; + DBT value = {}; + bool do_commit; - memset(&key, 0, sizeof(key)); - memset(&value, 0, sizeof(&value)); - - trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot); - +#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099 + tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot); if (thd_sql_command(thd) == SQLCOM_CREATE_TABLE && trx && trx->sub_sp_level) { + do_commit = false; txn = trx->sub_sp_level; - } - else { - do_commit = true; + } else { error = txn_begin(db_env, 0, &txn, 0, thd); - if (error) { goto cleanup; } + if (error) { goto cleanup; } + do_commit = true; } +#else + error = txn_begin(db_env, 0, &txn, 0, thd); + if (error) { goto cleanup; } + do_commit = true; +#endif error = open_status_dictionary(&status_db, path, txn); if (error) { goto cleanup; } @@ -1017,7 +1019,7 @@ cleanup: status_db->close(status_db,0); } if (do_commit && txn) { - commit_txn(txn,0); + commit_txn(txn, 0); } TOKUDB_DBUG_RETURN(error); } @@ -1094,24 +1096,24 @@ static bool tokudb_show_engine_status(THD * thd, stat_print_fn * stat_print) { case CHARSTR: snprintf(buf, bufsiz, "%s", mystat[row].value.str); break; - case UNIXTIME: - { - time_t t = mystat[row].value.num; - char tbuf[26]; - snprintf(buf, bufsiz, "%.24s", ctime_r(&t, tbuf)); - } + case UNIXTIME: { + time_t t = mystat[row].value.num; + char tbuf[26]; + snprintf(buf, bufsiz, "%.24s", ctime_r(&t, tbuf)); break; - case TOKUTIME: - { - double t = tokutime_to_seconds(mystat[row].value.num); - snprintf(buf, bufsiz, "%.6f", t); - } + } + case TOKUTIME: { + double t = tokutime_to_seconds(mystat[row].value.num); + snprintf(buf, bufsiz, "%.6f", t); break; - case PARCOUNT: - { - uint64_t v = read_partitioned_counter(mystat[row].value.parcount); - snprintf(buf, bufsiz, "%" PRIu64, v); - } + } + case PARCOUNT: { + uint64_t v = read_partitioned_counter(mystat[row].value.parcount); + snprintf(buf, bufsiz, "%" PRIu64, v); + break; + } + case DOUBLE: + snprintf(buf, bufsiz, "%.6f", mystat[row].value.dnum); break; default: snprintf(buf, bufsiz, "UNKNOWN STATUS TYPE: %d", mystat[row].type); @@ -1335,7 +1337,6 @@ static void tokudb_fsync_log_period_update(THD *thd, struct st_mysql_sys_var *sy static MYSQL_SYSVAR_UINT(fsync_log_period, tokudb_fsync_log_period, 0, "TokuDB fsync log period", NULL, tokudb_fsync_log_period_update, 0, 0, ~0U, 0); - static struct st_mysql_sys_var *tokudb_system_variables[] = { MYSQL_SYSVAR(cache_size), MYSQL_SYSVAR(max_lock_memory), @@ -1383,6 +1384,10 @@ static struct st_mysql_sys_var *tokudb_system_variables[] = { MYSQL_SYSVAR(loader_memory_size), MYSQL_SYSVAR(hide_default_row_format), MYSQL_SYSVAR(killed_time), + MYSQL_SYSVAR(empty_scan), +#if TOKUDB_CHECK_JEMALLOC + MYSQL_SYSVAR(check_jemalloc), +#endif NULL }; @@ -1947,7 +1952,6 @@ static void tokudb_lock_timeout_callback(DB *db, uint64_t requesting_txnid, cons THDVAR(thd, last_lock_timeout) = new_lock_timeout; tokudb_my_free(old_lock_timeout); #if TOKU_THDVAR_MEMALLOC_BUG - if (0) TOKUDB_TRACE("thd %p %p %p", thd, old_lock_timeout, new_lock_timeout); tokudb_pthread_mutex_lock(&tokudb_map_mutex); struct tokudb_map_pair old_key = { thd, old_lock_timeout }; tree_delete(&tokudb_map, &old_key, sizeof old_key, NULL); @@ -2205,42 +2209,39 @@ static int show_tokudb_vars(THD *thd, SHOW_VAR *var, char *buff) { status_var.type = SHOW_CHAR; status_var.value = (char*)status_row.value.str; break; - case UNIXTIME: - { - status_var.type = SHOW_CHAR; - time_t t = status_row.value.num; - char tbuf[26]; - // Reuse the memory in status_row. (It belongs to us). - snprintf(status_row.value.datebuf, sizeof(status_row.value.datebuf), "%.24s", ctime_r(&t, tbuf)); - status_var.value = (char*)&status_row.value.datebuf[0]; - } + case UNIXTIME: { + status_var.type = SHOW_CHAR; + time_t t = status_row.value.num; + char tbuf[26]; + // Reuse the memory in status_row. (It belongs to us). + snprintf(status_row.value.datebuf, sizeof(status_row.value.datebuf), "%.24s", ctime_r(&t, tbuf)); + status_var.value = (char*)&status_row.value.datebuf[0]; break; + } case TOKUTIME: - { - status_var.type = SHOW_DOUBLE; - double t = tokutime_to_seconds(status_row.value.num); - // Reuse the memory in status_row. (It belongs to us). - status_row.value.dnum = t; - status_var.value = (char*)&status_row.value.dnum; - } + status_var.type = SHOW_DOUBLE; + // Reuse the memory in status_row. (It belongs to us). + status_row.value.dnum = tokutime_to_seconds(status_row.value.num); + status_var.value = (char*)&status_row.value.dnum; break; - case PARCOUNT: - { - status_var.type = SHOW_LONGLONG; - uint64_t v = read_partitioned_counter(status_row.value.parcount); - // Reuse the memory in status_row. (It belongs to us). - status_row.value.num = v; - status_var.value = (char*)&status_row.value.num; - } + case PARCOUNT: { + status_var.type = SHOW_LONGLONG; + uint64_t v = read_partitioned_counter(status_row.value.parcount); + // Reuse the memory in status_row. (It belongs to us). + status_row.value.num = v; + status_var.value = (char*)&status_row.value.num; + break; + } + case DOUBLE: + status_var.type = SHOW_DOUBLE; + status_var.value = (char*) &status_row.value.dnum; break; default: - { - status_var.type = SHOW_CHAR; - // Reuse the memory in status_row.datebuf. (It belongs to us). - // UNKNOWN TYPE: %d fits in 26 bytes (sizeof datebuf) for any integer. - snprintf(status_row.value.datebuf, sizeof(status_row.value.datebuf), "UNKNOWN TYPE: %d", status_row.type); - status_var.value = (char*)&status_row.value.datebuf[0]; - } + status_var.type = SHOW_CHAR; + // Reuse the memory in status_row.datebuf. (It belongs to us). + // UNKNOWN TYPE: %d fits in 26 bytes (sizeof datebuf) for any integer. + snprintf(status_row.value.datebuf, sizeof(status_row.value.datebuf), "UNKNOWN TYPE: %d", status_row.type); + status_var.value = (char*)&status_row.value.datebuf[0]; break; } } @@ -2261,6 +2262,16 @@ static SHOW_VAR toku_global_status_variables_export[]= { {NullS, NullS, SHOW_LONG} }; +#if TOKU_INCLUDE_BACKTRACE +#include <execinfo.h> +static void tokudb_backtrace(void) { + const int N_POINTERS = 30; + void *backtrace_pointers[N_POINTERS]; + int n = backtrace(backtrace_pointers, N_POINTERS); + backtrace_symbols_fd(backtrace_pointers, n, fileno(stderr)); +} +#endif + mysql_declare_plugin(tokudb) { MYSQL_STORAGE_ENGINE_PLUGIN, @@ -2399,7 +2410,7 @@ maria_declare_plugin(tokudb) toku_global_status_variables_export, /* status variables */ tokudb_system_variables, /* system variables */ TOKUDB_PLUGIN_VERSION_STR, /* string version */ - MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */ + MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ }, { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -2414,7 +2425,7 @@ maria_declare_plugin(tokudb) NULL, /* status variables */ NULL, /* system variables */ TOKUDB_PLUGIN_VERSION_STR, /* string version */ - MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */ + MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ }, { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -2429,7 +2440,7 @@ maria_declare_plugin(tokudb) NULL, /* status variables */ NULL, /* system variables */ TOKUDB_PLUGIN_VERSION_STR, /* string version */ - MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */ + MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ }, { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -2444,7 +2455,7 @@ maria_declare_plugin(tokudb) NULL, /* status variables */ NULL, /* system variables */ TOKUDB_PLUGIN_VERSION_STR, /* string version */ - MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */ + MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ }, { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -2459,7 +2470,7 @@ maria_declare_plugin(tokudb) NULL, /* status variables */ NULL, /* system variables */ TOKUDB_PLUGIN_VERSION_STR, /* string version */ - MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */ + MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ }, { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -2474,7 +2485,7 @@ maria_declare_plugin(tokudb) NULL, /* status variables */ NULL, /* system variables */ TOKUDB_PLUGIN_VERSION_STR, /* string version */ - MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */ + MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ }, { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -2489,7 +2500,7 @@ maria_declare_plugin(tokudb) NULL, /* status variables */ NULL, /* system variables */ TOKUDB_PLUGIN_VERSION_STR, /* string version */ - MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */ + MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ } maria_declare_plugin_end; |