MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include <ndb_global.h>
19 #include <ndb_opts.h>
20 #include <kernel/NodeBitmask.hpp>
21 #include <portlib/ndb_daemon.h>
22 
23 #include "ndbd.hpp"
24 #include "angel.hpp"
25 
26 #include <EventLogger.hpp>
27 extern EventLogger * g_eventLogger;
28 
29 static int opt_daemon, opt_no_daemon, opt_foreground,
30  opt_initialstart, opt_verbose;
31 static const char* opt_nowait_nodes = 0;
32 static const char* opt_bind_address = 0;
33 static int opt_report_fd;
34 static int opt_initial;
35 static int opt_no_start;
36 static unsigned opt_allocated_nodeid;
37 
38 extern NdbNodeBitmask g_nowait_nodes;
39 
40 static struct my_option my_long_options[] =
41 {
42  NDB_STD_OPTS("ndbd"),
43  { "initial", NDB_OPT_NOSHORT,
44  "Perform initial start of ndbd, including cleaning the file system. "
45  "Consult documentation before using this",
46  (uchar**) &opt_initial, (uchar**) &opt_initial, 0,
47  GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
48  { "nostart", 'n',
49  "Don't start ndbd immediately. Ndbd will await command from ndb_mgmd",
50  (uchar**) &opt_no_start, (uchar**) &opt_no_start, 0,
51  GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
52  { "daemon", 'd', "Start ndbd as daemon (default)",
53  (uchar**) &opt_daemon, (uchar**) &opt_daemon, 0,
54  GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
55  { "nodaemon", NDB_OPT_NOSHORT,
56  "Do not start ndbd as daemon, provided for testing purposes",
57  (uchar**) &opt_no_daemon, (uchar**) &opt_no_daemon, 0,
58  GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
59  { "foreground", NDB_OPT_NOSHORT,
60  "Run real ndbd in foreground, provided for debugging purposes"
61  " (implies --nodaemon)",
62  (uchar**) &opt_foreground, (uchar**) &opt_foreground, 0,
63  GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
64  { "nowait-nodes", NDB_OPT_NOSHORT,
65  "Nodes that will not be waited for during start",
66  (uchar**) &opt_nowait_nodes, (uchar**) &opt_nowait_nodes, 0,
67  GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
68  { "initial-start", NDB_OPT_NOSHORT,
69  "Perform a partial initial start of the cluster. "
70  "Each node should be started with this option, as well as --nowait-nodes",
71  (uchar**) &opt_initialstart, (uchar**) &opt_initialstart, 0,
72  GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
73  { "bind-address", NDB_OPT_NOSHORT,
74  "Local bind address",
75  (uchar**) &opt_bind_address, (uchar**) &opt_bind_address, 0,
76  GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
77  { "verbose", 'v',
78  "Write more log messages",
79  (uchar**) &opt_verbose, (uchar**) &opt_verbose, 0,
80  GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 },
81  { "report-fd", 256,
82  "INTERNAL: fd where to write extra shutdown status",
83  (uchar**) &opt_report_fd, (uchar**) &opt_report_fd, 0,
84  GET_UINT, REQUIRED_ARG, 0, 0, ~0, 0, 0, 0 },
85  { "allocated-nodeid", 256,
86  "INTERNAL: nodeid allocated by angel process",
87  (uchar**) &opt_allocated_nodeid, (uchar**) &opt_allocated_nodeid, 0,
88  GET_UINT, REQUIRED_ARG, 0, 0, ~0, 0, 0, 0 },
89  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
90 };
91 
92 const char *load_default_groups[]= { "mysql_cluster", "ndbd", 0 };
93 
94 
95 static void short_usage_sub(void)
96 {
97  ndb_short_usage_sub(NULL);
98  ndb_service_print_options("ndbd");
99 }
100 
101 static void usage()
102 {
103  ndb_usage(short_usage_sub, load_default_groups, my_long_options);
104 }
105 
106 extern int g_ndb_init_need_monotonic;
107 
108 #include "../common/util/parse_mask.hpp"
109 
116 int
117 real_main(int argc, char** argv)
118 {
119  g_ndb_init_need_monotonic = 1;
120  NDB_INIT(argv[0]);
121 
122  // Print to stdout/console
123  g_eventLogger->createConsoleHandler();
124 
125 #ifdef _WIN32
126  /* Output to Windows event log */
127  g_eventLogger->createEventLogHandler("MySQL Cluster Data Node Daemon");
128 #endif
129 
130  g_eventLogger->setCategory("ndbd");
131 
132  // Turn on max loglevel for startup messages
133  g_eventLogger->m_logLevel.setLogLevel(LogLevel::llStartUp, 15);
134 
135  ndb_opt_set_usage_funcs(short_usage_sub, usage);
136  load_defaults("my",load_default_groups,&argc,&argv);
137 
138 #ifndef DBUG_OFF
139  opt_debug= "d:t:O,/tmp/ndbd.trace";
140 #endif
141 
142  // Save the original program name and arguments for angel
143  const char* progname = argv[0];
144  Vector<BaseString> original_args;
145  for (int i = 0; i < argc; i++)
146  {
147  if (ndb_is_load_default_arg_separator(argv[i]))
148  continue;
149  original_args.push_back(argv[i]);
150  }
151 
152  int ho_error;
153  if ((ho_error=handle_options(&argc, &argv, my_long_options,
154  ndb_std_get_one_option)))
155  exit(ho_error);
156 
157  if (opt_no_daemon || opt_foreground) {
158  // --nodaemon or --forground implies --daemon=0
159  opt_daemon= 0;
160  }
161 
162  // Turn on debug printouts if --verbose
163  if (opt_verbose)
164  g_eventLogger->enable(Logger::LL_DEBUG);
165 
166  if (opt_nowait_nodes)
167  {
168  int res = parse_mask(opt_nowait_nodes, g_nowait_nodes);
169  if(res == -2 || (res > 0 && g_nowait_nodes.get(0)))
170  {
171  g_eventLogger->error("Invalid nodeid specified in nowait-nodes: %s",
172  opt_nowait_nodes);
173  exit(-1);
174  }
175  else if (res < 0)
176  {
177  g_eventLogger->error("Unable to parse nowait-nodes argument: %s",
178  opt_nowait_nodes);
179  exit(-1);
180  }
181  }
182 
183  if (opt_foreground ||
184  opt_allocated_nodeid ||
185  opt_report_fd)
186  {
187  ndbd_run(opt_foreground, opt_report_fd,
188  opt_ndb_connectstring, opt_ndb_nodeid, opt_bind_address,
189  opt_no_start, opt_initial, opt_initialstart,
190  opt_allocated_nodeid);
191  }
192 
193  angel_run(progname,
194  original_args,
195  opt_ndb_connectstring,
196  opt_ndb_nodeid,
197  opt_bind_address,
198  opt_initial,
199  opt_no_start,
200  opt_daemon);
201 
202  return 1; // Never reached
203 }
204 
205 int
206 main(int argc, char** argv)
207 {
208  return ndb_daemon_init(argc, argv, real_main, angel_stop,
209  "ndbd", "MySQL Cluster Data Node Daemon");
210 }