1 /*
2 Copyright (c) 2011, 2016, 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 "ndb_mi.h"
26 #include "ha_ndbcluster_glue.h"
27
28 #include "rpl_msr.h"
29 #include "rpl_mi.h"
30 #include "rpl_rli.h"
31
32 #ifdef HAVE_NDB_BINLOG
33
34 /*
35 Utility class for interacting with the global structure which
36 holds information about the current multi source replication setup.
37
38 The global structure requires locking to prevent that channels
39 are added or removed by concurrent replication setup commands while
40 accesing it.
41
42 So far the cluster replication only works with the default channel.
43 */
44 class Multisource_info_guard {
45 Multisource_info_guard(const Multisource_info_guard&);
46 Multisource_info_guard& operator=(const Multisource_info_guard&);
47 public:
Multisource_info_guard()48 Multisource_info_guard()
49 {
50 channel_map.rdlock();
51 }
52
53 // Return the default channels Master_info*
get_default_mi() const54 Master_info* get_default_mi() const
55 {
56 Master_info* default_mi = channel_map.get_default_channel_mi();
57 // There should always be a default Master_info at this point
58 DBUG_ASSERT(default_mi);
59 return default_mi;
60 }
61
~Multisource_info_guard()62 ~Multisource_info_guard()
63 {
64 // Unlock channel map
65 channel_map.unlock();
66 }
67 };
68
69
ndb_mi_get_master_server_id()70 uint32 ndb_mi_get_master_server_id()
71 {
72 Multisource_info_guard msi;
73 return (uint32) msi.get_default_mi()->master_id;
74 }
75
ndb_mi_get_group_master_log_name()76 const char* ndb_mi_get_group_master_log_name()
77 {
78 Multisource_info_guard msi;
79 return msi.get_default_mi()->rli->get_group_master_log_name();
80 }
81
ndb_mi_get_group_master_log_pos()82 uint64 ndb_mi_get_group_master_log_pos()
83 {
84 Multisource_info_guard msi;
85 return (uint64) msi.get_default_mi()->rli->get_group_master_log_pos();
86 }
87
ndb_mi_get_future_event_relay_log_pos()88 uint64 ndb_mi_get_future_event_relay_log_pos()
89 {
90 Multisource_info_guard msi;
91 return (uint64) msi.get_default_mi()->rli->get_future_event_relay_log_pos();
92 }
93
ndb_mi_get_group_relay_log_pos()94 uint64 ndb_mi_get_group_relay_log_pos()
95 {
96 Multisource_info_guard msi;
97 return (uint64) msi.get_default_mi()->rli->get_group_relay_log_pos();
98 }
99
ndb_mi_get_ignore_server_id(uint32 server_id)100 bool ndb_mi_get_ignore_server_id(uint32 server_id)
101 {
102 Multisource_info_guard msi;
103 return (msi.get_default_mi()->shall_ignore_server_id(server_id) != 0);
104 }
105
ndb_mi_get_slave_run_id()106 uint32 ndb_mi_get_slave_run_id()
107 {
108 Multisource_info_guard msi;
109 return msi.get_default_mi()->rli->slave_run_id;
110 }
111
ndb_mi_get_relay_log_trans_retries()112 ulong ndb_mi_get_relay_log_trans_retries()
113 {
114 Multisource_info_guard msi;
115 return msi.get_default_mi()->rli->trans_retries;
116 }
117
ndb_mi_set_relay_log_trans_retries(ulong number)118 void ndb_mi_set_relay_log_trans_retries(ulong number)
119 {
120 Multisource_info_guard msi;
121 msi.get_default_mi()->rli->trans_retries = number;
122 }
123
ndb_mi_get_slave_sql_running()124 bool ndb_mi_get_slave_sql_running()
125 {
126 Multisource_info_guard msi;
127 return msi.get_default_mi()->rli->slave_running;
128 }
129
130 #endif
131