#include <ndb_global.h>#include <my_sys.h>#include <my_getopt.h>#include <mysql_version.h>#include <netdb.h>#include <NdbOut.hpp>#include <mgmapi.h>#include <mgmapi_configuration.hpp>#include <ConfigInfo.hpp>#include <Config.hpp>Include dependency graph for ndb_condig.cpp:

Go to the source code of this file.
Classes | |
| struct | Match |
| struct | HostMatch |
| struct | Apply |
| struct | NodeTypeApply |
| struct | ConnectionTypeApply |
Typedefs | |
| typedef ndb_mgm_configuration_iterator | Iter |
Functions | |
| static void | ndb_std_print_version () |
| static void | usage () |
| static my_bool | ndb_std_get_one_option (int optid, const struct my_option *opt __attribute__((unused)), char *argument) |
| static int | parse_query (Vector< Apply * > &, int &argc, char **&argv) |
| static int | parse_where (Vector< Match * > &, int &argc, char **&argv) |
| static int | eval (const Iter &, const Vector< Match * > &) |
| static int | apply (const Iter &, const Vector< Apply * > &) |
| static ndb_mgm_configuration * | fetch_configuration () |
| static ndb_mgm_configuration * | load_configuration () |
| int | main (int argc, char **argv) |
Variables | |
| static int | g_verbose = 0 |
| static int | try_reconnect = 3 |
| static int | g_nodes |
| static int | g_connections |
| static int | g_section |
| static const char * | g_connectstring = 0 |
| static const char * | g_query = 0 |
| static int | g_nodeid = 0 |
| static const char * | g_type = 0 |
| static const char * | g_host = 0 |
| static const char * | g_field_delimiter = "," |
| static const char * | g_row_delimiter = " " |
| static const char * | g_config_file = 0 |
| static int | g_mycnf = 0 |
| int | g_print_full_config |
| int | opt_ndb_shm |
| my_bool | opt_core |
| static struct my_option | my_long_options [] |
| typedef ndb_mgm_configuration_iterator Iter |
Definition at line 51 of file ndb_condig.cpp.
Definition at line 365 of file ndb_condig.cpp.
References g_field_delimiter, and list().
Referenced by main().
00366 { 00367 for(unsigned i = 0; i<list.size(); i++) 00368 { 00369 list[i]->apply(iter); 00370 if(i + 1 != list.size()) 00371 printf("%s", g_field_delimiter); 00372 } 00373 return 0; 00374 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ndb_mgm_configuration * fetch_configuration | ( | ) | [static] |
Definition at line 496 of file ndb_condig.cpp.
References g_connectstring, g_verbose, ndb_mgm_connect(), ndb_mgm_create_handle(), ndb_mgm_destroy_handle(), ndb_mgm_disconnect(), ndb_mgm_get_configuration(), ndb_mgm_get_connected_host(), ndb_mgm_get_connected_port(), ndb_mgm_get_latest_error(), ndb_mgm_get_latest_error_desc(), ndb_mgm_get_latest_error_msg(), ndb_mgm_set_connectstring(), ndb_mgm_set_error_stream(), NULL, and try_reconnect.
Referenced by main().
00497 { 00498 ndb_mgm_configuration* conf = 0; 00499 NdbMgmHandle mgm = ndb_mgm_create_handle(); 00500 if(mgm == NULL) { 00501 fprintf(stderr, "Cannot create handle to management server.\n"); 00502 return 0; 00503 } 00504 00505 ndb_mgm_set_error_stream(mgm, stderr); 00506 00507 if (ndb_mgm_set_connectstring(mgm, g_connectstring)) 00508 { 00509 fprintf(stderr, "* %5d: %s\n", 00510 ndb_mgm_get_latest_error(mgm), 00511 ndb_mgm_get_latest_error_msg(mgm)); 00512 fprintf(stderr, 00513 "* %s", ndb_mgm_get_latest_error_desc(mgm)); 00514 goto noconnect; 00515 } 00516 00517 if(ndb_mgm_connect(mgm, try_reconnect-1, 5, 1)) 00518 { 00519 fprintf(stderr, "Connect failed"); 00520 fprintf(stderr, " code: %d, msg: %s\n", 00521 ndb_mgm_get_latest_error(mgm), 00522 ndb_mgm_get_latest_error_msg(mgm)); 00523 goto noconnect; 00524 } 00525 else if(g_verbose) 00526 { 00527 fprintf(stderr, "Connected to %s:%d\n", 00528 ndb_mgm_get_connected_host(mgm), 00529 ndb_mgm_get_connected_port(mgm)); 00530 } 00531 00532 conf = ndb_mgm_get_configuration(mgm, 0); 00533 if(conf == 0) 00534 { 00535 fprintf(stderr, "Could not get configuration"); 00536 fprintf(stderr, "code: %d, msg: %s\n", 00537 ndb_mgm_get_latest_error(mgm), 00538 ndb_mgm_get_latest_error_msg(mgm)); 00539 } 00540 else if(g_verbose) 00541 { 00542 fprintf(stderr, "Fetched configuration\n"); 00543 } 00544 00545 ndb_mgm_disconnect(mgm); 00546 noconnect: 00547 ndb_mgm_destroy_handle(&mgm); 00548 00549 return conf; 00550 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ndb_mgm_configuration * load_configuration | ( | ) | [static] |
Definition at line 555 of file ndb_condig.cpp.
References g_config_file, g_verbose, Config::m_configValues, and parser.
Referenced by main().
00556 { 00557 InitConfigFileParser parser(stderr); 00558 if (g_config_file) 00559 { 00560 if (g_verbose) 00561 fprintf(stderr, "Using config.ini : %s", g_config_file); 00562 00563 Config* conf = parser.parseConfig(g_config_file); 00564 if (conf) 00565 return conf->m_configValues; 00566 } 00567 00568 if (g_verbose) 00569 fprintf(stderr, "Using my.cnf"); 00570 00571 Config* conf = parser.parse_mycnf(); 00572 if (conf) 00573 return conf->m_configValues; 00574 00575 return 0; 00576 }
Here is the caller graph for this function:

| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 177 of file ndb_condig.cpp.
References apply(), CFG_SECTION_CONNECTION, CFG_SECTION_NODE, eval(), exit, fetch_configuration(), ndb_mgm_configuration_iterator::first(), g_config_file, g_connections, g_field_delimiter, g_mycnf, g_nodes, g_row_delimiter, g_section, handle_options(), load_configuration(), load_default_groups, load_defaults(), my_long_options, NDB_INIT, ndb_std_get_one_option(), ndb_mgm_configuration_iterator::next(), parse_query(), parse_where(), strcmp(), and ndb_mgm_configuration_iterator::valid().
00177 { 00178 NDB_INIT(argv[0]); 00179 const char *load_default_groups[]= { "mysql_cluster",0 }; 00180 load_defaults("my",load_default_groups,&argc,&argv); 00181 int ho_error; 00182 if ((ho_error=handle_options(&argc, &argv, my_long_options, 00183 ndb_std_get_one_option))) 00184 return -1; 00185 00186 if (g_nodes && g_connections) 00187 { 00188 fprintf(stderr, 00189 "Only one option of --nodes and --connections allowed\n"); 00190 return -1; 00191 } 00192 00193 g_section = CFG_SECTION_NODE; //default 00194 if (g_connections) 00195 g_section = CFG_SECTION_CONNECTION; 00196 00197 ndb_mgm_configuration * conf = 0; 00198 00199 if (g_config_file || g_mycnf) 00200 conf = load_configuration(); 00201 else 00202 conf = fetch_configuration(); 00203 00204 if (conf == 0) 00205 { 00206 return -1; 00207 } 00208 00209 Vector<Apply*> select_list; 00210 Vector<Match*> where_clause; 00211 00212 if(strcmp(g_row_delimiter, "\\n") == 0) 00213 g_row_delimiter = "\n"; 00214 if(strcmp(g_field_delimiter, "\\n") == 0) 00215 g_field_delimiter = "\n"; 00216 00217 if(parse_query(select_list, argc, argv)) 00218 { 00219 exit(0); 00220 } 00221 00222 if(parse_where(where_clause, argc, argv)) 00223 { 00224 exit(0); 00225 } 00226 00227 Iter iter(* conf, g_section); 00228 bool prev= false; 00229 iter.first(); 00230 for(iter.first(); iter.valid(); iter.next()) 00231 { 00232 if(eval(iter, where_clause)) 00233 { 00234 if(prev) 00235 printf("%s", g_row_delimiter); 00236 prev= true; 00237 apply(iter, select_list); 00238 } 00239 } 00240 printf("\n"); 00241 return 0; 00242 }
Here is the call graph for this function:

| static my_bool ndb_std_get_one_option | ( | int | optid, | |
| const struct my_option *opt | __attribute__((unused)), | |||
| char * | argument | |||
| ) | [static] |
Definition at line 121 of file ndb_condig.cpp.
References exit, ndb_std_print_version(), and usage().
00124 { 00125 switch (optid) { 00126 case 'V': 00127 ndb_std_print_version(); 00128 exit(0); 00129 case '?': 00130 usage(); 00131 exit(0); 00132 } 00133 return 0; 00134 }
Here is the call graph for this function:

| static void ndb_std_print_version | ( | ) | [static] |
Definition at line 53 of file ndb_condig.cpp.
References MACHINE_TYPE, MYSQL_SERVER_VERSION, and SYSTEM_TYPE.
00054 { 00055 printf("MySQL distrib %s, for %s (%s)\n", 00056 MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); 00057 }
Definition at line 246 of file ndb_condig.cpp.
References CFG_NODE_HOST, CFG_NODE_ID, CFG_SECTION_CONNECTION, CFG_SECTION_NODE, g_query, g_section, list(), ConfigInfo::m_NoOfParams, ConfigInfo::m_ParamInfo, ndbout_c(), p, Vector< T >::push_back(), BaseString::split(), strcasecmp, strcmp(), and strncasecmp.
Referenced by main().
00247 { 00248 if(g_query) 00249 { 00250 BaseString q(g_query); 00251 Vector<BaseString> list; 00252 q.split(list, ","); 00253 for(unsigned i = 0; i<list.size(); i++) 00254 { 00255 const char * str= list[i].c_str(); 00256 if(g_section == CFG_SECTION_NODE) 00257 { 00258 if(strcasecmp(str, "id") == 0 || strcasecmp(str, "nodeid") == 0) 00259 { 00260 select.push_back(new Apply(CFG_NODE_ID)); 00261 continue; 00262 } 00263 else if(strncasecmp(str, "host", 4) == 0) 00264 { 00265 select.push_back(new Apply(CFG_NODE_HOST)); 00266 continue; 00267 } 00268 else if(strcasecmp(str, "type") == 0) 00269 { 00270 select.push_back(new NodeTypeApply()); 00271 continue; 00272 } 00273 } 00274 else if (g_section == CFG_SECTION_CONNECTION) 00275 { 00276 if(strcasecmp(str, "type") == 0) 00277 { 00278 select.push_back(new ConnectionTypeApply()); 00279 continue; 00280 } 00281 } 00282 { 00283 bool found = false; 00284 for(int p = 0; p<ConfigInfo::m_NoOfParams; p++) 00285 { 00286 if(0)ndbout_c("%s %s", 00287 ConfigInfo::m_ParamInfo[p]._section, 00288 ConfigInfo::m_ParamInfo[p]._fname); 00289 if(g_section == CFG_SECTION_CONNECTION && 00290 (strcmp(ConfigInfo::m_ParamInfo[p]._section, "TCP") == 0 || 00291 strcmp(ConfigInfo::m_ParamInfo[p]._section, "SCI") == 0 || 00292 strcmp(ConfigInfo::m_ParamInfo[p]._section, "SHM") == 0) 00293 || 00294 g_section == CFG_SECTION_NODE && 00295 (strcmp(ConfigInfo::m_ParamInfo[p]._section, "DB") == 0 || 00296 strcmp(ConfigInfo::m_ParamInfo[p]._section, "API") == 0 || 00297 strcmp(ConfigInfo::m_ParamInfo[p]._section, "MGM") == 0)) 00298 { 00299 if(strcasecmp(ConfigInfo::m_ParamInfo[p]._fname, str) == 0) 00300 { 00301 select.push_back(new Apply(ConfigInfo::m_ParamInfo[p]._paramId)); 00302 found = true; 00303 break; 00304 } 00305 } 00306 } 00307 if(!found) 00308 { 00309 fprintf(stderr, "Unknown query option: %s\n", str); 00310 return 1; 00311 } 00312 } 00313 } 00314 } 00315 return 0; 00316 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 320 of file ndb_condig.cpp.
References BaseString::assfmt(), CFG_NODE_HOST, CFG_NODE_ID, CFG_TYPE_OF_SECTION, g_host, g_nodeid, g_type, Match::m_key, Match::m_value, ndb_mgm_match_node_type(), and where.
Referenced by main().
00321 { 00322 Match m; 00323 if(g_host) 00324 { 00325 HostMatch *m = new HostMatch; 00326 m->m_key = CFG_NODE_HOST; 00327 m->m_value.assfmt("%s", g_host); 00328 where.push_back(m); 00329 } 00330 00331 if(g_type) 00332 { 00333 m.m_key = CFG_TYPE_OF_SECTION; 00334 m.m_value.assfmt("%d", ndb_mgm_match_node_type(g_type)); 00335 where.push_back(new Match(m)); 00336 } 00337 00338 if(g_nodeid) 00339 { 00340 m.m_key = CFG_NODE_ID; 00341 m.m_value.assfmt("%d", g_nodeid); 00342 where.push_back(new Match(m)); 00343 } 00344 return 0; 00345 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void usage | ( | void | ) | [static] |
Definition at line 112 of file ndb_condig.cpp.
References my_long_options, my_print_help(), my_print_variables(), and ndb_std_print_version().
00113 { 00114 char desc[] = 00115 "This program will retreive config options for a ndb cluster\n"; 00116 ndb_std_print_version(); 00117 my_print_help(my_long_options); 00118 my_print_variables(my_long_options); 00119 }
Here is the call graph for this function:

const char* g_config_file = 0 [static] |
int g_connections [static] |
const char* g_connectstring = 0 [static] |
const char* g_field_delimiter = "," [static] |
const char* g_host = 0 [static] |
int g_mycnf = 0 [static] |
int g_nodeid = 0 [static] |
int g_nodes [static] |
const char* g_query = 0 [static] |
const char* g_row_delimiter = " " [static] |
int g_section [static] |
const char* g_type = 0 [static] |
int g_verbose = 0 [static] |
ndb_config --nodes --query=nodeid --type=ndbd --host=local1
Definition at line 33 of file ndb_condig.cpp.
Referenced by fetch_configuration(), and load_configuration().
struct my_option my_long_options[] [static] |
Definition at line 59 of file ndb_condig.cpp.
Definition at line 49 of file ndb_condig.cpp.
| int opt_ndb_shm |
Definition at line 48 of file ndb_condig.cpp.
int try_reconnect = 3 [static] |
1.4.7

