Commit 3131340b authored by marko's avatar marko

branches/zip: Simplify the locking of the data dictionary.

row_upd_index_is_referenced(), row_upd_check_references_constraints(),
row_purge_parse_undo_rec(): Remove duplicated code that calls
row_mysql_unfreeze_data_dictionary().

row_undo_ins_remove_clust_rec():
Assert that the data dictionary is X-latched.  Do not attempt to re-latch
the data dictionary, because doing so introduces race conditions.  This
re-latching was probably made unnecessary already in r1676, which keeps
the data dictionary X-latched in ha_innobase::add_index() for the complete
duration of the data dictionary operations.

row_undo_ins_parse_undo_rec(): Do not attempt to acquire the data dictionary
latch.  The data dictionary should be already X-latched when a transaction
that modifies system tables is rolled back.  This also holds in the rollback
during crash recovery: trx_rollback_active() will X-latch the data dictionary
when needed.
parent da70d126
......@@ -526,9 +526,8 @@ row_purge_parse_undo_rec(
if (node->table == NULL) {
/* The table has been dropped: no need to do purge */
err_exit:
row_mysql_unfreeze_data_dictionary(trx);
return(FALSE);
}
......@@ -537,9 +536,7 @@ row_purge_parse_undo_rec(
node->table = NULL;
row_mysql_unfreeze_data_dictionary(trx);
return(FALSE);
goto err_exit;
}
clust_index = dict_table_get_first_index(node->table);
......@@ -547,9 +544,7 @@ row_purge_parse_undo_rec(
if (clust_index == NULL) {
/* The table was corrupt in the data dictionary */
row_mysql_unfreeze_data_dictionary(trx);
return(FALSE);
goto err_exit;
}
ptr = trx_undo_rec_get_row_ref(ptr, clust_index, &(node->ref),
......
......@@ -53,24 +53,7 @@ row_undo_ins_remove_clust_rec(
ut_a(success);
if (ut_dulint_cmp(node->table->id, DICT_INDEXES_ID) == 0) {
trx_t* trx;
ibool thawed_dictionary = FALSE;
ibool locked_dictionary = FALSE;
trx = node->trx;
if (trx->dict_operation_lock_mode == RW_S_LATCH) {
row_mysql_unfreeze_data_dictionary(trx);
thawed_dictionary = TRUE;
}
if (trx->dict_operation_lock_mode != RW_X_LATCH) {
row_mysql_lock_data_dictionary(trx);
locked_dictionary = TRUE;
}
ut_ad(node->trx->dict_operation_lock_mode == RW_X_LATCH);
/* Drop the index tree associated with the row in
SYS_INDEXES table: */
......@@ -84,14 +67,6 @@ row_undo_ins_remove_clust_rec(
success = btr_pcur_restore_position(BTR_MODIFY_LEAF,
&(node->pcur), &mtr);
ut_a(success);
if (locked_dictionary) {
row_mysql_unlock_data_dictionary(trx);
}
if (thawed_dictionary) {
row_mysql_freeze_data_dictionary(trx);
}
}
btr_cur = btr_pcur_get_btr_cur(&(node->pcur));
......@@ -288,31 +263,7 @@ row_undo_ins_parse_undo_rec(
if (node->rec_type == TRX_UNDO_INSERT_REC) {
trx_t* trx;
ibool thawed_dictionary = FALSE;
ibool locked_dictionary = FALSE;
trx = node->trx;
/* If it is a system table, acquire the
dictionary lock in exclusive mode. */
if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0) {
if (trx->dict_operation_lock_mode == RW_S_LATCH) {
row_mysql_unfreeze_data_dictionary(trx);
thawed_dictionary = TRUE;
}
if (trx->dict_operation_lock_mode != RW_X_LATCH) {
row_mysql_lock_data_dictionary(trx);
locked_dictionary = TRUE;
}
}
node->table = dict_table_get_on_id(table_id, trx);
node->table = dict_table_get_on_id(table_id, node->trx);
/* If we can't find the table or .ibd file is missing,
we skip the UNDO.*/
......@@ -327,14 +278,6 @@ row_undo_ins_parse_undo_rec(
ptr = trx_undo_rec_get_row_ref(
ptr, clust_index, &node->ref, node->heap);
}
if (locked_dictionary) {
row_mysql_unlock_data_dictionary(trx);
}
if (thawed_dictionary) {
row_mysql_freeze_data_dictionary(trx);
}
}
}
......
......@@ -107,6 +107,7 @@ row_upd_index_is_referenced(
dict_table_t* table = index->table;
dict_foreign_t* foreign;
ibool froze_data_dict = FALSE;
ibool is_referenced = FALSE;
if (!UT_LIST_GET_FIRST(table->referenced_list)) {
......@@ -123,21 +124,19 @@ row_upd_index_is_referenced(
while (foreign) {
if (foreign->referenced_index == index) {
if (froze_data_dict) {
row_mysql_unfreeze_data_dictionary(trx);
}
return(TRUE);
is_referenced = TRUE;
goto func_exit;
}
foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
}
func_exit:
if (froze_data_dict) {
row_mysql_unfreeze_data_dictionary(trx);
}
return(FALSE);
return(is_referenced);
}
/*************************************************************************
......@@ -237,27 +236,24 @@ row_upd_check_references_constraints(
}
if (err != DB_SUCCESS) {
if (got_s_lock) {
row_mysql_unfreeze_data_dictionary(
trx);
}
mem_heap_free(heap);
return(err);
goto func_exit;
}
}
foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
}
err = DB_SUCCESS;
func_exit:
if (got_s_lock) {
row_mysql_unfreeze_data_dictionary(trx);
}
mem_heap_free(heap);
return(DB_SUCCESS);
return(err);
}
/*************************************************************************
......
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