mirror of
https://github.com/MariaDB/server.git
synced 2025-01-20 14:02:32 +01:00
2361720c98
into mysql.com:/home/my/mysql-5.1 BUILD/FINISH.sh: Auto merged BitKeeper/deleted/.del-makefilewin.i~5c8479dcb8a455b2: Auto merged BitKeeper/deleted/.del-makefilewin~13888739357b3025: Auto merged BitKeeper/deleted/.del-makefilewin~14f24a4a173e2fcd: Auto merged BitKeeper/deleted/.del-makefilewin~15e9e5c9e8fa870b: Auto merged BitKeeper/deleted/.del-makefilewin~1c53f31b88dd36e: Auto merged BitKeeper/deleted/.del-makefilewin~1dbc058d76ebf1db: Auto merged BitKeeper/deleted/.del-makefilewin~2e0407fe123f8365: Auto merged BitKeeper/deleted/.del-makefilewin~2fc379bd4065c995: Auto merged BitKeeper/deleted/.del-makefilewin~389ee2dcf79afb79: Auto merged BitKeeper/deleted/.del-makefilewin~4d139e182457e553: Auto merged BitKeeper/deleted/.del-makefilewin~5104767c73775697: Auto merged BitKeeper/deleted/.del-makefilewin~608ed49dcd88e0f7: Auto merged BitKeeper/deleted/.del-makefilewin~63acd666293282a: Auto merged BitKeeper/deleted/.del-makefilewin~6ba64863bce3d0b8: Auto merged BitKeeper/deleted/.del-makefilewin~72a64128bacce71b: Auto merged BitKeeper/deleted/.del-makefilewin~78000390c783b1c5: Auto merged BitKeeper/deleted/.del-makefilewin~7a9d7d5a42bbfaf5: Auto merged Makefile.am: Auto merged BitKeeper/deleted/.del-makefilewin~a40ea12eebdd6ef0: Auto merged BitKeeper/deleted/.del-makefilewin~aeea7c82f21f7cf5: Auto merged BitKeeper/deleted/.del-makefilewin~b643e38d8da389ac: Auto merged BitKeeper/deleted/.del-makefilewin~c7b621c745e5de95: Auto merged BitKeeper/deleted/.del-makefilewin~c8273a47b90f52bb: Auto merged BitKeeper/deleted/.del-makefilewin~d1a9d1f7d33fcb73: Auto merged BitKeeper/deleted/.del-makefilewin~d37b6b303348c871: Auto merged BitKeeper/deleted/.del-makefilewin~d90f35fdc3f2ee5f: Auto merged BitKeeper/deleted/.del-makefilewin~dc4b8ad5ea53bd: Auto merged BitKeeper/deleted/.del-makefilewin~dea10ec1c94f7be: Auto merged BitKeeper/deleted/.del-makefilewin~ef3a208fa0e9b0db: Auto merged BitKeeper/deleted/.del-makefilewin~f1e3b890aa1c9ea3: Auto merged BitKeeper/deleted/.del-makefilewin~f4b7b99a887b7de: Auto merged BitKeeper/deleted/.del-makefilewin~fdda94ad32fa9e34: Auto merged BitKeeper/deleted/.del-my_cnf~977f69858affc57b: Auto merged BitKeeper/etc/config: Auto merged VC++Files/libmysqld/libmysqld.dsp: Auto merged VC++Files/sql/mysqld.dsp: Auto merged client/mysqltest.c: Auto merged include/Makefile.am: Auto merged include/base64.h: Auto merged include/my_base.h: Auto merged include/mysql_com.h: Auto merged libmysqld/Makefile.am: Auto merged mysql-test/mysql-test-run.pl: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/ndb_basic.result: Auto merged mysql-test/r/ndb_condition_pushdown.result: Auto merged mysql-test/t/alter_table.test: Auto merged mysql-test/t/disabled.def: Auto merged mysql-test/t/query_cache.test: Auto merged mysys/Makefile.am: Auto merged mysys/base64.c: Auto merged scripts/make_win_src_distribution.sh: Auto merged scripts/mysql_create_system_tables.sh: Auto merged scripts/mysql_fix_privilege_tables.sql: Auto merged sql/Makefile.am: Auto merged sql/field.cc: Auto merged sql/field.h: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_berkeley.h: Auto merged sql/ha_federated.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_myisam.cc: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/handler.h: Auto merged sql/item.cc: Auto merged sql/item_subselect.cc: Auto merged sql/log.cc: Auto merged sql/log_event.cc: Auto merged sql/mysqld.cc: Auto merged sql/opt_range.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/slave.cc: Auto merged sql/slave.h: Auto merged sql/sp.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_cache.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_delete.cc: Auto merged sql/sql_help.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_load.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sql_prepare.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_select.h: Auto merged sql/sql_show.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/table.h: Auto merged storage/heap/_check.c: Auto merged storage/heap/hp_create.c: Auto merged storage/innobase/include/Makefile.am: Auto merged storage/innobase/include/rem0rec.h: Auto merged storage/innobase/include/rem0rec.ic: Auto merged storage/innobase/row/row0ins.c: Auto merged storage/innobase/row/row0upd.c: Auto merged storage/myisam/mi_check.c: Auto merged storage/myisam/mi_delete.c: Auto merged storage/myisam/mi_rkey.c: Auto merged storage/myisam/mi_rnext_same.c: Auto merged storage/myisam/mi_search.c: Auto merged storage/myisam/mi_write.c: Auto merged storage/myisam/myisamchk.c: Auto merged storage/myisam/myisamdef.h: Auto merged storage/myisam/sort.c: Auto merged storage/myisammrg/myrg_queue.c: Auto merged storage/ndb/config/type_util.mk.am: Auto merged storage/ndb/include/kernel/signaldata/DumpStateOrd.hpp: Auto merged storage/ndb/include/mgmapi/mgmapi_config_parameters.h: Auto merged storage/ndb/include/mgmapi/ndbd_exit_codes.h: Auto merged storage/ndb/include/transporter/TransporterCallback.hpp: Auto merged storage/ndb/src/common/mgmcommon/IPCConfig.cpp: Auto merged storage/ndb/src/common/transporter/SHM_Transporter.cpp: Auto merged storage/ndb/src/common/transporter/SHM_Transporter.hpp: Auto merged storage/ndb/src/common/transporter/SHM_Transporter.unix.cpp: Auto merged storage/ndb/src/common/transporter/SHM_Transporter.win32.cpp: Auto merged storage/ndb/src/common/transporter/Transporter.hpp: Auto merged storage/ndb/src/common/transporter/TransporterRegistry.cpp: Auto merged storage/ndb/src/common/util/Makefile.am: Auto merged storage/ndb/src/common/util/Parser.cpp: Auto merged storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Auto merged storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp: Auto merged storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp: Auto merged storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp: Auto merged storage/ndb/src/kernel/error/ndbd_exit_codes.c: Auto merged storage/ndb/src/kernel/vm/FastScheduler.cpp: Auto merged storage/ndb/src/kernel/vm/TransporterCallback.cpp: Auto merged storage/ndb/src/kernel/vm/VMSignal.hpp: Auto merged storage/ndb/src/mgmapi/mgmapi.cpp: Auto merged storage/ndb/src/mgmsrv/ConfigInfo.cpp: Auto merged storage/ndb/src/mgmsrv/InitConfigFileParser.cpp: Auto merged storage/ndb/src/mgmsrv/MgmtSrvr.cpp: Auto merged storage/ndb/src/mgmsrv/MgmtSrvr.hpp: Auto merged storage/ndb/src/mgmsrv/Services.cpp: Auto merged storage/ndb/src/ndbapi/TransporterFacade.cpp: Auto merged storage/ndb/test/ndbapi/testBackup.cpp: Auto merged storage/ndb/test/ndbapi/testOperations.cpp: Auto merged storage/ndb/test/src/HugoCalculator.cpp: Auto merged storage/ndb/tools/ndb_condig.cpp: Auto merged strings/ctype-big5.c: Auto merged strings/ctype-ucs2.c: Auto merged support-files/mysql.spec.sh: Auto merged BUILD/SETUP.sh: manual merge configure.in: manual merge mysql-test/r/alter_table.result: manual merge sql/handler.cc: manual merge sql/mysql_priv.h: manual merge sql/records.cc: manual merge sql/share/errmsg.txt: manual merge sql/sql_table.cc: manual merge Fix labels sql/sql_update.cc: manual merge sql/table.cc: manual merge sql/unireg.cc: manual merge storage/ndb/config/type_ndbapi.mk.am: manual merge
576 lines
13 KiB
C++
576 lines
13 KiB
C++
/* Copyright (C) 2003 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
/**
|
|
* ndb_config --nodes --query=nodeid --type=ndbd --host=local1
|
|
*/
|
|
|
|
#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>
|
|
|
|
static int g_verbose = 0;
|
|
static int try_reconnect = 3;
|
|
|
|
static int g_nodes, g_connections, 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, opt_ndb_shm;
|
|
my_bool opt_core;
|
|
|
|
typedef ndb_mgm_configuration_iterator Iter;
|
|
|
|
static void ndb_std_print_version()
|
|
{
|
|
printf("MySQL distrib %s, for %s (%s)\n",
|
|
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
|
|
}
|
|
|
|
static struct my_option my_long_options[] =
|
|
{
|
|
{ "usage", '?', "Display this help and exit.",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
|
|
{ "help", '?', "Display this help and exit.",
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
|
|
{ "version", 'V', "Output version information and exit.", 0, 0, 0,
|
|
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
|
|
{ "ndb-connectstring", 256,
|
|
"Set connect string for connecting to ndb_mgmd. "
|
|
"Syntax: \"[nodeid=<id>;][host=]<hostname>[:<port>]\". "
|
|
"Overides specifying entries in NDB_CONNECTSTRING and Ndb.cfg",
|
|
(gptr*) &g_connectstring, (gptr*) &g_connectstring,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
|
|
{ "ndb-shm", 256, "Print nodes",
|
|
(gptr*) &opt_ndb_shm, (gptr*) &opt_ndb_shm,
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "nodes", 256, "Print nodes",
|
|
(gptr*) &g_nodes, (gptr*) &g_nodes,
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "connections", 256, "Print connections",
|
|
(gptr*) &g_connections, (gptr*) &g_connections,
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "query", 'q', "Query option(s)",
|
|
(gptr*) &g_query, (gptr*) &g_query,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "host", 256, "Host",
|
|
(gptr*) &g_host, (gptr*) &g_host,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "type", 258, "Type of node/connection",
|
|
(gptr*) &g_type, (gptr*) &g_type,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "id", 258, "Nodeid",
|
|
(gptr*) &g_nodeid, (gptr*) &g_nodeid,
|
|
0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "nodeid", 258, "Nodeid",
|
|
(gptr*) &g_nodeid, (gptr*) &g_nodeid,
|
|
0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "fields", 'f', "Field separator",
|
|
(gptr*) &g_field_delimiter, (gptr*) &g_field_delimiter,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "rows", 'r', "Row separator",
|
|
(gptr*) &g_row_delimiter, (gptr*) &g_row_delimiter,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "config-file", 256, "Path to config.ini",
|
|
(gptr*) &g_config_file, (gptr*) &g_config_file,
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ "mycnf", 256, "Read config from my.cnf",
|
|
(gptr*) &g_mycnf, (gptr*) &g_mycnf,
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
|
|
};
|
|
|
|
static void usage()
|
|
{
|
|
char desc[] =
|
|
"This program will retreive config options for a ndb cluster\n";
|
|
ndb_std_print_version();
|
|
my_print_help(my_long_options);
|
|
my_print_variables(my_long_options);
|
|
}
|
|
static my_bool
|
|
ndb_std_get_one_option(int optid,
|
|
const struct my_option *opt __attribute__((unused)),
|
|
char *argument)
|
|
{
|
|
switch (optid) {
|
|
case 'V':
|
|
ndb_std_print_version();
|
|
exit(0);
|
|
case '?':
|
|
usage();
|
|
exit(0);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Match/Apply framework
|
|
*/
|
|
struct Match
|
|
{
|
|
int m_key;
|
|
BaseString m_value;
|
|
virtual int eval(const Iter&);
|
|
};
|
|
|
|
struct HostMatch : public Match
|
|
{
|
|
virtual int eval(NdbMgmHandle, const Iter&);
|
|
};
|
|
|
|
struct Apply
|
|
{
|
|
Apply() {}
|
|
Apply(int val) { m_key = val;}
|
|
int m_key;
|
|
virtual int apply(const Iter&);
|
|
};
|
|
|
|
struct NodeTypeApply : public Apply
|
|
{
|
|
virtual int apply(const Iter&);
|
|
};
|
|
|
|
struct ConnectionTypeApply : public Apply
|
|
{
|
|
virtual int apply(const Iter&);
|
|
};
|
|
|
|
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){
|
|
NDB_INIT(argv[0]);
|
|
const char *load_default_groups[]= { "mysql_cluster",0 };
|
|
load_defaults("my",load_default_groups,&argc,&argv);
|
|
int ho_error;
|
|
if ((ho_error=handle_options(&argc, &argv, my_long_options,
|
|
ndb_std_get_one_option)))
|
|
return -1;
|
|
|
|
if (g_nodes && g_connections)
|
|
{
|
|
fprintf(stderr,
|
|
"Only one option of --nodes and --connections allowed\n");
|
|
return -1;
|
|
}
|
|
|
|
g_section = CFG_SECTION_NODE; //default
|
|
if (g_connections)
|
|
g_section = CFG_SECTION_CONNECTION;
|
|
|
|
ndb_mgm_configuration * conf = 0;
|
|
|
|
if (g_config_file || g_mycnf)
|
|
conf = load_configuration();
|
|
else
|
|
conf = fetch_configuration();
|
|
|
|
if (conf == 0)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
Vector<Apply*> select_list;
|
|
Vector<Match*> where_clause;
|
|
|
|
if(strcmp(g_row_delimiter, "\\n") == 0)
|
|
g_row_delimiter = "\n";
|
|
if(strcmp(g_field_delimiter, "\\n") == 0)
|
|
g_field_delimiter = "\n";
|
|
|
|
if(parse_query(select_list, argc, argv))
|
|
{
|
|
exit(0);
|
|
}
|
|
|
|
if(parse_where(where_clause, argc, argv))
|
|
{
|
|
exit(0);
|
|
}
|
|
|
|
Iter iter(* conf, g_section);
|
|
bool prev= false;
|
|
iter.first();
|
|
for(iter.first(); iter.valid(); iter.next())
|
|
{
|
|
if(eval(iter, where_clause))
|
|
{
|
|
if(prev)
|
|
printf("%s", g_row_delimiter);
|
|
prev= true;
|
|
apply(iter, select_list);
|
|
}
|
|
}
|
|
printf("\n");
|
|
return 0;
|
|
}
|
|
|
|
static
|
|
int
|
|
parse_query(Vector<Apply*>& select, int &argc, char**& argv)
|
|
{
|
|
if(g_query)
|
|
{
|
|
BaseString q(g_query);
|
|
Vector<BaseString> list;
|
|
q.split(list, ",");
|
|
for(unsigned i = 0; i<list.size(); i++)
|
|
{
|
|
const char * str= list[i].c_str();
|
|
if(g_section == CFG_SECTION_NODE)
|
|
{
|
|
if(strcasecmp(str, "id") == 0 || strcasecmp(str, "nodeid") == 0)
|
|
{
|
|
select.push_back(new Apply(CFG_NODE_ID));
|
|
continue;
|
|
}
|
|
else if(strncasecmp(str, "host", 4) == 0)
|
|
{
|
|
select.push_back(new Apply(CFG_NODE_HOST));
|
|
continue;
|
|
}
|
|
else if(strcasecmp(str, "type") == 0)
|
|
{
|
|
select.push_back(new NodeTypeApply());
|
|
continue;
|
|
}
|
|
}
|
|
else if (g_section == CFG_SECTION_CONNECTION)
|
|
{
|
|
if(strcasecmp(str, "type") == 0)
|
|
{
|
|
select.push_back(new ConnectionTypeApply());
|
|
continue;
|
|
}
|
|
}
|
|
{
|
|
bool found = false;
|
|
for(int p = 0; p<ConfigInfo::m_NoOfParams; p++)
|
|
{
|
|
if(0)ndbout_c("%s %s",
|
|
ConfigInfo::m_ParamInfo[p]._section,
|
|
ConfigInfo::m_ParamInfo[p]._fname);
|
|
if(g_section == CFG_SECTION_CONNECTION &&
|
|
(strcmp(ConfigInfo::m_ParamInfo[p]._section, "TCP") == 0 ||
|
|
strcmp(ConfigInfo::m_ParamInfo[p]._section, "SCI") == 0 ||
|
|
strcmp(ConfigInfo::m_ParamInfo[p]._section, "SHM") == 0)
|
|
||
|
|
g_section == CFG_SECTION_NODE &&
|
|
(strcmp(ConfigInfo::m_ParamInfo[p]._section, "DB") == 0 ||
|
|
strcmp(ConfigInfo::m_ParamInfo[p]._section, "API") == 0 ||
|
|
strcmp(ConfigInfo::m_ParamInfo[p]._section, "MGM") == 0))
|
|
{
|
|
if(strcasecmp(ConfigInfo::m_ParamInfo[p]._fname, str) == 0)
|
|
{
|
|
select.push_back(new Apply(ConfigInfo::m_ParamInfo[p]._paramId));
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(!found)
|
|
{
|
|
fprintf(stderr, "Unknown query option: %s\n", str);
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static
|
|
int
|
|
parse_where(Vector<Match*>& where, int &argc, char**& argv)
|
|
{
|
|
Match m;
|
|
if(g_host)
|
|
{
|
|
HostMatch *m = new HostMatch;
|
|
m->m_key = CFG_NODE_HOST;
|
|
m->m_value.assfmt("%s", g_host);
|
|
where.push_back(m);
|
|
}
|
|
|
|
if(g_type)
|
|
{
|
|
m.m_key = CFG_TYPE_OF_SECTION;
|
|
m.m_value.assfmt("%d", ndb_mgm_match_node_type(g_type));
|
|
where.push_back(new Match(m));
|
|
}
|
|
|
|
if(g_nodeid)
|
|
{
|
|
m.m_key = CFG_NODE_ID;
|
|
m.m_value.assfmt("%d", g_nodeid);
|
|
where.push_back(new Match(m));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
template class Vector<Apply*>;
|
|
template class Vector<Match*>;
|
|
|
|
static
|
|
int
|
|
eval(const Iter& iter, const Vector<Match*>& where)
|
|
{
|
|
for(unsigned i = 0; i<where.size(); i++)
|
|
{
|
|
if(where[i]->eval(iter) == 0)
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
static
|
|
int
|
|
apply(const Iter& iter, const Vector<Apply*>& list)
|
|
{
|
|
for(unsigned i = 0; i<list.size(); i++)
|
|
{
|
|
list[i]->apply(iter);
|
|
if(i + 1 != list.size())
|
|
printf("%s", g_field_delimiter);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
Match::eval(const Iter& iter)
|
|
{
|
|
Uint32 val32;
|
|
Uint64 val64;
|
|
const char* valc;
|
|
if (iter.get(m_key, &val32) == 0)
|
|
{
|
|
if(atoi(m_value.c_str()) != (int)val32)
|
|
return 0;
|
|
}
|
|
else if(iter.get(m_key, &val64) == 0)
|
|
{
|
|
if(strtoll(m_value.c_str(), (char **)NULL, 10) != (long long)val64)
|
|
return 0;
|
|
}
|
|
else if(iter.get(m_key, &valc) == 0)
|
|
{
|
|
if(strcmp(m_value.c_str(), valc) != 0)
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
HostMatch::eval(NdbMgmHandle h, const Iter& iter)
|
|
{
|
|
const char* valc;
|
|
|
|
if(iter.get(m_key, &valc) == 0)
|
|
{
|
|
struct hostent *h1, *h2;
|
|
|
|
h1 = gethostbyname(m_value.c_str());
|
|
if (h1 == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
h2 = gethostbyname(valc);
|
|
if (h2 == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
if (h1->h_addrtype != h2->h_addrtype) {
|
|
return 0;
|
|
}
|
|
|
|
if (h1->h_length != h2->h_length)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return 0 == memcmp(h1->h_addr, h2->h_addr, h1->h_length);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
Apply::apply(const Iter& iter)
|
|
{
|
|
Uint32 val32;
|
|
Uint64 val64;
|
|
const char* valc;
|
|
if (iter.get(m_key, &val32) == 0)
|
|
{
|
|
printf("%u", val32);
|
|
}
|
|
else if(iter.get(m_key, &val64) == 0)
|
|
{
|
|
printf("%llu", val64);
|
|
}
|
|
else if(iter.get(m_key, &valc) == 0)
|
|
{
|
|
printf("%s", valc);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
NodeTypeApply::apply(const Iter& iter)
|
|
{
|
|
Uint32 val32;
|
|
if (iter.get(CFG_TYPE_OF_SECTION, &val32) == 0)
|
|
{
|
|
printf("%s", ndb_mgm_get_node_type_alias_string((ndb_mgm_node_type)val32, 0));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
ConnectionTypeApply::apply(const Iter& iter)
|
|
{
|
|
Uint32 val32;
|
|
if (iter.get(CFG_TYPE_OF_SECTION, &val32) == 0)
|
|
{
|
|
switch (val32)
|
|
{
|
|
case CONNECTION_TYPE_TCP:
|
|
printf("tcp");
|
|
break;
|
|
case CONNECTION_TYPE_SCI:
|
|
printf("sci");
|
|
break;
|
|
case CONNECTION_TYPE_SHM:
|
|
printf("shm");
|
|
break;
|
|
default:
|
|
printf("<unknown>");
|
|
break;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
ndb_mgm_configuration*
|
|
fetch_configuration()
|
|
{
|
|
ndb_mgm_configuration* conf = 0;
|
|
NdbMgmHandle mgm = ndb_mgm_create_handle();
|
|
if(mgm == NULL) {
|
|
fprintf(stderr, "Cannot create handle to management server.\n");
|
|
return 0;
|
|
}
|
|
|
|
ndb_mgm_set_error_stream(mgm, stderr);
|
|
|
|
if (ndb_mgm_set_connectstring(mgm, g_connectstring))
|
|
{
|
|
fprintf(stderr, "* %5d: %s\n",
|
|
ndb_mgm_get_latest_error(mgm),
|
|
ndb_mgm_get_latest_error_msg(mgm));
|
|
fprintf(stderr,
|
|
"* %s", ndb_mgm_get_latest_error_desc(mgm));
|
|
goto noconnect;
|
|
}
|
|
|
|
if(ndb_mgm_connect(mgm, try_reconnect-1, 5, 1))
|
|
{
|
|
fprintf(stderr, "Connect failed");
|
|
fprintf(stderr, " code: %d, msg: %s\n",
|
|
ndb_mgm_get_latest_error(mgm),
|
|
ndb_mgm_get_latest_error_msg(mgm));
|
|
goto noconnect;
|
|
}
|
|
else if(g_verbose)
|
|
{
|
|
fprintf(stderr, "Connected to %s:%d\n",
|
|
ndb_mgm_get_connected_host(mgm),
|
|
ndb_mgm_get_connected_port(mgm));
|
|
}
|
|
|
|
conf = ndb_mgm_get_configuration(mgm, 0);
|
|
if(conf == 0)
|
|
{
|
|
fprintf(stderr, "Could not get configuration");
|
|
fprintf(stderr, "code: %d, msg: %s\n",
|
|
ndb_mgm_get_latest_error(mgm),
|
|
ndb_mgm_get_latest_error_msg(mgm));
|
|
}
|
|
else if(g_verbose)
|
|
{
|
|
fprintf(stderr, "Fetched configuration\n");
|
|
}
|
|
|
|
ndb_mgm_disconnect(mgm);
|
|
noconnect:
|
|
ndb_mgm_destroy_handle(&mgm);
|
|
|
|
return conf;
|
|
}
|
|
|
|
#include <Config.hpp>
|
|
|
|
ndb_mgm_configuration*
|
|
load_configuration()
|
|
{
|
|
InitConfigFileParser parser(stderr);
|
|
if (g_config_file)
|
|
{
|
|
if (g_verbose)
|
|
fprintf(stderr, "Using config.ini : %s", g_config_file);
|
|
|
|
Config* conf = parser.parseConfig(g_config_file);
|
|
if (conf)
|
|
return conf->m_configValues;
|
|
}
|
|
|
|
if (g_verbose)
|
|
fprintf(stderr, "Using my.cnf");
|
|
|
|
Config* conf = parser.parse_mycnf();
|
|
if (conf)
|
|
return conf->m_configValues;
|
|
|
|
return 0;
|
|
}
|