@@ -153,6 +153,11 @@ static MYSQL* mysql = NULL;
153153static char * dirname_for_local_load= 0 ;
154154static uint opt_server_id_bits = 0 ;
155155static ulong opt_server_id_mask = 0 ;
156+ Sid_map *global_sid_map= NULL ;
157+ Checkable_rwlock *global_sid_lock= NULL ;
158+ Gtid_set *gtid_set_included= NULL ;
159+ Gtid_set *gtid_set_excluded= NULL ;
160+
156161
157162/* *
158163 Pointer to the Format_description_log_event of the currently active binlog.
@@ -181,9 +186,6 @@ static char *opt_include_gtids_str= NULL,
181186 *opt_exclude_gtids_str= NULL ;
182187static my_bool opt_skip_gtids= 0 ;
183188static bool filter_based_on_gtids= false ;
184- static Gtid_set gtid_set_included (&global_sid_map);
185- static Gtid_set gtid_set_excluded (&global_sid_map);
186-
187189static Exit_status dump_local_log_entries (PRINT_EVENT_INFO *print_event_info,
188190 const char * logname);
189191static Exit_status dump_remote_log_entries (PRINT_EVENT_INFO *print_event_info,
@@ -728,14 +730,14 @@ static bool shall_skip_gtids(Log_event* ev)
728730 if (opt_include_gtids_str != NULL )
729731 {
730732 filtered= filtered ||
731- !gtid_set_included. contains_gtid (gtid->get_sidno (true ),
733+ !gtid_set_included-> contains_gtid (gtid->get_sidno (true ),
732734 gtid->get_gno ());
733735 }
734736
735737 if (opt_exclude_gtids_str != NULL )
736738 {
737739 filtered= filtered ||
738- gtid_set_excluded. contains_gtid (gtid->get_sidno (true ),
740+ gtid_set_excluded-> contains_gtid (gtid->get_sidno (true ),
739741 gtid->get_gno ());
740742 }
741743 filter_based_on_gtids= filtered;
@@ -1915,10 +1917,10 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
19151917 {
19161918 command= COM_BINLOG_DUMP_GTID;
19171919
1918- Gtid_set gtid_set (& global_sid_map);
1919- global_sid_lock. rdlock ();
1920+ Gtid_set gtid_set (global_sid_map);
1921+ global_sid_lock-> rdlock ();
19201922
1921- gtid_set.add_gtid_set (& gtid_set_excluded);
1923+ gtid_set.add_gtid_set (gtid_set_excluded);
19221924
19231925 // allocate buffer
19241926 size_t unused_size= 0 ;
@@ -1931,7 +1933,7 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
19311933 if (!(command_buffer= (uchar *) my_malloc (allocation_size, MYF (MY_WME))))
19321934 {
19331935 error (" Got fatal error allocating memory." );
1934- global_sid_lock. unlock ();
1936+ global_sid_lock-> unlock ();
19351937 DBUG_RETURN (ERROR_STOP);
19361938 }
19371939 uchar* ptr_buffer= command_buffer;
@@ -1966,7 +1968,7 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
19661968 unused_size= ::BINLOG_DATA_SIZE_INFO_SIZE + encoded_data_size;
19671969 }
19681970
1969- global_sid_lock. unlock ();
1971+ global_sid_lock-> unlock ();
19701972
19711973 command_size= ptr_buffer - command_buffer;
19721974 DBUG_ASSERT (command_size == (allocation_size - unused_size - 1 ));
@@ -2535,35 +2537,70 @@ static int args_post_process(void)
25352537 }
25362538 }
25372539
2538- global_sid_lock. rdlock ();
2540+ global_sid_lock-> rdlock ();
25392541
25402542 if (opt_include_gtids_str != NULL )
25412543 {
2542- if (gtid_set_included. add_gtid_text (opt_include_gtids_str) !=
2544+ if (gtid_set_included-> add_gtid_text (opt_include_gtids_str) !=
25432545 RETURN_STATUS_OK)
25442546 {
25452547 error (" Could not configure --include-gtids '%s'" , opt_include_gtids_str);
2546- global_sid_lock. unlock ();
2548+ global_sid_lock-> unlock ();
25472549 DBUG_RETURN (ERROR_STOP);
25482550 }
25492551 }
25502552
25512553 if (opt_exclude_gtids_str != NULL )
25522554 {
2553- if (gtid_set_excluded. add_gtid_text (opt_exclude_gtids_str) !=
2555+ if (gtid_set_excluded-> add_gtid_text (opt_exclude_gtids_str) !=
25542556 RETURN_STATUS_OK)
25552557 {
25562558 error (" Could not configure --exclude-gtids '%s'" , opt_exclude_gtids_str);
2557- global_sid_lock. unlock ();
2559+ global_sid_lock-> unlock ();
25582560 DBUG_RETURN (ERROR_STOP);
25592561 }
25602562 }
25612563
2562- global_sid_lock. unlock ();
2564+ global_sid_lock-> unlock ();
25632565
25642566 DBUG_RETURN (OK_CONTINUE);
25652567}
25662568
2569+ /* *
2570+ GTID cleanup destroys objects and reset their pointer.
2571+ Function is reentrant.
2572+ */
2573+ inline void gtid_client_cleanup ()
2574+ {
2575+ delete global_sid_lock;
2576+ delete global_sid_map;
2577+ delete gtid_set_excluded;
2578+ delete gtid_set_included;
2579+ global_sid_lock= NULL ;
2580+ global_sid_map= NULL ;
2581+ gtid_set_excluded= NULL ;
2582+ gtid_set_included= NULL ;
2583+ }
2584+
2585+ /* *
2586+ GTID initialization.
2587+
2588+ @return true if allocation does not succeed
2589+ false if OK
2590+ */
2591+ inline bool gtid_client_init ()
2592+ {
2593+ bool res=
2594+ (!(global_sid_lock= new Checkable_rwlock) ||
2595+ !(global_sid_map= new Sid_map (global_sid_lock)) ||
2596+ !(gtid_set_excluded= new Gtid_set (global_sid_map)) ||
2597+ !(gtid_set_included= new Gtid_set (global_sid_map)));
2598+ if (res)
2599+ {
2600+ gtid_client_cleanup ();
2601+ }
2602+ return res;
2603+ }
25672604
25682605int main (int argc, char ** argv)
25692606{
@@ -2604,6 +2641,12 @@ int main(int argc, char** argv)
26042641 exit (1 );
26052642 }
26062643
2644+ if (gtid_client_init ())
2645+ {
2646+ error (" Could not initialize GTID structuress." );
2647+ exit (1 );
2648+ }
2649+
26072650 /* Check for argument conflicts and do any post-processing */
26082651 if (args_post_process () == ERROR_STOP)
26092652 exit (1 );
@@ -2700,6 +2743,7 @@ int main(int argc, char** argv)
27002743 load_processor.destroy ();
27012744 /* We cannot free DBUG, it is used in global destructors after exit(). */
27022745 my_end (my_end_arg | MY_DONT_FREE_DBUG);
2746+ gtid_client_cleanup ();
27032747
27042748 exit (retval == ERROR_STOP ? 1 : 0 );
27052749 /* Keep compilers happy. */
0 commit comments