Commit 9c34e5f9 authored by marko's avatar marko

branches/zip: Do not call trx_allocate_for_mysql() directly, but use

helper functions that initialize some members of the transaction struct.
(Bug #41680)

innobase_trx_init(): New function: initialize some fields of a
transaction struct from a MySQL THD object.

innobase_trx_allocate(): New function: allocate and initialize a
transaction struct.

check_trx_exists(): Use the above two functions.

ha_innobase::delete_table(), ha_innobase::rename_table(),
ha_innobase::add_index(), ha_innobase::final_drop_index():
Use innobase_trx_allocate().

innobase_drop_database(): In the Windows plugin, initialize the trx_t
specially, because the THD is not available.  Otherwise, use
innobase_trx_allocate().

rb://69 accepted by Heikki Tuuri
parent 334de42c
......@@ -1211,6 +1211,53 @@ innobase_next_autoinc(
return(next_value);
}
/*************************************************************************
Initializes some fields in an InnoDB transaction object. */
static
void
innobase_trx_init(
/*==============*/
THD* thd, /* in: user thread handle */
trx_t* trx) /* in/out: InnoDB transaction handle */
{
DBUG_ENTER("innobase_trx_init");
DBUG_ASSERT(EQ_CURRENT_THD(thd));
DBUG_ASSERT(thd == trx->mysql_thd);
trx->check_foreigns = !thd_test_options(
thd, OPTION_NO_FOREIGN_KEY_CHECKS);
trx->check_unique_secondary = !thd_test_options(
thd, OPTION_RELAXED_UNIQUE_CHECKS);
DBUG_VOID_RETURN;
}
/*************************************************************************
Allocates an InnoDB transaction for a MySQL handler object. */
extern "C" UNIV_INTERN
trx_t*
innobase_trx_allocate(
/*==================*/
/* out: InnoDB transaction handle */
THD* thd) /* in: user thread handle */
{
trx_t* trx;
DBUG_ENTER("innobase_trx_allocate");
DBUG_ASSERT(thd != NULL);
DBUG_ASSERT(EQ_CURRENT_THD(thd));
trx = trx_allocate_for_mysql();
trx->mysql_thd = thd;
trx->mysql_query_str = thd_query(thd);
innobase_trx_init(thd, trx);
DBUG_RETURN(trx);
}
/*************************************************************************
Gets the InnoDB transaction handle for a MySQL handler object, creates
an InnoDB transaction struct if the corresponding MySQL thread struct still
......@@ -1227,31 +1274,13 @@ check_trx_exists(
ut_ad(EQ_CURRENT_THD(thd));
if (trx == NULL) {
DBUG_ASSERT(thd != NULL);
trx = trx_allocate_for_mysql();
trx->mysql_thd = thd;
trx->mysql_query_str = thd_query(thd);
} else {
if (trx->magic_n != TRX_MAGIC_N) {
mem_analyze_corruption(trx);
ut_error;
}
}
if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
trx->check_foreigns = FALSE;
} else {
trx->check_foreigns = TRUE;
trx = innobase_trx_allocate(thd);
} else if (UNIV_UNLIKELY(trx->magic_n != TRX_MAGIC_N)) {
mem_analyze_corruption(trx);
ut_error;
}
if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
trx->check_unique_secondary = FALSE;
} else {
trx->check_unique_secondary = TRUE;
}
innobase_trx_init(thd, trx);
return(trx);
}
......@@ -5931,18 +5960,7 @@ ha_innobase::create(
trx_search_latch_release_if_reserved(parent_trx);
trx = trx_allocate_for_mysql();
trx->mysql_thd = thd;
trx->mysql_query_str = thd_query(thd);
if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
trx->check_foreigns = FALSE;
}
if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
trx->check_unique_secondary = FALSE;
}
trx = innobase_trx_allocate(thd);
if (lower_case_table_names) {
srv_lower_case_table_names = TRUE;
......@@ -6348,25 +6366,14 @@ ha_innobase::delete_table(
trx_search_latch_release_if_reserved(parent_trx);
trx = innobase_trx_allocate(thd);
if (lower_case_table_names) {
srv_lower_case_table_names = TRUE;
} else {
srv_lower_case_table_names = FALSE;
}
trx = trx_allocate_for_mysql();
trx->mysql_thd = thd;
trx->mysql_query_str = thd_query(thd);
if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
trx->check_foreigns = FALSE;
}
if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS)) {
trx->check_unique_secondary = FALSE;
}
name_len = strlen(name);
ut_a(name_len < 1000);
......@@ -6449,19 +6456,14 @@ innobase_drop_database(
#ifdef __WIN__
innobase_casedn_str(namebuf);
#endif
#if defined __WIN__ && !defined MYSQL_SERVER
/* In the Windows plugin, thd = current_thd is always NULL */
trx = trx_allocate_for_mysql();
trx->mysql_thd = thd;
if (thd) {
trx->mysql_query_str = thd_query(thd);
if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
trx->check_foreigns = FALSE;
}
} else {
/* In the Windows plugin, thd = current_thd is always NULL */
trx->mysql_query_str = NULL;
}
trx->mysql_thd = NULL;
trx->mysql_query_str = NULL;
#else
trx = innobase_trx_allocate(thd);
#endif
error = row_drop_database_for_mysql(namebuf, trx);
my_free(namebuf, MYF(0));
......@@ -6571,13 +6573,7 @@ ha_innobase::rename_table(
trx_search_latch_release_if_reserved(parent_trx);
trx = trx_allocate_for_mysql();
trx->mysql_thd = thd;
trx->mysql_query_str = thd_query(thd);
if (thd_test_options(thd, OPTION_NO_FOREIGN_KEY_CHECKS)) {
trx->check_foreigns = FALSE;
}
trx = innobase_trx_allocate(thd);
error = innobase_rename_table(trx, from, to, TRUE);
......
......@@ -269,3 +269,12 @@ convert_error_code_to_mysql(
int error, /* in: InnoDB error code */
ulint flags, /* in: InnoDB table flags, or 0 */
MYSQL_THD thd); /* in: user thread handle or NULL */
/*************************************************************************
Allocates an InnoDB transaction for a MySQL handler object. */
extern "C"
trx_t*
innobase_trx_allocate(
/*==================*/
/* out: InnoDB transaction handle */
MYSQL_THD thd); /* in: user thread handle */
......@@ -633,12 +633,9 @@ ha_innobase::add_index(
/* Create a background transaction for the operations on
the data dictionary tables. */
trx = trx_allocate_for_mysql();
trx = innobase_trx_allocate(user_thd);
trx_start_if_not_started(trx);
trx->mysql_thd = user_thd;
trx->mysql_query_str = thd_query(user_thd);
innodb_table = indexed_table
= dict_table_get(prebuilt->table->name, FALSE);
......@@ -1125,12 +1122,9 @@ ha_innobase::final_drop_index(
/* Create a background transaction for the operations on
the data dictionary tables. */
trx = trx_allocate_for_mysql();
trx = innobase_trx_allocate(user_thd);
trx_start_if_not_started(trx);
trx->mysql_thd = user_thd;
trx->mysql_query_str = thd_query(user_thd);
/* Flag this transaction as a dictionary operation, so that
the data dictionary will be locked in crash recovery. */
trx_set_dict_operation(trx, TRX_DICT_OP_INDEX);
......
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