Skip to content

Commit 8bb8f21

Browse files
Merge branch 'mysql-5.6-cluster-7.4' into mysql-5.7-cluster-7.5
2 parents ab52242 + 086d610 commit 8bb8f21

File tree

1 file changed

+132
-63
lines changed

1 file changed

+132
-63
lines changed

storage/ndb/tools/ndb_config.cpp

Lines changed: 132 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -75,6 +75,7 @@ static int g_verbose = 0;
7575

7676
static int g_nodes, g_connections, g_system, g_section;
7777
static const char * g_query = 0;
78+
static int g_query_all = 0;
7879

7980
static int g_nodeid = 0;
8081
static const char * g_type = 0;
@@ -136,6 +137,9 @@ static struct my_option my_long_options[] =
136137
{ "config_from_node", NDB_OPT_NOSHORT, "Use current config from node with given nodeid",
137138
(uchar**) &g_config_from_node, (uchar**) &g_config_from_node,
138139
0, GET_INT, REQUIRED_ARG, INT_MIN, INT_MIN, 0, 0, 0, 0},
140+
{ "query_all", 'a', "Query all the options",
141+
(uchar**)&g_query_all, (uchar**)&g_query_all,
142+
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
139143
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
140144
};
141145

@@ -173,21 +177,29 @@ struct HostMatch : public Match
173177
struct Apply
174178
{
175179
Apply() {}
176-
Apply(int val) { m_key = val;}
180+
Apply(const char *s):m_name(s) {}
181+
BaseString m_name;
182+
virtual int apply(const Iter&) = 0;
183+
virtual ~Apply() {}
184+
};
185+
186+
187+
struct ParamApply : public Apply
188+
{
189+
ParamApply(int val,const char *s) :Apply(s), m_key(val) {}
177190
int m_key;
178191
virtual int apply(const Iter&);
179-
virtual ~Apply() {}
180192
};
181193

182194
struct NodeTypeApply : public Apply
183195
{
184-
NodeTypeApply() {}
196+
NodeTypeApply(const char *s) :Apply(s) {}
185197
virtual int apply(const Iter&);
186198
};
187199

188200
struct ConnectionTypeApply : public Apply
189201
{
190-
ConnectionTypeApply() {}
202+
ConnectionTypeApply(const char *s) :Apply(s) {}
191203
virtual int apply(const Iter&);
192204
};
193205

@@ -205,6 +217,7 @@ main(int argc, char** argv){
205217
ndb_opt_set_usage_funcs(short_usage_sub, usage);
206218
ndb_load_defaults(NULL,load_default_groups,&argc,&argv);
207219
int ho_error;
220+
bool print_headers = false;
208221
if ((ho_error=handle_options(&argc, &argv, my_long_options,
209222
ndb_std_get_one_option)))
210223
exit(255);
@@ -274,6 +287,17 @@ main(int argc, char** argv){
274287
if(strcmp(g_field_delimiter, "\\n") == 0)
275288
g_field_delimiter = "\n";
276289

290+
if (g_query_all)
291+
{
292+
if (g_query)
293+
{
294+
fprintf(stderr,
295+
"Error: Only one of the options: --query_all, --query is allowed.\n");
296+
exit(0);
297+
}
298+
print_headers = true;
299+
}
300+
277301
if(parse_query(select_list, argc, argv))
278302
{
279303
exit(0);
@@ -284,6 +308,17 @@ main(int argc, char** argv){
284308
exit(0);
285309
}
286310

311+
if (print_headers)
312+
{
313+
printf("%s", select_list[0]->m_name.c_str());
314+
for (unsigned i = 1; i < select_list.size(); i++)
315+
{
316+
printf("%s", g_field_delimiter);
317+
printf("%s", select_list[i]->m_name.c_str());
318+
}
319+
printf("%s", g_row_delimiter);
320+
}
321+
287322
Iter iter(* conf, g_section);
288323
bool prev= false;
289324
iter.first();
@@ -301,6 +336,91 @@ main(int argc, char** argv){
301336
return 0;
302337
}
303338

339+
static
340+
int
341+
helper(Vector<Apply*>& select, const char * str)
342+
{
343+
bool all = false;
344+
bool retflag = false;
345+
346+
if (g_query_all)
347+
{
348+
all = true;
349+
}
350+
351+
if (g_section == CFG_SECTION_NODE)
352+
{
353+
if (all)
354+
{
355+
select.push_back(new ParamApply(CFG_NODE_ID, "nodeid"));
356+
select.push_back(new ParamApply(CFG_NODE_HOST, "host"));
357+
select.push_back(new NodeTypeApply("type"));
358+
}
359+
else if (native_strcasecmp(str, "nodeid") == 0)
360+
{
361+
select.push_back(new ParamApply(CFG_NODE_ID, "nodeid"));
362+
retflag = true;
363+
}
364+
else if (native_strncasecmp(str, "host", 4) == 0)
365+
{
366+
select.push_back(new ParamApply(CFG_NODE_HOST, "host"));
367+
retflag = true;
368+
}
369+
else if (native_strcasecmp(str, "type") == 0)
370+
{
371+
select.push_back(new NodeTypeApply("type"));
372+
retflag = true;
373+
}
374+
}
375+
else if (g_section == CFG_SECTION_CONNECTION)
376+
{
377+
if (all || native_strcasecmp(str, "type") == 0)
378+
{
379+
select.push_back(new ConnectionTypeApply("type"));
380+
retflag = true;
381+
}
382+
}
383+
if (all || !retflag)
384+
{
385+
bool found = false;
386+
for (int p = 0; p < ConfigInfo::m_NoOfParams; p++)
387+
{
388+
if (0)ndbout_c("%s %s",
389+
ConfigInfo::m_ParamInfo[p]._section,
390+
ConfigInfo::m_ParamInfo[p]._fname);
391+
if ((g_section == CFG_SECTION_CONNECTION &&
392+
(strcmp(ConfigInfo::m_ParamInfo[p]._section, "TCP") == 0 ||
393+
strcmp(ConfigInfo::m_ParamInfo[p]._section, "SCI") == 0 ||
394+
strcmp(ConfigInfo::m_ParamInfo[p]._section, "SHM") == 0))
395+
||
396+
(g_section == CFG_SECTION_NODE &&
397+
(strcmp(ConfigInfo::m_ParamInfo[p]._section, "DB") == 0 ||
398+
strcmp(ConfigInfo::m_ParamInfo[p]._section, "API") == 0 ||
399+
strcmp(ConfigInfo::m_ParamInfo[p]._section, "MGM") == 0))
400+
||
401+
(g_section == CFG_SECTION_SYSTEM))
402+
{
403+
if (all || native_strcasecmp(ConfigInfo::m_ParamInfo[p]._fname, str) == 0)
404+
{
405+
select.push_back(new ParamApply(ConfigInfo::m_ParamInfo[p]._paramId,
406+
ConfigInfo::m_ParamInfo[p]._fname));
407+
if (!all)
408+
{
409+
found = true;
410+
break;
411+
}
412+
}
413+
}
414+
}
415+
if (!all && !found)
416+
{
417+
fprintf(stderr, "Unknown query option: %s\n", str);
418+
return 1;
419+
}
420+
}
421+
return 0;
422+
}
423+
304424
static
305425
int
306426
parse_query(Vector<Apply*>& select, int &argc, char**& argv)
@@ -313,67 +433,16 @@ parse_query(Vector<Apply*>& select, int &argc, char**& argv)
313433
for(unsigned i = 0; i<list.size(); i++)
314434
{
315435
const char * str= list[i].c_str();
316-
if(g_section == CFG_SECTION_NODE)
436+
if (helper(select, str))
317437
{
318-
if(native_strcasecmp(str, "nodeid") == 0)
319-
{
320-
select.push_back(new Apply(CFG_NODE_ID));
321-
continue;
322-
}
323-
else if(native_strncasecmp(str, "host", 4) == 0)
324-
{
325-
select.push_back(new Apply(CFG_NODE_HOST));
326-
continue;
327-
}
328-
else if(native_strcasecmp(str, "type") == 0)
329-
{
330-
select.push_back(new NodeTypeApply());
331-
continue;
332-
}
333-
}
334-
else if (g_section == CFG_SECTION_CONNECTION)
335-
{
336-
if(native_strcasecmp(str, "type") == 0)
337-
{
338-
select.push_back(new ConnectionTypeApply());
339-
continue;
340-
}
341-
}
342-
{
343-
bool found = false;
344-
for(int p = 0; p<ConfigInfo::m_NoOfParams; p++)
345-
{
346-
if(0)ndbout_c("%s %s",
347-
ConfigInfo::m_ParamInfo[p]._section,
348-
ConfigInfo::m_ParamInfo[p]._fname);
349-
if((g_section == CFG_SECTION_CONNECTION &&
350-
(strcmp(ConfigInfo::m_ParamInfo[p]._section, "TCP") == 0 ||
351-
strcmp(ConfigInfo::m_ParamInfo[p]._section, "SCI") == 0 ||
352-
strcmp(ConfigInfo::m_ParamInfo[p]._section, "SHM") == 0))
353-
||
354-
(g_section == CFG_SECTION_NODE &&
355-
(strcmp(ConfigInfo::m_ParamInfo[p]._section, "DB") == 0 ||
356-
strcmp(ConfigInfo::m_ParamInfo[p]._section, "API") == 0 ||
357-
strcmp(ConfigInfo::m_ParamInfo[p]._section, "MGM") == 0))
358-
||
359-
(g_section == CFG_SECTION_SYSTEM))
360-
{
361-
if(native_strcasecmp(ConfigInfo::m_ParamInfo[p]._fname, str) == 0)
362-
{
363-
select.push_back(new Apply(ConfigInfo::m_ParamInfo[p]._paramId));
364-
found = true;
365-
break;
366-
}
367-
}
368-
}
369-
if(!found)
370-
{
371-
fprintf(stderr, "Unknown query option: %s\n", str);
372-
return 1;
373-
}
438+
return 1;
374439
}
375440
}
376441
}
442+
if (g_query_all)
443+
{
444+
return helper(select, NULL);
445+
}
377446
return 0;
378447
}
379448

@@ -517,7 +586,7 @@ HostMatch::eval(const Iter& iter)
517586
}
518587

519588
int
520-
Apply::apply(const Iter& iter)
589+
ParamApply::apply(const Iter& iter)
521590
{
522591
Uint32 val32;
523592
Uint64 val64;

0 commit comments

Comments
 (0)