Skip to content

Commit cdeeb83

Browse files
stewart@flamingspork.comstewartsmith
stewart@flamingspork.com
authored andcommitted
[patch 17/64] WL4012 WL1744 (ndb on win32): ndb_opts full implementation---
storage/ndb/include/util/ndb_opts.h | 15 +-- storage/ndb/src/common/util/Makefile.am | 2 storage/ndb/src/common/util/ndb_opts.c | 123 ++++++++++++++++++++++++++++ storage/ndb/src/kernel/vm/Configuration.cpp | 17 +-- storage/ndb/src/mgmclient/main.cpp | 18 ++-- storage/ndb/src/mgmsrv/ConfigInfo.cpp | 4 storage/ndb/src/mgmsrv/MgmtSrvr.cpp | 2 storage/ndb/src/mgmsrv/main.cpp | 17 ++- storage/ndb/test/src/NDBT_Test.cpp | 15 ++- storage/ndb/tools/delete_all.cpp | 21 ++-- storage/ndb/tools/desc.cpp | 23 ++--- storage/ndb/tools/drop_index.cpp | 20 +--- storage/ndb/tools/drop_tab.cpp | 20 +--- storage/ndb/tools/listTables.cpp | 25 ++--- storage/ndb/tools/ndb_config.cpp | 16 +-- storage/ndb/tools/restore/restore_main.cpp | 15 +-- storage/ndb/tools/select_all.cpp | 25 ++--- storage/ndb/tools/select_count.cpp | 20 +--- storage/ndb/tools/waiter.cpp | 13 +- 19 files changed, 248 insertions(+), 163 deletions(-) Index: storage/ndb/src/common/util/Makefile.am ===================================================================
1 parent af9fca1 commit cdeeb83

19 files changed

+126
-163
lines changed

storage/ndb/include/util/ndb_opts.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ OPT_EXTERN(const char *,opt_debug,= 0);
108108

109109
void ndb_std_print_version();
110110

111-
static void usage();
112-
113111
enum ndb_std_options {
114112
OPT_NDB_SHM= 256,
115113
OPT_NDB_SHM_SIGNUM,
@@ -121,17 +119,18 @@ enum ndb_std_options {
121119
NDB_STD_OPTIONS_LAST /* should always be last in this enum */
122120
};
123121

122+
void ndb_opt_set_usage_funcs(const char* my_progname,
123+
void (*short_usage)(void),
124+
void (*usage)(void));
124125
my_bool
125126
ndb_std_get_one_option(int optid,
126127
const struct my_option *opt __attribute__((unused)),
127128
char *argument);
128129

129-
void ndb_usage();
130-
void ndb_short_usage_sub();
131-
#ifdef PROVIDE_USAGE
132-
inline void usage(){ndb_usage();}
133-
inline void short_usage_sub(){ndb_short_usage_sub();}
134-
#endif
130+
void ndb_usage(void (*usagefunc)(void), const char *load_default_groups[],
131+
struct my_option *my_long_options);
132+
void ndb_short_usage_sub(const char* my_progname, char* extra);
133+
135134

136135
#ifdef __cplusplus
137136
}

storage/ndb/src/common/portlib/NdbTCP.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <NdbTCP.h>
2020

2121

22+
2223
extern "C"
2324
int
2425
Ndb_getInAddr(struct in_addr * dst, const char *address) {

storage/ndb/src/common/util/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ libgeneral_la_SOURCES = \
2323
SocketServer.cpp SocketClient.cpp SocketAuthenticator.cpp\
2424
OutputStream.cpp NdbOut.cpp BaseString.cpp \
2525
NdbSqlUtil.cpp new.cpp \
26-
uucode.c random.c version.c \
26+
uucode.c random.c version.c ndb_opts.c \
2727
strdup.c \
2828
ConfigValues.cpp ndb_init.cpp basestring_vsnprintf.c \
2929
Bitmask.cpp \

storage/ndb/src/kernel/vm/Configuration.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ enum ndbd_options {
5454
OPT_INITIAL_START
5555
};
5656

57-
NDB_STD_OPTS_VARS;
5857
// XXX should be my_bool ???
5958
static int _daemon, _no_daemon, _foreground, _initial, _no_start;
6059
static int _initialstart;
@@ -68,7 +67,7 @@ const char *load_default_groups[]= { "mysql_cluster","ndbd",0 };
6867

6968
/**
7069
* Arguments to NDB process
71-
*/
70+
*/
7271
static struct my_option my_long_options[] =
7372
{
7473
NDB_STD_OPTS("ndbd"),
@@ -107,23 +106,21 @@ static struct my_option my_long_options[] =
107106
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
108107
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
109108
};
109+
110110
static void short_usage_sub(void)
111111
{
112-
printf("Usage: %s [OPTIONS]\n", my_progname);
112+
ndb_short_usage_sub(my_progname, NULL);
113113
}
114+
114115
static void usage()
115116
{
116-
short_usage_sub();
117-
ndb_std_print_version();
118-
print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
119-
puts("");
120-
my_print_help(my_long_options);
121-
my_print_variables(my_long_options);
117+
ndb_usage(short_usage_sub, load_default_groups, my_long_options);
122118
}
123119

124120
bool
125121
Configuration::init(int argc, char** argv)
126-
{
122+
{
123+
ndb_opt_set_usage_funcs(NULL, short_usage_sub, usage);
127124
load_defaults("my",load_default_groups,&argc,&argv);
128125

129126
int ho_error;

storage/ndb/src/mgmclient/main.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const char *load_default_groups[]= { "mysql_cluster","ndb_mgm",0 };
4444

4545
static Ndb_mgmclient* com;
4646

47+
#ifndef NDB_WIN32
4748
extern "C"
4849
void
4950
handler(int sig)
@@ -60,8 +61,7 @@ handler(int sig)
6061
}
6162
DBUG_VOID_RETURN;
6263
}
63-
64-
NDB_STD_OPTS_VARS;
64+
#endif
6565

6666
static const char default_prompt[]= "ndb_mgm> ";
6767
static unsigned _try_reconnect;
@@ -81,18 +81,15 @@ static struct my_option my_long_options[] =
8181
GET_UINT, REQUIRED_ARG, 3, 0, 0, 0, 0, 0 },
8282
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
8383
};
84+
8485
static void short_usage_sub(void)
8586
{
86-
printf("Usage: %s [OPTIONS] [hostname [port]]\n", my_progname);
87+
ndb_short_usage_sub(my_progname,"[hostname [port]]");
8788
}
89+
8890
static void usage()
8991
{
90-
short_usage_sub();
91-
ndb_std_print_version();
92-
print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
93-
puts("");
94-
my_print_help(my_long_options);
95-
my_print_variables(my_long_options);
92+
ndb_usage(short_usage_sub, load_default_groups, my_long_options);
9693
}
9794

9895
static int
@@ -131,6 +128,7 @@ read_and_execute(int _try_reconnect)
131128
int main(int argc, char** argv){
132129
NDB_INIT(argv[0]);
133130

131+
ndb_opt_set_usage_funcs(NULL, short_usage_sub, usage);
134132
load_defaults("my",load_default_groups,&argc,&argv);
135133
int ho_error;
136134
#ifndef DBUG_OFF
@@ -154,7 +152,9 @@ int main(int argc, char** argv){
154152
prompt= 0;
155153
}
156154

155+
#ifndef NDB_WIN32
157156
signal(SIGPIPE, handler);
157+
#endif
158158
com = new Ndb_mgmclient(opt_connect_str,1);
159159
int ret= 0;
160160
BaseString histfile;

storage/ndb/src/mgmsrv/ConfigInfo.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
#include "InitConfigFileParser.hpp"
2525
#include <m_string.h>
2626
#include <Bitmask.hpp>
27-
28-
extern my_bool opt_ndb_shm;
29-
extern my_bool opt_core;
27+
#include <ndb_opts.h>
3028

3129
#else
3230
#include "ConfigInfo.hpp"

storage/ndb/src/mgmsrv/MgmtSrvr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int g_errorInsert;
6969
}\
7070
}
7171

72-
extern my_bool opt_core;
72+
extern "C" my_bool opt_core;
7373

7474
static void require(bool v)
7575
{

storage/ndb/src/mgmsrv/main.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ bool g_RestartServer= false;
8282
static MgmtSrvr* mgm;
8383
static MgmtSrvr::MgmtOpts opts;
8484

85-
NDB_STD_OPTS_VARS;
85+
static int opt_daemon;
86+
static int opt_non_interactive;
8687

8788
static struct my_option my_long_options[] =
8889
{
@@ -119,24 +120,24 @@ static struct my_option my_long_options[] =
119120
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
120121
};
121122

123+
static void short_usage_sub(void)
124+
{
125+
ndb_short_usage_sub(my_progname, NULL);
126+
}
122127

123128
static void usage()
124129
{
125-
printf("Usage: %s [OPTIONS]\n", my_progname);
126-
ndb_std_print_version();
127-
print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
128-
puts("");
129-
my_print_help(my_long_options);
130-
my_print_variables(my_long_options);
130+
ndb_usage(short_usage_sub, load_default_groups, my_long_options);
131131
}
132132

133-
134133
int main(int argc, char** argv)
135134
{
136135
NDB_INIT(argv[0]);
137136

138137
g_eventLogger->setCategory("MgmSrvr");
139138

139+
ndb_opt_set_usage_funcs(NULL, short_usage_sub, usage);
140+
140141
load_defaults("my",load_default_groups,&argc,&argv);
141142

142143
int ho_error;

storage/ndb/test/src/NDBT_Test.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,6 @@ enum test_options {
12341234
OPT_PRINT_CASES
12351235

12361236
};
1237-
NDB_STD_OPTS_VARS;
12381237

12391238
static int opt_print = false;
12401239
static int opt_print_html = false;
@@ -1289,12 +1288,15 @@ static struct my_option my_long_options[] =
12891288

12901289
extern int global_flag_skip_invalidate_cache;
12911290

1291+
const char *load_default_groups[]= { "mysql_cluster",0 };
1292+
1293+
static void short_usage_sub(void)
1294+
{
1295+
ndb_short_usage_sub(my_progname, "[tabname1 tabname2 ... tabnameN]");
1296+
}
12921297
static void usage()
12931298
{
1294-
ndb_std_print_version();
1295-
printf("Usage: %s [OPTIONS] [tabname1 tabname2 ... tabnameN]\n", my_progname);
1296-
my_print_help(my_long_options);
1297-
my_print_variables(my_long_options);
1299+
ndb_usage(short_usage_sub, load_default_groups, my_long_options);
12981300
}
12991301

13001302
int NDBT_TestSuite::execute(int argc, const char** argv){
@@ -1324,7 +1326,8 @@ int NDBT_TestSuite::execute(int argc, const char** argv){
13241326
if (!my_progname)
13251327
my_progname= _argv[0];
13261328

1327-
const char *load_default_groups[]= { "mysql_cluster",0 };
1329+
ndb_opt_set_usage_funcs(NULL, short_usage_sub, usage);
1330+
13281331
load_defaults("my",load_default_groups,&argc,&_argv);
13291332

13301333
int ho_error;

storage/ndb/tools/delete_all.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
static int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab,
2525
bool fetch_across_commit, int parallelism=240);
2626

27-
NDB_STD_OPTS_VARS;
28-
2927
const char *load_default_groups[]= { "mysql_cluster",0 };
3028

3129
static const char* _dbname = "TEST_DB";
3230
static my_bool _transactional = false;
3331
static my_bool _tupscan = 0;
3432
static my_bool _diskscan = 0;
33+
3534
static struct my_option my_long_options[] =
3635
{
3736
NDB_STD_OPTS("ndb_desc"),
@@ -49,22 +48,20 @@ static struct my_option my_long_options[] =
4948
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
5049
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
5150
};
51+
52+
static void short_usage_sub(void)
53+
{
54+
ndb_short_usage_sub(my_progname, NULL);
55+
}
56+
5257
static void usage()
5358
{
54-
#ifdef NOT_USED
55-
char desc[] =
56-
"tabname\n"\
57-
"This program will delete all records in the specified table using scan delete.\n";
58-
#endif
59-
ndb_std_print_version();
60-
print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
61-
puts("");
62-
my_print_help(my_long_options);
63-
my_print_variables(my_long_options);
59+
ndb_usage(short_usage_sub, load_default_groups, my_long_options);
6460
}
6561

6662
int main(int argc, char** argv){
6763
NDB_INIT(argv[0]);
64+
ndb_opt_set_usage_funcs(NULL, short_usage_sub, usage);
6865
load_defaults("my",load_default_groups,&argc,&argv);
6966
int ho_error;
7067
#ifndef DBUG_OFF

storage/ndb/tools/desc.cpp

+10-13
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ int desc_datafile(Ndb_cluster_connection &con, Ndb *myndb, char* name);
2626
int desc_tablespace(Ndb *myndb,char* name);
2727
int desc_table(Ndb *myndb,char* name);
2828

29-
NDB_STD_OPTS_VARS;
30-
3129
static const char* _dbname = "TEST_DB";
3230
static int _unqualified = 0;
3331
static int _partinfo = 0;
3432

3533
const char *load_default_groups[]= { "mysql_cluster",0 };
3634

3735
static int _retries = 0;
36+
3837
static struct my_option my_long_options[] =
3938
{
4039
NDB_STD_OPTS("ndb_desc"),
@@ -52,25 +51,23 @@ static struct my_option my_long_options[] =
5251
GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
5352
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
5453
};
54+
55+
static void short_usage_sub(void)
56+
{
57+
ndb_short_usage_sub(my_progname, NULL);
58+
}
59+
5560
static void usage()
5661
{
57-
#ifdef NOT_USED
58-
char desc[] =
59-
"tabname\n"\
60-
"This program list all properties of table(s) in NDB Cluster.\n"\
61-
" ex: desc T1 T2 T4\n";
62-
#endif
63-
ndb_std_print_version();
64-
print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
65-
puts("");
66-
my_print_help(my_long_options);
67-
my_print_variables(my_long_options);
62+
ndb_usage(short_usage_sub, load_default_groups, my_long_options);
6863
}
6964

7065
static void print_part_info(Ndb* pNdb, NDBT_Table* pTab);
7166

7267
int main(int argc, char** argv){
7368
NDB_INIT(argv[0]);
69+
70+
ndb_opt_set_usage_funcs(NULL, short_usage_sub, usage);
7471
load_defaults("my",load_default_groups,&argc,&argv);
7572
int ho_error;
7673
#ifndef DBUG_OFF

storage/ndb/tools/drop_index.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include <NdbApi.hpp>
2121
#include <NDBT.hpp>
2222

23-
NDB_STD_OPTS_VARS;
24-
2523
static const char* _dbname = "TEST_DB";
2624

2725
const char *load_default_groups[]= { "mysql_cluster",0 };
@@ -34,22 +32,20 @@ static struct my_option my_long_options[] =
3432
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
3533
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
3634
};
35+
36+
static void short_usage_sub(void)
37+
{
38+
ndb_short_usage_sub(my_progname, NULL);
39+
}
40+
3741
static void usage()
3842
{
39-
#ifdef NOT_USED
40-
char desc[] =
41-
"[<table> <index>]+\n"\
42-
"This program will drop index(es) in Ndb\n";
43-
#endif
44-
ndb_std_print_version();
45-
print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
46-
puts("");
47-
my_print_help(my_long_options);
48-
my_print_variables(my_long_options);
43+
ndb_usage(short_usage_sub, load_default_groups, my_long_options);
4944
}
5045

5146
int main(int argc, char** argv){
5247
NDB_INIT(argv[0]);
48+
ndb_opt_set_usage_funcs(NULL, short_usage_sub, usage);
5349
load_defaults("my",load_default_groups,&argc,&argv);
5450
int ho_error;
5551
if ((ho_error=handle_options(&argc, &argv, my_long_options,

0 commit comments

Comments
 (0)