From 68691df3c509670dd148df9d3058aba222c78315 Mon Sep 17 00:00:00 2001 From: Insensiblee <1097434462@qq.com> Date: Thu, 19 Jun 2025 19:39:52 +0800 Subject: [PATCH] lock tune --- azure-pipelines.yml | 2 +- storage/innobase/xtrabackup/src/xtrabackup.cc | 62 ++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7705d554e846..a458bce1bf4d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,7 +1,7 @@ jobs: - job: BiDiScan pool: - vmImage: 'ubuntu-18.04' + vmImage: 'ubuntu-latest' steps: - checkout: self diff --git a/storage/innobase/xtrabackup/src/xtrabackup.cc b/storage/innobase/xtrabackup/src/xtrabackup.cc index 682e3335b60c..bf0116338ff2 100644 --- a/storage/innobase/xtrabackup/src/xtrabackup.cc +++ b/storage/innobase/xtrabackup/src/xtrabackup.cc @@ -195,6 +195,7 @@ static os_thread_id_t thread_ids[SRV_MAX_N_IO_THREADS + 6]; lsn_t checkpoint_lsn_start; lsn_t checkpoint_no_start; lsn_t log_copy_scanned_lsn; +lsn_t latest_cp = 0; ibool log_copying = TRUE; ibool log_copying_running = FALSE; ibool io_watching_thread_running = FALSE; @@ -3014,6 +3015,13 @@ xtrabackup_scan_log_recs( log_block = log_sys->buf; while (log_block < log_sys->buf + RECV_SCAN_SIZE && !*finished) { + if (latest_cp > 0 && scanned_lsn > latest_cp) { + *finished = true; + msg("xtrabackup: Stop scanning at LSN " LSN_PF + " as it exceeds latest checkpoint LSN " LSN_PF "\n", + scanned_lsn, latest_cp); + break; + } ulint no = log_block_get_hdr_no(log_block); ulint scanned_no = log_block_convert_lsn_to_no(scanned_lsn); ibool checksum_is_ok = log_block_checksum_is_ok(log_block); @@ -4652,7 +4660,7 @@ void xtrabackup_backup_func(void) { MY_STAT stat_info; - lsn_t latest_cp; + lsn_t latest_cp_before_lock; uint i; uint count; ib_mutex_t count_mutex; @@ -5071,6 +5079,58 @@ xtrabackup_backup_func(void) } } + /* read the latest checkpoint lsn before lock and + wait until the redo log copying thread catches up to the latest checkpoint lsn*/ + latest_cp_before_lock = 0; + + { + log_group_t* max_cp_group; + ulint max_cp_field; + ulint err; + + mutex_enter(&log_sys->mutex); + + err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field); + + if (err != DB_SUCCESS) { + msg("xtrabackup: Error: recv_find_max_checkpoint() failed.\n"); + mutex_exit(&log_sys->mutex); + goto skip_last_cp; + } + + log_group_header_read(max_cp_group, max_cp_field); + + xtrabackup_choose_lsn_offset(checkpoint_lsn_start); + + latest_cp_before_lock = mach_read_from_8(log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN); + + mutex_exit(&log_sys->mutex); + + msg_ts("xtrabackup: The latest checkpoint LSN before lock: '" + LSN_PF "'\n", latest_cp_before_lock); + + bool first_wait = true; + + while (true) { + if (log_copy_scanned_lsn >= latest_cp_before_lock) { + msg_ts("xtrabackup: The log_copy LSN (" LSN_PF + ") is larger than latest checkpoint LSN (" LSN_PF ")\n", + log_copy_scanned_lsn, latest_cp_before_lock); + break; + } else { + if (first_wait) { + msg_ts("xtrabackup: Waiting for log copy thread to catchup to LSN " + LSN_PF " (currently parsing at " LSN_PF ")\n", + latest_cp_before_lock, log_copy_scanned_lsn); + first_wait = false; + } else { + msg("."); + } + os_thread_sleep(1000000); + } + } + } + if (!backup_start()) { exit(EXIT_FAILURE); }