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