Commit 87de0e21 authored by Monty's avatar Monty

Minor cleanups of atomic ddl code

- Rename DDL_IGNORE_LOG_ENTRY_CODE to DDL_LOG_IGNORE_ENTRY_CODE
  This makes it similar to all other ddl_log_entry_code's.
- Added some new comments
- ddl_log_revert() now returns != 0 if revert didn't succeed
parent 83a47134
...@@ -421,7 +421,7 @@ static bool disable_execute_entry(uint entry_pos) ...@@ -421,7 +421,7 @@ static bool disable_execute_entry(uint entry_pos)
uchar buff[1]; uchar buff[1];
DBUG_ENTER("disable_execute_entry"); DBUG_ENTER("disable_execute_entry");
buff[0]= DDL_IGNORE_LOG_ENTRY_CODE; buff[0]= DDL_LOG_IGNORE_ENTRY_CODE;
DBUG_RETURN(mysql_file_pwrite(global_ddl_log.file_id, buff, sizeof(buff), DBUG_RETURN(mysql_file_pwrite(global_ddl_log.file_id, buff, sizeof(buff),
global_ddl_log.io_size * entry_pos + global_ddl_log.io_size * entry_pos +
DDL_LOG_ENTRY_TYPE_POS, DDL_LOG_ENTRY_TYPE_POS,
...@@ -858,7 +858,7 @@ static bool ddl_log_increment_phase_no_lock(uint entry_pos) ...@@ -858,7 +858,7 @@ static bool ddl_log_increment_phase_no_lock(uint entry_pos)
if (ddl_log_entry_phases[action] <= phase) if (ddl_log_entry_phases[action] <= phase)
{ {
DBUG_ASSERT(phase == ddl_log_entry_phases[action]); DBUG_ASSERT(phase == ddl_log_entry_phases[action]);
/* Same effect as setting DDL_IGNORE_LOG_ENTRY_CODE */ /* Same effect as setting DDL_LOG_IGNORE_ENTRY_CODE */
phase= DDL_LOG_FINAL_PHASE; phase= DDL_LOG_FINAL_PHASE;
} }
file_entry_buf[DDL_LOG_PHASE_POS]= phase; file_entry_buf[DDL_LOG_PHASE_POS]= phase;
...@@ -1306,7 +1306,7 @@ static int ddl_log_execute_action(THD *thd, MEM_ROOT *mem_root, ...@@ -1306,7 +1306,7 @@ static int ddl_log_execute_action(THD *thd, MEM_ROOT *mem_root,
ddl_log_entry->from_name.str, ddl_log_entry->from_name.str,
ddl_log_entry->tmp_name.str)); ddl_log_entry->tmp_name.str));
if (ddl_log_entry->entry_type == DDL_IGNORE_LOG_ENTRY_CODE || if (ddl_log_entry->entry_type == DDL_LOG_IGNORE_ENTRY_CODE ||
ddl_log_entry->phase == DDL_LOG_FINAL_PHASE) ddl_log_entry->phase == DDL_LOG_FINAL_PHASE)
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
...@@ -1421,7 +1421,7 @@ static int ddl_log_execute_action(THD *thd, MEM_ROOT *mem_root, ...@@ -1421,7 +1421,7 @@ static int ddl_log_execute_action(THD *thd, MEM_ROOT *mem_root,
(void) file->ha_rename_table(ddl_log_entry->tmp_name.str, (void) file->ha_rename_table(ddl_log_entry->tmp_name.str,
ddl_log_entry->name.str); ddl_log_entry->name.str);
/* disable the entry and sync */ /* disable the entry and sync */
file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]= DDL_IGNORE_LOG_ENTRY_CODE; file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]= DDL_LOG_IGNORE_ENTRY_CODE;
(void) write_ddl_log_file_entry(entry_pos); (void) write_ddl_log_file_entry(entry_pos);
(void) ddl_log_sync_no_lock(); (void) ddl_log_sync_no_lock();
break; break;
...@@ -2400,7 +2400,7 @@ static bool ddl_log_execute_entry_no_lock(THD *thd, uint first_entry) ...@@ -2400,7 +2400,7 @@ static bool ddl_log_execute_entry_no_lock(THD *thd, uint first_entry)
break; break;
} }
DBUG_ASSERT(ddl_log_entry.entry_type == DDL_LOG_ENTRY_CODE || DBUG_ASSERT(ddl_log_entry.entry_type == DDL_LOG_ENTRY_CODE ||
ddl_log_entry.entry_type == DDL_IGNORE_LOG_ENTRY_CODE); ddl_log_entry.entry_type == DDL_LOG_IGNORE_ENTRY_CODE);
if (ddl_log_execute_action(thd, &mem_root, &ddl_log_entry)) if (ddl_log_execute_action(thd, &mem_root, &ddl_log_entry))
{ {
...@@ -2902,23 +2902,24 @@ void ddl_log_complete(DDL_LOG_STATE *state) ...@@ -2902,23 +2902,24 @@ void ddl_log_complete(DDL_LOG_STATE *state)
This is called for failed rename table, create trigger or drop trigger. This is called for failed rename table, create trigger or drop trigger.
*/ */
void ddl_log_revert(THD *thd, DDL_LOG_STATE *state) bool ddl_log_revert(THD *thd, DDL_LOG_STATE *state)
{ {
bool res= 0;
DBUG_ENTER("ddl_log_revert"); DBUG_ENTER("ddl_log_revert");
if (unlikely(!state->list)) if (unlikely(!state->list))
DBUG_VOID_RETURN; // ddl log not used DBUG_RETURN(0); // ddl log not used
mysql_mutex_lock(&LOCK_gdl); mysql_mutex_lock(&LOCK_gdl);
if (likely(state->execute_entry)) if (likely(state->execute_entry))
{ {
ddl_log_execute_entry_no_lock(thd, state->list->entry_pos); res= ddl_log_execute_entry_no_lock(thd, state->list->entry_pos);
ddl_log_disable_execute_entry(&state->execute_entry); ddl_log_disable_execute_entry(&state->execute_entry);
} }
ddl_log_release_entries(state); ddl_log_release_entries(state);
mysql_mutex_unlock(&LOCK_gdl); mysql_mutex_unlock(&LOCK_gdl);
state->list= 0; state->list= 0;
DBUG_VOID_RETURN; DBUG_RETURN(res);
} }
...@@ -3124,6 +3125,16 @@ bool ddl_log_drop_view_init(THD *thd, DDL_LOG_STATE *ddl_state, ...@@ -3124,6 +3125,16 @@ bool ddl_log_drop_view_init(THD *thd, DDL_LOG_STATE *ddl_state,
db, &empty_clex_str); db, &empty_clex_str);
} }
/**
Log DROP TABLE to the ddl log.
This code does not call ddl_log_write() as we want the events to
be stored in call order instead of reverse order, which is the normal
case for all other events.
See also comment before ddl_log_drop_init().
*/
static bool ddl_log_drop(THD *thd, DDL_LOG_STATE *ddl_state, static bool ddl_log_drop(THD *thd, DDL_LOG_STATE *ddl_state,
ddl_log_action_code action_code, ddl_log_action_code action_code,
uint phase, uint phase,
......
...@@ -34,13 +34,13 @@ enum ddl_log_entry_code ...@@ -34,13 +34,13 @@ enum ddl_log_entry_code
DDL_LOG_ENTRY_CODE: DDL_LOG_ENTRY_CODE:
An entry to be executed in a linked list from an execute log An entry to be executed in a linked list from an execute log
entry. entry.
DDL_IGNORE_LOG_ENTRY_CODE: DDL_LOG_IGNORE_ENTRY_CODE:
An entry that is to be ignored An entry that is to be ignored
*/ */
DDL_LOG_UNKNOWN= 0, DDL_LOG_UNKNOWN= 0,
DDL_LOG_EXECUTE_CODE= 1, DDL_LOG_EXECUTE_CODE= 1,
DDL_LOG_ENTRY_CODE= 2, DDL_LOG_ENTRY_CODE= 2,
DDL_IGNORE_LOG_ENTRY_CODE= 3, DDL_LOG_IGNORE_ENTRY_CODE= 3,
DDL_LOG_ENTRY_CODE_LAST= 4 DDL_LOG_ENTRY_CODE_LAST= 4
}; };
...@@ -267,7 +267,7 @@ bool ddl_log_write_execute_entry(uint first_entry, ...@@ -267,7 +267,7 @@ bool ddl_log_write_execute_entry(uint first_entry,
bool ddl_log_disable_execute_entry(DDL_LOG_MEMORY_ENTRY **active_entry); bool ddl_log_disable_execute_entry(DDL_LOG_MEMORY_ENTRY **active_entry);
void ddl_log_complete(DDL_LOG_STATE *ddl_log_state); void ddl_log_complete(DDL_LOG_STATE *ddl_log_state);
void ddl_log_revert(THD *thd, DDL_LOG_STATE *ddl_log_state); bool ddl_log_revert(THD *thd, DDL_LOG_STATE *ddl_log_state);
bool ddl_log_update_phase(DDL_LOG_STATE *entry, uchar phase); bool ddl_log_update_phase(DDL_LOG_STATE *entry, uchar phase);
bool ddl_log_add_flag(DDL_LOG_STATE *entry, uint16 flag); bool ddl_log_add_flag(DDL_LOG_STATE *entry, uint16 flag);
......
...@@ -697,7 +697,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) ...@@ -697,7 +697,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
ddl_log_complete(&ddl_log_state); ddl_log_complete(&ddl_log_state);
debug_crash_here("ddl_log_drop_before_delete_tmp"); debug_crash_here("ddl_log_drop_before_delete_tmp");
/* delete any created log files */ /* delete any created log files */
ddl_log_revert(thd, &ddl_log_state_tmp_file); result|= ddl_log_revert(thd, &ddl_log_state_tmp_file);
/* /*
If we are under LOCK TABLES we should restore original state of If we are under LOCK TABLES we should restore original state of
meta-data locks. Otherwise all locks will be released along meta-data locks. Otherwise all locks will be released along
......
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