diff options
author | unknown <tomas@poseidon.ndb.mysql.com> | 2004-11-01 13:55:43 +0000 |
---|---|---|
committer | unknown <tomas@poseidon.ndb.mysql.com> | 2004-11-01 13:55:43 +0000 |
commit | a2e4768f2019f0d4ffb10ad6afcb443e15f99602 (patch) | |
tree | 3ff4c0a0dfa3044edc7beaad3bc8fd54f77f9661 /ndb/tools | |
parent | d46c7366ebf3e7cd37253f61b927d62fbe180170 (diff) | |
download | mariadb-git-a2e4768f2019f0d4ffb10ad6afcb443e15f99602.tar.gz |
aligned ndb versioning with mysql
changed define SNPRINTF_RETURN_ZERO to SNPRINTF_RETURN_TRUNC
added define NDB_INIT
removed getarg, strlcat, strlcpy
aligned ndb version with mysql version
cpcd: removed old way of reading config file and replaced with mysql load_defaults
changed from using getarg to my_getopts
use mysql my_progname
moved getarg to test
BitKeeper/deleted/.del-strlcat.c~250851f8f1ac1c2c:
Delete: ndb/src/common/util/strlcat.c
BitKeeper/deleted/.del-strlcpy.c~43266e312d11c47b:
Delete: ndb/src/common/util/strlcpy.c
ndb/test/include/getarg.h:
Rename: ndb/include/util/getarg.h -> ndb/test/include/getarg.h
configure.in:
aligned ndb versioning with mysql
changed define SNPRINTF_RETURN_ZERO to SNPRINTF_RETURN_TRUNC
ndb/include/ndb_global.h:
added define NDB_INIT
removed strlcpy, strlcat
ndb/src/common/editline/sysunix.c:
removed usage of strlcat
ndb/src/common/util/Makefile.am:
removed getarg, strlcat, strlcpy
ndb/src/common/util/basestring_vsnprintf.c:
changed define from SNPRINTF_RETURN_ZERO to SNPRINTF_RETURN_TRUNC
ndb/src/common/util/socket_io.cpp:
removed usage of strlcat
ndb/src/common/util/version.c:
aligned ndb version with mysql version
ndb/src/cw/cpcd/common.cpp:
removed old way of reading config file and replaced with mysql load_defaults
ndb/src/cw/cpcd/common.hpp:
removed old way of reading config file and replaced with mysql load_defaults
ndb/src/cw/cpcd/main.cpp:
changed from usin getarg to my_opts
ndb/src/kernel/blocks/backup/restore/main.cpp:
changed from usin getarg to my_opts
ndb/src/kernel/error/ErrorReporter.cpp:
use mysql my_progname
ndb/src/kernel/main.cpp:
removed const in main declaration
ndb/src/kernel/vm/Configuration.cpp:
changed from usin getarg to my_opts
ndb/src/kernel/vm/Configuration.hpp:
removed const in main declaration
ndb/src/mgmclient/main.cpp:
changed from usin getarg to my_opts
ndb/src/mgmsrv/main.cpp:
changed from usin getarg to my_opts
ndb/src/ndbapi/Ndb.cpp:
fixed compiler warnings
ndb/test/run-test/Makefile.am:
moved getarg to test
ndb/test/src/Makefile.am:
moved getarg to test
ndb/test/src/getarg.c:
moved strlcat and strlcpy into getarg.c
ndb/tools/delete_all.cpp:
changed from usin getarg to my_opts
ndb/tools/desc.cpp:
changed from usin getarg to my_opts
ndb/tools/drop_index.cpp:
changed from usin getarg to my_opts
ndb/tools/drop_tab.cpp:
changed from usin getarg to my_opts
ndb/tools/listTables.cpp:
changed from usin getarg to my_opts
ndb/tools/select_all.cpp:
changed from usin getarg to my_opts
ndb/tools/select_count.cpp:
changed from usin getarg to my_opts
ndb/tools/waiter.cpp:
changed from usin getarg to my_opts
Diffstat (limited to 'ndb/tools')
-rw-r--r-- | ndb/tools/delete_all.cpp | 73 | ||||
-rw-r--r-- | ndb/tools/desc.cpp | 82 | ||||
-rw-r--r-- | ndb/tools/drop_index.cpp | 70 | ||||
-rw-r--r-- | ndb/tools/drop_tab.cpp | 78 | ||||
-rw-r--r-- | ndb/tools/listTables.cpp | 106 | ||||
-rw-r--r-- | ndb/tools/select_all.cpp | 124 | ||||
-rw-r--r-- | ndb/tools/select_count.cpp | 82 | ||||
-rw-r--r-- | ndb/tools/waiter.cpp | 75 |
8 files changed, 447 insertions, 243 deletions
diff --git a/ndb/tools/delete_all.cpp b/ndb/tools/delete_all.cpp index aa5798376ae..a4fd73a5128 100644 --- a/ndb/tools/delete_all.cpp +++ b/ndb/tools/delete_all.cpp @@ -15,41 +15,65 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <ndb_global.h> +#include <ndb_opts.h> #include <NdbOut.hpp> #include <NdbApi.hpp> #include <NdbSleep.h> #include <NDBT.hpp> -#include <getarg.h> - static int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism=240); -int main(int argc, const char** argv){ - ndb_init(); - - const char* _tabname = NULL; - const char* _dbname = "TEST_DB"; - int _help = 0; - - struct getargs args[] = { - { "usage", '?', arg_flag, &_help, "Print help", "" }, - { "database", 'd', arg_string, &_dbname, "dbname", - "Name of database table is in"} - }; - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; +static const char* opt_connect_str= 0; +static const char* _dbname = "TEST_DB"; +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "database", 'd', "Name of database table is in", + (gptr*) &_dbname, (gptr*) &_dbname, 0, + GET_STR, REQUIRED_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 print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); +} +static void usage() +{ char desc[] = "tabname\n"\ "This program will delete all records in the specified table using scan delete.\n"; - - if(getarg(args, num_args, argc, argv, &optind) || - argv[optind] == NULL || _help) { - arg_printusage(args, num_args, argv[0], desc); - return NDBT_ProgramExit(NDBT_WRONGARGS); + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_delete_all.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); } - _tabname = argv[optind]; + return 0; +} +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + return NDBT_ProgramExit(NDBT_WRONGARGS); + + Ndb::setConnectString(opt_connect_str); // Connect to Ndb Ndb MyNdb(_dbname); @@ -64,13 +88,12 @@ int main(int argc, const char** argv){ // Check if table exists in db int res = NDBT_OK; - for(int i = optind; i<argc; i++){ + for(int i = 0; i<argc; i++){ const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, argv[i]); if(pTab == NULL){ - ndbout << " Table " << _tabname << " does not exist!" << endl; + ndbout << " Table " << argv[i] << " does not exist!" << endl; return NDBT_ProgramExit(NDBT_WRONGARGS); } - ndbout << "Deleting all from " << argv[i] << "..."; if(clear_table(&MyNdb, pTab) == NDBT_FAILED){ res = NDBT_FAILED; diff --git a/ndb/tools/desc.cpp b/ndb/tools/desc.cpp index 9eed1485a6d..8f7a2031ef0 100644 --- a/ndb/tools/desc.cpp +++ b/ndb/tools/desc.cpp @@ -14,40 +14,66 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <getarg.h> +#include <ndb_global.h> +#include <ndb_opts.h> #include <NDBT.hpp> #include <NdbApi.hpp> - - - -int main(int argc, const char** argv){ - ndb_init(); - const char* _tabname = NULL; - const char* _dbname = "TEST_DB"; - int _unqualified = 0; - int _help = 0; - - struct getargs args[] = { - { "unqualified", 'u', arg_flag, &_unqualified, "unqualified", - "Use unqualified table names"}, - { "database", 'd', arg_string, &_dbname, "dbname", - "Name of database table is in"}, - { "usage", '?', arg_flag, &_help, "Print help", "" } - }; - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; +static const char* opt_connect_str= 0; +static const char* _dbname = "TEST_DB"; +static int _unqualified = 0; +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "database", 'd', "Name of database table is in", + (gptr*) &_dbname, (gptr*) &_dbname, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "unqualified", 'u', "Use unqualified table names", + (gptr*) &_unqualified, (gptr*) &_unqualified, 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 print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); +} +static void usage() +{ char desc[] = "tabname\n"\ "This program list all properties of table(s) in NDB Cluster.\n"\ - " ex: desc T1 T2 T4\n"; - - if(getarg(args, num_args, argc, argv, &optind) || - argv[optind] == NULL ||_help) { - arg_printusage(args, num_args, argv[0], desc); - return NDBT_ProgramExit(NDBT_WRONGARGS); + " ex: desc T1 T2 T4\n"; + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_desc.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); } - _tabname = argv[optind]; + return 0; +} + +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + return NDBT_ProgramExit(NDBT_WRONGARGS); + + Ndb::setConnectString(opt_connect_str); Ndb* pMyNdb; pMyNdb = new Ndb(_dbname); @@ -60,7 +86,7 @@ int main(int argc, const char** argv){ ndbout << endl; NdbDictionary::Dictionary * dict = pMyNdb->getDictionary(); - for (int i = optind; i < argc; i++) { + for (int i = 0; i < argc; i++) { NDBT_Table* pTab = (NDBT_Table*)dict->getTable(argv[i]); if (pTab != 0){ ndbout << (* pTab) << endl; diff --git a/ndb/tools/drop_index.cpp b/ndb/tools/drop_index.cpp index 70c29461c23..1d4b454682f 100644 --- a/ndb/tools/drop_index.cpp +++ b/ndb/tools/drop_index.cpp @@ -15,38 +15,66 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <ndb_global.h> +#include <ndb_opts.h> #include <NdbOut.hpp> #include <NdbApi.hpp> #include <NDBT.hpp> -#include <getarg.h> - -int main(int argc, const char** argv){ - ndb_init(); - - const char* _tabname = NULL; - const char* _dbname = "TEST_DB"; - int _help = 0; - - struct getargs args[] = { - { "database", 'd', arg_string, &_dbname, "dbname", - "Name of database table is in"}, - { "usage", '?', arg_flag, &_help, "Print help", "" } - }; - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; +static const char* opt_connect_str= 0; +static const char* _dbname = "TEST_DB"; +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "database", 'd', "Name of database table is in", + (gptr*) &_dbname, (gptr*) &_dbname, 0, + GET_STR, REQUIRED_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 print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); +} +static void usage() +{ char desc[] = "<indexname>+\n"\ "This program will drop index(es) in Ndb\n"; + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_drop_index.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); + } + return 0; +} - if(getarg(args, num_args, argc, argv, &optind) || - argv[optind] == NULL || _help){ - arg_printusage(args, num_args, argv[0], desc); +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + return NDBT_ProgramExit(NDBT_WRONGARGS); + if (argc < 1) { + usage(); return NDBT_ProgramExit(NDBT_WRONGARGS); } - _tabname = argv[optind]; + Ndb::setConnectString(opt_connect_str); // Connect to Ndb Ndb MyNdb(_dbname); if(MyNdb.init() != 0){ @@ -58,7 +86,7 @@ int main(int argc, const char** argv){ ndbout << "Waiting for ndb to become ready..." << endl; int res = 0; - for(int i = optind; i<argc; i++){ + for(int i = 0; i<argc; i++){ ndbout << "Dropping index " << argv[i] << "..."; int tmp; if((tmp = MyNdb.getDictionary()->dropIndex(argv[i], 0)) != 0){ diff --git a/ndb/tools/drop_tab.cpp b/ndb/tools/drop_tab.cpp index 15c229cb0fb..428730419fa 100644 --- a/ndb/tools/drop_tab.cpp +++ b/ndb/tools/drop_tab.cpp @@ -15,43 +15,67 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <ndb_global.h> +#include <ndb_opts.h> #include <NdbOut.hpp> #include <NdbApi.hpp> #include <NDBT.hpp> -#include <getarg.h> - -int main(int argc, const char** argv){ - ndb_init(); - - const char* _tabname = NULL; - const char* _dbname = "TEST_DB"; - const char* _connectstr = NULL; - int _help = 0; - - struct getargs args[] = { - { "database", 'd', arg_string, &_dbname, "dbname", - "Name of database table is in"}, - { "connstr", 'c', arg_string, &_connectstr, "connect string", - "How to connect to NDB"}, - { "usage", '?', arg_flag, &_help, "Print help", "" } - }; - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; +static const char* opt_connect_str= 0; +static const char* _dbname = "TEST_DB"; +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "database", 'd', "Name of database table is in", + (gptr*) &_dbname, (gptr*) &_dbname, 0, + GET_STR, REQUIRED_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 print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); + ndbPrintVersion(); +} +static void usage() +{ char desc[] = "tabname\n"\ "This program will drop one table in Ndb\n"; + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_drop_table.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); + } + return 0; +} - if(getarg(args, num_args, argc, argv, &optind) || - argv[optind] == NULL || _help){ - arg_printusage(args, num_args, argv[0], desc); +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + return NDBT_ProgramExit(NDBT_WRONGARGS); + if (argc < 1) { + usage(); return NDBT_ProgramExit(NDBT_WRONGARGS); } - _tabname = argv[optind]; - - if (_connectstr) - Ndb::setConnectString(_connectstr); + + Ndb::setConnectString(opt_connect_str); Ndb MyNdb(_dbname); if(MyNdb.init() != 0){ ERR(MyNdb.getNdbError()); @@ -62,7 +86,7 @@ int main(int argc, const char** argv){ ndbout << "Waiting for ndb to become ready..." << endl; int res = 0; - for(int i = optind; i<argc; i++){ + for(int i = 0; i<argc; i++){ ndbout << "Dropping table " << argv[i] << "..."; int tmp; if((tmp = MyNdb.getDictionary()->dropTable(argv[i])) != 0){ diff --git a/ndb/tools/listTables.cpp b/ndb/tools/listTables.cpp index 4fc5bcd7f21..2fc34394a9c 100644 --- a/ndb/tools/listTables.cpp +++ b/ndb/tools/listTables.cpp @@ -22,7 +22,7 @@ */ #include <ndb_global.h> -#include <getarg.h> +#include <ndb_opts.h> #include <NdbApi.hpp> #include <NDBT.hpp> @@ -161,39 +161,34 @@ list(const char * tabname, } } -#ifndef DBUG_OFF -const char *debug_option= 0; -#endif - -int main(int argc, const char** argv){ - ndb_init(); - int _loops = 1; - const char* _tabname = NULL; - const char* _dbname = "TEST_DB"; - int _type = 0; - int _help = 0; - const char* _connect_str = NULL; - - struct getargs args[] = { - { "loops", 'l', arg_integer, &_loops, "loops", - "Number of times to run(default = 1)" }, - { "unqualified", 'u', arg_flag, &_unqualified, "unqualified", - "Use unqualified table names"}, - { "database", 'd', arg_string, &_dbname, "dbname", - "Name of database table is in"}, - { "type", 't', arg_integer, &_type, "type", - "Type of objects to show, see NdbDictionary.hpp for numbers(default = 0)" }, - { "connect-string", 'c', arg_string, &_connect_str, - "Set connect string for connecting to ndb_mgmd. <constr>=\"host=<hostname:port>[;nodeid=<id>]\". Overides specifying entries in NDB_CONNECTSTRING and config file", - "<constr>" }, -#ifndef DBUG_OFF - { "debug", 0, arg_string, &debug_option, - "Specify debug options e.g. d:t:i:o,out.trace", "options" }, -#endif - { "usage", '?', arg_flag, &_help, "Print help", "" } - }; - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; +static const char* opt_connect_str= 0; +static const char* _dbname = "TEST_DB"; +static int _loops; +static int _type; +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "database", 'd', "Name of database table is in", + (gptr*) &_dbname, (gptr*) &_dbname, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "loops", 'l', "loops", + (gptr*) &_loops, (gptr*) &_loops, 0, + GET_INT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0 }, + { "type", 't', "type", + (gptr*) &_type, (gptr*) &_type, 0, + GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "unqualified", 'u', "Use unqualified table names", + (gptr*) &_unqualified, (gptr*) &_unqualified, 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 print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); + ndbPrintVersion(); +} +static void usage() +{ char desc[] = "tabname\n"\ "This program list all system objects in NDB Cluster.\n"\ @@ -201,19 +196,42 @@ int main(int argc, const char** argv){ " ex: list_tables -t 2 would show all UserTables\n"\ "To show all indexes for a table write table name as final argument\n"\ " ex: list_tables T1\n"; - - if(getarg(args, num_args, argc, argv, &optind) || _help) { - arg_printusage(args, num_args, argv[0], desc); + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_show_tables.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); + } + return 0; +} + +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char* _tabname; + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + return NDBT_ProgramExit(NDBT_WRONGARGS); + if ((_tabname = argv[0]) == 0) { + usage(); return NDBT_ProgramExit(NDBT_WRONGARGS); } - _tabname = argv[optind]; - -#ifndef DBUG_OFF - if (debug_option) - DBUG_PUSH(debug_option); -#endif - ndb_cluster_connection = new Ndb_cluster_connection(_connect_str); + ndb_cluster_connection = new Ndb_cluster_connection(opt_connect_str); ndb = new Ndb(ndb_cluster_connection, _dbname); if (ndb->init() != 0) fatal("init"); diff --git a/ndb/tools/select_all.cpp b/ndb/tools/select_all.cpp index 9f8108d9f32..758c1e48c88 100644 --- a/ndb/tools/select_all.cpp +++ b/ndb/tools/select_all.cpp @@ -16,6 +16,7 @@ #include <ndb_global.h> +#include <ndb_opts.h> #include <NdbOut.hpp> @@ -23,13 +24,8 @@ #include <NdbMain.h> #include <NDBT.hpp> #include <NdbSleep.h> -#include <getarg.h> #include <NdbScanFilter.hpp> -#ifndef DBUG_OFF -const char *debug_option= 0; -#endif - int scanReadRecords(Ndb*, const NdbDictionary::Table*, const NdbDictionary::Index*, @@ -40,39 +36,44 @@ int scanReadRecords(Ndb*, char delim, bool orderby); -int main(int argc, const char** argv){ - ndb_init(); - int _parallelism = 240; - const char* _delimiter = "\t"; - int _header = true; - int _useHexFormat = false; - const char* _tabname = NULL; - const char* _dbname = "TEST_DB"; - int _help = 0; - int _lock = 0; - int _order = 0; - - struct getargs args[] = { - { "database", 'd', arg_string, &_dbname, "dbname", - "Name of database table is in"}, - { "parallelism", 'p', arg_integer, &_parallelism, "parallelism", - "parallelism" }, - { "header", 'h', arg_flag, &_header, "Print header", "header" }, - { "useHexFormat", 'x', arg_flag, &_useHexFormat, - "Output numbers in hexadecimal format", "useHexFormat" }, - { "delimiter", 'd', arg_string, &_delimiter, "Column delimiter", - "delimiter" }, -#ifndef DBUG_OFF - { "debug", 0, arg_string, &debug_option, - "Specify debug options e.g. d:t:i:o,out.trace", "options" }, -#endif - { "usage", '?', arg_flag, &_help, "Print help", "" }, - { "lock", 'l', arg_integer, &_lock, - "Read(0), Read-hold(1), Exclusive(2)", "lock"}, - { "order", 'o', arg_flag, &_order, "Sort resultset according to index", ""} - }; - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; +static const char* opt_connect_str= 0; +static const char* _dbname = "TEST_DB"; +static const char* _delimiter = "\t"; +static int _unqualified, _header, _parallelism, _useHexFormat, _lock, + _order; + +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "database", 'd', "Name of database table is in", + (gptr*) &_dbname, (gptr*) &_dbname, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "parallelism", 'p', "parallelism", + (gptr*) &_parallelism, (gptr*) &_parallelism, 0, + GET_INT, REQUIRED_ARG, 240, 0, 0, 0, 0, 0 }, + { "lock", 'l', "Read(0), Read-hold(1), Exclusive(2)", + (gptr*) &_lock, (gptr*) &_lock, 0, + GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "order", 'o', "Sort resultset according to index", + (gptr*) &_order, (gptr*) &_order, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "header", 'h', "Print header", + (gptr*) &_header, (gptr*) &_header, 0, + GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 }, + { "useHexFormat", 'x', "Output numbers in hexadecimal format", + (gptr*) &_useHexFormat, (gptr*) &_useHexFormat, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "delimiter", 'D', "Column delimiter", + (gptr*) &_delimiter, (gptr*) &_delimiter, 0, + GET_STR, REQUIRED_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 print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); +} +static void usage() +{ char desc[] = "tabname\n"\ "This program reads all records from one table in NDB Cluster\n"\ @@ -80,19 +81,42 @@ int main(int argc, const char** argv){ "(It only print error messages if it encounters a permanent error.)\n"\ "It can also be used to dump the content of a table to file \n"\ " ex: select_all --no-header --delimiter=';' T4 > T4.data\n"; - - if(getarg(args, num_args, argc, argv, &optind) || - argv[optind] == NULL || _help) { - arg_printusage(args, num_args, argv[0], desc); - return NDBT_ProgramExit(NDBT_WRONGARGS); + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_select_all.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); } - _tabname = argv[optind]; + return 0; +} -#ifndef DBUG_OFF - if (debug_option) - DBUG_PUSH(debug_option); -#endif +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); + const char* _tabname; + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + return NDBT_ProgramExit(NDBT_WRONGARGS); + if ((_tabname = argv[0]) == 0) { + usage(); + return NDBT_ProgramExit(NDBT_WRONGARGS); + } + Ndb::setConnectString(opt_connect_str); // Connect to Ndb Ndb MyNdb(_dbname); @@ -108,8 +132,8 @@ int main(int argc, const char** argv){ // Check if table exists in db const NdbDictionary::Table* pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname); const NdbDictionary::Index * pIdx = 0; - if(optind+1 < argc){ - pIdx = MyNdb.getDictionary()->getIndex(argv[optind+1], _tabname); + if(argc > 1){ + pIdx = MyNdb.getDictionary()->getIndex(argv[0], _tabname); } if(pTab == NULL){ diff --git a/ndb/tools/select_count.cpp b/ndb/tools/select_count.cpp index 6650421e637..6ee49ddbff0 100644 --- a/ndb/tools/select_count.cpp +++ b/ndb/tools/select_count.cpp @@ -16,6 +16,7 @@ #include <ndb_global.h> +#include <ndb_opts.h> #include <NdbOut.hpp> @@ -23,7 +24,6 @@ #include <NdbMain.h> #include <NDBT.hpp> #include <NdbSleep.h> -#include <getarg.h> #include <UtilTransactions.hpp> static int @@ -32,34 +32,68 @@ select_count(Ndb* pNdb, const NdbDictionary::Table* pTab, int* count_rows, UtilTransactions::ScanLock lock); -int main(int argc, const char** argv){ - ndb_init(); - const char* _dbname = "TEST_DB"; - int _parallelism = 240; - int _help = 0; - int _lock = 0; - - struct getargs args[] = { - { "database", 'd', arg_string, &_dbname, "dbname", - "Name of database table is in"}, - { "parallelism", 's', arg_integer, &_parallelism, "parallelism", "parallelism" }, - { "usage", '?', arg_flag, &_help, "Print help", "" }, - { "lock", 'l', arg_integer, &_lock, - "Read(0), Read-hold(1), Exclusive(2)", "lock"} - - }; - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; +static const char* opt_connect_str= 0; +static const char* _dbname = "TEST_DB"; +static int _parallelism = 240; +static int _lock = 0; +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "database", 'd', "Name of database table is in", + (gptr*) &_dbname, (gptr*) &_dbname, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "parallelism", 'p', "parallelism", + (gptr*) &_parallelism, (gptr*) &_parallelism, 0, + GET_INT, REQUIRED_ARG, 240, 0, 0, 0, 0, 0 }, + { "lock", 'l', "Read(0), Read-hold(1), Exclusive(2)", + (gptr*) &_lock, (gptr*) &_lock, 0, + GET_INT, REQUIRED_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 print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); +} +static void usage() +{ char desc[] = "tabname1 ... tabnameN\n"\ "This program will count the number of records in tables\n"; - - if(getarg(args, num_args, argc, argv, &optind) || - argv[optind] == NULL || _help) { - arg_printusage(args, num_args, argv[0], desc); + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_select_count.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); + } + return 0; +} + +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + return NDBT_ProgramExit(NDBT_WRONGARGS); + if (argc < 1) { + usage(); return NDBT_ProgramExit(NDBT_WRONGARGS); } + Ndb::setConnectString(opt_connect_str); // Connect to Ndb Ndb MyNdb(_dbname); @@ -72,7 +106,7 @@ int main(int argc, const char** argv){ while(MyNdb.waitUntilReady() != 0) ndbout << "Waiting for ndb to become ready..." << endl; - for(int i = optind; i<argc; i++){ + for(int i = 0; i<argc; i++){ // Check if table exists in db const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, argv[i]); if(pTab == NULL){ diff --git a/ndb/tools/waiter.cpp b/ndb/tools/waiter.cpp index c01a3f9192e..1ff852b90cb 100644 --- a/ndb/tools/waiter.cpp +++ b/ndb/tools/waiter.cpp @@ -16,11 +16,12 @@ #include <ndb_global.h> +#include <ndb_opts.h> + #include <mgmapi.h> #include <NdbMain.h> #include <NdbOut.hpp> #include <NdbSleep.h> -#include <getarg.h> #include <kernel/ndb_limits.h> #include "../include/mgmcommon/LocalConfig.hpp" @@ -29,34 +30,60 @@ int waitClusterStatus(const char* _addr, ndb_mgm_node_status _status, unsigned int _timeout); -int main(int argc, const char** argv){ - ndb_init(); +static const char* opt_connect_str= 0; +static int _no_contact = 0; +static int _timeout = 120; +static struct my_option my_long_options[] = +{ + NDB_STD_OPTS("ndb_desc"), + { "no-contact", 'n', "Wait for cluster no contact", + (gptr*) &_no_contact, (gptr*) &_no_contact, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "timeout", 't', "Timeout to wait", + (gptr*) &_timeout, (gptr*) &_timeout, 0, + GET_INT, REQUIRED_ARG, 120, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; +static void print_version() +{ + printf("MySQL distrib %s, for %s (%s)\n",MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); + ndbPrintVersion(); +} +static void usage() +{ + print_version(); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/ndb_drop_table.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); + } + return 0; +} +int main(int argc, char** argv){ + NDB_INIT(argv[0]); + const char *load_default_groups[]= { "ndb_tools",0 }; + load_defaults("my",load_default_groups,&argc,&argv); const char* _hostName = NULL; - int _no_contact = 0; - int _help = 0; - int _timeout = 120; - - struct getargs args[] = { - { "timeout", 0, arg_integer, &_timeout, "Timeout to wait", "#" }, - { "no-contact", 0, arg_flag, &_no_contact, "Wait for cluster no contact", "" }, - { "usage", '?', arg_flag, &_help, "Print help", "" } - }; - - int num_args = sizeof(args) / sizeof(args[0]); - int optind = 0; - char desc[] = - "hostname:port\n"\ - "This program will connect to the mgmsrv of a NDB cluster.\n"\ - "It will then wait for all nodes to be started\n"; - - if(getarg(args, num_args, argc, argv, &optind) || _help) { - arg_printusage(args, num_args, argv[0], desc); + int ho_error; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) return NDBT_ProgramExit(NDBT_WRONGARGS); - } char buf[255]; - _hostName = argv[optind]; + _hostName = argv[0]; if (_hostName == NULL){ LocalConfig lcfg; |