18 #include <ndb_global.h>
21 #include <socket_io.h>
22 #include <util/version.h>
24 #include <EventLogger.hpp>
25 #include <signaldata/SetLogLevelOrd.hpp>
26 #include <LogLevel.hpp>
27 #include <BaseString.hpp>
29 #include <ConfigValues.hpp>
30 #include <mgmapi_configuration.hpp>
32 #include "Services.hpp"
33 #include "../mgmapi/ndb_logevent.hpp"
35 #include "ndb_mgmd_error.h"
37 #include <ndb_base64.h>
40 extern bool g_StopServer;
41 extern bool g_RestartServer;
57 #define MGM_CMD(name, fun, desc) \
60 ParserRow<MgmApiSession>::Cmd, \
61 ParserRow<MgmApiSession>::String, \
62 ParserRow<MgmApiSession>::Optional, \
63 ParserRow<MgmApiSession>::IgnoreMinMax, \
68 #define MGM_ARG(name, type, opt, desc) \
71 ParserRow<MgmApiSession>::Arg, \
72 ParserRow<MgmApiSession>::type, \
73 ParserRow<MgmApiSession>::opt, \
74 ParserRow<MgmApiSession>::IgnoreMinMax, \
79 #define MGM_ARG2(name, type, opt, min, max, desc) \
82 ParserRow<MgmApiSession>::Arg, \
83 ParserRow<MgmApiSession>::type, \
84 ParserRow<MgmApiSession>::opt, \
85 ParserRow<MgmApiSession>::IgnoreMinMax, \
93 ParserRow<MgmApiSession>::Arg, \
94 ParserRow<MgmApiSession>::Int, \
95 ParserRow<MgmApiSession>::Optional, \
96 ParserRow<MgmApiSession>::IgnoreMinMax, \
101 #define MGM_CMD_ALIAS(name, realName, fun) \
104 ParserRow<MgmApiSession>::CmdAlias, \
105 ParserRow<MgmApiSession>::Int, \
106 ParserRow<MgmApiSession>::Optional, \
107 ParserRow<MgmApiSession>::IgnoreMinMax, \
112 #define MGM_ARG_ALIAS(name, realName, fun) \
115 ParserRow<MgmApiSession>::ArgAlias, \
116 ParserRow<MgmApiSession>::Int, \
117 ParserRow<MgmApiSession>::Optional, \
118 ParserRow<MgmApiSession>::IgnoreMinMax, \
125 MGM_CMD(
"get config", &MgmApiSession::getConfig,
""),
126 MGM_ARG(
"version", Int, Mandatory,
"Configuration version number"),
127 MGM_ARG(
"node", Int, Optional,
"Node ID"),
128 MGM_ARG(
"nodetype", Int, Optional,
"Type of requesting node"),
129 MGM_ARG(
"from_node", Int, Optional,
"Node to get config from"),
131 MGM_CMD(
"get nodeid", &MgmApiSession::get_nodeid,
""),
132 MGM_ARG(
"version", Int, Mandatory,
"Configuration version number"),
133 MGM_ARG(
"nodetype", Int, Mandatory,
"Node type"),
134 MGM_ARG(
"transporter",
String, Optional,
"Transporter type"),
135 MGM_ARG(
"nodeid", Int, Optional,
"Node ID"),
136 MGM_ARG(
"user",
String, Mandatory,
"Password"),
137 MGM_ARG(
"password",
String, Mandatory,
"Password"),
138 MGM_ARG(
"public key",
String, Mandatory,
"Public key"),
139 MGM_ARG(
"endian",
String, Optional,
"Endianness"),
140 MGM_ARG(
"name",
String, Optional,
"Name of connection"),
141 MGM_ARG(
"timeout", Int, Optional,
"Timeout in seconds"),
142 MGM_ARG(
"log_event", Int, Optional,
"Log failure in cluster log"),
144 MGM_CMD(
"get version", &MgmApiSession::getVersion,
""),
146 MGM_CMD(
"get status", &MgmApiSession::getStatus,
""),
147 MGM_ARG(
"types",
String, Optional,
"Types"),
149 MGM_CMD(
"get info clusterlog", &MgmApiSession::getInfoClusterLog,
""),
150 MGM_CMD(
"get cluster loglevel", &MgmApiSession::getClusterLogLevel,
""),
152 MGM_CMD(
"restart node", &MgmApiSession::restart_v1,
""),
153 MGM_ARG(
"node",
String, Mandatory,
"Nodes to restart"),
154 MGM_ARG(
"initialstart", Int, Optional,
"Initial start"),
155 MGM_ARG(
"nostart", Int, Optional,
"No start"),
156 MGM_ARG(
"abort", Int, Optional,
"Abort"),
158 MGM_CMD(
"restart node v2", &MgmApiSession::restart_v2,
""),
159 MGM_ARG(
"node",
String, Mandatory,
"Nodes to restart"),
160 MGM_ARG(
"initialstart", Int, Optional,
"Initial start"),
161 MGM_ARG(
"nostart", Int, Optional,
"No start"),
162 MGM_ARG(
"abort", Int, Optional,
"Abort"),
163 MGM_ARG(
"force", Int, Optional,
"Force"),
165 MGM_CMD(
"restart all", &MgmApiSession::restartAll,
""),
166 MGM_ARG(
"initialstart", Int, Optional,
"Initial start"),
167 MGM_ARG(
"nostart", Int, Optional,
"No start"),
168 MGM_ARG(
"abort", Int, Optional,
"Abort"),
170 MGM_CMD(
"insert error", &MgmApiSession::insertError,
""),
171 MGM_ARG(
"node", Int, Mandatory,
"Node to receive error"),
172 MGM_ARG(
"error", Int, Mandatory,
"Errorcode to insert"),
174 MGM_CMD(
"set trace", &MgmApiSession::setTrace,
""),
175 MGM_ARG(
"node", Int, Mandatory,
"Node"),
176 MGM_ARG(
"trace", Int, Mandatory,
"Trace number"),
178 MGM_CMD(
"log signals", &MgmApiSession::logSignals,
""),
179 MGM_ARG(
"node", Int, Mandatory,
"Node"),
180 MGM_ARG(
"blocks",
String, Mandatory,
"Blocks (space separated)"),
181 MGM_ARG(
"in", Int, Mandatory,
"Log input signals"),
182 MGM_ARG(
"out", Int, Mandatory,
"Log output signals"),
184 MGM_CMD(
"start signallog", &MgmApiSession::startSignalLog,
""),
185 MGM_ARG(
"node", Int, Mandatory,
"Node"),
187 MGM_CMD(
"stop signallog", &MgmApiSession::stopSignalLog,
""),
188 MGM_ARG(
"node", Int, Mandatory,
"Node"),
190 MGM_CMD(
"dump state", &MgmApiSession::dumpState,
""),
191 MGM_ARG(
"node", Int, Mandatory ,
"Node"),
192 MGM_ARG(
"args",
String, Mandatory,
"Args(space separated int's)"),
194 MGM_CMD(
"start backup", &MgmApiSession::startBackup,
""),
195 MGM_ARG(
"completed", Int, Optional ,
"Wait until completed"),
196 MGM_ARG(
"backupid", Int, Optional ,
"User input backup id"),
197 MGM_ARG(
"backuppoint", Int, Optional ,
"backup snapshot at start time or complete time"),
199 MGM_CMD(
"abort backup", &MgmApiSession::abortBackup,
""),
200 MGM_ARG(
"id", Int, Mandatory,
"Backup id"),
202 MGM_CMD(
"stop", &MgmApiSession::stop_v1,
""),
203 MGM_ARG(
"node",
String, Mandatory,
"Node"),
204 MGM_ARG(
"abort", Int, Mandatory,
"Node"),
206 MGM_CMD(
"stop v2", &MgmApiSession::stop_v2,
""),
207 MGM_ARG(
"node",
String, Mandatory,
"Node"),
208 MGM_ARG(
"abort", Int, Mandatory,
"Node"),
209 MGM_ARG(
"force", Int, Optional,
"Force"),
211 MGM_CMD(
"stop all", &MgmApiSession::stopAll,
""),
212 MGM_ARG(
"abort", Int, Mandatory,
"Node"),
213 MGM_ARG(
"stop",
String, Optional,
"MGM/DB or both"),
215 MGM_CMD(
"enter single user", &MgmApiSession::enterSingleUser,
""),
216 MGM_ARG(
"nodeId", Int, Mandatory,
"Node"),
218 MGM_CMD(
"exit single user", &MgmApiSession::exitSingleUser,
""),
221 MGM_CMD(
"start", &MgmApiSession::start,
""),
222 MGM_ARG(
"node", Int, Mandatory,
"Node"),
224 MGM_CMD(
"start all", &MgmApiSession::startAll,
""),
226 MGM_CMD(
"bye", &MgmApiSession::bye,
""),
228 MGM_CMD(
"end session", &MgmApiSession::endSession,
""),
230 MGM_CMD(
"set loglevel", &MgmApiSession::setLogLevel,
""),
231 MGM_ARG(
"node", Int, Mandatory,
"Node"),
232 MGM_ARG(
"category", Int, Mandatory,
"Event category"),
233 MGM_ARG(
"level", Int, Mandatory,
"Log level (0-15)"),
235 MGM_CMD(
"set cluster loglevel", &MgmApiSession::setClusterLogLevel,
""),
236 MGM_ARG(
"node", Int, Mandatory,
"Node"),
237 MGM_ARG(
"category", Int, Mandatory,
"Event category"),
238 MGM_ARG(
"level", Int, Mandatory,
"Log level (0-15)"),
240 MGM_CMD(
"set logfilter", &MgmApiSession::setLogFilter,
""),
241 MGM_ARG(
"level", Int, Mandatory,
"Severety level"),
242 MGM_ARG(
"enable", Int, Mandatory,
"1=disable, 0=enable, -1=toggle"),
244 MGM_CMD(
"set parameter", &MgmApiSession::setParameter,
""),
245 MGM_ARG(
"node", Int, Mandatory,
"Node"),
246 MGM_ARG(
"parameter", Int, Mandatory,
"Parameter"),
247 MGM_ARG(
"value",
String, Mandatory,
"Value"),
249 MGM_CMD(
"set connection parameter",
250 &MgmApiSession::setConnectionParameter,
""),
251 MGM_ARG(
"node1", Int, Mandatory,
"Node1 ID"),
252 MGM_ARG(
"node2", Int, Mandatory,
"Node2 ID"),
253 MGM_ARG(
"param", Int, Mandatory,
"Parameter"),
254 MGM_ARG(
"value", Int, Mandatory,
"Value"),
256 MGM_CMD(
"get connection parameter",
257 &MgmApiSession::getConnectionParameter,
""),
258 MGM_ARG(
"node1", Int, Mandatory,
"Node1 ID"),
259 MGM_ARG(
"node2", Int, Mandatory,
"Node2 ID"),
260 MGM_ARG(
"param", Int, Mandatory,
"Parameter"),
262 MGM_CMD(
"listen event", &MgmApiSession::listen_event,
""),
263 MGM_ARG(
"node", Int, Optional,
"Node"),
264 MGM_ARG(
"parsable", Int, Optional,
"Parsable"),
265 MGM_ARG(
"filter",
String, Mandatory,
"Event category"),
267 MGM_CMD(
"purge stale sessions", &MgmApiSession::purge_stale_sessions,
""),
269 MGM_CMD(
"check connection", &MgmApiSession::check_connection,
""),
271 MGM_CMD(
"transporter connect", &MgmApiSession::transporter_connect,
""),
273 MGM_CMD(
"get mgmd nodeid", &MgmApiSession::get_mgmd_nodeid,
""),
275 MGM_CMD(
"report event", &MgmApiSession::report_event,
""),
276 MGM_ARG(
"length", Int, Mandatory,
"Length"),
277 MGM_ARG(
"data",
String, Mandatory,
"Data"),
279 MGM_CMD(
"list sessions", &MgmApiSession::listSessions,
""),
281 MGM_CMD(
"get session id", &MgmApiSession::getSessionId,
""),
283 MGM_CMD(
"get session", &MgmApiSession::getSession,
""),
284 MGM_ARG(
"id", Int, Mandatory,
"SessionID"),
286 MGM_CMD(
"set config", &MgmApiSession::setConfig,
""),
287 MGM_ARG(
"Content-Length", Int, Mandatory,
"Length of config"),
288 MGM_ARG(
"Content-Type",
String, Mandatory,
"Type of config"),
289 MGM_ARG(
"Content-Transfer-Encoding",
String, Mandatory,
"encoding"),
291 MGM_CMD(
"create nodegroup", &MgmApiSession::create_nodegroup,
""),
292 MGM_ARG(
"nodes",
String, Mandatory,
"Nodes"),
294 MGM_CMD(
"drop nodegroup", &MgmApiSession::drop_nodegroup,
""),
295 MGM_ARG(
"ng", Int, Mandatory,
"Nodegroup"),
297 MGM_CMD(
"show config", &MgmApiSession::showConfig,
""),
298 MGM_ARG(
"Section",
String, Optional,
"Section name"),
299 MGM_ARG(
"NodeId", Int, Optional,
"Nodeid"),
300 MGM_ARG(
"Name",
String, Optional,
"Parameter name"),
302 MGM_CMD(
"reload config", &MgmApiSession::reloadConfig,
""),
303 MGM_ARG(
"config_filename",
String, Optional,
"Reload from path"),
304 MGM_ARG(
"mycnf", Int, Optional,
"Reload from my.cnf"),
305 MGM_ARG(
"force", Int, Optional,
"Force reload"),
307 MGM_CMD(
"show variables", &MgmApiSession::show_variables,
""),
309 MGM_CMD(
"dump events", &MgmApiSession::dump_events,
""),
310 MGM_ARG(
"type", Int, Mandatory,
"Type of event"),
311 MGM_ARG(
"nodes",
String, Optional,
"Nodes to include"),
325 extern int g_errorInsert;
326 #define ERROR_INSERTED(x) (g_errorInsert == x || m_errorInsert == x)
328 #define SLEEP_ERROR_INSERTED(x) if(ERROR_INSERTED(x)){NdbSleep_SecSleep(10);}
330 MgmApiSession::MgmApiSession(
class MgmtSrvr & mgm, NDB_SOCKET_TYPE sock, Uint64 session_id)
331 :
SocketServer::Session(sock), m_mgmsrv(mgm), m_name(
"unknown:0")
333 DBUG_ENTER(
"MgmApiSession::MgmApiSession");
336 m_parser =
new Parser_t(commands, *m_input,
true,
true,
true);
340 m_session_id= session_id;
341 m_mutex= NdbMutex_Create();
344 struct sockaddr_in addr;
345 SOCKET_SIZE_TYPE addrlen=
sizeof(addr);
346 if (my_getpeername(sock, (
struct sockaddr*)&addr, &addrlen) == 0)
347 m_name.assfmt(
"%s:%d", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
348 DBUG_PRINT(
"info", (
"new connection from: %s", m_name.c_str()));
353 MgmApiSession::~MgmApiSession()
355 DBUG_ENTER(
"MgmApiSession::~MgmApiSession");
362 if (m_allocated_resources)
363 delete m_allocated_resources;
364 if(my_socket_valid(m_socket))
366 NDB_CLOSE_SOCKET(m_socket);
367 my_socket_invalidate(&m_socket);
370 g_RestartServer=
true;
373 NdbMutex_Destroy(m_mutex);
378 MgmApiSession::runSession()
380 DBUG_ENTER(
"MgmApiSession::runSession");
382 g_eventLogger->
debug(
"%s: Connected!",
name());
385 ctx.m_mutex= m_mutex;
389 NdbMutex_Lock(m_mutex);
391 m_input->reset_timeout();
392 m_output->reset_timeout();
394 if (m_parser->
run(ctx, *
this))
397 assert(ctx.m_status == Parser_t::Ok);
402 const char*
msg= NULL;
403 switch(ctx.m_status) {
406 g_eventLogger->
debug(
"%s: Eof!",
name());
409 case Parser_t::ExternalStop:
411 g_eventLogger->
debug(
"%s: ExternalStop!",
name());
414 case Parser_t::NoLine:
415 case Parser_t::EmptyLine:
418 case Parser_t::UnknownCommand: msg=
"Unknown command";
break;
419 case Parser_t::UnknownArgument: msg=
"Unknown argument";
break;
420 case Parser_t::TypeMismatch: msg=
"Type mismatch";
break;
421 case Parser_t::InvalidArgumentFormat: msg=
"Invalid arg. format";
break;
422 case Parser_t::UnknownArgumentType: msg=
"Unknown argument type";
break;
423 case Parser_t::ArgumentGivenTwice: msg=
"Argument given twice";
break;
424 case Parser_t::MissingMandatoryArgument: msg=
"Missing arg.";
break;
427 case Parser_t::CommandWithoutFunction:
433 g_eventLogger->
debug(
"%s: %s, '%s'",
436 ctx.m_currentToken != 0 ?
437 ctx.m_currentToken :
"<NULL>");
440 m_output->println(
"result: %s, '%s'",
442 ctx.m_currentToken != 0 ?
443 ctx.m_currentToken :
"<NULL>");
444 m_output->print(
"\n");
448 NdbMutex_Unlock(m_mutex);
455 g_eventLogger->
debug(
"%s: Stopped!",
name());
457 NdbMutex_Lock(m_mutex);
459 if(my_socket_valid(m_socket))
461 my_socket_close(m_socket);
462 my_socket_invalidate(&m_socket);
464 NdbMutex_Unlock(m_mutex);
466 g_eventLogger->
debug(
"%s: Disconnected!",
name());
475 Uint32 version, nodeid= 0, nodetype= 0xff;
477 const char * transporter;
479 const char * password;
480 const char * public_key;
481 const char * endian= NULL;
482 const char *
name= NULL;
484 bool log_event_version;
485 union {
long l;
char c[
sizeof(long)]; } endian_check;
487 args.get(
"version", &version);
488 args.get(
"nodetype", &nodetype);
489 args.get(
"transporter", &transporter);
490 args.get(
"nodeid", &nodeid);
491 args.get(
"user", &user);
492 args.get(
"password", &password);
493 args.get(
"public key", &public_key);
494 args.get(
"endian", &endian);
495 args.get(
"name", &name);
496 args.get(
"timeout", &timeout);
498 log_event_version= args.get(
"log_event", &log_event);
500 m_output->println(
"get nodeid reply");
504 && strcmp(endian,(endian_check.c[
sizeof(
long)-1])?
"big":
"little")!=0) {
505 m_output->println(
"result: Node does not have the same endianness as the management server.");
506 m_output->println(
"%s",
"");
514 compatible = ndbCompatible_mgmt_api(NDB_VERSION, version);
517 compatible = ndbCompatible_mgmt_ndb(NDB_VERSION, version);
520 m_output->println(
"result: unknown nodetype %d", nodetype);
521 m_output->println(
"%s",
"");
525 struct sockaddr_in addr;
526 SOCKET_SIZE_TYPE addrlen=
sizeof(addr);
527 int r = my_getpeername(m_socket, (
struct sockaddr*)&addr, &addrlen);
529 m_output->println(
"result: getpeername(" MY_SOCKET_FORMAT \
531 MY_SOCKET_FORMAT_VALUE(m_socket), r);
532 m_output->println(
"%s",
"");
537 if (nodeid > MAX_NODES_ID)
539 m_output->println(
"result: illegal nodeid %u", nodeid);
540 m_output->println(
"%s",
"");
545 if(tmp == 0 || !m_allocated_resources->is_reserved(tmp)){
551 (
struct sockaddr*)&addr, &addrlen,
552 error_code, error_string,
553 tick == 0 ? 0 : log_event,
557 if (tick == 0 && error_code != NDB_MGM_ALLOCID_CONFIG_MISMATCH)
560 tick= NdbTick_CurrentMillisecond();
562 m_mgmsrv.get_connected_nodes(ps.free_nodes);
567 m_mgmsrv.get_socket_server()->
568 foreachSession(stop_session_if_timed_out,&ps);
569 m_mgmsrv.get_socket_server()->checkSessions();
577 m_output->println(
"result: %s", error_string.
c_str());
579 if (log_event_version)
580 m_output->println(
"error_code: %d", error_code);
581 m_output->println(
"%s",
"");
588 m_output->println(cmd);
589 m_output->println(
"result: incompatible version mgmt 0x%x and node 0x%x",
590 NDB_VERSION, version);
591 m_output->println(
"%s",
"");
596 m_output->println(
"nodeid: %u", tmp);
597 m_output->println(
"result: Ok");
598 m_output->println(
"%s",
"");
599 m_allocated_resources->reserve_node(tmp, timeout*1000);
602 g_eventLogger->
info(
"Node %d: %s", tmp, name);
611 Uint32 nodetype = NDB_MGM_NODE_TYPE_UNKNOWN;
612 Uint32 from_node = 0;
616 args.get(
"nodetype", &nodetype);
617 args.get(
"from_node", &from_node);
619 SLEEP_ERROR_INSERTED(1);
620 m_output->println(
"get config reply");
626 bool success = (from_node > 0) ?
627 m_mgmsrv.get_packed_config_from_node(from_node,
634 m_output->println(
"result: %s", error.
c_str());
635 m_output->print(
"\n");
639 m_output->println(
"result: Ok");
640 m_output->println(
"Content-Length: %u", pack64.
length());
641 m_output->println(
"Content-Type: ndbconfig/octet-stream");
642 SLEEP_ERROR_INSERTED(2);
643 m_output->println(
"Content-Transfer-Encoding: base64");
644 m_output->print(
"\n");
646 if(ERROR_INSERTED(3))
650 m_output->println(half64.
c_str());
653 m_output->println(pack64.
c_str());
654 m_output->print(
"\n");
661 Uint32 node = 0, error = 0;
664 args.get(
"node", &node);
665 args.get(
"error", &error);
667 if(node==m_mgmsrv.getOwnNodeId()
668 && error < MGM_ERROR_MAX_INJECT_SESSION_ONLY)
670 m_errorInsert= error;
672 g_errorInsert= error;
679 m_output->println(
"insert error reply");
681 m_output->println(
"result: %s", get_error_text(result));
683 m_output->println(
"result: Ok");
684 m_output->println(
"%s",
"");
690 Uint32 node = 0, trace = 0;
692 args.get(
"node", &node);
693 args.get(
"trace", &trace);
695 int result = m_mgmsrv.setTraceNo(node, trace);
697 m_output->println(
"set trace reply");
699 m_output->println(
"result: %s", get_error_text(result));
701 m_output->println(
"result: Ok");
702 m_output->println(
"%s",
"");
708 m_output->println(
"version");
709 m_output->println(
"id: %d", NDB_VERSION_D);
710 m_output->println(
"major: %d", NDB_VERSION_MAJOR);
711 m_output->println(
"minor: %d", NDB_VERSION_MINOR);
712 m_output->println(
"build: %d", NDB_VERSION_BUILD);
713 m_output->println(
"string: %s", m_mgmsrv.get_version_string());
714 m_output->println(
"mysql_major: %d", NDB_MYSQL_VERSION_MAJOR);
715 m_output->println(
"mysql_minor: %d", NDB_MYSQL_VERSION_MINOR);
716 m_output->println(
"mysql_build: %d", NDB_MYSQL_VERSION_BUILD);
717 m_output->println(
"%s",
"");
723 DBUG_ENTER(
"MgmApiSession::startBackup");
725 unsigned input_backupId= 0;
726 unsigned backuppoint= 0;
730 args.get(
"completed", &completed);
733 args.get(
"backupid", &input_backupId);
735 args.get(
"backuppoint", &backuppoint);
737 result = m_mgmsrv.
startBackup(backupId, completed, input_backupId, backuppoint);
739 m_output->println(
"start backup reply");
742 m_output->println(
"result: %s", get_error_text(result));
745 m_output->println(
"result: Ok");
747 m_output->println(
"id: %d", backupId);
749 m_output->println(
"%s",
"");
760 int result = m_mgmsrv.abortBackup(
id);
762 m_output->println(
"abort backup reply");
764 m_output->println(
"result: %s", get_error_text(result));
766 m_output->println(
"result: Ok");
767 m_output->println(
"%s",
"");
778 args.get(
"node", &node);
779 args.get(
"args", args_str);
782 m_output->println(
"dump state reply");
784 m_output->println(
"result: %s", get_error_text(result));
786 m_output->println(
"result: Ok");
787 m_output->println(
"%s",
"");
800 if(m_allocated_resources)
801 delete m_allocated_resources;
805 SLEEP_ERROR_INSERTED(4);
806 m_output->println(
"end session reply");
811 const char* names[] = {
"startup",
824 int loglevel_count = (CFG_MAX_LOGLEVEL - CFG_MIN_LOGLEVEL + 1) ;
825 LogLevel::EventCategory category;
827 m_output->println(
"get cluster loglevel");
828 for(
int i = 0;
i < loglevel_count;
i++) {
829 category = (LogLevel::EventCategory)
i;
832 m_output->println(
"%s",
"");
838 Uint32 node,
level, cat;
840 DBUG_ENTER(
"MgmApiSession::setClusterLogLevel");
841 args.get(
"node", &node);
842 args.get(
"category", &cat);
843 args.get(
"level", &level);
845 DBUG_PRINT(
"enter",(
"node=%d, category=%d, level=%d", node, cat, level));
847 m_output->println(
"set cluster loglevel reply");
849 if(level > NDB_MGM_MAX_LOGLEVEL) {
850 m_output->println(
"result: Invalid loglevel %d", level);
851 m_output->println(
"%s",
"");
855 LogLevel::EventCategory category=
856 (LogLevel::EventCategory)(cat-(
int)CFG_MIN_LOGLEVEL);
858 m_mgmsrv.m_event_listner.lock();
861 m_output->println(
"result: Invalid category %d", category);
862 m_output->println(
"%s",
"");
863 m_mgmsrv.m_event_listner.unlock();
866 m_mgmsrv.m_event_listner.unlock();
870 m_mgmsrv.m_event_listner.update_max_log_level(tmp);
873 m_output->println(
"result: Ok");
874 m_output->println(
"%s",
"");
881 Uint32 node = 0, level = 0, cat;
885 args.get(
"node", &node);
886 args.get(
"category", &cat);
887 args.get(
"level", &level);
889 if(level > NDB_MGM_MAX_LOGLEVEL) {
890 m_output->println(
"set loglevel reply");
891 m_output->println(
"result: Invalid loglevel: %s", errorString.
c_str());
892 m_output->println(
"%s",
"");
896 LogLevel::EventCategory category=
897 (LogLevel::EventCategory)(cat-(
int)CFG_MIN_LOGLEVEL);
902 m_mgmsrv.m_event_listner.update_max_log_level(ll);
905 m_output->println(
"set loglevel reply");
906 m_output->println(
"result: Ok");
907 m_output->println(
"%s",
"");
915 args.get(
"node", &node);
917 int result = m_mgmsrv.stopSignalTracing(node);
919 m_output->println(
"stop signallog");
921 m_output->println(
"result: %s", get_error_text(result));
923 m_output->println(
"result: Ok");
924 m_output->println(
"%s",
"");
940 MgmApiSession::restart(
Properties const &args,
int version) {
944 abort = 0, force = 0;
948 args.get(
"initialstart", &initialstart);
949 args.get(
"nostart", &nostart);
950 args.get(
"abort", &abort);
951 args.get(
"node", (
const char **)&nodes_str);
952 args.get(
"force", &force);
955 for((p = strtok_r(nodes_str,
" ", &last));
957 (p = strtok_r(NULL,
" ", &last))) {
958 nodes.push_back(atoi(p));
971 (result == NODE_SHUTDOWN_WOULD_CAUSE_SYSTEM_CRASH ||
972 result == UNSUPPORTED_NODE_SHUTDOWN))
975 result = m_mgmsrv.
restartDB(nostart, initialstart,
false, &restarted);
978 m_output->println(
"restart reply");
980 m_output->println(
"result: %d-%s", result, get_error_text(result));
982 m_output->println(
"result: Ok");
983 m_output->println(
"restarted: %d", restarted);
985 m_output->println(
"disconnect: %d", (m_stopSelf)?1:0);
986 m_output->println(
"%s",
"");
994 Uint32 initialstart = 0;
997 args.get(
"initialstart", &initialstart);
998 args.get(
"abort", &abort);
999 args.get(
"nostart", &nostart);
1002 int result = m_mgmsrv.
restartDB(nostart, initialstart, abort, &count);
1004 m_output->println(
"restart reply");
1006 m_output->println(
"result: %s", get_error_text(result));
1008 m_output->println(
"result: Ok");
1009 m_output->println(
"restarted: %d", count);
1010 m_output->println(
"%s",
"");
1020 Uint32 startPhase = 0,
1021 version = 0, mysql_version = 0,
1026 const char *address= NULL;
1027 mgmsrv.
status(nodeId, &status, &version, &mysql_version, &startPhase,
1028 &system, &dynamicId, &nodeGroup, &connectCount,
1030 output->println(
"node.%d.type: %s",
1033 output->println(
"node.%d.status: %s",
1036 output->println(
"node.%d.version: %d", nodeId, version);
1037 output->println(
"node.%d.mysql_version: %d", nodeId, mysql_version);
1038 output->println(
"node.%d.startphase: %d", nodeId, startPhase);
1039 output->println(
"node.%d.dynamic_id: %d", nodeId, dynamicId);
1040 output->println(
"node.%d.node_group: %d", nodeId, nodeGroup);
1041 output->println(
"node.%d.connect_count: %d", nodeId, connectCount);
1042 output->println(
"node.%d.address: %s", nodeId, address ? address :
"");
1054 if (args.get(
"types", typestring))
1057 typestring.
split(tmp,
" ");
1058 for (i = 0; i < tmp.size(); i++)
1062 types[
i] = NDB_MGM_NODE_TYPE_UNKNOWN;
1069 types[3] = NDB_MGM_NODE_TYPE_UNKNOWN;
1072 for (i = 0; types[
i] != NDB_MGM_NODE_TYPE_UNKNOWN; i++)
1079 SLEEP_ERROR_INSERTED(5);
1080 m_output->println(
"node status");
1081 SLEEP_ERROR_INSERTED(6);
1082 m_output->println(
"nodes: %d", noOfNodes);
1083 for (i = 0; types[
i] != NDB_MGM_NODE_TYPE_UNKNOWN; i++)
1085 SLEEP_ERROR_INSERTED(
int(7+i));
1086 printNodeStatus(m_output, m_mgmsrv, types[i]);
1088 m_output->println(
"%s",
"");
1093 isEventLogFilterEnabled(
int severity)
1101 const char* names[] = {
"enabled",
1109 m_output->println(
"clusterlog");
1110 for(
int i = 0; i < 7; i++) {
1111 m_output->println(
"%s: %d",
1113 isEventLogFilterEnabled(i));
1115 m_output->println(
"%s",
"");
1131 MgmApiSession::stop(
Properties const &args,
int version) {
1132 Uint32 abort, force = 0;
1136 args.get(
"node", (
const char **)&nodes_str);
1137 if(nodes_str == NULL)
1139 m_output->println(
"stop reply");
1140 m_output->println(
"result: empty node list");
1141 m_output->println(
"%s",
"");
1144 args.get(
"abort", &abort);
1145 args.get(
"force", &force);
1148 for((p = strtok_r(nodes_str,
" ", &last));
1150 (p = strtok_r(NULL,
" ", &last))) {
1151 nodes.push_back(atoi(p));
1158 result= m_mgmsrv.
stopNodes(nodes, &stopped, abort != 0, force != 0,
1162 (result == NODE_SHUTDOWN_WOULD_CAUSE_SYSTEM_CRASH ||
1163 result == UNSUPPORTED_NODE_SHUTDOWN))
1166 result = m_mgmsrv.
shutdownDB(&stopped,
false);
1170 m_output->println(
"stop reply");
1172 m_output->println(
"result: %s", get_error_text(result));
1174 m_output->println(
"result: Ok");
1175 m_output->println(
"stopped: %d", stopped);
1177 m_output->println(
"disconnect: %d", (m_stopSelf)?1:0);
1178 m_output->println(
"%s",
"");
1184 int stopped[2] = {0,0};
1186 args.get(
"abort", &abort);
1189 const char* tostop=
"db";
1191 if (args.get(
"stop", stop))
1193 tostop= stop.
c_str();
1198 if(strstr(tostop,
"db"))
1199 result= m_mgmsrv.
shutdownDB(&stopped[0], abort != 0);
1200 if(!result && strstr(tostop,
"mgm"))
1201 result= m_mgmsrv.shutdownMGM(&stopped[1], abort!=0, &m_stopSelf);
1203 m_output->println(
"stop reply");
1205 m_output->println(
"result: %s", get_error_text(result));
1207 m_output->println(
"result: Ok");
1208 m_output->println(
"stopped: %d", stopped[0]+stopped[1]);
1210 m_output->println(
"disconnect: %d", (m_stopSelf)?1:0);
1211 m_output->println(
"%s",
"");
1220 args.get(
"nodeId", &nodeId);
1223 m_output->println(
"enter single user reply");
1225 m_output->println(
"result: %s", get_error_text(result));
1228 m_output->println(
"result: Ok");
1230 m_output->println(
"%s",
"");
1238 m_output->println(
"exit single user reply");
1240 m_output->println(
"result: %s", get_error_text(result));
1242 m_output->println(
"result: Ok");
1243 m_output->println(
"%s",
"");
1252 args.get(
"node", &node);
1254 int result = m_mgmsrv.startSignalTracing(node);
1256 m_output->println(
"start signallog reply");
1258 m_output->println(
"result: %s", get_error_text(result));
1260 m_output->println(
"result: Ok");
1261 m_output->println(
"%s",
"");
1267 Uint32 node = 0, in = 0, out = 0;
1271 args.get(
"node", &node);
1272 args.get(
"in", &in);
1273 args.get(
"out", &out);
1274 args.get(
"blocks", blockList);
1280 blockName=strtok(buf,
"|");
1281 while( blockName != NULL)
1283 blocks.push_back(blockName);
1284 blockName=strtok(NULL,
"|");
1288 if(in > 1 || out > 1)
1299 int result = m_mgmsrv.setSignalLoggingMode(node, mode, blocks);
1301 m_output->println(
"log signals reply");
1303 m_output->println(
"result: %s", get_error_text(result));
1305 m_output->println(
"result: Ok");
1306 m_output->println(
"%s",
"");
1314 args.get(
"node", &node);
1316 int result = m_mgmsrv.start(node);
1318 m_output->println(
"start reply");
1320 m_output->println(
"result: %s", get_error_text(result));
1322 m_output->println(
"result: Ok");
1323 m_output->println(
"%s",
"");
1333 if(m_mgmsrv.start(node) == 0)
1336 m_output->println(
"start reply");
1337 m_output->println(
"result: Ok");
1338 m_output->println(
"started: %d", started);
1339 m_output->println(
"%s",
"");
1344 setEventLogFilter(
int severity,
int enable)
1348 g_eventLogger->
enable(level);
1349 }
else if (enable == 0) {
1350 g_eventLogger->
disable(level);
1355 if (g_eventLogger->
isEnable(level))
1356 g_eventLogger->
disable(level);
1358 g_eventLogger->
enable(level);
1360 return g_eventLogger->
isEnable(level);
1370 args.get(
"level", &severity);
1371 args.get(
"enable", &enable);
1373 bool result = setEventLogFilter(severity, enable);
1375 m_output->println(
"set logfilter reply");
1376 m_output->println(
"result: %d", result);
1377 m_output->println(
"%s",
"");
1383 operator<<(NdbOut& out,
const LogLevel & ll)
1385 out <<
"[LogLevel: ";
1386 for(
size_t i = 0; i<LogLevel::LOGLEVEL_CATEGORIES; i++)
1387 out << ll.
getLogLevel((LogLevel::EventCategory)i) <<
" ";
1396 const Uint32* theData,
1398 NodeId nodeId, Uint32
timeval,
1399 char* pretty_text,
size_t pretty_text_size)
1401 str.
assign(
"log event reply\n");
1402 str.
appfmt(
"type=%d\n", eventType);
1403 str.
appfmt(
"time=%d\n", timeval);
1404 str.
appfmt(
"source_nodeid=%d\n", nodeId);
1406 for (i = 0; ndb_logevent_body[
i].token; i++)
1408 if ( ndb_logevent_body[i].type == eventType)
1412 if (ndb_logevent_body[i].token)
1415 int val= theData[ndb_logevent_body[
i].index];
1416 if (ndb_logevent_body[i].index_fn)
1417 val= (*(ndb_logevent_body[
i].index_fn))(val);
1418 str.
appfmt(
"%s=%d\n",ndb_logevent_body[i].token, val);
1419 if(strcmp(ndb_logevent_body[i].token,
"error") == 0)
1421 int pretty_text_len= strlen(pretty_text);
1422 if(pretty_text_size-pretty_text_len-3 > 0)
1425 ndb_error_string(val, pretty_text+(pretty_text_len+3),
1426 pretty_text_size-pretty_text_len-3);
1429 }
while (ndb_logevent_body[++i].type == eventType);
1434 for (i = 1; i<len; i++)
1435 str.
appfmt(
"%u ", theData[i]);
1442 Ndb_mgmd_event_service::log(
int eventType,
const Uint32* theData,
1443 Uint32 len, NodeId nodeId){
1446 LogLevel::EventCategory cat;
1450 DBUG_ENTER(
"Ndb_mgmd_event_service::log");
1451 DBUG_PRINT(
"enter",(
"eventType=%d, nodeid=%d", eventType, nodeId));
1453 if (EventLoggerBase::event_lookup(eventType,cat,threshold,severity,textF))
1457 char pretty_text[512];
1459 textF, theData, len, nodeId);
1465 logevent2str(str, eventType, theData, len, nodeId, 0,
1466 pretty_text,
sizeof(pretty_text));
1470 for(i = m_clients.size() - 1; i >= 0; i--)
1474 if(!my_socket_valid(m_clients[i].m_socket))
1480 if (m_clients[i].m_parsable)
1481 r= out.println(str.
c_str());
1483 r= out.println(pretty_text);
1487 copy.push_back(m_clients[i].m_socket);
1488 m_clients.erase(i,
false);
1494 if ((n= (
int)copy.size()))
1496 for(i= 0; i <
n; i++)
1497 NDB_CLOSE_SOCKET(copy[i]);
1501 for(i= m_clients.size() - 1; i >= 0; i--)
1502 tmp.
set_max(m_clients[i].m_logLevel);
1504 update_log_level(tmp);
1510 Ndb_mgmd_event_service::update_max_log_level(
const LogLevel &log_level)
1514 for(
int i = m_clients.size() - 1; i >= 0; i--)
1515 tmp.
set_max(m_clients[i].m_logLevel);
1517 update_log_level(tmp);
1521 Ndb_mgmd_event_service::update_log_level(
const LogLevel &tmp)
1528 m_mgmsrv->m_log_level_requests.push_back(req);
1532 Ndb_mgmd_event_service::check_listeners()
1535 DBUG_ENTER(
"Ndb_mgmd_event_service::check_listeners");
1537 for(i= m_clients.size() - 1; i >= 0; i--)
1539 if(!my_socket_valid(m_clients[i].m_socket))
1544 DBUG_PRINT(
"info",(
"%d " MY_SOCKET_FORMAT,
1546 MY_SOCKET_FORMAT_VALUE(m_clients[i].m_socket)));
1548 if(out.println(
"<PING>") < 0)
1550 NDB_CLOSE_SOCKET(m_clients[i].m_socket);
1551 m_clients.erase(i,
false);
1558 for(i= m_clients.size() - 1; i >= 0; i--)
1559 tmp.
set_max(m_clients[i].m_logLevel);
1560 update_log_level(tmp);
1567 Ndb_mgmd_event_service::add_listener(
const Event_listener& client)
1569 DBUG_ENTER(
"Ndb_mgmd_event_service::add_listener");
1570 DBUG_PRINT(
"enter",(
"client.m_socket: " MY_SOCKET_FORMAT,
1571 MY_SOCKET_FORMAT_VALUE(client.m_socket)));
1575 m_clients.push_back(client);
1576 update_max_log_level(client.m_logLevel);
1582 Ndb_mgmd_event_service::stop_sessions(){
1584 for(
int i = m_clients.size() - 1; i >= 0; i--){
1585 if(my_socket_valid(m_clients[i].m_socket))
1587 NDB_CLOSE_SOCKET(m_clients[i].m_socket);
1600 args.get(
"node", &node);
1601 args.get(
"parameter", ¶m);
1602 args.get(
"value", value);
1610 m_output->println(
"set parameter reply");
1611 m_output->println(
"message: %s", result.
c_str());
1612 m_output->println(
"result: %d", ret);
1613 m_output->println(
"%s",
"");
1620 Uint32 node1, node2, param, value;
1621 args.get(
"node1", &node1);
1622 args.get(
"node2", &node2);
1623 args.get(
"param", ¶m);
1624 args.get(
"value", &value);
1627 int ret = m_mgmsrv.setConnectionDbParameter(node1,
1633 m_output->println(
"set connection parameter reply");
1634 m_output->println(
"message: %s", result.
c_str());
1635 m_output->println(
"result: %s", (ret>0)?
"Ok":
"Failed");
1636 m_output->println(
"%s",
"");
1643 Uint32 node1, node2, param;
1646 args.get(
"node1", &node1);
1647 args.get(
"node2", &node2);
1648 args.get(
"param", ¶m);
1651 int ret = m_mgmsrv.getConnectionDbParameter(node1,
1657 m_output->println(
"get connection parameter reply");
1658 m_output->println(
"value: %d", value);
1659 m_output->println(
"result: %s", (ret>0)?
"Ok":result.
c_str());
1660 m_output->println(
"%s",
"");
1668 args.get(
"node", node);
1669 args.get(
"filter", param);
1670 args.get(
"parsable", &parsable);
1676 le.m_parsable = parsable;
1677 le.m_socket = m_socket;
1681 param.
split(list,
" ,");
1682 for(
size_t i = 0; i<list.size(); i++){
1685 list[
i].split(spec,
"=:");
1686 if(spec.size() != 2){
1687 msg.
appfmt(
"Invalid filter specification: >%s< >%s< %d",
1688 param.
c_str(), list[
i].c_str(), spec.size());
1693 spec[0].trim().ndb_toupper();
1694 int category = ndb_mgm_match_event_category(spec[0].c_str());
1696 category = atoi(spec[0].c_str());
1697 if(category < NDB_MGM_MIN_EVENT_CATEGORY ||
1698 category > NDB_MGM_MAX_EVENT_CATEGORY){
1699 msg.
appfmt(
"Unknown category: >%s<", spec[0].c_str());
1705 int level = atoi(spec[1].c_str());
1706 if(level < 0 || level > NDB_MGM_MAX_LOGLEVEL){
1707 msg.
appfmt(
"Invalid level: >%s<", spec[1].c_str());
1711 category -= CFG_MIN_LOGLEVEL;
1715 if(list.size() == 0){
1716 msg.
appfmt(
"Empty filter specification");
1722 m_output->println(
"listen event");
1723 m_output->println(
"result: %d", result);
1725 m_output->println(
"msg: %s", msg.
c_str());
1726 m_output->println(
"%s",
"");
1730 m_mgmsrv.m_event_listner.add_listener(le);
1732 my_socket_invalidate(&m_socket);
1741 if (s->m_allocated_resources->is_reserved(ps.free_nodes))
1744 ps.str->
appfmt(
" %d", s->m_allocated_resources->get_nodeid());
1754 if (s->m_allocated_resources->is_reserved(ps.free_nodes) &&
1755 s->m_allocated_resources->is_timed_out(ps.tick))
1769 m_mgmsrv.get_connected_nodes(ps.free_nodes);
1772 m_mgmsrv.get_socket_server()->foreachSession(stop_session_if_not_connected,&ps);
1773 m_mgmsrv.get_socket_server()->checkSessions();
1775 m_output->println(
"purge stale sessions reply");
1776 if (str.length() > 0)
1777 m_output->println(
"purged:%s",str.c_str());
1778 m_output->println(
"result: Ok");
1779 m_output->println(
"%s",
"");
1786 SLEEP_ERROR_INSERTED(1);
1787 m_output->println(
"check connection reply");
1788 SLEEP_ERROR_INSERTED(2);
1789 m_output->println(
"result: Ok");
1790 SLEEP_ERROR_INSERTED(3);
1791 m_output->println(
"%s",
"");
1799 if (!m_mgmsrv.transporter_connect(m_socket, errormsg))
1802 g_eventLogger->
warning(
"Failed to convert connection "
1803 "from '%s' to transporter: %s",
1816 my_socket_invalidate(&m_socket);
1826 m_output->println(
"get mgmd nodeid reply");
1827 m_output->println(
"nodeid:%u",m_mgmsrv.getOwnNodeId());
1828 SLEEP_ERROR_INSERTED(1);
1830 m_output->println(
"%s",
"");
1838 const char *data_string;
1841 args.get(
"length", &length);
1842 args.get(
"data", &data_string);
1846 tmp.split(item,
" ");
1847 for (
int i = 0; (Uint32) i < length ; i++)
1849 sscanf(item[i].c_str(),
"%u", data+i);
1852 m_mgmsrv.eventReport(data, length);
1853 m_output->println(
"report event reply");
1854 m_output->println(
"result: ok");
1855 m_output->println(
"%s",
"");
1869 args.get(
"nodes", nodestr);
1871 nodestr.
split(list,
" ");
1872 for (Uint32 i = 0; i < list.size() ; i++)
1876 if ((res = sscanf(list[i].c_str(),
"%u", &node)) != 1)
1879 result =
"FAIL: Invalid format for nodes";
1882 nodes.push_back(node);
1885 res = m_mgmsrv.createNodegroup(nodes.getBase(), nodes.size(), &ng);
1887 m_output->println(
"create nodegroup reply");
1888 m_output->println(
"ng: %d", ng);
1891 m_output->println(
"error_code: %d", res);
1892 m_output->println(
"result: %d-%s", res, get_error_text(res));
1896 m_output->println(
"result: Ok");
1898 m_output->println(
"%s",
"");
1908 args.get(
"ng", &ng);
1911 if((res = m_mgmsrv.dropNodegroup(ng)) != 0)
1913 result.assfmt(
"error: %d", res);
1917 m_output->println(
"drop nodegroup reply");
1918 m_output->println(
"result: %s", result.c_str());
1919 m_output->println(
"%s",
"");
1929 NdbMutex_Lock(s->m_mutex);
1931 Uint64
id= s->m_session_id;
1932 lister->m_output->println(
"session: %llu",
id);
1933 lister->m_output->println(
"session.%llu.m_stopSelf: %d",
id,s->m_stopSelf);
1934 lister->m_output->println(
"session.%llu.m_stop: %d",
id,s->m_stop);
1935 lister->m_output->println(
"session.%llu.allocated.nodeid: %d",
id,s->m_allocated_resources->get_nodeid());
1938 int l= strlen(s->m_ctx->m_tokenBuffer);
1939 char *buf= (
char*) malloc(2*l+1);
1941 for(
int i=0; i<l;i++)
1942 if(s->m_ctx->m_tokenBuffer[i]==
'\n')
1949 *b++= s->m_ctx->m_tokenBuffer[
i];
1953 lister->m_output->println(
"session.%llu.parser.buffer.len: %u",
id,l);
1954 lister->m_output->println(
"session.%llu.parser.buffer: %s",
id,buf);
1955 lister->m_output->println(
"session.%llu.parser.status: %d",
id,s->m_ctx->m_status);
1961 NdbMutex_Unlock(s->m_mutex);
1967 m_mgmsrv.get_socket_server()->foreachSession(list_session,(
void*)
this);
1969 m_output->println(
"%s",
"");
1975 m_output->println(
"get session id reply");
1976 m_output->println(
"id: %llu",m_session_id);
1977 m_output->println(
"%s",
"");
1993 NdbMutex_Lock(s->m_mutex);
1995 if(p->id != s->m_session_id)
1998 NdbMutex_Unlock(s->m_mutex);
2003 p->l->m_output->println(
"id: %llu",s->m_session_id);
2004 p->l->m_output->println(
"m_stopSelf: %d",s->m_stopSelf);
2005 p->l->m_output->println(
"m_stop: %d",s->m_stop);
2006 p->l->m_output->println(
"nodeid: %d",s->m_allocated_resources->get_nodeid());
2009 int l= strlen(s->m_ctx->m_tokenBuffer);
2010 p->l->m_output->println(
"parser_buffer_len: %u",l);
2011 p->l->m_output->println(
"parser_status: %d",s->m_ctx->m_status);
2015 NdbMutex_Unlock(s->m_mutex);
2024 args.get(
"id", &
id);
2030 m_output->println(
"get session reply");
2031 m_mgmsrv.get_socket_server()->foreachSession(get_session,(
void*)&p);
2034 m_output->println(
"id: 0");
2036 m_output->println(
"%s",
"");
2043 ConfigIter iter(config, CFG_SECTION_CONNECTION);
2045 for(;iter.valid();iter.next()) {
2047 if (iter.get(CFG_CONNECTION_NODE_1, &n1) != 0 &&
2048 iter.get(CFG_CONNECTION_NODE_2, &n2) != 0)
2052 if (iter.get(CFG_CONNECTION_SERVER_PORT, &port_value) != 0)
2055 int port = (int)port_value;
2060 Uint32 zero_port = 0;
2063 if (!i2.set(CFG_CONNECTION_SERVER_PORT, zero_port))
2078 args.get(
"Content-Type", &buf);
2079 if(strcmp(buf,
"ndbconfig/octet-stream")) {
2080 result.assfmt(
"Unhandled content type '%s'", buf);
2084 args.get(
"Content-Transfer-Encoding", &buf);
2085 if(strcmp(buf,
"base64")) {
2086 result.assfmt(
"Unhandled content encoding '%s'", buf);
2091 args.get(
"Content-Length", &len64);
2092 if(len64 ==0 || len64 > (1024*1024)) {
2093 result.assfmt(
"Illegal config length size %d", len64);
2099 char* buf64 =
new char[len64];
2103 if((r= read_socket(m_socket,
2109 result.assfmt(
"read_socket failed, errno: %d", errno);
2113 }
while(start < len64);
2115 char* decoded =
new char[base64_needed_decoded_length((
size_t)len64 - 1)];
2116 int decoded_len= ndb_base64_decode(buf64, len64-1, decoded, NULL);
2120 if(!cvf.unpack(decoded, decoded_len))
2123 result.assfmt(
"Failed to unpack config");
2128 Config new_config(cvf.getConfigValues());
2131 if (!clear_dynamic_ports_from_config(&new_config))
2133 result.assfmt(
"INTERNAL ERROR: Failed to clear dynamic "
2134 "ports from config");
2138 (void)m_mgmsrv.change_config(new_config, result);
2143 m_output->println(
"set config reply");
2144 m_output->println(
"result: %s", result.c_str());
2145 m_output->println(
"%s",
"");
2151 const char* section = NULL;
2152 const char* name = NULL;
2155 args.get(
"Section", §ion);
2156 args.get(
"NodeId", &nodeid);
2157 args.get(
"Name", &name);
2159 NdbOut socket_out(*m_output,
false );
2160 m_output->println(
"show config reply");
2161 m_mgmsrv.print_config(section, nodeid, name,
2163 m_output->println(
"%s",
"");
2171 const char* config_filename= NULL;
2174 args.get(
"config_filename", &config_filename);
2175 args.get(
"mycnf", &mycnf);
2177 g_eventLogger->
debug(
"config_filename: %s, mycnf: %s",
2178 str_null(config_filename),
2181 m_output->println(
"reload config reply");
2184 if (!m_mgmsrv.reload_config(config_filename, (mycnf != 0), msg))
2185 m_output->println(
"result: %s", msg.
c_str());
2187 m_output->println(
"result: Ok");
2189 m_output->println(
"%s",
"");
2197 m_output->println(
"show variables reply");
2198 NdbOut socket_out(*m_output,
false );
2199 m_mgmsrv.show_variables(socket_out);
2200 m_output->println(
"%s",
"");
2207 unsigned nodeid = 0;
2208 while((nodeid = nodes.
find(nodeid)) != NdbNodeBitmask::NotFound)
2210 if (nodeid == 0 || nodeid > max_nodeid)
2218 #include <signaldata/DumpStateOrd.hpp>
2219 #include "../common/util/parse_mask.hpp"
2222 struct dump_request {
2224 DumpStateOrd::DumpStateType dump_type;
2226 Uint32 reports_per_node;
2227 } dump_requests [] =
2230 DumpStateOrd::BackupStatus,
2234 DumpStateOrd::DumpPageMemory,
2237 { NDB_LE_SavedEvent,
2238 DumpStateOrd::DumpEventLog,
2241 { NDB_LE_ILLEGAL_TYPE, (DumpStateOrd::DumpStateType)0, 0 }
2248 m_output->println(
"dump events reply");
2252 args.get(
"type", &type);
2254 const dump_request*
request = dump_requests;
2256 for (; request->type != NDB_LE_ILLEGAL_TYPE; request++)
2262 if (request->type == NDB_LE_ILLEGAL_TYPE)
2264 m_output->println(
"result: ndb_logevent_type %u not supported", type);
2265 m_output->println(
"%s",
"");
2271 const char* nodes_str = NULL;
2272 args.get(
"nodes", &nodes_str);
2275 int res = parse_mask(nodes_str, nodes);
2276 if (res < 0 || !valid_nodes(nodes, MAX_NDB_NODES-1))
2278 m_output->println(
"result: invalid nodes: '%s'", nodes_str);
2279 m_output->println(
"%s",
"");
2286 if (!m_mgmsrv.request_events(nodes,
2287 request->reports_per_node,
2291 m_output->println(
"result: failed to dump events");
2292 m_output->println(
"%s",
"");
2297 m_output->println(
"result: Ok");
2298 m_output->println(
"events: %u", events.size());
2299 m_output->println(
"%s",
"");
2300 for (
unsigned i = 0; i < events.size(); i++)
2304 const NodeId nodeid = refToNode(events[i].header.theSendersBlockRef);
2307 assert(
event->getEventType() == request->type);
2310 char pretty_text[512];
2311 Uint32 tmpData[256];
2312 const Uint32 * dataPtr = events[
i].getDataPtr();
2313 Uint32 dataLen = events[
i].getLength();
2314 if (events[i].header.m_noOfSections == 1)
2316 if (dataLen + events[i].ptr[0].sz > NDB_ARRAY_SIZE(tmpData))
2318 events[
i].ptr[0].sz = NDB_ARRAY_SIZE(tmpData) - dataLen;
2320 memcpy(tmpData, dataPtr, 4 * dataLen);
2321 memcpy(tmpData + dataLen, events[i].ptr[0].p, 4*events[i].ptr[0].sz);
2323 dataLen += events[
i].ptr[0].sz;
2326 event->getEventType(),
2330 pretty_text,
sizeof(pretty_text));
2332 m_output->println(
"%s", str.c_str());