Start writing to a new log file or reopen the old file. @param need_lock_log If true, this function acquires LOCK_log; otherwise the caller should already have acquired it. @retval 0 success @retval nonzero - error @note The new file name is stored last in the index file */
| 5074 | @note The new file name is stored last in the index file |
| 5075 | */ |
| 5076 | int MYSQL_BIN_LOG::new_file_impl(bool need_lock_log, Format_description_log_event *extra_description_event) |
| 5077 | { |
| 5078 | int error= 0, close_on_error= FALSE; |
| 5079 | char new_name[FN_REFLEN], *new_name_ptr, *old_name, *file_to_open; |
| 5080 | |
| 5081 | DBUG_ENTER("MYSQL_BIN_LOG::new_file_impl"); |
| 5082 | if (!is_open()) |
| 5083 | { |
| 5084 | DBUG_PRINT("info",("log is closed")); |
| 5085 | DBUG_RETURN(error); |
| 5086 | } |
| 5087 | |
| 5088 | if (need_lock_log) |
| 5089 | mysql_mutex_lock(&LOCK_log); |
| 5090 | else |
| 5091 | mysql_mutex_assert_owner(&LOCK_log); |
| 5092 | DBUG_EXECUTE_IF("semi_sync_3-way_deadlock", |
| 5093 | DEBUG_SYNC(current_thd, "before_rotate_binlog");); |
| 5094 | mysql_mutex_lock(&LOCK_xids); |
| 5095 | /* |
| 5096 | We need to ensure that the number of prepared XIDs are 0. |
| 5097 | |
| 5098 | If m_prep_xids is not zero: |
| 5099 | - We wait for storage engine commit, hence decrease m_prep_xids |
| 5100 | - We keep the LOCK_log to block new transactions from being |
| 5101 | written to the binary log. |
| 5102 | */ |
| 5103 | while (get_prep_xids() > 0) |
| 5104 | { |
| 5105 | DEBUG_SYNC(current_thd, "before_rotate_binlog_file"); |
| 5106 | mysql_cond_wait(&m_prep_xids_cond, &LOCK_xids); |
| 5107 | } |
| 5108 | mysql_mutex_unlock(&LOCK_xids); |
| 5109 | |
| 5110 | mysql_mutex_lock(&LOCK_index); |
| 5111 | |
| 5112 | if (DBUG_EVALUATE_IF("expire_logs_always", 0, 1) |
| 5113 | && (error= ha_flush_logs(NULL))) |
| 5114 | goto end; |
| 5115 | |
| 5116 | mysql_mutex_assert_owner(&LOCK_log); |
| 5117 | mysql_mutex_assert_owner(&LOCK_index); |
| 5118 | |
| 5119 | |
| 5120 | /* |
| 5121 | If user hasn't specified an extension, generate a new log name |
| 5122 | We have to do this here and not in open as we want to store the |
| 5123 | new file name in the current binary log file. |
| 5124 | */ |
| 5125 | new_name_ptr= new_name; |
| 5126 | if ((error= generate_new_name(new_name, name))) |
| 5127 | { |
| 5128 | // Use the old name if generation of new name fails. |
| 5129 | strcpy(new_name, name); |
| 5130 | close_on_error= TRUE; |
| 5131 | goto end; |
| 5132 | } |
| 5133 | else |
nothing calls this directly
no outgoing calls
no test coverage detected