Commit 177f7b9a authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #1087

make sure ::optimize uses valid transaction

git-svn-id: file:///svn/mysql/tokudb-engine/src@5648 c7de825b-a66e-492c-adef-691d508d4ae1
parent c86dc3f4
...@@ -4460,11 +4460,34 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) { ...@@ -4460,11 +4460,34 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) {
TOKUDB_DBUG_ENTER("ha_tokudb::optimize"); TOKUDB_DBUG_ENTER("ha_tokudb::optimize");
int error; int error;
DBC* tmp_cursor = NULL; DBC* tmp_cursor = NULL;
tokudb_trx_data *trx = NULL;
DB_TXN* txn = NULL;
bool do_commit = false;
uint curr_num_DBs = table->s->keys + test(hidden_primary_key); uint curr_num_DBs = table->s->keys + test(hidden_primary_key);
trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
if (trx == NULL) {
error = HA_ERR_UNSUPPORTED;
goto cleanup;
}
//
// optimize may be called without a valid transaction, so we have to do this
// in order to get a valid transaction
// this is a bit hacky, but it is the best we have right now
//
txn = trx->stmt ? trx->stmt : trx->sp_level;
if (txn == NULL) {
error = db_env->txn_begin(db_env, NULL, &txn, 0);
if (error) {
goto cleanup;
}
do_commit = true;
}
// //
// prelock so each scan goes faster // prelock so each scan goes faster
// //
error = acquire_table_lock(transaction,lock_read); error = acquire_table_lock(txn,lock_read);
if (error) { if (error) {
goto cleanup; goto cleanup;
} }
...@@ -4474,7 +4497,7 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) { ...@@ -4474,7 +4497,7 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) {
// //
for (uint i = 0; i < curr_num_DBs; i++) { for (uint i = 0; i < curr_num_DBs; i++) {
error = 0; error = 0;
if ((error = share->file->cursor(share->file, transaction, &tmp_cursor, 0))) { if ((error = share->file->cursor(share->file, txn, &tmp_cursor, 0))) {
tmp_cursor = NULL; tmp_cursor = NULL;
goto cleanup; goto cleanup;
} }
...@@ -4489,6 +4512,9 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) { ...@@ -4489,6 +4512,9 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) {
error = 0; error = 0;
cleanup: cleanup:
if (do_commit) {
error = txn->commit(txn, 0);
}
TOKUDB_DBUG_RETURN(error); TOKUDB_DBUG_RETURN(error);
} }
......
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