@@ -172,7 +172,6 @@ typedef struct xb_filter_entry_struct xb_filter_entry_t;
172
172
lsn_t checkpoint_lsn_start;
173
173
lsn_t checkpoint_no_start;
174
174
static lsn_t log_copy_scanned_lsn;
175
- static bool log_copying;
176
175
static bool log_copying_running;
177
176
static bool io_watching_thread_running;
178
177
@@ -2452,25 +2451,12 @@ xtrabackup_copy_datafile(fil_node_t* node, uint thread_n)
2452
2451
return (FALSE );
2453
2452
}
2454
2453
2455
- /* * How to copy a redo log segment in backup */
2456
- enum copy_logfile {
2457
- /* * Initial copying: copy at least one block */
2458
- COPY_FIRST,
2459
- /* * Tracking while copying data files */
2460
- COPY_ONLINE,
2461
- /* * Final copying: copy until the end of the log */
2462
- COPY_LAST
2463
- };
2464
-
2465
2454
/* * Copy redo log blocks to the data sink.
2466
- @param[in] copy how to copy the log
2467
- @param[in] start_lsn buffer start LSN
2468
- @param[in] end_lsn buffer end LSN
2469
- @return last scanned LSN (equals to last copied LSN if copy=COPY_LAST)
2455
+ @param start_lsn buffer start LSN
2456
+ @param end_lsn buffer end LSN
2457
+ @return last scanned LSN
2470
2458
@retval 0 on failure */
2471
- static
2472
- lsn_t
2473
- xtrabackup_copy_log (copy_logfile copy, lsn_t start_lsn, lsn_t end_lsn)
2459
+ static lsn_t xtrabackup_copy_log (lsn_t start_lsn, lsn_t end_lsn)
2474
2460
{
2475
2461
lsn_t scanned_lsn = start_lsn;
2476
2462
const byte* log_block = log_sys->buf ;
@@ -2485,6 +2471,9 @@ xtrabackup_copy_log(copy_logfile copy, lsn_t start_lsn, lsn_t end_lsn)
2485
2471
&& scanned_checkpoint - checkpoint >= 0x80000000UL ) {
2486
2472
/* Garbage from a log buffer flush which was made
2487
2473
before the most recent database recovery */
2474
+ msg (" mariabackup: checkpoint wrap: "
2475
+ LSN_PF " ,%zx,%zx\n " ,
2476
+ scanned_lsn, scanned_checkpoint, checkpoint);
2488
2477
break ;
2489
2478
}
2490
2479
@@ -2505,6 +2494,8 @@ xtrabackup_copy_log(copy_logfile copy, lsn_t start_lsn, lsn_t end_lsn)
2505
2494
>= OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE
2506
2495
|| data_len <= LOG_BLOCK_HDR_SIZE) {
2507
2496
/* We got a garbage block (abrupt end of the log). */
2497
+ msg (" mariabackup: garbage block: " LSN_PF " ,%zu\n " ,
2498
+ scanned_lsn, data_len);
2508
2499
break ;
2509
2500
} else {
2510
2501
/* We got a partial block (abrupt end of the log). */
@@ -2524,7 +2515,7 @@ xtrabackup_copy_log(copy_logfile copy, lsn_t start_lsn, lsn_t end_lsn)
2524
2515
2525
2516
log_sys->log .scanned_lsn = scanned_lsn;
2526
2517
2527
- end_lsn = copy == COPY_LAST
2518
+ end_lsn = metadata_to_lsn
2528
2519
? ut_uint64_align_up (scanned_lsn, OS_FILE_LOG_BLOCK_SIZE)
2529
2520
: scanned_lsn & ~lsn_t (OS_FILE_LOG_BLOCK_SIZE - 1 );
2530
2521
@@ -2544,10 +2535,8 @@ xtrabackup_copy_log(copy_logfile copy, lsn_t start_lsn, lsn_t end_lsn)
2544
2535
}
2545
2536
2546
2537
/* * Copy redo log until the current end of the log is reached
2547
- @param copy how to copy the log
2548
2538
@return whether the operation failed */
2549
- static bool
2550
- xtrabackup_copy_logfile (copy_logfile copy)
2539
+ static bool xtrabackup_copy_logfile ()
2551
2540
{
2552
2541
ut_a (dst_log_file != NULL );
2553
2542
ut_ad (recv_sys != NULL );
@@ -2560,33 +2549,29 @@ xtrabackup_copy_logfile(copy_logfile copy)
2560
2549
2561
2550
start_lsn = ut_uint64_align_down (log_copy_scanned_lsn,
2562
2551
OS_FILE_LOG_BLOCK_SIZE);
2563
- /* When copying the first or last part of the log, retry a few
2564
- times to ensure that all log up to the last checkpoint will be
2565
- read. */
2566
2552
do {
2567
2553
end_lsn = start_lsn + RECV_SCAN_SIZE;
2568
2554
2569
2555
xtrabackup_io_throttling ();
2570
2556
2571
2557
log_mutex_enter ();
2572
-
2573
2558
lsn_t lsn= start_lsn;
2574
- for (int retries= 0 ; retries < 100 ; retries++) {
2559
+ for (int retries= 0 ; retries < 100 ; retries++) {
2575
2560
if (log_group_read_log_seg (log_sys->buf , &log_sys->log ,
2576
- &lsn, end_lsn)){
2561
+ &lsn, end_lsn)
2562
+ || lsn != start_lsn) {
2577
2563
break ;
2578
2564
}
2579
- msg (" Retrying read of a redo log block " );
2565
+ msg (" Retrying read of log at LSN= " LSN_PF " \n " , lsn );
2580
2566
my_sleep (1000 );
2581
2567
}
2582
2568
2583
- start_lsn = xtrabackup_copy_log (copy, start_lsn, lsn);
2569
+ start_lsn = (lsn == start_lsn)
2570
+ ? 0 : xtrabackup_copy_log (start_lsn, lsn);
2584
2571
2585
2572
log_mutex_exit ();
2586
2573
2587
2574
if (!start_lsn) {
2588
- ds_close (dst_log_file);
2589
- dst_log_file = NULL ;
2590
2575
msg (" mariabackup: Error: xtrabackup_copy_logfile()"
2591
2576
" failed.\n " );
2592
2577
return (true );
@@ -2612,12 +2597,23 @@ static os_thread_ret_t log_copying_thread(void*)
2612
2597
*/
2613
2598
my_thread_init ();
2614
2599
2615
- do {
2600
+ for (;;) {
2616
2601
os_event_reset (log_copying_stop);
2617
2602
os_event_wait_time_low (log_copying_stop,
2618
2603
xtrabackup_log_copy_interval * 1000ULL ,
2619
2604
0 );
2620
- } while (log_copying && xtrabackup_copy_logfile (COPY_ONLINE));
2605
+ if (xtrabackup_copy_logfile ()) {
2606
+ break ;
2607
+ }
2608
+
2609
+ log_mutex_enter ();
2610
+ bool completed = metadata_to_lsn
2611
+ && metadata_to_lsn < log_copy_scanned_lsn;
2612
+ log_mutex_exit ();
2613
+ if (completed) {
2614
+ break ;
2615
+ }
2616
+ }
2621
2617
2622
2618
log_copying_running = false ;
2623
2619
my_thread_end ();
@@ -2632,7 +2628,7 @@ static os_thread_ret_t io_watching_thread(void*)
2632
2628
/* currently, for --backup only */
2633
2629
ut_a (xtrabackup_backup);
2634
2630
2635
- while (log_copying ) {
2631
+ while (log_copying_running && !metadata_to_lsn ) {
2636
2632
os_thread_sleep (1000000 ); /* 1 sec*/
2637
2633
io_ticket = xtrabackup_throttle;
2638
2634
os_event_set (wait_throttle);
@@ -3662,16 +3658,16 @@ xb_set_max_open_files(
3662
3658
3663
3659
static void stop_backup_threads ()
3664
3660
{
3665
- log_copying = false ;
3666
-
3667
- if (log_copying_stop) {
3661
+ if (log_copying_stop && log_copying_running) {
3668
3662
os_event_set (log_copying_stop);
3669
- msg (" mariabackup: Stopping log copying thread.\n " );
3663
+ fputs (" mariabackup: Stopping log copying thread" , stderr);
3664
+ fflush (stderr);
3670
3665
while (log_copying_running) {
3671
- msg (" ." );
3666
+ putc (' .' , stderr);
3667
+ fflush (stderr);
3672
3668
os_thread_sleep (200000 ); /* 0.2 sec*/
3673
3669
}
3674
- msg ( " \n " );
3670
+ putc ( ' \n ' , stderr );
3675
3671
os_event_destroy (log_copying_stop);
3676
3672
}
3677
3673
@@ -3686,10 +3682,10 @@ static void stop_backup_threads()
3686
3682
3687
3683
/* * Implement the core of --backup
3688
3684
@return whether the operation succeeded */
3689
- static
3690
- bool
3691
- xtrabackup_backup_low ()
3685
+ static bool xtrabackup_backup_low ()
3692
3686
{
3687
+ ut_ad (!metadata_to_lsn);
3688
+
3693
3689
/* read the latest checkpoint lsn */
3694
3690
{
3695
3691
ulint max_cp_field;
@@ -3698,25 +3694,24 @@ xtrabackup_backup_low()
3698
3694
3699
3695
if (recv_find_max_checkpoint (&max_cp_field) == DB_SUCCESS
3700
3696
&& log_sys->log .format != 0 ) {
3697
+ if (max_cp_field == LOG_CHECKPOINT_1) {
3698
+ log_group_header_read (&log_sys->log ,
3699
+ max_cp_field);
3700
+ }
3701
3701
metadata_to_lsn = mach_read_from_8 (
3702
3702
log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN);
3703
3703
msg (" mariabackup: The latest check point"
3704
3704
" (for incremental): '" LSN_PF " '\n " ,
3705
3705
metadata_to_lsn);
3706
3706
} else {
3707
- metadata_to_lsn = 0 ;
3708
3707
msg (" mariabackup: Error: recv_find_max_checkpoint() failed.\n " );
3709
3708
}
3710
3709
log_mutex_exit ();
3711
3710
}
3712
3711
3713
3712
stop_backup_threads ();
3714
3713
3715
- if (!dst_log_file || xtrabackup_copy_logfile (COPY_LAST)) {
3716
- return false ;
3717
- }
3718
-
3719
- if (ds_close (dst_log_file)) {
3714
+ if (ds_close (dst_log_file) || !metadata_to_lsn) {
3720
3715
dst_log_file = NULL ;
3721
3716
return false ;
3722
3717
}
@@ -3795,6 +3790,7 @@ xtrabackup_backup_func()
3795
3790
srv_read_only_mode = TRUE ;
3796
3791
3797
3792
srv_operation = SRV_OPERATION_BACKUP;
3793
+ metadata_to_lsn = 0 ;
3798
3794
3799
3795
if (xb_close_files)
3800
3796
msg (" mariabackup: warning: close-files specified. Use it "
@@ -3805,7 +3801,12 @@ xtrabackup_backup_func()
3805
3801
/* initialize components */
3806
3802
if (innodb_init_param ()) {
3807
3803
fail:
3804
+ metadata_to_lsn = log_copying_running;
3808
3805
stop_backup_threads ();
3806
+ if (dst_log_file) {
3807
+ ds_close (dst_log_file);
3808
+ dst_log_file = NULL ;
3809
+ }
3809
3810
if (fil_system) {
3810
3811
innodb_shutdown ();
3811
3812
}
@@ -3814,7 +3815,6 @@ xtrabackup_backup_func()
3814
3815
3815
3816
xb_normalize_init_values ();
3816
3817
3817
-
3818
3818
if (srv_file_flush_method_str == NULL ) {
3819
3819
/* These are the default options */
3820
3820
srv_file_flush_method = SRV_FSYNC;
@@ -4058,9 +4058,7 @@ xtrabackup_backup_func()
4058
4058
goto log_write_fail;
4059
4059
}
4060
4060
4061
- /* start flag */
4062
- log_copying = TRUE ;
4063
-
4061
+ log_copying_running = true ;
4064
4062
/* start io throttle */
4065
4063
if (xtrabackup_throttle) {
4066
4064
os_thread_id_t io_watching_thread_id;
@@ -4078,18 +4076,19 @@ xtrabackup_backup_func()
4078
4076
if (err != DB_SUCCESS) {
4079
4077
msg (" mariabackup: error: xb_load_tablespaces() failed with"
4080
4078
" error %s.\n " , ut_strerr (err));
4079
+ fail_before_log_copying_thread_start:
4080
+ log_copying_running = false ;
4081
4081
goto fail;
4082
4082
}
4083
4083
4084
4084
/* copy log file by current position */
4085
4085
log_copy_scanned_lsn = checkpoint_lsn_start;
4086
4086
recv_sys->recovered_lsn = log_copy_scanned_lsn;
4087
4087
4088
- if (xtrabackup_copy_logfile (COPY_FIRST ))
4089
- goto fail ;
4088
+ if (xtrabackup_copy_logfile ())
4089
+ goto fail_before_log_copying_thread_start ;
4090
4090
4091
4091
log_copying_stop = os_event_create (0 );
4092
- log_copying_running = true ;
4093
4092
os_thread_create (log_copying_thread, NULL , &log_copying_thread_id);
4094
4093
4095
4094
/* FLUSH CHANGED_PAGE_BITMAPS call */
0 commit comments