Skip to content

Commit

Permalink
Merge tag 'tokudb-7.5.5' into bb-5.5-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova committed Feb 11, 2015
2 parents 8e80f91 + d8493f4 commit ed83905
Show file tree
Hide file tree
Showing 29 changed files with 552 additions and 56 deletions.
Binary file modified storage/tokudb/doc2/sysbench.update.ma10.tokudb754.loglog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified storage/tokudb/doc2/sysbench.update.ma10.tokudb754.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 39 additions & 4 deletions storage/tokudb/ha_tokudb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,31 @@ static inline uint32_t get_len_of_offsets(KEY_AND_COL_INFO* kc_info, TABLE_SHARE
}


static int get_thread_query_string(my_thread_id id, String &qs) {
mysql_mutex_lock(&LOCK_thread_count);
I_List_iterator<THD> it(threads);
THD* tmp;
while ((tmp= it++))
{
/* ID */
if (tmp->thread_id == id)
{
/* Lock THD mutex that protects its data when looking at it. */
mysql_mutex_lock(&tmp->LOCK_thd_data);

/* INFO */
if (tmp->query())
{
qs = String(tmp->query(), tmp->query_length(), system_charset_info);
}
mysql_mutex_unlock(&tmp->LOCK_thd_data);
break;
}
}
mysql_mutex_unlock(&LOCK_thread_count);
return 0;
}

static int allocate_key_and_col_info ( TABLE_SHARE* table_share, KEY_AND_COL_INFO* kc_info) {
int error;
//
Expand Down Expand Up @@ -3557,8 +3582,12 @@ static void maybe_do_unique_checks_delay(THD *thd) {
}
}

static bool need_read_only(THD *thd) {
return opt_readonly || !THDVAR(thd, rpl_check_readonly);
}

static bool do_unique_checks(THD *thd, bool do_rpl_event) {
if (do_rpl_event && thd->slave_thread && opt_readonly && !THDVAR(thd, rpl_unique_checks))
if (do_rpl_event && thd->slave_thread && need_read_only(thd) && !THDVAR(thd, rpl_unique_checks))
return false;
else
return !thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS);
Expand Down Expand Up @@ -5378,9 +5407,12 @@ int ha_tokudb::get_next(uchar* buf, int direction, DBT* key_to_compare, bool do_
}

if (!error) {
tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(ha_thd(), tokudb_hton);
THD *thd = ha_thd();
tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
trx->stmt_progress.queried++;
track_progress(ha_thd());
track_progress(thd);
if (thd_killed(thd))
error = ER_ABORTING_CONNECTION;
}
cleanup:
return error;
Expand Down Expand Up @@ -7253,7 +7285,7 @@ double ha_tokudb::index_only_read_time(uint keynr, double records) {
// HA_POS_ERROR - Something is wrong with the index tree
//
ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range* end_key) {
TOKUDB_HANDLER_DBUG_ENTER("");
TOKUDB_HANDLER_DBUG_ENTER("%d %p %p", keynr, start_key, end_key);
DBT *pleft_key, *pright_key;
DBT left_key, right_key;
ha_rows ret_val = HA_TOKUDB_RANGE_COUNT;
Expand Down Expand Up @@ -7309,6 +7341,9 @@ ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range*
ret_val = (ha_rows) (rows <= 1 ? 1 : rows);

cleanup:
if (tokudb_debug & TOKUDB_DEBUG_RETURN) {
TOKUDB_HANDLER_TRACE("%" PRIu64 " %" PRIu64, (uint64_t) ret_val, rows);
}
DBUG_RETURN(ret_val);
}

Expand Down
39 changes: 35 additions & 4 deletions storage/tokudb/ha_tokudb_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand All @@ -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
Expand All @@ -225,20 +243,33 @@ 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;
hc.write_status_msg = this->write_status_msg;
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;
}
Expand Down
3 changes: 3 additions & 0 deletions storage/tokudb/hatoku_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ PATENT RIGHTS GRANT:
#define TOKU_INCLUDE_EXTENDED_KEYS 1
#define TOKU_INCLUDE_OPTION_STRUCTS 1
#define TOKU_CLUSTERING_IS_COVERING 1
#define TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING 1
#else
#define TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING 1
#endif
#define TOKU_INCLUDE_HANDLERTON_HANDLE_FATAL_SIGNAL 0 /* MariaDB 5.5 */

Expand Down
50 changes: 45 additions & 5 deletions storage/tokudb/hatoku_hton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1403,8 +1403,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);
Expand Down Expand Up @@ -1441,7 +1439,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),
Expand Down Expand Up @@ -1482,6 +1479,10 @@ 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(rpl_check_readonly),
MYSQL_SYSVAR(optimize_index_name),
MYSQL_SYSVAR(optimize_index_fraction),
MYSQL_SYSVAR(optimize_throttle),
NULL
};

Expand Down Expand Up @@ -1974,6 +1975,33 @@ static int tokudb_fractal_tree_block_map_done(void *p) {
return 0;
}

#if TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING
struct tokudb_search_txn_extra {
bool match_found;
uint64_t match_txn_id;
uint64_t match_client_id;
};

static int tokudb_search_txn_callback(uint64_t txn_id, uint64_t client_id, iterate_row_locks_callback iterate_locks, void *locks_extra, void *extra) {
struct tokudb_search_txn_extra *e = reinterpret_cast<struct tokudb_search_txn_extra *>(extra);
if (e->match_txn_id == txn_id) {
e->match_found = true;
e->match_client_id = client_id;
return 1;
}
return 0;
}

static bool tokudb_txn_id_to_client_id(THD *thd, uint64_t blocking_txnid, uint64_t *blocking_client_id) {
struct tokudb_search_txn_extra e = { false, blocking_txnid, 0};
(void) db_env->iterate_live_transactions(db_env, tokudb_search_txn_callback, &e);
if (e.match_found) {
*blocking_client_id = e.match_client_id;
}
return e.match_found;
}
#endif

static void tokudb_pretty_key(const DB *db, const DBT *key, const char *default_key, String *out) {
if (key->data == NULL) {
out->append(default_key);
Expand Down Expand Up @@ -2023,8 +2051,9 @@ static void tokudb_lock_timeout_callback(DB *db, uint64_t requesting_txnid, cons
// generate a JSON document with the lock timeout info
String log_str;
log_str.append("{");
uint64_t mysql_thread_id = thd->thread_id;
log_str.append("\"mysql_thread_id\":");
log_str.append_ulonglong(thd->thread_id);
log_str.append_ulonglong(mysql_thread_id);
log_str.append(", \"dbname\":");
log_str.append("\""); log_str.append(tokudb_get_index_name(db)); log_str.append("\"");
log_str.append(", \"requesting_txnid\":");
Expand Down Expand Up @@ -2064,7 +2093,18 @@ static void tokudb_lock_timeout_callback(DB *db, uint64_t requesting_txnid, cons
}
// dump to stderr
if (lock_timeout_debug & 2) {
sql_print_error("%s: %s", tokudb_hton_name, log_str.c_ptr());
sql_print_error("%s: lock timeout %s", tokudb_hton_name, log_str.c_ptr());
LEX_STRING *qs = thd_query_string(thd);
sql_print_error("%s: requesting_thread_id:%" PRIu64 " q:%.*s", tokudb_hton_name, mysql_thread_id, (int) qs->length, qs->str);
#if TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING
uint64_t blocking_thread_id = 0;
if (tokudb_txn_id_to_client_id(thd, blocking_txnid, &blocking_thread_id)) {
String blocking_qs;
if (get_thread_query_string(blocking_thread_id, blocking_qs) == 0) {
sql_print_error("%s: blocking_thread_id:%" PRIu64 " q:%.*s", tokudb_hton_name, blocking_thread_id, blocking_qs.length(), blocking_qs.c_ptr());
}
}
#endif
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions storage/tokudb/hatoku_hton.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ 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_BOOL(rpl_check_readonly, PLUGIN_VAR_THDLOCAL, "check if the slave is read only",
NULL /*check*/, NULL /*update*/, true /*default*/);

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;
Expand Down
3 changes: 3 additions & 0 deletions storage/tokudb/mysql-test/rpl/disabled.def
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ rpl_tokudb_write_pk: unreliable, uses timestamp differences
rpl_tokudb_write_pk_uc1: unreliable, uses timestamp differences
rpl_tokudb_write_unique: unreliable, uses timestamp differences
rpl_tokudb_write_unique_uc1: unreliable, uses timestamp differences
rpl_tokudb_read_only_ff: unreliable, uses timestamp differences
rpl_tokudb_read_only_tf: unreliable, uses timestamp differences
rpl_tokudb_read_only_tt: unreliable, uses timestamp differences
14 changes: 14 additions & 0 deletions storage/tokudb/mysql-test/rpl/r/rpl_tokudb_read_only_ff.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include/master-slave.inc
[connection master]
drop table if exists t;
create table t (a bigint not null, primary key(a)) engine=tokudb;
select unix_timestamp() into @tstart;
insert into t values (1);
insert into t values (2),(3);
insert into t values (4);
select unix_timestamp()-@tstart <= 10;
unix_timestamp()-@tstart <= 10
1
include/diff_tables.inc [master:test.t, slave:test.t]
drop table if exists t;
include/rpl_end.inc
14 changes: 14 additions & 0 deletions storage/tokudb/mysql-test/rpl/r/rpl_tokudb_read_only_ft.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include/master-slave.inc
[connection master]
drop table if exists t;
create table t (a bigint not null, primary key(a)) engine=tokudb;
select unix_timestamp() into @tstart;
insert into t values (1);
insert into t values (2),(3);
insert into t values (4);
select unix_timestamp()-@tstart <= 10;
unix_timestamp()-@tstart <= 10
0
include/diff_tables.inc [master:test.t, slave:test.t]
drop table if exists t;
include/rpl_end.inc
14 changes: 14 additions & 0 deletions storage/tokudb/mysql-test/rpl/r/rpl_tokudb_read_only_tf.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include/master-slave.inc
[connection master]
drop table if exists t;
create table t (a bigint not null, primary key(a)) engine=tokudb;
select unix_timestamp() into @tstart;
insert into t values (1);
insert into t values (2),(3);
insert into t values (4);
select unix_timestamp()-@tstart <= 10;
unix_timestamp()-@tstart <= 10
1
include/diff_tables.inc [master:test.t, slave:test.t]
drop table if exists t;
include/rpl_end.inc
14 changes: 14 additions & 0 deletions storage/tokudb/mysql-test/rpl/r/rpl_tokudb_read_only_tt.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include/master-slave.inc
[connection master]
drop table if exists t;
create table t (a bigint not null, primary key(a)) engine=tokudb;
select unix_timestamp() into @tstart;
insert into t values (1);
insert into t values (2),(3);
insert into t values (4);
select unix_timestamp()-@tstart <= 10;
unix_timestamp()-@tstart <= 10
1
include/diff_tables.inc [master:test.t, slave:test.t]
drop table if exists t;
include/rpl_end.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--read-only=OFF --tokudb-rpl-check-readonly=OFF --tokudb-rpl-unique-checks-delay=5000 --tokudb-rpl-unique-checks=OFF
Loading

0 comments on commit ed83905

Please sign in to comment.