#include <ConfigRetriever.hpp>
Collaboration diagram for ConfigRetriever:

Definition at line 28 of file ConfigRetriever.hpp.
enum ConfigRetriever::ErrorType [private] |
Definition at line 86 of file ConfigRetriever.hpp.
00086 { 00087 CR_NO_ERROR = 0, 00088 CR_ERROR = 1, 00089 CR_RETRY = 2 00090 };
Definition at line 47 of file ConfigRetriever.cpp.
References _ownNodeId, BaseString::append(), BaseString::c_str(), CR_ERROR, DBUG_ENTER, DBUG_VOID_RETURN, m_end_session, m_handle, m_node_type, m_version, ndb_mgm_create_handle(), ndb_mgm_get_latest_error_desc(), ndb_mgm_get_latest_error_msg(), ndb_mgm_set_connectstring(), resetError(), and setError().
00049 { 00050 DBUG_ENTER("ConfigRetriever::ConfigRetriever"); 00051 00052 m_version = version; 00053 m_node_type = node_type; 00054 _ownNodeId= 0; 00055 m_end_session= true; 00056 00057 m_handle= ndb_mgm_create_handle(); 00058 00059 if (m_handle == 0) { 00060 setError(CR_ERROR, "Unable to allocate mgm handle"); 00061 DBUG_VOID_RETURN; 00062 } 00063 00064 if (ndb_mgm_set_connectstring(m_handle, _connect_string)) 00065 { 00066 BaseString tmp(ndb_mgm_get_latest_error_msg(m_handle)); 00067 tmp.append(" : "); 00068 tmp.append(ndb_mgm_get_latest_error_desc(m_handle)); 00069 setError(CR_ERROR, tmp.c_str()); 00070 DBUG_VOID_RETURN; 00071 } 00072 resetError(); 00073 DBUG_VOID_RETURN; 00074 }
Here is the call graph for this function:

| ConfigRetriever::~ConfigRetriever | ( | ) |
Definition at line 76 of file ConfigRetriever.cpp.
References DBUG_ENTER, DBUG_VOID_RETURN, m_end_session, m_handle, ndb_mgm_destroy_handle(), ndb_mgm_disconnect(), and ndb_mgm_end_session().
00077 { 00078 DBUG_ENTER("ConfigRetriever::~ConfigRetriever"); 00079 if (m_handle) { 00080 if(m_end_session) 00081 ndb_mgm_end_session(m_handle); 00082 ndb_mgm_disconnect(m_handle); 00083 ndb_mgm_destroy_handle(&m_handle); 00084 } 00085 DBUG_VOID_RETURN; 00086 }
Here is the call graph for this function:

| Uint32 ConfigRetriever::allocNodeId | ( | int | no_retries, | |
| int | retry_delay_in_seconds | |||
| ) |
Definition at line 346 of file ConfigRetriever.cpp.
References _ownNodeId, BaseString::append(), BaseString::c_str(), CR_ERROR, error, m_handle, m_node_type, m_version, ndb_mgm_alloc_nodeid(), NDB_MGM_ALLOCID_CONFIG_MISMATCH, ndb_mgm_connect(), ndb_mgm_get_latest_error(), ndb_mgm_get_latest_error_desc(), ndb_mgm_get_latest_error_msg(), ndb_mgm_is_connected(), NdbSleep_SecSleep(), and setError().
Referenced by Ndb_cluster_connection::connect(), and MgmtSrvr::MgmtSrvr().
00347 { 00348 int res; 00349 _ownNodeId= 0; 00350 if(m_handle != 0) 00351 { 00352 while (1) 00353 { 00354 if(!ndb_mgm_is_connected(m_handle)) 00355 if(!ndb_mgm_connect(m_handle, 0, 0, 0)) 00356 goto next; 00357 00358 res= ndb_mgm_alloc_nodeid(m_handle, m_version, m_node_type, 00359 no_retries == 0 /* only log last retry */); 00360 if(res >= 0) 00361 return _ownNodeId= (Uint32)res; 00362 00363 next: 00364 int error = ndb_mgm_get_latest_error(m_handle); 00365 if (no_retries == 0 || error == NDB_MGM_ALLOCID_CONFIG_MISMATCH) 00366 break; 00367 no_retries--; 00368 NdbSleep_SecSleep(retry_delay_in_seconds); 00369 } 00370 BaseString tmp(ndb_mgm_get_latest_error_msg(m_handle)); 00371 tmp.append(" : "); 00372 tmp.append(ndb_mgm_get_latest_error_desc(m_handle)); 00373 setError(CR_ERROR, tmp.c_str()); 00374 } else 00375 setError(CR_ERROR, "management server handle not initialized"); 00376 return 0; 00377 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int ConfigRetriever::disconnect | ( | ) |
Definition at line 122 of file ConfigRetriever.cpp.
References m_handle, and ndb_mgm_disconnect().
00123 { 00124 return ndb_mgm_disconnect(m_handle); 00125 }
Here is the call graph for this function:

| int ConfigRetriever::do_connect | ( | int | no_retries, | |
| int | retry_delay_in_seconds, | |||
| int | verbose | |||
| ) |
Definition at line 113 of file ConfigRetriever.cpp.
References m_handle, and ndb_mgm_connect().
Referenced by Ndb_cluster_connection::connect(), Configuration::fetch_configuration(), and MgmtSrvr::MgmtSrvr().
00115 { 00116 return 00117 (ndb_mgm_connect(m_handle,no_retries,retry_delay_in_seconds,verbose)==0) ? 00118 0 : -1; 00119 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void ConfigRetriever::end_session | ( | bool | end | ) | [inline] |
Definition at line 81 of file ConfigRetriever.hpp.
References m_end_session.
Referenced by Configuration::closeConfiguration().
00081 { m_end_session= end; };
Here is the caller graph for this function:

| Uint32 ConfigRetriever::get_configuration_nodeid | ( | ) | const |
Definition at line 89 of file ConfigRetriever.cpp.
References m_handle, and ndb_mgm_get_configuration_nodeid().
Referenced by MgmtSrvr::MgmtSrvr().
00090 { 00091 return ndb_mgm_get_configuration_nodeid(m_handle); 00092 }
Here is the call graph for this function:

Here is the caller graph for this function:

| const char * ConfigRetriever::get_connectstring | ( | char * | buf, | |
| int | buf_sz | |||
| ) | const |
Definition at line 104 of file ConfigRetriever.cpp.
References m_handle, and ndb_mgm_get_connectstring().
Referenced by Ndb_cluster_connection::get_connectstring().
00105 { 00106 return ndb_mgm_get_connectstring(m_handle, buf, buf_sz); 00107 }
Here is the call graph for this function:

Here is the caller graph for this function:

| const char * ConfigRetriever::get_mgmd_host | ( | ) | const |
Definition at line 99 of file ConfigRetriever.cpp.
References m_handle, and ndb_mgm_get_connected_host().
Referenced by Configuration::fetch_configuration(), and Ndb_cluster_connection::get_connected_host().
00100 { 00101 return ndb_mgm_get_connected_host(m_handle); 00102 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Uint32 ConfigRetriever::get_mgmd_port | ( | ) | const |
Definition at line 94 of file ConfigRetriever.cpp.
References m_handle, and ndb_mgm_get_connected_port().
Referenced by Configuration::fetch_configuration(), and Ndb_cluster_connection::get_connected_port().
00095 { 00096 return ndb_mgm_get_connected_port(m_handle); 00097 }
Here is the call graph for this function:

Here is the caller graph for this function:

| NdbMgmHandle ConfigRetriever::get_mgmHandle | ( | ) | [inline] |
Definition at line 79 of file ConfigRetriever.hpp.
References m_handle.
Referenced by Ndb_cluster_connection::connect(), Ndb_cluster_connection_impl::Ndb_cluster_connection_impl(), and Ndb_cluster_connection_impl::set_name().
00079 { return m_handle; };
Here is the caller graph for this function:

| NdbMgmHandle* ConfigRetriever::get_mgmHandlePtr | ( | ) | [inline] |
Definition at line 80 of file ConfigRetriever.hpp.
References m_handle.
Referenced by main().
00080 { return &m_handle; };
Here is the caller graph for this function:

| ndb_mgm_configuration * ConfigRetriever::getConfig | ( | const char * | file | ) |
Get config from file
Definition at line 166 of file ConfigRetriever.cpp.
References buf, CR_ERROR, f, ConfigValuesFactory::m_cfg, setError(), BaseString::snprintf(), and ConfigValuesFactory::unpack().
00166 { 00167 #ifndef NDB_WIN32 00168 00169 struct stat sbuf; 00170 const int res = stat(filename, &sbuf); 00171 if(res != 0){ 00172 char buf[255]; 00173 BaseString::snprintf(buf, sizeof(buf), "Could not find file: \"%s\"", filename); 00174 setError(CR_ERROR, buf); 00175 return 0; 00176 } 00177 const Uint32 bytes = sbuf.st_size; 00178 00179 Uint32 * buf2 = new Uint32[bytes/4+1]; 00180 00181 FILE * f = fopen(filename, "rb"); 00182 if(f == 0){ 00183 setError(CR_ERROR, "Failed to open file"); 00184 delete []buf2; 00185 return 0; 00186 } 00187 Uint32 sz = fread(buf2, 1, bytes, f); 00188 fclose(f); 00189 if(sz != bytes){ 00190 setError(CR_ERROR, "Failed to read file"); 00191 delete []buf2; 00192 return 0; 00193 } 00194 00195 ConfigValuesFactory cvf; 00196 if(!cvf.unpack(buf2, bytes)){ 00197 char buf[255]; 00198 BaseString::snprintf(buf, sizeof(buf), "Error while unpacking"); 00199 setError(CR_ERROR, buf); 00200 delete []buf2; 00201 return 0; 00202 } 00203 delete [] buf2; 00204 return (ndb_mgm_configuration*)cvf.m_cfg; 00205 #else 00206 return 0; 00207 #endif 00208 }
Here is the call graph for this function:

| ndb_mgm_configuration * ConfigRetriever::getConfig | ( | NdbMgmHandle | handle | ) |
Get config using socket
Definition at line 151 of file ConfigRetriever.cpp.
References BaseString::append(), BaseString::c_str(), CR_ERROR, m_handle, m_version, ndb_mgm_get_configuration(), ndb_mgm_get_latest_error_desc(), ndb_mgm_get_latest_error_msg(), and setError().
00152 { 00153 ndb_mgm_configuration * conf = ndb_mgm_get_configuration(m_handle,m_version); 00154 if(conf == 0) 00155 { 00156 BaseString tmp(ndb_mgm_get_latest_error_msg(m_handle)); 00157 tmp.append(" : "); 00158 tmp.append(ndb_mgm_get_latest_error_desc(m_handle)); 00159 setError(CR_ERROR, tmp.c_str()); 00160 return 0; 00161 } 00162 return conf; 00163 }
Here is the call graph for this function:

| struct ndb_mgm_configuration * ConfigRetriever::getConfig | ( | ) |
Get configuration for current node.
Configuration is fetched from one MGM server configured in local config file. The method loops over all the configured MGM servers and tries to establish a connection. This is repeated until a connection is established, so the function hangs until a connection is established.
Definition at line 132 of file ConfigRetriever.cpp.
References _ownNodeId, free, m_handle, p, and verifyConfig().
Referenced by Ndb_cluster_connection::connect(), MgmtSrvr::fetchConfig(), and NDB_COMMAND().
00132 { 00133 00134 struct ndb_mgm_configuration * p = 0; 00135 00136 if(m_handle != 0) 00137 p = getConfig(m_handle); 00138 00139 if(p == 0) 00140 return 0; 00141 00142 if(!verifyConfig(p, _ownNodeId)){ 00143 free(p); 00144 p= 0; 00145 } 00146 00147 return p; 00148 }
Here is the call graph for this function:

Here is the caller graph for this function:

| const char * ConfigRetriever::getErrorString | ( | ) |
Definition at line 228 of file ConfigRetriever.cpp.
References BaseString::c_str(), and errorString.
Referenced by Ndb_cluster_connection::connect(), Configuration::fetch_configuration(), MgmtSrvr::MgmtSrvr(), Ndb_cluster_connection_impl::Ndb_cluster_connection_impl(), and NDB_COMMAND().
00228 { 00229 return errorString.c_str(); 00230 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int ConfigRetriever::hasError | ( | ) |
Definition at line 222 of file ConfigRetriever.cpp.
References CR_NO_ERROR, and latestErrorType.
Referenced by Configuration::fetch_configuration(), and Ndb_cluster_connection_impl::Ndb_cluster_connection_impl().
00223 { 00224 return latestErrorType != CR_NO_ERROR; 00225 }
Here is the caller graph for this function:

| void ConfigRetriever::resetError | ( | ) |
Definition at line 217 of file ConfigRetriever.cpp.
References CR_NO_ERROR, and setError().
Referenced by ConfigRetriever().
00217 { 00218 setError(CR_NO_ERROR,0); 00219 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void ConfigRetriever::setError | ( | ErrorType | , | |
| const char * | errorMsg | |||
| ) | [private] |
Definition at line 211 of file ConfigRetriever.cpp.
References BaseString::assign(), errorString, and latestErrorType.
Referenced by allocNodeId(), ConfigRetriever(), getConfig(), resetError(), and verifyConfig().
00211 { 00212 errorString.assign(s ? s : ""); 00213 latestErrorType = et; 00214 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int ConfigRetriever::setNodeId | ( | Uint32 | nodeid | ) |
Definition at line 340 of file ConfigRetriever.cpp.
References m_handle, and ndb_mgm_set_configuration_nodeid().
00341 { 00342 return ndb_mgm_set_configuration_nodeid(m_handle, nodeid); 00343 }
Here is the call graph for this function:

| bool ConfigRetriever::verifyConfig | ( | const struct ndb_mgm_configuration * | , | |
| Uint32 | nodeid | |||
| ) |
Verify config
Check hostnames
Definition at line 233 of file ConfigRetriever.cpp.
References _type, buf, CFG_CONNECTION_HOSTNAME_1, CFG_CONNECTION_HOSTNAME_2, CFG_CONNECTION_NODE_1, CFG_CONNECTION_NODE_2, CFG_NODE_DATADIR, CFG_NODE_HOST, CFG_NODE_ID, CFG_SECTION_CONNECTION, CFG_SECTION_NODE, CFG_TYPE_OF_SECTION, CONNECTION_TYPE_TCP, CR_ERROR, datadir, errno, ndb_mgm_configuration_iterator::first(), ndb_mgm_configuration_iterator::get(), m_node_type, name, Ndb_getInAddr(), ndb_mgm_create_configuration_iterator(), ndb_mgm_find(), ndb_mgm_get_int_parameter(), ndb_mgm_get_node_type_alias_string(), ndb_mgm_get_string_parameter(), NdbConfig_SetPath(), ndb_mgm_configuration_iterator::next(), setError(), BaseString::snprintf(), strlen(), SocketServer::tryBind(), and ndb_mgm_configuration_iterator::valid().
Referenced by getConfig(), and MgmtSrvr::MgmtSrvr().
00233 { 00234 00235 char buf[255]; 00236 ndb_mgm_configuration_iterator * it; 00237 it = ndb_mgm_create_configuration_iterator((struct ndb_mgm_configuration *)conf, 00238 CFG_SECTION_NODE); 00239 00240 if(it == 0){ 00241 BaseString::snprintf(buf, 255, "Unable to create config iterator"); 00242 setError(CR_ERROR, buf); 00243 return false; 00244 00245 } 00246 NdbAutoPtr<ndb_mgm_configuration_iterator> ptr(it); 00247 00248 if(ndb_mgm_find(it, CFG_NODE_ID, nodeid) != 0){ 00249 BaseString::snprintf(buf, 255, "Unable to find node with id: %d", nodeid); 00250 setError(CR_ERROR, buf); 00251 return false; 00252 } 00253 00254 const char * hostname; 00255 if(ndb_mgm_get_string_parameter(it, CFG_NODE_HOST, &hostname)){ 00256 BaseString::snprintf(buf, 255, "Unable to get hostname(%d) from config",CFG_NODE_HOST); 00257 setError(CR_ERROR, buf); 00258 return false; 00259 } 00260 00261 const char * datadir; 00262 if(!ndb_mgm_get_string_parameter(it, CFG_NODE_DATADIR, &datadir)){ 00263 NdbConfig_SetPath(datadir); 00264 } 00265 00266 if (hostname && hostname[0] != 0 && 00267 !SocketServer::tryBind(0,hostname)) { 00268 BaseString::snprintf(buf, 255, "Config hostname(%s) don't match a local interface," 00269 " tried to bind, error = %d - %s", 00270 hostname, errno, strerror(errno)); 00271 setError(CR_ERROR, buf); 00272 return false; 00273 } 00274 00275 unsigned int _type; 00276 if(ndb_mgm_get_int_parameter(it, CFG_TYPE_OF_SECTION, &_type)){ 00277 BaseString::snprintf(buf, 255, "Unable to get type of node(%d) from config", 00278 CFG_TYPE_OF_SECTION); 00279 setError(CR_ERROR, buf); 00280 return false; 00281 } 00282 00283 if(_type != m_node_type){ 00284 const char *type_s, *alias_s, *type_s2, *alias_s2; 00285 alias_s= ndb_mgm_get_node_type_alias_string((enum ndb_mgm_node_type)m_node_type, 00286 &type_s); 00287 alias_s2= ndb_mgm_get_node_type_alias_string((enum ndb_mgm_node_type)_type, 00288 &type_s2); 00289 BaseString::snprintf(buf, 255, "This node type %s(%s) and config " 00290 "node type %s(%s) don't match for nodeid %d", 00291 alias_s, type_s, alias_s2, type_s2, nodeid); 00292 setError(CR_ERROR, buf); 00293 return false; 00294 } 00295 00299 ndb_mgm_configuration_iterator iter(* conf, CFG_SECTION_CONNECTION); 00300 for(iter.first(); iter.valid(); iter.next()){ 00301 00302 Uint32 type = CONNECTION_TYPE_TCP + 1; 00303 if(iter.get(CFG_TYPE_OF_SECTION, &type)) continue; 00304 if(type != CONNECTION_TYPE_TCP) continue; 00305 00306 Uint32 nodeId1, nodeId2, remoteNodeId; 00307 if(iter.get(CFG_CONNECTION_NODE_1, &nodeId1)) continue; 00308 if(iter.get(CFG_CONNECTION_NODE_2, &nodeId2)) continue; 00309 00310 if(nodeId1 != nodeid && nodeId2 != nodeid) continue; 00311 remoteNodeId = (nodeid == nodeId1 ? nodeId2 : nodeId1); 00312 00313 const char * name; 00314 struct in_addr addr; 00315 BaseString tmp; 00316 if(!iter.get(CFG_CONNECTION_HOSTNAME_1, &name) && strlen(name)){ 00317 if(Ndb_getInAddr(&addr, name) != 0){ 00318 tmp.assfmt("Unable to lookup/illegal hostname %s, " 00319 "connection from node %d to node %d", 00320 name, nodeid, remoteNodeId); 00321 setError(CR_ERROR, tmp.c_str()); 00322 return false; 00323 } 00324 } 00325 00326 if(!iter.get(CFG_CONNECTION_HOSTNAME_2, &name) && strlen(name)){ 00327 if(Ndb_getInAddr(&addr, name) != 0){ 00328 tmp.assfmt("Unable to lookup/illegal hostname %s, " 00329 "connection from node %d to node %d", 00330 name, nodeid, remoteNodeId); 00331 setError(CR_ERROR, tmp.c_str()); 00332 return false; 00333 } 00334 } 00335 } 00336 return true; 00337 }
Here is the call graph for this function:

Here is the caller graph for this function:

Uint32 ConfigRetriever::_ownNodeId [private] |
Definition at line 95 of file ConfigRetriever.hpp.
Referenced by allocNodeId(), ConfigRetriever(), and getConfig().
BaseString ConfigRetriever::errorString [private] |
ErrorType ConfigRetriever::latestErrorType [private] |
bool ConfigRetriever::m_end_session [private] |
Definition at line 96 of file ConfigRetriever.hpp.
Referenced by ConfigRetriever(), end_session(), and ~ConfigRetriever().
NdbMgmHandle ConfigRetriever::m_handle [private] |
Definition at line 105 of file ConfigRetriever.hpp.
Referenced by allocNodeId(), ConfigRetriever(), disconnect(), do_connect(), get_configuration_nodeid(), get_connectstring(), get_mgmd_host(), get_mgmd_port(), get_mgmHandle(), get_mgmHandlePtr(), getConfig(), setNodeId(), and ~ConfigRetriever().
Uint32 ConfigRetriever::m_node_type [private] |
Definition at line 104 of file ConfigRetriever.hpp.
Referenced by allocNodeId(), ConfigRetriever(), and verifyConfig().
Uint32 ConfigRetriever::m_version [private] |
Definition at line 103 of file ConfigRetriever.hpp.
Referenced by allocNodeId(), ConfigRetriever(), and getConfig().
1.4.7

