Commit 710deaf6 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#4695 use alter table txn to write frm data and drop indexes. add index to do next refs[t:4695]

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@41665 c7de825b-a66e-492c-adef-691d508d4ae1
parent 41daa75c
...@@ -7712,11 +7712,11 @@ int ha_tokudb::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, hand ...@@ -7712,11 +7712,11 @@ int ha_tokudb::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, hand
TOKUDB_DBUG_ENTER("ha_tokudb::add_index"); TOKUDB_DBUG_ENTER("ha_tokudb::add_index");
while (ha_tokudb_add_index_wait) sleep(1); // debug while (ha_tokudb_add_index_wait) sleep(1); // debug
DB_TXN* txn = NULL;
int error; int error;
bool incremented_numDBs = false; bool incremented_numDBs = false;
bool modified_DBs = false; bool modified_DBs = false;
DB_TXN* txn = NULL;
error = db_env->txn_begin(db_env, 0, &txn, 0); error = db_env->txn_begin(db_env, 0, &txn, 0);
if (error) { goto cleanup; } if (error) { goto cleanup; }
...@@ -7768,41 +7768,6 @@ int ha_tokudb::final_add_index(handler_add_index *add_arg, bool commit) { ...@@ -7768,41 +7768,6 @@ int ha_tokudb::final_add_index(handler_add_index *add_arg, bool commit) {
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
} }
#else
int ha_tokudb::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys) {
TOKUDB_DBUG_ENTER("ha_tokudb::add_index");
DB_TXN* txn = NULL;
int error;
bool incremented_numDBs = false;
bool modified_DBs = false;
error = db_env->txn_begin(db_env, 0, &txn, 0);
if (error) { goto cleanup; }
error = tokudb_add_index(
table_arg,
key_info,
num_of_keys,
txn,
&incremented_numDBs,
&modified_DBs
);
if (error) { goto cleanup; }
cleanup:
if (error) {
if (txn) {
restore_add_index(table_arg, num_of_keys, incremented_numDBs, modified_DBs);
abort_txn(txn);
}
}
else {
commit_txn(txn, 0);
}
TOKUDB_DBUG_RETURN(error);
}
#endif #endif
volatile int ha_tokudb_drop_indexes_wait = 0; // debug volatile int ha_tokudb_drop_indexes_wait = 0; // debug
...@@ -7902,6 +7867,14 @@ int ha_tokudb::prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_k ...@@ -7902,6 +7867,14 @@ int ha_tokudb::prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_k
TOKUDB_DBUG_ENTER("ha_tokudb::prepare_drop_index"); TOKUDB_DBUG_ENTER("ha_tokudb::prepare_drop_index");
while (ha_tokudb_prepare_drop_index_wait) sleep(1); // debug while (ha_tokudb_prepare_drop_index_wait) sleep(1); // debug
#if MYSQL_VERSION_ID >= 50521
DB_TXN *txn = transaction;
assert(txn);
int error = drop_indexes(table_arg, key_num, num_of_keys, txn);
#else
int error; int error;
DB_TXN* txn = NULL; DB_TXN* txn = NULL;
...@@ -7921,6 +7894,8 @@ cleanup: ...@@ -7921,6 +7894,8 @@ cleanup:
commit_txn(txn,0); commit_txn(txn,0);
} }
} }
#endif
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
} }
...@@ -10099,6 +10074,7 @@ ha_tokudb::is_alter_table_hot() { ...@@ -10099,6 +10074,7 @@ ha_tokudb::is_alter_table_hot() {
TOKUDB_DBUG_RETURN(is_hot); TOKUDB_DBUG_RETURN(is_hot);
} }
// write the new frm data to the status dictionary using the alter table transaction
int int
ha_tokudb::new_alter_table_frm_data(const uchar *frm_data, size_t frm_len) { ha_tokudb::new_alter_table_frm_data(const uchar *frm_data, size_t frm_len) {
TOKUDB_DBUG_ENTER("new_alter_table_path"); TOKUDB_DBUG_ENTER("new_alter_table_path");
...@@ -10106,7 +10082,8 @@ ha_tokudb::new_alter_table_frm_data(const uchar *frm_data, size_t frm_len) { ...@@ -10106,7 +10082,8 @@ ha_tokudb::new_alter_table_frm_data(const uchar *frm_data, size_t frm_len) {
int error = 0; int error = 0;
if (table->part_info == NULL) { if (table->part_info == NULL) {
// write frmdata to status // write frmdata to status
DB_TXN *txn = NULL; // TODO use transaction (creatged in prepare_for_alter) DB_TXN *txn = transaction; // use alter table transaction
assert(txn);
error = write_to_status(share->status_block, hatoku_frm_data, (void *)frm_data, (uint)frm_len, txn); error = write_to_status(share->status_block, hatoku_frm_data, (void *)frm_data, (uint)frm_len, txn);
} }
...@@ -10117,10 +10094,19 @@ void ...@@ -10117,10 +10094,19 @@ void
ha_tokudb::prepare_for_alter() { ha_tokudb::prepare_for_alter() {
TOKUDB_DBUG_ENTER("prepare_for_alter"); TOKUDB_DBUG_ENTER("prepare_for_alter");
// create a transaction used to add indexes, drop indexes, and write the new frm data // this is here because mysql commits the transaction before prepare_for_alter is called.
// this transaction will be retired by mysql alter table // we need a transaction to add indexes, drop indexes, and write the new frm data, so we
DB_TXN *txn = NULL; // create one. this transaction will be retired by mysql alter table when it commits
txn = txn; // TODO create a new transaction //
// if we remove the commit before prepare_for_alter, then this is not needed.
transaction = NULL;
THD *thd = ha_thd();
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
assert(trx);
int error = create_txn(thd, trx);
assert(error == 0);
assert(thd->in_sub_stmt == 0);
transaction = trx->sub_sp_level;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
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