1 /*
2    Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #include "storage/ndb/plugin/ndb_mi.h"
26 
27 #include "my_dbug.h"
28 #include "sql/rpl_mi.h"
29 #include "sql/rpl_msr.h"
30 #include "sql/rpl_rli.h"
31 
32 /*
33   Utility class for interacting with the global structure which
34   holds information about the current multi source replication setup.
35 
36   The global structure requires locking to prevent that channels
37   are added or removed by concurrent replication setup commands while
38   accesing it.
39 
40   So far the cluster replication only works with the default channel.
41 */
42 class Multisource_info_guard {
43   Multisource_info_guard(const Multisource_info_guard &);
44   Multisource_info_guard &operator=(const Multisource_info_guard &);
45 
46  public:
Multisource_info_guard()47   Multisource_info_guard() { channel_map.rdlock(); }
48 
49   // Return the default channels Master_info*
get_default_mi() const50   Master_info *get_default_mi() const {
51     Master_info *default_mi = channel_map.get_default_channel_mi();
52     // There should always be a default Master_info at this point
53     DBUG_ASSERT(default_mi);
54     return default_mi;
55   }
56 
~Multisource_info_guard()57   ~Multisource_info_guard() {
58     // Unlock channel map
59     channel_map.unlock();
60   }
61 };
62 
ndb_mi_get_master_server_id()63 uint32 ndb_mi_get_master_server_id() {
64   Multisource_info_guard msi;
65   return (uint32)msi.get_default_mi()->master_id;
66 }
67 
ndb_mi_get_group_master_log_name()68 const char *ndb_mi_get_group_master_log_name() {
69   Multisource_info_guard msi;
70   return msi.get_default_mi()->rli->get_group_master_log_name();
71 }
72 
ndb_mi_get_group_master_log_pos()73 uint64 ndb_mi_get_group_master_log_pos() {
74   Multisource_info_guard msi;
75   return (uint64)msi.get_default_mi()->rli->get_group_master_log_pos();
76 }
77 
ndb_mi_get_future_event_relay_log_pos()78 uint64 ndb_mi_get_future_event_relay_log_pos() {
79   Multisource_info_guard msi;
80   return (uint64)msi.get_default_mi()->rli->get_future_event_relay_log_pos();
81 }
82 
ndb_mi_get_group_relay_log_pos()83 uint64 ndb_mi_get_group_relay_log_pos() {
84   Multisource_info_guard msi;
85   return (uint64)msi.get_default_mi()->rli->get_group_relay_log_pos();
86 }
87 
ndb_mi_get_ignore_server_id(uint32 server_id)88 bool ndb_mi_get_ignore_server_id(uint32 server_id) {
89   Multisource_info_guard msi;
90   return (msi.get_default_mi()->shall_ignore_server_id(server_id) != 0);
91 }
92 
ndb_mi_get_slave_run_id()93 uint32 ndb_mi_get_slave_run_id() {
94   Multisource_info_guard msi;
95   return msi.get_default_mi()->rli->slave_run_id;
96 }
97 
ndb_mi_get_relay_log_trans_retries()98 ulong ndb_mi_get_relay_log_trans_retries() {
99   Multisource_info_guard msi;
100   return msi.get_default_mi()->rli->trans_retries;
101 }
102 
ndb_mi_set_relay_log_trans_retries(ulong number)103 void ndb_mi_set_relay_log_trans_retries(ulong number) {
104   Multisource_info_guard msi;
105   msi.get_default_mi()->rli->trans_retries = number;
106 }
107 
ndb_mi_get_slave_sql_running()108 bool ndb_mi_get_slave_sql_running() {
109   Multisource_info_guard msi;
110   return msi.get_default_mi()->rli->slave_running;
111 }
112 
ndb_mi_get_slave_parallel_workers()113 ulong ndb_mi_get_slave_parallel_workers() {
114   Multisource_info_guard msi;
115   return msi.get_default_mi()->rli->opt_slave_parallel_workers;
116 }
117 
ndb_get_number_of_channels()118 uint32 ndb_get_number_of_channels() {
119   Multisource_info_guard msi;
120   return channel_map.get_num_instances();
121 }
122