Skip to content

Commit ed83905

Browse files
committed
Merge tag 'tokudb-7.5.5' into bb-5.5-merge
2 parents 8e80f91 + d8493f4 commit ed83905

29 files changed

+552
-56
lines changed
262 Bytes
Loading
176 Bytes
Loading

storage/tokudb/ha_tokudb.cc

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,31 @@ static inline uint32_t get_len_of_offsets(KEY_AND_COL_INFO* kc_info, TABLE_SHARE
172172
}
173173

174174

175+
static int get_thread_query_string(my_thread_id id, String &qs) {
176+
mysql_mutex_lock(&LOCK_thread_count);
177+
I_List_iterator<THD> it(threads);
178+
THD* tmp;
179+
while ((tmp= it++))
180+
{
181+
/* ID */
182+
if (tmp->thread_id == id)
183+
{
184+
/* Lock THD mutex that protects its data when looking at it. */
185+
mysql_mutex_lock(&tmp->LOCK_thd_data);
186+
187+
/* INFO */
188+
if (tmp->query())
189+
{
190+
qs = String(tmp->query(), tmp->query_length(), system_charset_info);
191+
}
192+
mysql_mutex_unlock(&tmp->LOCK_thd_data);
193+
break;
194+
}
195+
}
196+
mysql_mutex_unlock(&LOCK_thread_count);
197+
return 0;
198+
}
199+
175200
static int allocate_key_and_col_info ( TABLE_SHARE* table_share, KEY_AND_COL_INFO* kc_info) {
176201
int error;
177202
//
@@ -3557,8 +3582,12 @@ static void maybe_do_unique_checks_delay(THD *thd) {
35573582
}
35583583
}
35593584

3585+
static bool need_read_only(THD *thd) {
3586+
return opt_readonly || !THDVAR(thd, rpl_check_readonly);
3587+
}
3588+
35603589
static bool do_unique_checks(THD *thd, bool do_rpl_event) {
3561-
if (do_rpl_event && thd->slave_thread && opt_readonly && !THDVAR(thd, rpl_unique_checks))
3590+
if (do_rpl_event && thd->slave_thread && need_read_only(thd) && !THDVAR(thd, rpl_unique_checks))
35623591
return false;
35633592
else
35643593
return !thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS);
@@ -5378,9 +5407,12 @@ int ha_tokudb::get_next(uchar* buf, int direction, DBT* key_to_compare, bool do_
53785407
}
53795408

53805409
if (!error) {
5381-
tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(ha_thd(), tokudb_hton);
5410+
THD *thd = ha_thd();
5411+
tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
53825412
trx->stmt_progress.queried++;
5383-
track_progress(ha_thd());
5413+
track_progress(thd);
5414+
if (thd_killed(thd))
5415+
error = ER_ABORTING_CONNECTION;
53845416
}
53855417
cleanup:
53865418
return error;
@@ -7253,7 +7285,7 @@ double ha_tokudb::index_only_read_time(uint keynr, double records) {
72537285
// HA_POS_ERROR - Something is wrong with the index tree
72547286
//
72557287
ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range* end_key) {
7256-
TOKUDB_HANDLER_DBUG_ENTER("");
7288+
TOKUDB_HANDLER_DBUG_ENTER("%d %p %p", keynr, start_key, end_key);
72577289
DBT *pleft_key, *pright_key;
72587290
DBT left_key, right_key;
72597291
ha_rows ret_val = HA_TOKUDB_RANGE_COUNT;
@@ -7309,6 +7341,9 @@ ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range*
73097341
ret_val = (ha_rows) (rows <= 1 ? 1 : rows);
73107342

73117343
cleanup:
7344+
if (tokudb_debug & TOKUDB_DEBUG_RETURN) {
7345+
TOKUDB_HANDLER_TRACE("%" PRIu64 " %" PRIu64, (uint64_t) ret_val, rows);
7346+
}
73127347
DBUG_RETURN(ret_val);
73137348
}
73147349

storage/tokudb/ha_tokudb_admin.cc

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ PATENT RIGHTS GRANT:
8989
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
9090
#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."
9191

92+
#include "toku_time.h"
93+
9294
struct analyze_progress_extra {
9395
THD *thd;
9496
TOKUDB_SHARE *share;
@@ -186,9 +188,12 @@ typedef struct hot_optimize_context {
186188
uint progress_stage;
187189
uint current_table;
188190
uint num_tables;
191+
float progress_limit;
192+
uint64_t progress_last_time;
193+
uint64_t throttle;
189194
} *HOT_OPTIMIZE_CONTEXT;
190195

191-
static int hot_poll_fun(void *extra, float progress) {
196+
static int hot_optimize_progress_fun(void *extra, float progress) {
192197
HOT_OPTIMIZE_CONTEXT context = (HOT_OPTIMIZE_CONTEXT)extra;
193198
if (thd_killed(context->thd)) {
194199
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) {
207212
// the percentage we report here is for the current stage/db
208213
thd_progress_report(context->thd, (unsigned long long) percentage, 100);
209214
#endif
210-
return 0;
215+
216+
// throttle the optimize table
217+
if (context->throttle) {
218+
uint64_t time_now = toku_current_time_microsec();
219+
uint64_t dt = time_now - context->progress_last_time;
220+
uint64_t throttle_time = 1000000ULL / context->throttle;
221+
if (throttle_time > dt) {
222+
usleep(throttle_time - dt);
223+
}
224+
context->progress_last_time = toku_current_time_microsec();
225+
}
226+
227+
// return 1 if progress has reach the progress limit
228+
return progress >= context->progress_limit;
211229
}
212230

213231
// flatten all DB's in this table, to do so, peform hot optimize on each db
214232
int ha_tokudb::do_optimize(THD *thd) {
215233
TOKUDB_HANDLER_DBUG_ENTER("%s", share->table_name);
234+
int error = 0;
216235
const char *orig_proc_info = tokudb_thd_get_proc_info(thd);
217-
int error;
218236
uint curr_num_DBs = table->s->keys + tokudb_test(hidden_primary_key);
219237

220238
#ifdef HA_TOKUDB_HAS_THD_PROGRESS
@@ -225,20 +243,33 @@ int ha_tokudb::do_optimize(THD *thd) {
225243

226244
// for each DB, run optimize and hot_optimize
227245
for (uint i = 0; i < curr_num_DBs; i++) {
246+
// only optimize the index if it matches the optimize_index_name session variable
247+
const char *optimize_index_name = THDVAR(thd, optimize_index_name);
248+
if (optimize_index_name) {
249+
const char *this_index_name = i >= table_share->keys ? "primary" : table_share->key_info[i].name;
250+
if (strcasecmp(optimize_index_name, this_index_name) != 0) {
251+
continue;
252+
}
253+
}
254+
228255
DB* db = share->key_file[i];
229256
error = db->optimize(db);
230257
if (error) {
231258
goto cleanup;
232259
}
260+
233261
struct hot_optimize_context hc;
234262
memset(&hc, 0, sizeof hc);
235263
hc.thd = thd;
236264
hc.write_status_msg = this->write_status_msg;
237265
hc.ha = this;
238266
hc.current_table = i;
239267
hc.num_tables = curr_num_DBs;
268+
hc.progress_limit = THDVAR(thd, optimize_index_fraction);
269+
hc.progress_last_time = toku_current_time_microsec();
270+
hc.throttle = THDVAR(thd, optimize_throttle);
240271
uint64_t loops_run;
241-
error = db->hot_optimize(db, NULL, NULL, hot_poll_fun, &hc, &loops_run);
272+
error = db->hot_optimize(db, NULL, NULL, hot_optimize_progress_fun, &hc, &loops_run);
242273
if (error) {
243274
goto cleanup;
244275
}

storage/tokudb/hatoku_defines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ PATENT RIGHTS GRANT:
162162
#define TOKU_INCLUDE_EXTENDED_KEYS 1
163163
#define TOKU_INCLUDE_OPTION_STRUCTS 1
164164
#define TOKU_CLUSTERING_IS_COVERING 1
165+
#define TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING 1
166+
#else
167+
#define TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING 1
165168
#endif
166169
#define TOKU_INCLUDE_HANDLERTON_HANDLE_FATAL_SIGNAL 0 /* MariaDB 5.5 */
167170

storage/tokudb/hatoku_hton.cc

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,6 @@ static MYSQL_SYSVAR_STR(data_dir, tokudb_data_dir, PLUGIN_VAR_READONLY, "TokuDB
14031403

14041404
static MYSQL_SYSVAR_STR(version, tokudb_version, PLUGIN_VAR_READONLY, "TokuDB Version", NULL, NULL, NULL);
14051405

1406-
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);
1407-
14081406
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);
14091407
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);
14101408
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);
@@ -1441,7 +1439,6 @@ static struct st_mysql_sys_var *tokudb_system_variables[] = {
14411439
MYSQL_SYSVAR(create_index_online),
14421440
MYSQL_SYSVAR(disable_prefetching),
14431441
MYSQL_SYSVAR(version),
1444-
MYSQL_SYSVAR(init_flags),
14451442
MYSQL_SYSVAR(checkpointing_period),
14461443
MYSQL_SYSVAR(prelock_empty),
14471444
MYSQL_SYSVAR(checkpoint_lock),
@@ -1482,6 +1479,10 @@ static struct st_mysql_sys_var *tokudb_system_variables[] = {
14821479
MYSQL_SYSVAR(rpl_unique_checks_delay),
14831480
MYSQL_SYSVAR(rpl_lookup_rows),
14841481
MYSQL_SYSVAR(rpl_lookup_rows_delay),
1482+
MYSQL_SYSVAR(rpl_check_readonly),
1483+
MYSQL_SYSVAR(optimize_index_name),
1484+
MYSQL_SYSVAR(optimize_index_fraction),
1485+
MYSQL_SYSVAR(optimize_throttle),
14851486
NULL
14861487
};
14871488

@@ -1974,6 +1975,33 @@ static int tokudb_fractal_tree_block_map_done(void *p) {
19741975
return 0;
19751976
}
19761977

1978+
#if TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING
1979+
struct tokudb_search_txn_extra {
1980+
bool match_found;
1981+
uint64_t match_txn_id;
1982+
uint64_t match_client_id;
1983+
};
1984+
1985+
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) {
1986+
struct tokudb_search_txn_extra *e = reinterpret_cast<struct tokudb_search_txn_extra *>(extra);
1987+
if (e->match_txn_id == txn_id) {
1988+
e->match_found = true;
1989+
e->match_client_id = client_id;
1990+
return 1;
1991+
}
1992+
return 0;
1993+
}
1994+
1995+
static bool tokudb_txn_id_to_client_id(THD *thd, uint64_t blocking_txnid, uint64_t *blocking_client_id) {
1996+
struct tokudb_search_txn_extra e = { false, blocking_txnid, 0};
1997+
(void) db_env->iterate_live_transactions(db_env, tokudb_search_txn_callback, &e);
1998+
if (e.match_found) {
1999+
*blocking_client_id = e.match_client_id;
2000+
}
2001+
return e.match_found;
2002+
}
2003+
#endif
2004+
19772005
static void tokudb_pretty_key(const DB *db, const DBT *key, const char *default_key, String *out) {
19782006
if (key->data == NULL) {
19792007
out->append(default_key);
@@ -2023,8 +2051,9 @@ static void tokudb_lock_timeout_callback(DB *db, uint64_t requesting_txnid, cons
20232051
// generate a JSON document with the lock timeout info
20242052
String log_str;
20252053
log_str.append("{");
2054+
uint64_t mysql_thread_id = thd->thread_id;
20262055
log_str.append("\"mysql_thread_id\":");
2027-
log_str.append_ulonglong(thd->thread_id);
2056+
log_str.append_ulonglong(mysql_thread_id);
20282057
log_str.append(", \"dbname\":");
20292058
log_str.append("\""); log_str.append(tokudb_get_index_name(db)); log_str.append("\"");
20302059
log_str.append(", \"requesting_txnid\":");
@@ -2064,7 +2093,18 @@ static void tokudb_lock_timeout_callback(DB *db, uint64_t requesting_txnid, cons
20642093
}
20652094
// dump to stderr
20662095
if (lock_timeout_debug & 2) {
2067-
sql_print_error("%s: %s", tokudb_hton_name, log_str.c_ptr());
2096+
sql_print_error("%s: lock timeout %s", tokudb_hton_name, log_str.c_ptr());
2097+
LEX_STRING *qs = thd_query_string(thd);
2098+
sql_print_error("%s: requesting_thread_id:%" PRIu64 " q:%.*s", tokudb_hton_name, mysql_thread_id, (int) qs->length, qs->str);
2099+
#if TOKU_INCLUDE_LOCK_TIMEOUT_QUERY_STRING
2100+
uint64_t blocking_thread_id = 0;
2101+
if (tokudb_txn_id_to_client_id(thd, blocking_txnid, &blocking_thread_id)) {
2102+
String blocking_qs;
2103+
if (get_thread_query_string(blocking_thread_id, blocking_qs) == 0) {
2104+
sql_print_error("%s: blocking_thread_id:%" PRIu64 " q:%.*s", tokudb_hton_name, blocking_thread_id, blocking_qs.length(), blocking_qs.c_ptr());
2105+
}
2106+
}
2107+
#endif
20682108
}
20692109
}
20702110
}

storage/tokudb/hatoku_hton.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,15 @@ static MYSQL_THDVAR_BOOL(rpl_lookup_rows, PLUGIN_VAR_THDLOCAL, "lookup a row on
491491
static MYSQL_THDVAR_ULONGLONG(rpl_lookup_rows_delay, PLUGIN_VAR_THDLOCAL, "time in milliseconds to add to lookups on replication slave",
492492
NULL, NULL, 0 /*default*/, 0 /*min*/, ~0ULL /*max*/, 1 /*blocksize*/);
493493

494+
static MYSQL_THDVAR_BOOL(rpl_check_readonly, PLUGIN_VAR_THDLOCAL, "check if the slave is read only",
495+
NULL /*check*/, NULL /*update*/, true /*default*/);
496+
497+
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*/);
498+
499+
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);
500+
501+
static MYSQL_THDVAR_ULONGLONG(optimize_throttle, 0, "optimize throttle (default no throttle)", NULL /*check*/, NULL /*update*/, 0 /*def*/, 0 /*min*/, ~0ULL /*max*/, 1);
502+
494503
extern HASH tokudb_open_tables;
495504
extern pthread_mutex_t tokudb_mutex;
496505
extern uint32_t tokudb_write_status_frequency;

storage/tokudb/mysql-test/rpl/disabled.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ rpl_tokudb_write_pk: unreliable, uses timestamp differences
1010
rpl_tokudb_write_pk_uc1: unreliable, uses timestamp differences
1111
rpl_tokudb_write_unique: unreliable, uses timestamp differences
1212
rpl_tokudb_write_unique_uc1: unreliable, uses timestamp differences
13+
rpl_tokudb_read_only_ff: unreliable, uses timestamp differences
14+
rpl_tokudb_read_only_tf: unreliable, uses timestamp differences
15+
rpl_tokudb_read_only_tt: unreliable, uses timestamp differences
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include/master-slave.inc
2+
[connection master]
3+
drop table if exists t;
4+
create table t (a bigint not null, primary key(a)) engine=tokudb;
5+
select unix_timestamp() into @tstart;
6+
insert into t values (1);
7+
insert into t values (2),(3);
8+
insert into t values (4);
9+
select unix_timestamp()-@tstart <= 10;
10+
unix_timestamp()-@tstart <= 10
11+
1
12+
include/diff_tables.inc [master:test.t, slave:test.t]
13+
drop table if exists t;
14+
include/rpl_end.inc
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
include/master-slave.inc
2+
[connection master]
3+
drop table if exists t;
4+
create table t (a bigint not null, primary key(a)) engine=tokudb;
5+
select unix_timestamp() into @tstart;
6+
insert into t values (1);
7+
insert into t values (2),(3);
8+
insert into t values (4);
9+
select unix_timestamp()-@tstart <= 10;
10+
unix_timestamp()-@tstart <= 10
11+
0
12+
include/diff_tables.inc [master:test.t, slave:test.t]
13+
drop table if exists t;
14+
include/rpl_end.inc

0 commit comments

Comments
 (0)