1 /*
2    Copyright (C) 2003-2006, 2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
3     All rights reserved. Use is subject to license terms.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License, version 2.0,
7    as published by the Free Software Foundation.
8 
9    This program is also distributed with certain software (including
10    but not limited to OpenSSL) that is licensed under separate terms,
11    as designated in a particular file or component or in included license
12    documentation.  The authors of MySQL hereby grant you an additional
13    permission to link the program and your derivative works with the
14    separately licensed software that they have included with MySQL.
15 
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License, version 2.0, for more details.
20 
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 */
25 
26 #ifndef Config_H
27 #define Config_H
28 
29 #include <kernel/NodeBitmask.hpp>
30 #include "ConfigInfo.hpp"
31 #include <mgmapi.h>
32 #include "../mgmapi/mgmapi_configuration.hpp"
33 
34 
35 /**
36  * @class Config
37  * @brief Cluster Configuration Wrapper
38  *
39  * Adds a C++ wrapper around 'ndb_mgm_configuration' which is
40  * exposed from mgmapi_configuration
41  *
42  */
43 
44 class Config {
45 public:
46   Config(struct ndb_mgm_configuration *config_values = NULL);
47   Config(ConfigValues* config_values);
48   Config(const Config*);
49   virtual ~Config();
50 
51   void print(const char* section_filter = NULL, NodeId nodeid_filter = NULL,
52              const char* param_filter = NULL,
53              NdbOut& out = ndbout) const;
54 
55   /*
56     Returns generation of the config
57     0 => not set(yet), ie. config has never been committed
58    */
59   Uint32 getGeneration() const;
60   bool setGeneration(Uint32);
61 
62   /*
63     Returns name of the config
64   */
65   const char* getName() const;
66   bool setName(const char* new_name);
67 
68   /*
69     Returns primary MGM node of the config, this is used to
70     protect the config being overwritten by an "old" config.ini
71     or my.cnf - i.e as soon as the config.ini has been updated
72     and reloaded from one node, the config.ini on other nodes
73     become obsolete and a reload from those would revert to an
74     old config.
75     0 => config updated from mgmapi, no node is primary anymore
76     1 - MAX_NODES => only node with specified nodeid can reload
77                      config without force
78    */
79   Uint32 getPrimaryMgmNode() const;
80   bool setPrimaryMgmNode(Uint32);
81 
82   /*
83    Pack the config into a UtilBuffer and return it's size in bytes
84   */
85   Uint32 pack(UtilBuffer&) const;
86 
87   /*
88     Pack the config as base64
89   */
90   bool pack64(BaseString&) const;
91 
92   /*
93     Compare against another config and return a list of
94     differences in a Properties object
95   */
96   void diff(const Config* other, Properties& diff_list,
97             const unsigned* exclude=NULL) const;
98 
99   /*
100     Print the difference against another config
101    */
102   void print_diff(const Config* other) const;
103 
104 
105   /*
106     Get the full connectstring for this configuration. ie
107     a list of all the mgmd servers and their port separated
108     by separator.
109    */
110   void getConnectString(BaseString&,
111                         const BaseString& separator = BaseString(";")) const;
112 
113   /*
114     Print the difference to string buffer
115   */
116   const char* diff2str(const Config* other, BaseString& str,
117                        const unsigned* exclude = NULL) const;
118 
119   /*
120     Determine if changing to the other config is illegal
121   */
122   bool illegal_change(const Config* other) const;
123 
124   /*
125     Check if the config is equal to another config
126   */
127   bool equal(const Config*, const unsigned* exclude = NULL) const;
128 
129   /*
130     Return the checksum of the config. The checksum can be used to compare
131     two configs without having the whole config available(for example on
132     a remote host). It can also be printed to log files for manual verification
133     that same config is used
134   */
135   Uint32 checksum(void) const;
136 
137   /*
138     Return bitmask of all defined nodes of a certain type
139     returns all defined nodes by default.
140    */
141   void get_nodemask(NodeBitmask& mask,
142                     ndb_mgm_node_type type = NDB_MGM_NODE_TYPE_UNKNOWN) const;
143 
144   struct ndb_mgm_configuration * m_configValues;
values(void) const145   struct ndb_mgm_configuration * values(void) const { return m_configValues; };
146 
147 private:
148   bool setValue(Uint32 section, Uint32 section_no,
149                 Uint32 id, Uint32 new_val);
150   bool setValue(Uint32 section, Uint32 section_no,
151                 Uint32 id, const char* new_val);
152 
153   bool illegal_change(const Properties&) const;
154   bool equal(const Properties&) const;
155   const char* diff2str(const Properties&, BaseString& str) const;
156 };
157 
158 class ConfigIter : public ndb_mgm_configuration_iterator {
159 public:
ConfigIter(const Config * conf,unsigned type)160   ConfigIter(const Config* conf, unsigned type) :
161     ndb_mgm_configuration_iterator(*conf->m_configValues, type) {};
162 };
163 
164 #endif // Config_H
165