1 /* 2 Copyright (c) 2003, 2021, Oracle and/or its affiliates. 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 ConfigRetriever_H 26 #define ConfigRetriever_H 27 28 #include <ndb_types.h> 29 #include <mgmapi.h> 30 #include <BaseString.hpp> 31 32 /** 33 * @class ConfigRetriever 34 * @brief Used by nodes (DB, MGM, API) to get their config from MGM server. 35 */ 36 class ConfigRetriever { 37 public: 38 ConfigRetriever(const char * _connect_string, int force_nodeid, 39 Uint32 version, ndb_mgm_node_type nodeType, 40 const char * _bind_address = 0, 41 int timeout_ms = 30000); 42 ~ConfigRetriever(); 43 44 int do_connect(int no_retries, int retry_delay_in_seconds, int verbose); 45 int disconnect(); 46 bool is_connected(); 47 48 /** 49 * Get configuration for current node. 50 * 51 * Configuration is fetched from one MGM server configured in local config 52 * file. The method loops over all the configured MGM servers and tries 53 * to establish a connection. This is repeated until a connection is 54 * established, so the function hangs until a connection is established. 55 * 56 * @return ndb_mgm_configuration object if succeeded, 57 * NULL if erroneous local config file or configuration error. 58 */ 59 struct ndb_mgm_configuration * getConfig(Uint32 nodeid); 60 61 void resetError(); 62 int hasError(); 63 const char * getErrorString(); 64 65 /** 66 * @return Node id of this node (as stated in local config or connectString) 67 */ 68 Uint32 allocNodeId(int no_retries, int retry_delay_in_seconds); 69 Uint32 allocNodeId(int no_retries, int retry_delay_in_seconds, 70 int verbose, int& error); 71 72 int setNodeId(Uint32 nodeid); 73 74 /** 75 * Get config using socket 76 */ 77 struct ndb_mgm_configuration * getConfig(NdbMgmHandle handle); 78 79 /** 80 * Get config from file 81 */ 82 struct ndb_mgm_configuration * getConfig(const char * file); 83 84 /** 85 * Verify config 86 */ 87 bool verifyConfig(const struct ndb_mgm_configuration *, Uint32 nodeid); 88 89 Uint32 get_mgmd_port() const; 90 const char *get_mgmd_host() const; 91 const char *get_connectstring(char *buf, int buf_sz) const; get_mgmHandle()92 NdbMgmHandle get_mgmHandle() { return m_handle; }; get_mgmHandlePtr()93 NdbMgmHandle* get_mgmHandlePtr() { return &m_handle; }; end_session(bool end)94 void end_session(bool end) { m_end_session= end; }; 95 96 Uint32 get_configuration_nodeid() const; 97 private: 98 BaseString errorString; 99 enum ErrorType { 100 CR_NO_ERROR = 0, 101 CR_ERROR = 1 102 }; 103 ErrorType latestErrorType; 104 105 void setError(ErrorType, const char * errorMsg); 106 void setError(ErrorType, BaseString err); 107 108 bool m_end_session; 109 Uint32 m_version; 110 ndb_mgm_node_type m_node_type; 111 NdbMgmHandle m_handle; 112 }; 113 114 #endif 115 116 117