MCPcopy Create free account
hub / github.com/Tencent/phxsql / reset_logs

Method reset_logs

phx_percona/percona/sql/binlog.cc:3909–4059  ·  view source on GitHub ↗

Removes files, as part of a RESET MASTER or RESET SLAVE statement, by deleting all logs refered to in the index file. Then, it starts writing to a new log file. The new index file will only contain this file. @param thd Thread @note If not called from slave thread, write start event to new log @retval 0 ok @retval 1 error */

Source from the content-addressed store, hash-verified

3907 1 error
3908*/
3909bool MYSQL_BIN_LOG::reset_logs(THD* thd)
3910{
3911 LOG_INFO linfo;
3912 bool error=0;
3913 int err;
3914 const char* save_name;
3915 DBUG_ENTER("reset_logs");
3916
3917 /*
3918 Flush logs for storage engines, so that the last transaction
3919 is fsynced inside storage engines.
3920 */
3921 if (ha_flush_logs(NULL))
3922 DBUG_RETURN(1);
3923
3924 ha_reset_logs(thd);
3925
3926 /*
3927 We need to get both locks to be sure that no one is trying to
3928 write to the index log file.
3929 */
3930 mysql_mutex_lock(&LOCK_log);
3931 mysql_mutex_lock(&LOCK_index);
3932
3933 /*
3934 The following mutex is needed to ensure that no threads call
3935 'delete thd' as we would then risk missing a 'rollback' from this
3936 thread. If the transaction involved MyISAM tables, it should go
3937 into binlog even on rollback.
3938 */
3939 mysql_mutex_lock(&LOCK_thread_count);
3940
3941 global_sid_lock->wrlock();
3942
3943 /* Save variables so that we can reopen the log */
3944 save_name=name;
3945 name=0; // Protect against free
3946 close(LOG_CLOSE_TO_BE_OPENED);
3947
3948 /*
3949 First delete all old log files and then update the index file.
3950 As we first delete the log files and do not use sort of logging,
3951 a crash may lead to an inconsistent state where the index has
3952 references to non-existent files.
3953
3954 We need to invert the steps and use the purge_index_file methods
3955 in order to make the operation safe.
3956 */
3957
3958 if ((err= find_log_pos(&linfo, NullS, false/*need_lock_index=false*/)) != 0)
3959 {
3960 uint errcode= purge_log_get_error_code(err);
3961 sql_print_error("Failed to locate old binlog or relay log files");
3962 my_message(errcode, ER(errcode), MYF(0));
3963 error= 1;
3964 goto err;
3965 }
3966

Callers

nothing calls this directly

Calls 1

initMethod · 0.45

Tested by

no test coverage detected