Commit bb82f894 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

refs #5590 remove the old 5.5 add/drop index code

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@53742 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8b848f3e
......@@ -599,16 +599,16 @@ public:
public:
#endif
#if TOKU_INCLUDE_ALTER_55
public:
int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, handler_add_index **add);
int final_add_index(handler_add_index *add, bool commit);
int prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys);
int final_drop_index(TABLE *table_arg);
public:
// Returns true of the 5.6 inplace alter table interface is used.
bool try_hot_alter_table();
bool is_alter_table_hot();
// We need a txn in the mysql_alter_table function to write new frm data, so this function
// gets called to sometimes create one.
void prepare_for_alter();
// Used by the partition storage engine to provide new frm data for the table.
int new_alter_table_frm_data(const uchar *frm_data, size_t frm_len);
bool try_hot_alter_table();
#endif
private:
......
#if TOKU_INCLUDE_ALTER_55
#include "ha_tokudb_alter_common.cc"
class ha_tokudb_add_index : public handler_add_index {
public:
DB_TXN *txn;
bool incremented_numDBs;
bool modified_DBs;
ha_tokudb_add_index(TABLE* table, KEY* key_info, uint num_of_keys, DB_TXN *txn, bool incremented_numDBs, bool modified_DBs) :
handler_add_index(table, key_info, num_of_keys), txn(txn), incremented_numDBs(incremented_numDBs), modified_DBs(modified_DBs) {
}
~ha_tokudb_add_index() {
}
};
volatile int ha_tokudb_add_index_wait = 0;
int ha_tokudb::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, handler_add_index **add) {
TOKUDB_DBUG_ENTER("ha_tokudb::add_index");
while (ha_tokudb_add_index_wait) sleep(1); // debug
int error;
bool incremented_numDBs = false;
bool modified_DBs = false;
// transaction is created in prepare_for_alter
DB_TXN* txn = transaction;
error = tokudb_add_index(
table_arg,
key_info,
num_of_keys,
txn,
&incremented_numDBs,
&modified_DBs
);
if (error) { goto cleanup; }
cleanup:
DBUG_EXECUTE_IF("add_index_fail", {
error = 1;
});
if (error) {
if (txn) {
restore_add_index(table_arg, num_of_keys, incremented_numDBs, modified_DBs);
}
} else {
*add = new ha_tokudb_add_index(table_arg, key_info, num_of_keys, txn, incremented_numDBs, modified_DBs);
}
TOKUDB_DBUG_RETURN(error);
}
volatile int ha_tokudb_final_add_index_wait = 0;
int ha_tokudb::final_add_index(handler_add_index *add_arg, bool commit) {
TOKUDB_DBUG_ENTER("ha_tokudb::final_add_index");
while (ha_tokudb_final_add_index_wait) sleep(1); // debug
// extract the saved state variables
ha_tokudb_add_index *add = static_cast<class ha_tokudb_add_index*>(add_arg);
bool incremented_numDBs = add->incremented_numDBs;
bool modified_DBs = add->modified_DBs;
TABLE *table = add->table;
uint num_of_keys = add->num_of_keys;
delete add;
int error = 0;
DBUG_EXECUTE_IF("final_add_index_fail", {
error = 1;
});
// at this point, the metadata lock ensures that the
// newly created indexes cannot be modified,
// regardless of whether the add index was hot.
// Because a subsequent drop index may cause an
// error requireing us to abort the transaction,
// we prematurely close the added indexes, regardless
// of whether we are committing or aborting.
restore_add_index(table, num_of_keys, incremented_numDBs, modified_DBs);
// transaction does not need to be committed,
// we depend on MySQL to rollback the transaction
// by calling tokudb_rollback
TOKUDB_DBUG_RETURN(error);
}
volatile int ha_tokudb_prepare_drop_index_wait = 0; //debug
//
// Prepares to drop indexes to the table. For each value, i, in the array key_num,
// table->key_info[i] is a key that is to be dropped.
// ***********NOTE*******************
// Although prepare_drop_index is supposed to just get the DB's ready for removal,
// and not actually do the removal, we are doing it here and not in final_drop_index
// For the flags we expose in alter_table_flags, namely xxx_NO_WRITES, this is allowed
// Changes for "future-proofing" this so that it works when we have the equivalent flags
// that are not NO_WRITES are not worth it at the moments
// Parameters:
// [in] table_arg - table that is being modified, seems to be identical to this->table
// [in] key_num - array of indexes that specify which keys of the array table->key_info
// are to be dropped
// num_of_keys - size of array, key_num
// Returns:
// 0 on success, error otherwise
//
int ha_tokudb::prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys) {
TOKUDB_DBUG_ENTER("ha_tokudb::prepare_drop_index");
while (ha_tokudb_prepare_drop_index_wait) sleep(1); // debug
DB_TXN *txn = transaction;
assert(txn);
int error = drop_indexes(table_arg, key_num, num_of_keys, table_arg->key_info, txn);
DBUG_EXECUTE_IF("prepare_drop_index_fail", {
error = 1;
});
TOKUDB_DBUG_RETURN(error);
}
volatile int ha_tokudb_final_drop_index_wait = 0; // debug
// ***********NOTE*******************
// Although prepare_drop_index is supposed to just get the DB's ready for removal,
// and not actually do the removal, we are doing it here and not in final_drop_index
// For the flags we expose in alter_table_flags, namely xxx_NO_WRITES, this is allowed
// Changes for "future-proofing" this so that it works when we have the equivalent flags
// that are not NO_WRITES are not worth it at the moments, therefore, we can make
// this function just return
int ha_tokudb::final_drop_index(TABLE *table_arg) {
TOKUDB_DBUG_ENTER("ha_tokudb::final_drop_index");
while (ha_tokudb_final_drop_index_wait) sleep(1); // debug
int error = 0;
DBUG_EXECUTE_IF("final_drop_index_fail", {
error = 1;
});
TOKUDB_DBUG_RETURN(error);
}
bool ha_tokudb::is_alter_table_hot() {
TOKUDB_DBUG_ENTER("is_alter_table_hot");
bool is_hot = false;
bool ha_tokudb::try_hot_alter_table() {
TOKUDB_DBUG_ENTER("try_hot_alter_table");
THD *thd = ha_thd();
if (get_create_index_online(thd) && thd_sql_command(thd)== SQLCOM_CREATE_INDEX) {
// this code must match the logic in ::store_lock for hot indexing
rw_rdlock(&share->num_DBs_lock);
if (share->num_DBs == (table->s->keys + test(hidden_primary_key))) {
is_hot = true;
}
rw_unlock(&share->num_DBs_lock);
}
TOKUDB_DBUG_RETURN(is_hot);
}
int ha_tokudb::new_alter_table_frm_data(const uchar *frm_data, size_t frm_len) {
return write_frm_data(frm_data, frm_len);
bool disable_hot_alter = get_disable_hot_alter(thd);
DBUG_RETURN(!disable_hot_alter);
}
void ha_tokudb::prepare_for_alter() {
......@@ -180,11 +30,8 @@ void ha_tokudb::prepare_for_alter() {
DBUG_VOID_RETURN;
}
bool ha_tokudb::try_hot_alter_table() {
TOKUDB_DBUG_ENTER("try_hot_alter_table");
THD *thd = ha_thd();
bool disable_hot_alter = get_disable_hot_alter(thd);
DBUG_RETURN(!disable_hot_alter);
int ha_tokudb::new_alter_table_frm_data(const uchar *frm_data, size_t frm_len) {
return write_frm_data(frm_data, frm_len);
}
#endif
......@@ -228,9 +228,6 @@ static int tokudb_commit_by_xid(handlerton* hton, XID* xid);
static int tokudb_rollback_by_xid(handlerton* hton, XID* xid);
#endif
#if defined(HA_INPLACE_ADD_INDEX_NO_READ_WRITE)
static uint tokudb_alter_table_flags(uint flags);
#endif
static int tokudb_rollback_to_savepoint(handlerton * hton, THD * thd, void *savepoint);
static int tokudb_savepoint(handlerton * hton, THD * thd, void *savepoint);
static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoint);
......@@ -389,9 +386,6 @@ static int tokudb_init_func(void *p) {
tokudb_hton->panic = tokudb_end;
tokudb_hton->flush_logs = tokudb_flush_logs;
tokudb_hton->show_status = tokudb_show_status;
#if defined(HA_INPLACE_ADD_INDEX_NO_READ_WRITE)
tokudb_hton->alter_table_flags = tokudb_alter_table_flags;
#endif
if (!tokudb_home)
tokudb_home = mysql_real_data_home;
DBUG_PRINT("info", ("tokudb_home: %s", tokudb_home));
......@@ -1773,18 +1767,6 @@ static void tokudb_cleanup_log_files(void) {
DBUG_VOID_RETURN;
}
#if defined(HA_INPLACE_ADD_INDEX_NO_READ_WRITE)
static uint tokudb_alter_table_flags(uint flags) {
return HA_INPLACE_ADD_INDEX_NO_READ_WRITE
| HA_INPLACE_ADD_INDEX_NO_WRITE
| HA_INPLACE_DROP_INDEX_NO_READ_WRITE
| HA_INPLACE_ADD_UNIQUE_INDEX_NO_READ_WRITE
| HA_INPLACE_ADD_UNIQUE_INDEX_NO_WRITE
| HA_INPLACE_DROP_UNIQUE_INDEX_NO_READ_WRITE;
}
#endif
// options flags
// PLUGIN_VAR_THDLOCAL Variable is per-connection
// PLUGIN_VAR_READONLY Server variable is read only
......
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