summaryrefslogtreecommitdiff
path: root/storage/tokudb
diff options
context:
space:
mode:
authorRich Prohaska <prohaska@tokutek.com>2015-01-15 14:09:57 -0500
committerRich Prohaska <prohaska@tokutek.com>2015-01-15 14:09:57 -0500
commitc87f8151acc8337baad822ed6af31dbef50834ee (patch)
tree95c3ca8ddfdea85aa96d988d9ada7eb072d864b4 /storage/tokudb
parent23c4a7864391693a06fdf94f38bcc1ae27ef44e1 (diff)
downloadmariadb-git-c87f8151acc8337baad822ed6af31dbef50834ee.tar.gz
DB-478 DB-788 DB-789 optimize tokudb table enhancements
Diffstat (limited to 'storage/tokudb')
-rw-r--r--storage/tokudb/ha_tokudb_admin.cc39
-rw-r--r--storage/tokudb/hatoku_hton.cc6
-rw-r--r--storage/tokudb/hatoku_hton.h6
3 files changed, 44 insertions, 7 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;
}
diff --git a/storage/tokudb/hatoku_hton.cc b/storage/tokudb/hatoku_hton.cc
index ff849256f77..42f2fddfabf 100644
--- a/storage/tokudb/hatoku_hton.cc
+++ b/storage/tokudb/hatoku_hton.cc
@@ -1390,8 +1390,6 @@ static MYSQL_SYSVAR_STR(data_dir, tokudb_data_dir, PLUGIN_VAR_READONLY, "TokuDB
static MYSQL_SYSVAR_STR(version, tokudb_version, PLUGIN_VAR_READONLY, "TokuDB Version", NULL, NULL, NULL);
-static MYSQL_SYSVAR_UINT(init_flags, tokudb_init_flags, PLUGIN_VAR_READONLY, "Sets TokuDB DB_ENV->open flags", NULL, NULL, tokudb_init_flags, 0, ~0U, 0);
-
static MYSQL_SYSVAR_UINT(write_status_frequency, tokudb_write_status_frequency, 0, "TokuDB frequency that show processlist updates status of writes", NULL, NULL, 1000, 0, ~0U, 0);
static MYSQL_SYSVAR_UINT(read_status_frequency, tokudb_read_status_frequency, 0, "TokuDB frequency that show processlist updates status of reads", NULL, NULL, 10000, 0, ~0U, 0);
static MYSQL_SYSVAR_INT(fs_reserve_percent, tokudb_fs_reserve_percent, PLUGIN_VAR_READONLY, "TokuDB file system space reserve (percent free required)", NULL, NULL, 5, 0, 100, 0);
@@ -1428,7 +1426,6 @@ static struct st_mysql_sys_var *tokudb_system_variables[] = {
MYSQL_SYSVAR(create_index_online),
MYSQL_SYSVAR(disable_prefetching),
MYSQL_SYSVAR(version),
- MYSQL_SYSVAR(init_flags),
MYSQL_SYSVAR(checkpointing_period),
MYSQL_SYSVAR(prelock_empty),
MYSQL_SYSVAR(checkpoint_lock),
@@ -1469,6 +1466,9 @@ static struct st_mysql_sys_var *tokudb_system_variables[] = {
MYSQL_SYSVAR(rpl_unique_checks_delay),
MYSQL_SYSVAR(rpl_lookup_rows),
MYSQL_SYSVAR(rpl_lookup_rows_delay),
+ MYSQL_SYSVAR(optimize_index_name),
+ MYSQL_SYSVAR(optimize_index_fraction),
+ MYSQL_SYSVAR(optimize_throttle),
NULL
};
diff --git a/storage/tokudb/hatoku_hton.h b/storage/tokudb/hatoku_hton.h
index 9169e36f158..d6c1f9fa146 100644
--- a/storage/tokudb/hatoku_hton.h
+++ b/storage/tokudb/hatoku_hton.h
@@ -545,6 +545,12 @@ static MYSQL_THDVAR_BOOL(rpl_lookup_rows, PLUGIN_VAR_THDLOCAL, "lookup a row on
static MYSQL_THDVAR_ULONGLONG(rpl_lookup_rows_delay, PLUGIN_VAR_THDLOCAL, "time in milliseconds to add to lookups on replication slave",
NULL, NULL, 0 /*default*/, 0 /*min*/, ~0ULL /*max*/, 1 /*blocksize*/);
+static MYSQL_THDVAR_STR(optimize_index_name, PLUGIN_VAR_THDLOCAL + PLUGIN_VAR_MEMALLOC, "optimize index name (default all indexes)", NULL /*check*/, NULL /*update*/, NULL /*default*/);
+
+static MYSQL_THDVAR_DOUBLE(optimize_index_fraction, 0, "optimize index fraction (default 1.0 all)", NULL /*check*/, NULL /*update*/, 1.0 /*def*/, 0 /*min*/, 1.0 /*max*/, 1);
+
+static MYSQL_THDVAR_ULONGLONG(optimize_throttle, 0, "optimize throttle (default no throttle)", NULL /*check*/, NULL /*update*/, 0 /*def*/, 0 /*min*/, ~0ULL /*max*/, 1);
+
extern HASH tokudb_open_tables;
extern pthread_mutex_t tokudb_mutex;
extern uint32_t tokudb_write_status_frequency;