As I analyzed this while you were developing the patch a I have just one
comment. See it in-line.
Luís Soares wrote:
> #At file:///stuff/workspace/mysql-server/5.1-rpl-39325/
>
> 2684 Luís Soares 2008-10-28
> In purge_first_log: flushes first the relay-log.info and only then purges the
> logs. Fix BUG#39325.
> modified:
> sql/log.cc
>
> === modified file 'sql/log.cc'
> --- a/sql/log.cc 2008-10-06 08:27:36 +0000
> +++ b/sql/log.cc 2008-10-28 15:34:29 +0000
> @@ -2918,10 +2918,11 @@ err:
>
> IMPLEMENTATION
> - Protects index file with LOCK_index
> + - Read the next file name from the index file and store in rli->linfo
> - Delete relevant relay log files
> - Copy all file names after these ones to the front of the index file
> - If the OS has truncate, truncate the file, else fill it with \n'
> - - Read the next file name from the index file and store in rli->linfo
> +
>
> @param rli Relay log information
> @param included If false, all relay logs that are strictly before
> @@ -2952,6 +2953,7 @@ err:
> int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
> {
> int error;
> + char *to_purge_if_included = NULL;
> DBUG_ENTER("purge_first_log");
>
> DBUG_ASSERT(is_open());
> @@ -2959,36 +2961,20 @@ int MYSQL_BIN_LOG::purge_first_log(Relay
> DBUG_ASSERT(!strcmp(rli->linfo.log_file_name,rli->event_relay_log_name));
>
> pthread_mutex_lock(&LOCK_index);
> - pthread_mutex_lock(&rli->log_space_lock);
> - rli->relay_log.purge_logs(rli->group_relay_log_name, included,
> - 0, 0, &rli->log_space_total);
> - // Tell the I/O thread to take the relay_log_space_limit into account
> - rli->ignore_log_space_limit= 0;
> - pthread_mutex_unlock(&rli->log_space_lock);
> + to_purge_if_included = my_strdup(rli->group_relay_log_name, MYF(0));
>
> /*
> - Ok to broadcast after the critical region as there is no risk of
> - the mutex being destroyed by this thread later - this helps save
> - context switches
> - */
> - pthread_cond_broadcast(&rli->log_space_cond);
> -
> - /*
> Read the next log file name from the index file and pass it back to
> - the caller
> - If included is true, we want the first relay log;
> - otherwise we want the one after event_relay_log_name.
> - */
> - if ((included && (error=find_log_pos(&rli->linfo, NullS, 0))) ||
> - (!included &&
> - ((error=find_log_pos(&rli->linfo, rli->event_relay_log_name, 0))
> ||
> - (error=find_next_log(&rli->linfo, 0)))))
> + the caller.
> + */
> + if((error=find_log_pos(&rli->linfo, rli->event_relay_log_name, 0)) ||
> + (error=find_next_log(&rli->linfo, 0)))
> {
> char buff[22];
> sql_print_error("next log error: %d offset: %s log: %s included: %d",
> error,
> llstr(rli->linfo.index_file_offset,buff),
> - rli->group_relay_log_name,
> + rli->event_relay_log_name,
> included);
> goto err;
> }
> @@ -3013,10 +2999,48 @@ int MYSQL_BIN_LOG::purge_first_log(Relay
> rli->notify_group_relay_log_name_update();
> }
>
> + DBUG_EXECUTE_IF("crash_before_flush_relay_log_info", abort(););
> +
> /* Store where we are in the new file for the execution thread */
> flush_relay_log_info(rli);
>
>
> + DBUG_EXECUTE_IF("crash_before_purge_logs", abort(););
>
This is not necessary as the same thing is done in
BUG#38826
> +
> + pthread_mutex_lock(&rli->log_space_lock);
> + rli->relay_log.purge_logs(to_purge_if_included, included,
> + 0, 0, &rli->log_space_total);
> + // Tell the I/O thread to take the relay_log_space_limit into account
> + rli->ignore_log_space_limit= 0;
> + pthread_mutex_unlock(&rli->log_space_lock);
> +
> + /*
> + Ok to broadcast after the critical region as there is no risk of
> + the mutex being destroyed by this thread later - this helps save
> + context switches
> + */
> + pthread_cond_broadcast(&rli->log_space_cond);
> +
> + /*
> + * Need to update the log pos because purge logs has been called
> + * after fetching initially the log pos at the begining of the method.
> + */
> + if(error=find_log_pos(&rli->linfo, rli->event_relay_log_name, 0))
> + {
> + char buff[22];
> + sql_print_error("next log error: %d offset: %s log: %s included: %d",
> + error,
> + llstr(rli->linfo.index_file_offset,buff),
> + rli->group_relay_log_name,
> + included);
> + goto err;
> + }
> +
> + /* If included was passed, rli->linfo should be the first entry. */
> + DBUG_ASSERT(!included || rli->linfo.index_file_start_offset == 0);
> +
> +
> err:
> + my_free(to_purge_if_included, MYF(0));
> pthread_mutex_unlock(&LOCK_index);
> DBUG_RETURN(error);
> }
>
>
Cheers.