diff options
Diffstat (limited to 'storage/tokudb/ha_tokudb_admin.cc')
-rw-r--r-- | storage/tokudb/ha_tokudb_admin.cc | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/storage/tokudb/ha_tokudb_admin.cc b/storage/tokudb/ha_tokudb_admin.cc index c3b895bf4f4..d6da45733a5 100644 --- a/storage/tokudb/ha_tokudb_admin.cc +++ b/storage/tokudb/ha_tokudb_admin.cc @@ -89,6 +89,8 @@ 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." +#include "toku_time.h" + struct analyze_progress_extra { THD *thd; TOKUDB_SHARE *share; @@ -186,9 +188,12 @@ typedef struct hot_optimize_context { uint progress_stage; uint current_table; uint num_tables; + float progress_limit; + uint64_t progress_last_time; + uint64_t throttle; } *HOT_OPTIMIZE_CONTEXT; -static int hot_poll_fun(void *extra, float progress) { +static int hot_optimize_progress_fun(void *extra, float progress) { HOT_OPTIMIZE_CONTEXT context = (HOT_OPTIMIZE_CONTEXT)extra; if (thd_killed(context->thd)) { sprintf(context->write_status_msg, "The process has been killed, aborting hot optimize."); @@ -207,14 +212,27 @@ static int hot_poll_fun(void *extra, float progress) { // the percentage we report here is for the current stage/db thd_progress_report(context->thd, (unsigned long long) percentage, 100); #endif - return 0; + + // throttle the optimize table + if (context->throttle) { + uint64_t time_now = toku_current_time_microsec(); + uint64_t dt = time_now - context->progress_last_time; + uint64_t throttle_time = 1000000ULL / context->throttle; + if (throttle_time > dt) { + usleep(throttle_time - dt); + } + context->progress_last_time = toku_current_time_microsec(); + } + + // return 1 if progress has reach the progress limit + return progress >= context->progress_limit; } // flatten all DB's in this table, to do so, peform hot optimize on each db int ha_tokudb::do_optimize(THD *thd) { TOKUDB_HANDLER_DBUG_ENTER("%s", share->table_name); + int error = 0; const char *orig_proc_info = tokudb_thd_get_proc_info(thd); - int error; uint curr_num_DBs = table->s->keys + tokudb_test(hidden_primary_key); #ifdef HA_TOKUDB_HAS_THD_PROGRESS @@ -225,11 +243,21 @@ int ha_tokudb::do_optimize(THD *thd) { // for each DB, run optimize and hot_optimize for (uint i = 0; i < curr_num_DBs; i++) { + // only optimize the index if it matches the optimize_index_name session variable + const char *optimize_index_name = THDVAR(thd, optimize_index_name); + if (optimize_index_name) { + const char *this_index_name = i >= table_share->keys ? "primary" : table_share->key_info[i].name; + if (strcasecmp(optimize_index_name, this_index_name) != 0) { + continue; + } + } + DB* db = share->key_file[i]; error = db->optimize(db); if (error) { goto cleanup; } + struct hot_optimize_context hc; memset(&hc, 0, sizeof hc); hc.thd = thd; @@ -237,8 +265,11 @@ int ha_tokudb::do_optimize(THD *thd) { hc.ha = this; hc.current_table = i; hc.num_tables = curr_num_DBs; + hc.progress_limit = THDVAR(thd, optimize_index_fraction); + hc.progress_last_time = toku_current_time_microsec(); + hc.throttle = THDVAR(thd, optimize_throttle); uint64_t loops_run; - error = db->hot_optimize(db, NULL, NULL, hot_poll_fun, &hc, &loops_run); + error = db->hot_optimize(db, NULL, NULL, hot_optimize_progress_fun, &hc, &loops_run); if (error) { goto cleanup; } |