Commit d21febec authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:2025], [t:2007], allow option for flattening in show user data, make...

[t:2025], [t:2007], allow option for flattening in show user data, make function exit if thread has been killed

git-svn-id: file:///svn/mysql/tokudb-engine/src@14621 c7de825b-a66e-492c-adef-691d508d4ae1
parent 5597c57c
...@@ -819,7 +819,6 @@ static int add_table_to_metadata(const char *name, TABLE* table) { ...@@ -819,7 +819,6 @@ static int add_table_to_metadata(const char *name, TABLE* table) {
DBT val; DBT val;
DB_TXN* txn = NULL; DB_TXN* txn = NULL;
uchar hidden_primary_key = (table->s->primary_key >= MAX_KEY); uchar hidden_primary_key = (table->s->primary_key >= MAX_KEY);
pthread_mutex_lock(&tokudb_meta_mutex);
error = db_env->txn_begin(db_env, 0, &txn, 0); error = db_env->txn_begin(db_env, 0, &txn, 0);
...@@ -846,7 +845,6 @@ cleanup: ...@@ -846,7 +845,6 @@ cleanup:
int r = !error ? txn->commit(txn,0) : txn->abort(txn); int r = !error ? txn->commit(txn,0) : txn->abort(txn);
assert(!r); assert(!r);
} }
pthread_mutex_unlock(&tokudb_meta_mutex);
return error; return error;
} }
...@@ -855,7 +853,6 @@ static int drop_table_from_metadata(const char *name) { ...@@ -855,7 +853,6 @@ static int drop_table_from_metadata(const char *name) {
DBT key; DBT key;
DBT data; DBT data;
DB_TXN* txn = NULL; DB_TXN* txn = NULL;
pthread_mutex_lock(&tokudb_meta_mutex);
error = db_env->txn_begin(db_env, 0, &txn, 0); error = db_env->txn_begin(db_env, 0, &txn, 0);
if (error) { if (error) {
goto cleanup; goto cleanup;
...@@ -877,7 +874,6 @@ cleanup: ...@@ -877,7 +874,6 @@ cleanup:
int r = !error ? txn->commit(txn,0) : txn->abort(txn); int r = !error ? txn->commit(txn,0) : txn->abort(txn);
assert(!r); assert(!r);
} }
pthread_mutex_unlock(&tokudb_meta_mutex);
return error; return error;
} }
...@@ -887,7 +883,6 @@ static int rename_table_in_metadata(const char *from, const char *to) { ...@@ -887,7 +883,6 @@ static int rename_table_in_metadata(const char *from, const char *to) {
DBT to_key; DBT to_key;
DBT val; DBT val;
DB_TXN* txn = NULL; DB_TXN* txn = NULL;
pthread_mutex_lock(&tokudb_meta_mutex);
error = db_env->txn_begin(db_env, 0, &txn, 0); error = db_env->txn_begin(db_env, 0, &txn, 0);
if (error) { if (error) {
goto cleanup; goto cleanup;
...@@ -944,7 +939,6 @@ cleanup: ...@@ -944,7 +939,6 @@ cleanup:
} }
my_free(val.data, MYF(MY_ALLOW_ZERO_PTR)); my_free(val.data, MYF(MY_ALLOW_ZERO_PTR));
pthread_mutex_unlock(&tokudb_meta_mutex);
return error; return error;
} }
...@@ -4764,6 +4758,7 @@ int ha_tokudb::create(const char *name, TABLE * form, HA_CREATE_INFO * create_in ...@@ -4764,6 +4758,7 @@ int ha_tokudb::create(const char *name, TABLE * form, HA_CREATE_INFO * create_in
KEY* prim_key = NULL; KEY* prim_key = NULL;
char* fn_ret = NULL; char* fn_ret = NULL;
pthread_mutex_lock(&tokudb_meta_mutex);
bzero(&row_descriptor, sizeof(row_descriptor)); bzero(&row_descriptor, sizeof(row_descriptor));
row_desc_buff = (uchar *)my_malloc(2*(form->s->fields * 6)+10 ,MYF(MY_WME)); row_desc_buff = (uchar *)my_malloc(2*(form->s->fields * 6)+10 ,MYF(MY_WME));
if (row_desc_buff == NULL){ error = ENOMEM; goto cleanup;} if (row_desc_buff == NULL){ error = ENOMEM; goto cleanup;}
...@@ -4931,6 +4926,7 @@ cleanup: ...@@ -4931,6 +4926,7 @@ cleanup:
my_free(newname, MYF(MY_ALLOW_ZERO_PTR)); my_free(newname, MYF(MY_ALLOW_ZERO_PTR));
my_free(dirname, MYF(MY_ALLOW_ZERO_PTR)); my_free(dirname, MYF(MY_ALLOW_ZERO_PTR));
my_free(row_desc_buff, MYF(MY_ALLOW_ZERO_PTR)); my_free(row_desc_buff, MYF(MY_ALLOW_ZERO_PTR));
pthread_mutex_unlock(&tokudb_meta_mutex);
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
} }
...@@ -4960,6 +4956,7 @@ int ha_tokudb::delete_table(const char *name) { ...@@ -4960,6 +4956,7 @@ int ha_tokudb::delete_table(const char *name) {
int error; int error;
char* newname = NULL; char* newname = NULL;
pthread_mutex_lock(&tokudb_meta_mutex);
// remove all of the dictionaries in the table directory // remove all of the dictionaries in the table directory
error = drop_table_from_metadata(name); error = drop_table_from_metadata(name);
if (error) { if (error) {
...@@ -4975,6 +4972,7 @@ int ha_tokudb::delete_table(const char *name) { ...@@ -4975,6 +4972,7 @@ int ha_tokudb::delete_table(const char *name) {
my_errno = error; my_errno = error;
cleanup: cleanup:
my_free(newname, MYF(MY_ALLOW_ZERO_PTR)); my_free(newname, MYF(MY_ALLOW_ZERO_PTR));
pthread_mutex_unlock(&tokudb_meta_mutex);
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
} }
...@@ -4993,6 +4991,7 @@ int ha_tokudb::rename_table(const char *from, const char *to) { ...@@ -4993,6 +4991,7 @@ int ha_tokudb::rename_table(const char *from, const char *to) {
int error; int error;
char* newfrom = NULL; char* newfrom = NULL;
char* newto = NULL; char* newto = NULL;
pthread_mutex_lock(&tokudb_meta_mutex);
// //
// this can only fail if we have not opened the environment // this can only fail if we have not opened the environment
...@@ -5032,6 +5031,7 @@ cleanup: ...@@ -5032,6 +5031,7 @@ cleanup:
} }
my_free(newfrom, MYF(MY_ALLOW_ZERO_PTR)); my_free(newfrom, MYF(MY_ALLOW_ZERO_PTR));
my_free(newto, MYF(MY_ALLOW_ZERO_PTR)); my_free(newto, MYF(MY_ALLOW_ZERO_PTR));
pthread_mutex_unlock(&tokudb_meta_mutex);
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
} }
......
...@@ -512,14 +512,19 @@ static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoin ...@@ -512,14 +512,19 @@ static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoin
#endif #endif
static int smart_dbt_do_nothing (DBT const *key, DBT const *row, void *context) {
return 0;
}
static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print) { static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print, bool exact) {
TOKUDB_DBUG_ENTER("tokudb_show_engine_status"); TOKUDB_DBUG_ENTER("tokudb_show_engine_status");
int error; int error;
u_int64_t num_bytes_in_db = 0; u_int64_t num_bytes_in_db = 0;
DB* curr_db = NULL; DB* curr_db = NULL;
DB_TXN* txn = NULL; DB_TXN* txn = NULL;
DBC* tmp_cursor = NULL; DBC* tmp_cursor = NULL;
DBC* tmp_table_cursor = NULL;
DBT curr_key; DBT curr_key;
DBT curr_val; DBT curr_val;
char data_amount_msg[50] = {0}; char data_amount_msg[50] = {0};
...@@ -527,7 +532,7 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print) { ...@@ -527,7 +532,7 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print) {
memset(&curr_val, 0, sizeof curr_val); memset(&curr_val, 0, sizeof curr_val);
pthread_mutex_lock(&tokudb_meta_mutex); pthread_mutex_lock(&tokudb_meta_mutex);
error = db_env->txn_begin(db_env, 0, &txn, 0); error = db_env->txn_begin(db_env, 0, &txn, DB_READ_UNCOMMITTED);
if (error) { if (error) {
goto cleanup; goto cleanup;
} }
...@@ -536,6 +541,14 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print) { ...@@ -536,6 +541,14 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print) {
goto cleanup; goto cleanup;
} }
while (error == 0) { while (error == 0) {
//
// here, and in other places, check if process has been killed
// if so, get out of function so user is not stalled
//
if (thd->killed) {
break;
}
// //
// do not need this to be super fast, so use old simple API // do not need this to be super fast, so use old simple API
// //
...@@ -571,6 +584,33 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print) { ...@@ -571,6 +584,33 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print) {
error = curr_db->open(curr_db, 0, name_buff, NULL, DB_BTREE, DB_THREAD, 0); error = curr_db->open(curr_db, 0, name_buff, NULL, DB_BTREE, DB_THREAD, 0);
if (error) { goto cleanup; } if (error) { goto cleanup; }
if (exact) {
//
// flatten if exact is required
//
uint curr_num_items = 0;
error = curr_db->cursor(curr_db, txn, &tmp_table_cursor, 0);
if (error) {
tmp_table_cursor = NULL;
goto cleanup;
}
while (error != DB_NOTFOUND) {
error = tmp_table_cursor->c_getf_next(tmp_table_cursor, 0, smart_dbt_do_nothing, NULL);
if (error && error != DB_NOTFOUND) {
goto cleanup;
}
curr_num_items++;
//
// allow early exit if command has been killed
//
if ( (curr_num_items % 1000) == 0 && thd->killed) {
goto cleanup;
}
}
tmp_table_cursor->c_close(tmp_table_cursor);
tmp_table_cursor = NULL;
}
error = curr_db->stat64( error = curr_db->stat64(
curr_db, curr_db,
txn, txn,
...@@ -624,11 +664,14 @@ cleanup: ...@@ -624,11 +664,14 @@ cleanup:
if (tmp_cursor) { if (tmp_cursor) {
tmp_cursor->c_close(tmp_cursor); tmp_cursor->c_close(tmp_cursor);
} }
if (tmp_table_cursor) {
tmp_table_cursor->c_close(tmp_table_cursor);
}
if (txn) { if (txn) {
txn->commit(txn, 0); txn->commit(txn, 0);
} }
if (error) { if (error) {
printf("got an error %d in show engine status\n", error); sql_print_error("got an error %d in show_data_size\n", error);
} }
pthread_mutex_unlock(&tokudb_meta_mutex); pthread_mutex_unlock(&tokudb_meta_mutex);
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
...@@ -680,7 +723,7 @@ static bool tokudb_show_logs(THD * thd, stat_print_fn * stat_print) { ...@@ -680,7 +723,7 @@ static bool tokudb_show_logs(THD * thd, stat_print_fn * stat_print) {
bool tokudb_show_status(handlerton * hton, THD * thd, stat_print_fn * stat_print, enum ha_stat_type stat_type) { bool tokudb_show_status(handlerton * hton, THD * thd, stat_print_fn * stat_print, enum ha_stat_type stat_type) {
switch (stat_type) { switch (stat_type) {
case HA_ENGINE_DATA_AMOUNT: case HA_ENGINE_DATA_AMOUNT:
return tokudb_show_data_size(thd, stat_print); return tokudb_show_data_size(thd, stat_print, false);
break; break;
case HA_ENGINE_LOGS: case HA_ENGINE_LOGS:
return tokudb_show_logs(thd, stat_print); return tokudb_show_logs(thd, stat_print);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment