@@ -190,6 +190,7 @@ struct xb_filter_entry_t{
190
190
lsn_t checkpoint_lsn_start;
191
191
lsn_t checkpoint_no_start;
192
192
static lsn_t log_copy_scanned_lsn;
193
+ /* * whether log_copying_thread() is active; protected by log_sys.mutex */
193
194
static bool log_copying_running;
194
195
195
196
int xtrabackup_parallel;
@@ -3092,16 +3093,18 @@ static void log_copying_thread()
3092
3093
my_thread_end ();
3093
3094
}
3094
3095
3096
+ /* * whether io_watching_thread() is active; protected by log_sys.mutex */
3095
3097
static bool have_io_watching_thread;
3096
- static pthread_t io_watching_thread_id;
3097
3098
3098
3099
/* io throttle watching (rough) */
3099
- static void * io_watching_thread (void * )
3100
+ static void io_watching_thread ()
3100
3101
{
3102
+ my_thread_init ();
3101
3103
/* currently, for --backup only */
3102
- ut_a (xtrabackup_backup);
3104
+ ut_ad (xtrabackup_backup);
3103
3105
3104
3106
mysql_mutex_lock (&log_sys.mutex );
3107
+ ut_ad (have_io_watching_thread);
3105
3108
3106
3109
while (log_copying_running && !metadata_to_lsn)
3107
3110
{
@@ -3114,9 +3117,10 @@ static void *io_watching_thread(void*)
3114
3117
3115
3118
/* stop io throttle */
3116
3119
xtrabackup_throttle= 0 ;
3120
+ have_io_watching_thread= false ;
3117
3121
mysql_cond_broadcast (&wait_throttle);
3118
3122
mysql_mutex_unlock (&log_sys.mutex );
3119
- return nullptr ;
3123
+ my_thread_end () ;
3120
3124
}
3121
3125
3122
3126
#ifndef DBUG_OFF
@@ -4377,27 +4381,29 @@ static ulong xb_set_max_open_files(rlim_t max_file_limit)
4377
4381
# define xb_set_max_open_files (x ) 0UL
4378
4382
#endif
4379
4383
4380
- static void stop_backup_threads (bool running )
4384
+ static void stop_backup_threads ()
4381
4385
{
4382
- if (running)
4386
+ mysql_cond_broadcast (&log_copying_stop);
4387
+
4388
+ if (log_copying_running || have_io_watching_thread)
4383
4389
{
4390
+ mysql_mutex_unlock (&log_sys.mutex );
4384
4391
fputs (" mariabackup: Stopping log copying thread" , stderr);
4385
4392
fflush (stderr);
4386
- while (log_copying_running)
4393
+ mysql_mutex_lock (&log_sys.mutex );
4394
+ while (log_copying_running || have_io_watching_thread)
4387
4395
{
4396
+ mysql_cond_broadcast (&log_copying_stop);
4397
+ mysql_mutex_unlock (&log_sys.mutex );
4388
4398
putc (' .' , stderr);
4389
4399
fflush (stderr);
4390
4400
std::this_thread::sleep_for (std::chrono::milliseconds (200 ));
4401
+ mysql_mutex_lock (&log_sys.mutex );
4391
4402
}
4392
4403
putc (' \n ' , stderr);
4393
- mysql_cond_destroy (&log_copying_stop);
4394
4404
}
4395
4405
4396
- if (have_io_watching_thread)
4397
- {
4398
- pthread_join (io_watching_thread_id, nullptr );
4399
- mysql_cond_destroy (&wait_throttle);
4400
- }
4406
+ mysql_cond_destroy (&log_copying_stop);
4401
4407
}
4402
4408
4403
4409
/* * Implement the core of --backup
@@ -4427,11 +4433,7 @@ static bool xtrabackup_backup_low()
4427
4433
msg (" Error: recv_find_max_checkpoint() failed." );
4428
4434
}
4429
4435
4430
- mysql_cond_broadcast (&log_copying_stop);
4431
- const bool running= log_copying_running;
4432
- mysql_mutex_unlock (&log_sys.mutex );
4433
- stop_backup_threads (running);
4434
- mysql_mutex_lock (&log_sys.mutex );
4436
+ stop_backup_threads ();
4435
4437
}
4436
4438
4437
4439
if (metadata_to_lsn && xtrabackup_copy_logfile (true )) {
@@ -4532,9 +4534,8 @@ static bool xtrabackup_backup_func()
4532
4534
if (log_copying_running) {
4533
4535
mysql_mutex_lock (&log_sys.mutex );
4534
4536
metadata_to_lsn = 1 ;
4535
- mysql_cond_broadcast (&log_copying_stop );
4537
+ stop_backup_threads ( );
4536
4538
mysql_mutex_unlock (&log_sys.mutex );
4537
- stop_backup_threads (true );
4538
4539
}
4539
4540
4540
4541
log_file_op = NULL ;
@@ -4695,13 +4696,15 @@ static bool xtrabackup_backup_func()
4695
4696
4696
4697
aligned_free (log_hdr_buf);
4697
4698
log_copying_running = true ;
4699
+
4700
+ mysql_cond_init (0 , &log_copying_stop, nullptr );
4701
+
4698
4702
/* start io throttle */
4699
- if (xtrabackup_throttle) {
4703
+ if (xtrabackup_throttle) {
4700
4704
io_ticket = xtrabackup_throttle;
4701
4705
have_io_watching_thread = true ;
4702
4706
mysql_cond_init (0 , &wait_throttle, nullptr );
4703
- mysql_thread_create (0 , &io_watching_thread_id, nullptr ,
4704
- io_watching_thread, nullptr );
4707
+ std::thread (io_watching_thread).detach ();
4705
4708
}
4706
4709
4707
4710
/* Populate fil_system with tablespaces to copy */
@@ -4729,7 +4732,6 @@ static bool xtrabackup_backup_func()
4729
4732
4730
4733
DBUG_MARIABACKUP_EVENT (" before_innodb_log_copy_thread_started" , {});
4731
4734
4732
- mysql_cond_init (0 , &log_copying_stop, nullptr );
4733
4735
std::thread (log_copying_thread).detach ();
4734
4736
4735
4737
/* FLUSH CHANGED_PAGE_BITMAPS call */
0 commit comments