1 /* 2 Copyright (c) 2003, 2010, 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 #ifndef ConfigInfo_H 26 #define ConfigInfo_H 27 28 #ifndef NDB_MGMAPI 29 #include <kernel_types.h> 30 #include <Properties.hpp> 31 #include <ndb_limits.h> 32 #include <NdbOut.hpp> 33 #include "InitConfigFileParser.hpp" 34 #endif /* NDB_MGMAPI */ 35 36 // Parameter must be specified in config file 37 #define MANDATORY ((char*)~(UintPtr)0) 38 39 /** 40 * @class ConfigInfo 41 * @brief Metainformation about ALL cluster configuration parameters 42 * 43 * Use the getters to find out metainformation about parameters. 44 */ 45 class ConfigInfo { 46 public: 47 enum Type { CI_BOOL, 48 CI_INT, 49 CI_INT64, 50 CI_STRING, 51 CI_ENUM, // String externaly, int internally 52 CI_BITMASK, // String both externally and internally 53 CI_SECTION 54 }; 55 enum Status { CI_USED, ///< Active 56 CI_EXPERIMENTAL, ///< Active but experimental 57 CI_DEPRECATED, ///< Can be used, but shouldn't 58 CI_NOTIMPLEMENTED, ///< Is ignored. 59 CI_INTERNAL ///< Not configurable by the user 60 }; 61 62 enum Flags { 63 CI_ONLINE_UPDATEABLE = 1, // Parameter can be updated online 64 CI_CHECK_WRITABLE = 2, // Path given by parameter should be writable 65 66 /* 67 Flags telling how the system must be restarted for a changed 68 parameter to take effect 69 70 Default is none of these flags set, which means node restart 71 of one node at a time for the setting to take effect 72 73 CS_RESTART_INITIAL 74 Each data node need to be restarted one at a time with --initial 75 76 CS_RESTART_SYSTEM 77 The whole system need to be stopped and then started up again 78 79 CS_RESTART_SYSTEM + CS_RESTART_INITIAL 80 The whole system need to be stopped and then restarted with --initial 81 thus destroying any data in the cluster 82 83 These flags can not be combined with CI_ONLINE_UPDATABLE flag which 84 indicates that the parameter can be changed online without 85 restarting anything 86 */ 87 CI_RESTART_SYSTEM = 4, // System restart is necessary to apply setting 88 CI_RESTART_INITIAL = 8 // Initial restart is necessary to apply setting 89 }; 90 91 struct Typelib { 92 const char* name; 93 Uint32 value; 94 }; 95 96 /** 97 * Entry for one configuration parameter 98 */ 99 struct ParamInfo { 100 /** 101 * Internal id used to identify configuration parameter when accessing 102 * config. 103 */ 104 Uint32 _paramId; 105 /* External name, as given in text in config file. */ 106 const char* _fname; 107 /** 108 * Name (as it appears in config file text) of section that this extry 109 * belongs to. 110 * 111 * Each section alsa has one entry with the section name stored in both 112 * _fname and _section. 113 */ 114 const char* _section; 115 /* Short textual description/documentation for entry. */ 116 const char* _description; 117 Status _status; 118 Uint32 _flags; 119 Type _type; 120 /** 121 * Default value, minimum value (if any), and maximum value (if any). 122 * 123 * Stored as pointers to char * representation of default (eg "10k"). 124 * 125 * For section entries, instead the _default member gives the internal id 126 * of that kind of section (CONNECTION_TYPE_TCP, NODE_TYPE_MGM, etc.) 127 */ 128 const char* _default; 129 const char* _min; 130 const char* _max; 131 }; 132 133 /** 134 * section type is stored in _default 135 */ getSectionType(const ParamInfo & p)136 static Uint32 getSectionType(const ParamInfo& p) { 137 assert(p._type == CI_SECTION); 138 return Uint32(reinterpret_cast<UintPtr>(p._default)); 139 } 140 141 /** 142 * typelib ptr is stored in _min 143 */ getTypelibPtr(const ParamInfo & p)144 static const Typelib* getTypelibPtr(const ParamInfo& p) { 145 assert(p._type == CI_ENUM); 146 return reinterpret_cast<const Typelib*>(p._min); 147 } 148 149 class ParamInfoIter { 150 const ConfigInfo& m_info; 151 const char* m_section_name; 152 int m_curr_param; 153 public: 154 ParamInfoIter(const ConfigInfo& info, 155 Uint32 section, 156 Uint32 section_type = ~0); 157 158 const ParamInfo* next(void); 159 }; 160 161 #ifndef NDB_MGMAPI 162 struct AliasPair{ 163 const char * name; 164 const char * alias; 165 }; 166 167 /** 168 * Entry for one section rule 169 */ 170 struct SectionRule { 171 const char * m_section; 172 bool (* m_sectionRule)(struct InitConfigFileParser::Context &, 173 const char * m_ruleData); 174 const char * m_ruleData; 175 }; 176 177 /** 178 * Entry for config rule 179 */ 180 struct ConfigRuleSection { 181 BaseString m_sectionType; 182 Properties * m_sectionData; 183 }; 184 185 struct ConfigRule { 186 bool (* m_configRule)(Vector<ConfigRuleSection>&, 187 struct InitConfigFileParser::Context &, 188 const char * m_ruleData); 189 const char * m_ruleData; 190 }; 191 192 ConfigInfo(); 193 194 /** 195 * Checks if the suggested value is valid for the suggested parameter 196 * (i.e. if it is >= than min and <= than max). 197 * 198 * @param section Init Config file section name 199 * @param fname Name of parameter 200 * @param value Value to check 201 * @return true if parameter value is valid. 202 * 203 * @note Result is not defined if section/name are wrong! 204 */ 205 bool verify(const Properties* secti, const char* fname, Uint64 value) const; 206 bool verify_enum(const Properties * section, const char* fname, 207 const char* value, Uint32& value_int) const; 208 void get_enum_values(const Properties * section, const char* fname, 209 BaseString& err) const; 210 static const char* nameToAlias(const char*); 211 static const char* getAlias(const char*); 212 bool isSection(const char*) const; 213 214 const char* getDescription(const Properties * sec, const char* fname) const; 215 Type getType(const Properties * section, const char* fname) const; 216 Status getStatus(const Properties* section, const char* fname) const; 217 Uint64 getMin(const Properties * section, const char* fname) const; 218 Uint64 getMax(const Properties * section, const char* fname) const; 219 Uint64 getDefault(const Properties * section, const char* fname) const; 220 Uint32 getFlags(const Properties* section, const char* fname) const; 221 const char* getDefaultString(const Properties * section, 222 const char* fname) const; 223 bool getMandatory(const Properties * section, const char* fname) const; 224 bool hasDefault(const Properties * section, const char* fname) const; 225 226 const Properties * getInfo(const char * section) const; 227 const Properties * getDefaults(const char * section) const; 228 229 const char* sectionName(Uint32 section_type, Uint32 type) const; 230 231 void print(const char* section= NULL) const; 232 void print_xml(const char* section= NULL) const; 233 private: 234 bool is_internal_section(const Properties* sec) const; 235 void print_impl(const char* section, 236 class ConfigPrinter& printer) const; 237 private: 238 Properties m_info; 239 Properties m_systemDefaults; 240 241 static const AliasPair m_sectionNameAliases[]; 242 static const char* m_sectionNames[]; 243 static const int m_noOfSectionNames; 244 #endif /* NDB_MGMAPI */ 245 246 public: 247 static const ParamInfo m_ParamInfo[]; 248 static const int m_NoOfParams; 249 250 #ifndef NDB_MGMAPI 251 static const SectionRule m_SectionRules[]; 252 static const ConfigRule m_ConfigRules[]; 253 static const int m_NoOfRules; 254 #endif /* NDB_MGMAPI */ 255 }; 256 257 #endif // ConfigInfo_H 258