@@ -195,6 +195,7 @@ static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 6];
195195lsn_t checkpoint_lsn_start;
196196lsn_t checkpoint_no_start;
197197lsn_t log_copy_scanned_lsn;
198+ lsn_t latest_cp = 0 ;
198199ibool log_copying = TRUE ;
199200ibool log_copying_running = FALSE ;
200201ibool io_watching_thread_running = FALSE ;
@@ -3014,6 +3015,13 @@ xtrabackup_scan_log_recs(
30143015 log_block = log_sys->buf ;
30153016
30163017 while (log_block < log_sys->buf + RECV_SCAN_SIZE && !*finished) {
3018+ if (latest_cp > 0 && scanned_lsn > latest_cp) {
3019+ *finished = true ;
3020+ msg (" xtrabackup: Stop scanning at LSN " LSN_PF
3021+ " as it exceeds latest checkpoint LSN " LSN_PF " \n " ,
3022+ scanned_lsn, latest_cp);
3023+ break ;
3024+ }
30173025 ulint no = log_block_get_hdr_no (log_block);
30183026 ulint scanned_no = log_block_convert_lsn_to_no (scanned_lsn);
30193027 ibool checksum_is_ok = log_block_checksum_is_ok (log_block);
@@ -4652,7 +4660,7 @@ void
46524660xtrabackup_backup_func (void )
46534661{
46544662 MY_STAT stat_info;
4655- lsn_t latest_cp ;
4663+ lsn_t latest_cp_before_lock ;
46564664 uint i;
46574665 uint count;
46584666 ib_mutex_t count_mutex;
@@ -5071,6 +5079,58 @@ xtrabackup_backup_func(void)
50715079 }
50725080 }
50735081
5082+ /* read the latest checkpoint lsn before lock and
5083+ wait until the redo log copying thread catches up to the latest checkpoint lsn*/
5084+ latest_cp_before_lock = 0 ;
5085+
5086+ {
5087+ log_group_t * max_cp_group;
5088+ ulint max_cp_field;
5089+ ulint err;
5090+
5091+ mutex_enter (&log_sys->mutex );
5092+
5093+ err = recv_find_max_checkpoint (&max_cp_group, &max_cp_field);
5094+
5095+ if (err != DB_SUCCESS ) {
5096+ msg (" xtrabackup: Error: recv_find_max_checkpoint() failed.\n " );
5097+ mutex_exit (&log_sys->mutex );
5098+ goto skip_last_cp;
5099+ }
5100+
5101+ log_group_header_read (max_cp_group, max_cp_field);
5102+
5103+ xtrabackup_choose_lsn_offset (checkpoint_lsn_start);
5104+
5105+ latest_cp_before_lock = mach_read_from_8 (log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN );
5106+
5107+ mutex_exit (&log_sys->mutex );
5108+
5109+ msg_ts (" xtrabackup: The latest checkpoint LSN before lock: '"
5110+ LSN_PF " '\n " , latest_cp_before_lock);
5111+
5112+ bool first_wait = true ;
5113+
5114+ while (true ) {
5115+ if (log_copy_scanned_lsn >= latest_cp_before_lock) {
5116+ msg_ts (" xtrabackup: The log_copy LSN (" LSN_PF
5117+ " ) is larger than latest checkpoint LSN (" LSN_PF " )\n " ,
5118+ log_copy_scanned_lsn, latest_cp_before_lock);
5119+ break ;
5120+ } else {
5121+ if (first_wait) {
5122+ msg_ts (" xtrabackup: Waiting for log copy thread to catchup to LSN "
5123+ LSN_PF " (currently parsing at " LSN_PF " )\n " ,
5124+ latest_cp_before_lock, log_copy_scanned_lsn);
5125+ first_wait = false ;
5126+ } else {
5127+ msg (" ." );
5128+ }
5129+ os_thread_sleep (1000000 );
5130+ }
5131+ }
5132+ }
5133+
50745134 if (!backup_start ()) {
50755135 exit (EXIT_FAILURE );
50765136 }
0 commit comments