3242
3242
bool need_lock)
3245
char *fname= linfo->log_file_name;
3246
uint log_name_len= log_name ? (uint) strlen(log_name) : 0;
3245
char *full_fname= linfo->log_file_name;
3246
char full_log_name[FN_REFLEN], fname[FN_REFLEN];
3247
uint log_name_len= 0, fname_len= 0;
3247
3248
DBUG_ENTER("find_log_pos");
3248
DBUG_PRINT("enter",("log_name: %s", log_name ? log_name : "NULL"));
3249
full_log_name[0]= full_fname[0]= 0;
3251
3252
Mutex needed because we need to make sure the file pointer does not
3255
3256
mysql_mutex_lock(&LOCK_index);
3256
3257
mysql_mutex_assert_owner(&LOCK_index);
3259
// extend relative paths for log_name to be searched
3262
if(normalize_binlog_name(full_log_name, log_name, is_relay_log))
3264
error= LOG_INFO_EOF;
3269
log_name_len= log_name ? (uint) strlen(full_log_name) : 0;
3270
DBUG_PRINT("enter", ("log_name: %s, full_log_name: %s",
3271
log_name ? log_name : "NULL", full_log_name));
3258
3273
/* As the file is flushed, we can't get an error here */
3259
3274
(void) reinit_io_cache(&index_file, READ_CACHE, (my_off_t) 0, 0, 0);
3291
// extend relative paths and match against full path
3292
if (normalize_binlog_name(full_fname, fname, is_relay_log))
3294
error= LOG_INFO_EOF;
3297
fname_len= (uint) strlen(full_fname);
3276
3299
// if the log entry matches, null string matching anything
3277
3300
if (!log_name ||
3278
(log_name_len == length-1 && fname[log_name_len] == '\n' &&
3279
!memcmp(fname, log_name, log_name_len)))
3301
(log_name_len == fname_len-1 && full_fname[log_name_len] == '\n' &&
3302
!memcmp(full_fname, full_log_name, log_name_len)))
3281
DBUG_PRINT("info",("Found log file entry"));
3282
fname[length-1]=0; // remove last \n
3304
DBUG_PRINT("info", ("Found log file entry"));
3305
full_fname[fname_len-1]= 0; // remove last \n
3283
3306
linfo->index_file_start_offset= offset;
3284
3307
linfo->index_file_offset = my_b_tell(&index_file);
3290
3314
mysql_mutex_unlock(&LOCK_index);
3291
3315
DBUG_RETURN(error);
3336
3361
error = !index_file.error ? LOG_INFO_EOF : LOG_INFO_IO;
3339
fname[length-1]=0; // kill \n
3340
linfo->index_file_offset = my_b_tell(&index_file);
3367
if(normalize_binlog_name(full_fname, fname, is_relay_log))
3369
error= LOG_INFO_EOF;
3372
length= strlen(full_fname);
3375
full_fname[length-1]= 0; // kill \n
3376
linfo->index_file_offset= my_b_tell(&index_file);
5004
5040
if ((error= flush_and_sync(&synced)))
5007
if ((error= RUN_HOOK(binlog_storage, after_flush,
5042
mysql_mutex_unlock(&LOCK_log);
5044
else if ((error= RUN_HOOK(binlog_storage, after_flush,
5008
5045
(thd, log_file_name, file->pos_in_file, synced))))
5010
5047
sql_print_error("Failed to run 'after_flush' hooks");
5048
mysql_mutex_unlock(&LOCK_log);
5054
error= rotate(false, &check_purge);
5055
mysql_mutex_unlock(&LOCK_log);
5056
if (!error && check_purge)
5014
rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
5017
mysql_mutex_unlock(&LOCK_log);
5062
mysql_mutex_unlock(&LOCK_log);
5149
The method executes rotation when LOCK_log is already acquired
5152
@param force_rotate caller can request the log rotation
5153
@param check_purge is set to true if rotation took place
5104
5156
If rotation fails, for instance the server was unable
5105
5157
to create a new log file, we still try to write an
5106
5158
incident event to the current log.
5161
nonzero - error in rotating routine.
5111
int MYSQL_BIN_LOG::rotate_and_purge(uint flags)
5163
int MYSQL_BIN_LOG::rotate(bool force_rotate, bool* check_purge)
5114
DBUG_ENTER("MYSQL_BIN_LOG::rotate_and_purge");
5115
#ifdef HAVE_REPLICATION
5116
bool check_purge= false;
5118
if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
5119
mysql_mutex_lock(&LOCK_log);
5120
if ((flags & RP_FORCE_ROTATE) ||
5121
(my_b_tell(&log_file) >= (my_off_t) max_size))
5166
DBUG_ENTER("MYSQL_BIN_LOG::rotate");
5168
//todo: fix the macro def and restore safe_mutex_assert_owner(&LOCK_log);
5169
*check_purge= false;
5171
if (force_rotate || (my_b_tell(&log_file) >= (my_off_t) max_size))
5123
5173
if ((error= new_file_without_locking()))
5133
5183
if (!write_incident(current_thd, FALSE))
5134
5184
flush_and_sync(0);
5136
#ifdef HAVE_REPLICATION
5140
if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
5141
mysql_mutex_unlock(&LOCK_log);
5192
The method executes logs purging routine.
5195
nonzero - error in rotating routine.
5197
void MYSQL_BIN_LOG::purge()
5142
5199
#ifdef HAVE_REPLICATION
5144
NOTE: Run purge_logs wo/ holding LOCK_log
5145
as it otherwise will deadlock in ndbcluster_binlog_index_purge_file
5147
if (!error && check_purge && expire_logs_days)
5200
if (expire_logs_days)
5202
DEBUG_SYNC(current_thd, "at_purge_logs_before_date");
5149
5203
time_t purge_time= my_time(0) - expire_logs_days*24*60*60;
5150
5204
if (purge_time >= 0)
5151
5206
purge_logs_before_date(purge_time);
5213
The method is a shortcut of @c rotate() and @c purge().
5214
LOCK_log is acquired prior to rotate and is released after it.
5216
@param force_rotate caller can request the log rotation
5219
nonzero - error in rotating routine.
5221
int MYSQL_BIN_LOG::rotate_and_purge(bool force_rotate)
5224
DBUG_ENTER("MYSQL_BIN_LOG::rotate_and_purge");
5225
bool check_purge= false;
5227
//todo: fix the macro def and restore safe_mutex_assert_not_owner(&LOCK_log);
5228
mysql_mutex_lock(&LOCK_log);
5229
error= rotate(force_rotate, &check_purge);
5231
NOTE: Run purge_logs wo/ holding LOCK_log because it does not need
5232
the mutex. Otherwise causes various deadlocks.
5234
mysql_mutex_unlock(&LOCK_log);
5236
if (!error && check_purge)
5154
5239
DBUG_RETURN(error);
5353
5438
if (!error && !(error= flush_and_sync(0)))
5440
bool check_purge= false;
5355
5441
signal_update();
5356
error= rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
5358
mysql_mutex_unlock(&LOCK_log);
5442
error= rotate(false, &check_purge);
5443
mysql_mutex_unlock(&LOCK_log);
5444
if (!error && check_purge)
5449
mysql_mutex_unlock(&LOCK_log);
5360
5452
DBUG_RETURN(error);
5390
5482
DBUG_ENTER("MYSQL_BIN_LOG::write(THD *, IO_CACHE *, Log_event *)");
5391
mysql_mutex_lock(&LOCK_log);
5393
5484
DBUG_ASSERT(is_open());
5394
5485
if (likely(is_open())) // Should always be true
5489
mysql_mutex_lock(&LOCK_log);
5397
5491
We only bother to write to the binary log if there is anything
5460
5554
mysql_mutex_lock(&LOCK_prep_xids);
5461
5555
prepared_xids++;
5462
5556
mysql_mutex_unlock(&LOCK_prep_xids);
5557
mysql_mutex_unlock(&LOCK_log);
5465
if (rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED))
5561
if (rotate(false, &check_purge))
5563
mysql_mutex_unlock(&LOCK_log);
5468
mysql_mutex_unlock(&LOCK_log);
5470
5569
DBUG_RETURN(0);