18 #include <ndb_global.h>
20 #include <LocalConfig.hpp>
25 #include <mgmapi_internal.h>
26 #include <mgmapi_debug.h>
27 #include "mgmapi_configuration.hpp"
28 #include <socket_io.h>
32 #include <SocketServer.hpp>
33 #include <SocketClient.hpp>
35 #include <OutputStream.hpp>
36 #include <InputStream.hpp>
38 #include <ndb_base64.h>
41 #define MGM_CMD(name, fun, desc) \
44 ParserRow<ParserDummy>::Cmd, \
45 ParserRow<ParserDummy>::String, \
46 ParserRow<ParserDummy>::Optional, \
47 ParserRow<ParserDummy>::IgnoreMinMax, \
52 #define MGM_ARG(name, type, opt, desc) \
55 ParserRow<ParserDummy>::Arg, \
56 ParserRow<ParserDummy>::type, \
57 ParserRow<ParserDummy>::opt, \
58 ParserRow<ParserDummy>::IgnoreMinMax, \
66 ParserRow<ParserDummy>::Arg, \
67 ParserRow<ParserDummy>::Int, \
68 ParserRow<ParserDummy>::Optional, \
69 ParserRow<ParserDummy>::IgnoreMinMax, \
80 ParserDummy::ParserDummy(NDB_SOCKET_TYPE sock) :
SocketServer::Session(sock)
86 #define NDB_MGM_MAX_ERR_DESC_SIZE 256
94 char last_error_desc[NDB_MGM_MAX_ERR_DESC_SIZE];
97 NDB_SOCKET_TYPE socket;
106 int mgmd_version_major;
107 int mgmd_version_minor;
108 int mgmd_version_build;
110 int mgmd_version(
void)
const {
114 assert(mgmd_version_major >= 0 &&
115 mgmd_version_minor >= 0 &&
116 mgmd_version_build >= 0);
117 return NDB_MAKE_VERSION(mgmd_version_major,
122 char * m_bindaddress;
123 int m_bindaddress_port;
136 bool check_version_ge(Uint32 curr, ...)
138 Uint32 version, last = ~0;
141 va_start(versions, curr);
142 while ((version= va_arg(versions, Uint32)))
149 assert(version < last);
158 test_check_version_ge(
void)
160 assert(check_version_ge(NDB_MAKE_VERSION(7,0,19),
161 NDB_MAKE_VERSION(7,0,20),
163 assert(check_version_ge(NDB_MAKE_VERSION(7,0,19),
164 NDB_MAKE_VERSION(7,1,6),
165 NDB_MAKE_VERSION(7,0,20),
167 assert(check_version_ge(NDB_MAKE_VERSION(7,0,19),
168 NDB_MAKE_VERSION(7,1,6),
169 NDB_MAKE_VERSION(7,0,18),
171 assert(check_version_ge(NDB_MAKE_VERSION(7,1,8),
172 NDB_MAKE_VERSION(7,1,6),
173 NDB_MAKE_VERSION(7,0,18),
175 assert(check_version_ge(NDB_MAKE_VERSION(5,5,6),
176 NDB_MAKE_VERSION(7,1,6),
177 NDB_MAKE_VERSION(7,0,18),
181 #define SET_ERROR(h, e, s) setError((h), (e), __LINE__, (s))
185 setError(
NdbMgmHandle h,
int error,
int error_line,
const char *
msg, ...){
187 h->last_error = error; \
188 h->last_error_line = error_line;
192 BaseString::vsnprintf(h->last_error_desc,
sizeof(h->last_error_desc), msg, ap);
196 #define CHECK_HANDLE(handle, ret) \
201 #define CHECK_CONNECTED(handle, ret) \
202 if (handle->connected != 1) { \
203 SET_ERROR(handle, NDB_MGM_SERVER_NOT_CONNECTED , ""); \
207 #define CHECK_REPLY(handle, reply, ret) \
208 if (reply == NULL) { \
209 if(!handle->last_error) \
210 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY, ""); \
214 #define CHECK_TIMEDOUT(in, out) \
215 if(in.timedout() || out.timedout()) \
216 SET_ERROR(handle, ETIMEDOUT, \
217 "Time out talking to management server");
219 #define CHECK_TIMEDOUT_RET(h, in, out, ret) \
220 if(in.timedout() || out.timedout()) { \
221 SET_ERROR(h, ETIMEDOUT, \
222 "Time out talking to management server"); \
223 ndb_mgm_disconnect_quiet(h); \
235 DBUG_ENTER(
"ndb_mgm_create_handle");
242 h->last_error_line = 0;
243 my_socket_invalidate(&(h->socket));
246 h->errstream = stdout;
248 h->m_bindaddress = 0;
249 h->m_bindaddress_port = 0;
250 h->ignore_sigpipe =
true;
252 strncpy(h->last_error_desc,
"No error", NDB_MGM_MAX_ERR_DESC_SIZE);
261 h->mgmd_version_major= -1;
262 h->mgmd_version_minor= -1;
263 h->mgmd_version_build= -1;
265 DBUG_PRINT(
"info", (
"handle: 0x%lx", (
long) h));
273 free(handle->m_name);
274 handle->m_name= strdup(name);
281 DBUG_ENTER(
"ndb_mgm_set_connectstring");
282 DBUG_PRINT(
"info", (
"handle: 0x%lx", (
long) handle));
283 handle->cfg.~LocalConfig();
285 if (!handle->cfg.init(connect_string, 0) ||
286 handle->cfg.ids.size() == 0)
288 handle->cfg.~LocalConfig();
290 handle->cfg.
init(0, 0);
291 SET_ERROR(handle, NDB_MGM_ILLEGAL_CONNECT_STRING,
292 connect_string ? connect_string :
"");
296 handle->cfg.bind_address_port= handle->m_bindaddress_port;
297 handle->cfg.bind_address.assign(handle->m_bindaddress ? handle->m_bindaddress :
"");
305 DBUG_ENTER(
"ndb_mgm_set_bindaddress");
306 free(handle->m_bindaddress);
310 handle->m_bindaddress = strdup(arg);
311 char *port = strchr(handle->m_bindaddress,
':');
314 handle->m_bindaddress_port = atoi(port+1);
318 handle->m_bindaddress_port = 0;
322 handle->m_bindaddress = 0;
323 handle->m_bindaddress_port = 0;
325 if (handle->cfg.ids.size() != 0)
327 handle->cfg.bind_address_port= handle->m_bindaddress_port;
328 handle->cfg.bind_address.
assign(handle->m_bindaddress ? handle->m_bindaddress :
"");
337 DBUG_ENTER(
"ndb_mgm_set_ignore_sigpipe");
338 CHECK_HANDLE(handle, -1);
339 if (handle->connected){
340 SET_ERROR(handle, EINVAL,
"Can't change 'ignore_sigpipe' while connected");
343 handle->ignore_sigpipe = (val != 0);
354 DBUG_ENTER(
"ndb_mgm_destroy_handle");
357 DBUG_PRINT(
"info", (
"handle: 0x%lx", (
long) (* handle)));
362 if((* handle)->connected){
366 if ((* handle)->logfile != 0){
367 fclose((* handle)->logfile);
368 (* handle)->logfile = 0;
371 (*handle)->cfg.~LocalConfig();
372 free((*handle)->m_name);
373 free((*handle)->m_bindaddress);
383 handle->errstream =
file;
397 return h->last_error;
403 return h->last_error_desc;
410 return h->last_error_line;
417 for (
int i=0;
i<ndb_mgm_noOfErrorMsgs;
i++) {
418 if (ndb_mgm_error_msgs[
i].
code == h->last_error)
419 return ndb_mgm_error_msgs[
i].msg;
444 const char* cmd_bulk= NULL)
446 DBUG_ENTER(
"ndb_mgm_call");
447 DBUG_PRINT(
"enter",(
"handle->socket: " MY_SOCKET_FORMAT
", cmd: %s",
448 MY_SOCKET_FORMAT_VALUE(handle->socket), cmd));
452 out.println(
"%s", cmd);
458 f.println(
"OUT: %s", cmd);
461 if(cmd_args != NULL) {
464 while((name = iter.next()) != NULL) {
470 cmd_args->getTypeOf(name, &t);
472 case PropertiesType_Uint32:
473 cmd_args->get(name, &val_i);
474 out.println(
"%s: %d", name, val_i);
476 case PropertiesType_Uint64:
477 cmd_args->get(name, &val_64);
478 out.println(
"%s: %Ld", name, val_64);
480 case PropertiesType_char:
481 cmd_args->get(name, val_s);
482 out.println(
"%s: %s", name, val_s.
c_str());
484 case PropertiesType_Properties:
485 DBUG_PRINT(
"info",(
"Ignoring PropertiesType_Properties."));
489 DBUG_PRINT(
"info",(
"Ignoring PropertiesType: %d.",t));
496 cmd_args->print(handle->logfile,
"OUT: ");
499 out.println(
"%s",
"");
502 out.println(cmd_bulk);
504 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
508 Parser_t parser(command_reply, in,
true,
true,
true);
513 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
518 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
519 if(ctx.m_status==Parser_t::Eof
520 || ctx.m_status==Parser_t::NoLine)
523 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
529 fprintf(handle->errstream,
530 "Error in mgm protocol parser. cmd: >%s< status: %d curr: %s\n",
531 cmd, (Uint32)ctx.m_status,
532 (ctx.m_currentToken)?ctx.m_currentToken:
"NULL");
533 DBUG_PRINT(
"info",(
"ctx.status: %d, ctx.m_currentToken: %s",
534 ctx.m_status, ctx.m_currentToken));
542 p->print(handle->logfile,
"IN: ");
546 if(p && (in.timedout() || out.timedout()))
548 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
572 unsigned int min_timeout = 5*60*1000,
573 const char* cmd_bulk= NULL)
575 const unsigned int save_timeout = handle->timeout;
576 if (min_timeout > save_timeout)
577 handle->timeout = min_timeout;
579 cmd, cmd_args, cmd_bulk);
582 handle->timeout = save_timeout;
596 if(handle->connected)
598 if(Ndb_check_socket_hup(handle->socket))
600 handle->connected= 0;
601 NDB_CLOSE_SOCKET(handle->socket);
604 return handle->connected;
619 handle->timeout= timeout_ms;
630 for (i = 0; i < cfg.ids.size(); i++)
632 if (cfg.ids[i].type != MgmId_TCP)
643 assert(handle->connected);
645 if (handle->mgmd_version_major >= 0)
650 &(handle->mgmd_version_major),
651 &(handle->mgmd_version_minor),
652 &(handle->mgmd_version_build),
665 int retry_delay_in_seconds,
int verbose)
667 DBUG_ENTER(
"ndb_mgm_connect");
668 CHECK_HANDLE(handle, -1);
669 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_connect");
677 handle->logfile = fopen(logname,
"w");
681 #if defined SIGPIPE && !defined _WIN32
682 if (handle->ignore_sigpipe)
683 (void)signal(SIGPIPE, SIG_IGN);
690 NDB_SOCKET_TYPE sockfd;
691 my_socket_invalidate(&sockfd);
693 while (!my_socket_valid(sockfd))
696 for (i = 0; i < cfg.ids.size(); i++)
698 if (cfg.ids[i].type != MgmId_TCP)
702 const char *bind_address= NULL;
703 unsigned short bind_address_port= 0;
704 s.set_connect_timeout(handle->timeout);
707 fprintf(handle->errstream,
708 "Unable to create socket, "
709 "while trying to connect with connect string: %s\n",
710 cfg.makeConnectString(buf,
sizeof(buf)));
712 setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
713 "Unable to create socket, "
714 "while trying to connect with connect string: %s\n",
715 cfg.makeConnectString(buf,
sizeof(buf)));
718 if (handle->m_bindaddress)
720 bind_address= handle->m_bindaddress;
721 bind_address_port= handle->m_bindaddress_port;
723 else if (cfg.ids[i].bind_address.length())
725 bind_address= cfg.ids[
i].bind_address.c_str();
726 bind_address_port= cfg.ids[
i].bind_address_port;
731 if ((err = s.bind(bind_address, bind_address_port)) != 0)
733 if (!handle->m_bindaddress)
738 fprintf(handle->errstream,
739 "Unable to bind local address '%s:%d' errno: %d, "
740 "while trying to connect with connect string: '%s'\n",
741 bind_address, (
int)bind_address_port, err,
742 cfg.makeConnectString(buf,
sizeof(buf)));
744 setError(handle, NDB_MGM_BIND_ADDRESS, __LINE__,
745 "Unable to bind local address '%s:%d' errno: %d, "
746 "while trying to connect with connect string: '%s'\n",
747 bind_address, (
int)bind_address_port, err,
748 cfg.makeConnectString(buf,
sizeof(buf)));
752 sockfd = s.connect(cfg.ids[i].name.c_str(), cfg.ids[
i].port);
753 if (my_socket_valid(sockfd))
756 if (my_socket_valid(sockfd))
760 DBUG_PRINT(
"info",(
"Unable to connect with connect string: %s",
761 cfg.makeConnectString(buf,
sizeof(buf))));
765 fprintf(handle->errstream,
766 "Unable to connect with connect string: %s\n",
767 cfg.makeConnectString(buf,
sizeof(buf)));
770 if (no_retries == 0) {
771 setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
772 "Unable to connect with connect string: %s",
773 cfg.makeConnectString(buf,
sizeof(buf)));
775 fprintf(handle->errstream,
", failed.\n");
779 fprintf(handle->errstream,
"Retrying every %d seconds",
780 retry_delay_in_seconds);
782 fprintf(handle->errstream,
". Attempts left:");
784 fprintf(handle->errstream,
", until connected.");
785 fflush(handle->errstream);
788 if (no_retries > 0) {
790 fprintf(handle->errstream,
" %d", no_retries);
791 fflush(handle->errstream);
795 NdbSleep_SecSleep(retry_delay_in_seconds);
799 fprintf(handle->errstream,
"\n");
800 fflush(handle->errstream);
804 handle->socket = sockfd;
805 handle->connected = 1;
808 handle->mgmd_version_major= -1;
809 handle->mgmd_version_minor= -1;
810 handle->mgmd_version_build= -1;
824 return handle->socket.s;
831 return handle->socket.fd;
844 NDB_CLOSE_SOCKET(handle->socket);
845 my_socket_invalidate(&(handle->socket));
846 handle->connected = 0;
858 DBUG_ENTER(
"ndb_mgm_disconnect");
859 CHECK_HANDLE(handle, -1);
860 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_disconnect");
861 CHECK_CONNECTED(handle, -1);
863 DBUG_RETURN(ndb_mgm_disconnect_quiet(handle));
880 const int no_of_type_values = (
sizeof(type_values) /
888 return NDB_MGM_NODE_TYPE_UNKNOWN;
890 for(
int i = 0;
i<no_of_type_values;
i++)
891 if(strcmp(type, type_values[
i].str) == 0)
892 return type_values[
i].value;
893 else if(strcmp(type, type_values[
i].alias) == 0)
894 return type_values[
i].value;
896 return NDB_MGM_NODE_TYPE_UNKNOWN;
903 for(
int i = 0;
i<no_of_type_values;
i++)
904 if(type_values[
i].value == type)
905 return type_values[
i].str;
913 for(
int i = 0;
i<no_of_type_values;
i++)
914 if(type_values[
i].value == type)
917 *str= type_values[
i].str;
918 return type_values[
i].alias;
943 const int no_of_status_values = (
sizeof(status_values) /
953 for(
int i = 0;
i<no_of_status_values;
i++)
954 if(strcmp(status, status_values[
i].str) == 0)
955 return status_values[
i].value;
965 for(i = 0; i<no_of_status_values; i++)
966 if(status_values[i].value == status)
967 return status_values[
i].str;
969 for(i = 0; i<no_of_status_values; i++)
971 return status_values[
i].str;
981 if(strcmp(
"type", field) == 0){
983 }
else if(strcmp(
"status", field) == 0){
985 }
else if(strcmp(
"startphase", field) == 0){
987 }
else if(strcmp(
"dynamic_id", field) == 0){
989 }
else if(strcmp(
"node_group", field) == 0){
991 }
else if(strcmp(
"version", field) == 0){
993 }
else if(strcmp(
"mysql_version", field) == 0){
995 }
else if(strcmp(
"connect_count", field) == 0){
997 }
else if(strcmp(
"address", field) == 0){
1001 ndbout_c(
"Unknown field: %s", field);
1011 cmp_state(
const void *_a,
const void *_b)
1034 DBUG_ENTER(
"ndb_mgm_get_status2");
1035 CHECK_HANDLE(handle, NULL);
1036 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_get_status");
1037 CHECK_CONNECTED(handle, NULL);
1039 char typestring[1024];
1044 for (Uint32
i = 0; types[
i] != NDB_MGM_NODE_TYPE_UNKNOWN;
i++)
1046 if (
int(types[
i]) < NDB_MGM_NODE_TYPE_MIN ||
1047 int(types[i]) > NDB_MGM_NODE_TYPE_MAX)
1049 SET_ERROR(handle, EINVAL,
1050 "Incorrect node type for ndb_mgm_get_status2");
1056 for (Int32 j = i - 1; j >= 0; j--)
1058 if (types[i] == types[j])
1060 SET_ERROR(handle, EINVAL,
1061 "Duplicate types for ndb_mgm_get_status2");
1066 int left =
sizeof(typestring) - pos;
1072 SET_ERROR(handle, EINVAL,
1073 "Out of memory for type-string for ndb_mgm_get_status2");
1083 out.println(
"get status");
1086 out.println(
"types: %s", typestring);
1088 out.println(
"%s",
"");
1090 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
1093 if(!in.gets(buf,
sizeof(buf)))
1095 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
1096 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
"Probably disconnected");
1099 if(strcmp(
"node status\n", buf) != 0) {
1100 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
1101 ndbout << in.timedout() <<
" " << out.timedout() << buf << endl;
1102 SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf);
1105 if(!in.gets(buf,
sizeof(buf)))
1107 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
1108 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
"Probably disconnected");
1114 tmp.
split(split,
":");
1115 if(split.size() != 2){
1116 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
1117 SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf);
1121 if(!(split[0].trim() ==
"nodes")){
1122 SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf);
1126 const int noOfNodes = atoi(split[1].c_str());
1134 SET_ERROR(handle, NDB_MGM_OUT_OF_MEMORY,
1135 "Allocating ndb_mgm_cluster_state");
1143 for (i= 0; i < noOfNodes; i++) {
1147 for(; i<noOfNodes; ){
1148 if(!in.gets(buf,
sizeof(buf)))
1151 if(in.timedout() || out.timedout())
1152 SET_ERROR(handle, ETIMEDOUT,
1153 "Time out talking to management server");
1155 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
1156 "Probably disconnected");
1161 if(tmp.
trim() ==
""){
1166 tmp.
split(split2,
":.", 4);
1167 if(split2.size() != 4)
1170 const int id = atoi(split2[1].c_str());
1178 split2[3].trim(
" \t\n");
1180 if(status_ackumulate(ptr,split2[2].c_str(), split2[3].c_str()) != 0) {
1185 if(i+1 != noOfNodes){
1187 CHECK_TIMEDOUT_RET(handle, in, out, NULL);
1188 SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS,
"Node count mismatch");
1200 unsigned int nodeId,
1203 DBUG_ENTER(
"ndb_mgm_enter_single_user");
1204 CHECK_HANDLE(handle, -1);
1205 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_enter_single_user");
1207 MGM_CMD(
"enter single user reply", NULL,
""),
1208 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1211 CHECK_CONNECTED(handle, -1);
1214 args.
put(
"nodeId", nodeId);
1216 reply = ndb_mgm_call(handle, enter_single_reply,
"enter single user", &args);
1217 CHECK_REPLY(handle, reply, -1);
1220 reply->get(
"result", result);
1221 if(strcmp(result.
c_str(),
"Ok") != 0) {
1222 SET_ERROR(handle, NDB_MGM_COULD_NOT_ENTER_SINGLE_USER_MODE,
1237 DBUG_ENTER(
"ndb_mgm_exit_single_user");
1238 CHECK_HANDLE(handle, -1);
1239 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_exit_single_user");
1241 MGM_CMD(
"exit single user reply", NULL,
""),
1242 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1245 CHECK_CONNECTED(handle, -1);
1248 reply = ndb_mgm_call(handle, exit_single_reply,
"exit single user", 0);
1249 CHECK_REPLY(handle, reply, -1);
1252 reply->get(
"result", &buf);
1253 if(strcmp(buf,
"Ok")!=0) {
1254 SET_ERROR(handle, NDB_MGM_COULD_NOT_EXIT_SINGLE_USER_MODE, buf);
1276 return ndb_mgm_stop3(handle, no_of_nodes, node_list, abort, &disconnect);
1282 int abort,
int *disconnect)
1291 int abort,
int force,
int *disconnect)
1293 DBUG_ENTER(
"ndb_mgm_stop4");
1294 CHECK_HANDLE(handle, -1);
1295 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_stop4");
1297 MGM_CMD(
"stop reply", NULL,
""),
1298 MGM_ARG(
"stopped", Int, Optional,
"No of stopped nodes"),
1299 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1303 MGM_CMD(
"stop reply", NULL,
""),
1304 MGM_ARG(
"stopped", Int, Optional,
"No of stopped nodes"),
1305 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1306 MGM_ARG(
"disconnect", Int, Mandatory,
"Need to disconnect"),
1310 CHECK_CONNECTED(handle, -1);
1312 if (!get_mgmd_version(handle))
1315 int use_v2= ((handle->mgmd_version_major==5)
1317 (handle->mgmd_version_minor==0 && handle->mgmd_version_build>=21)
1318 ||(handle->mgmd_version_minor==1 && handle->mgmd_version_build>=12)
1319 ||(handle->mgmd_version_minor>1)
1322 || (handle->mgmd_version_major>5);
1324 if(no_of_nodes < -1){
1325 SET_ERROR(handle, NDB_MGM_ILLEGAL_NUMBER_OF_NODES,
1326 "Negative number of nodes requested to stop");
1330 if(no_of_nodes <= 0){
1335 args.
put(
"abort", abort);
1337 args.
put(
"stop", (no_of_nodes==-1)?
"mgm,db":
"db");
1341 reply = ndb_mgm_call_slow(handle, stop_reply_v2,
"stop all", &args);
1343 reply = ndb_mgm_call_slow(handle, stop_reply_v1,
"stop all", &args);
1344 CHECK_REPLY(handle, reply, -1);
1347 if(!reply->get(
"stopped", &stopped))
1349 SET_ERROR(handle, NDB_MGM_STOP_FAILED,
1350 "Could not get number of stopped nodes from mgm server");
1355 reply->get(
"disconnect", (Uint32*)disconnect);
1359 reply->get(
"result", result);
1360 if(strcmp(result.
c_str(),
"Ok") != 0) {
1361 SET_ERROR(handle, NDB_MGM_STOP_FAILED, result.
c_str());
1366 DBUG_RETURN(stopped);
1375 node_list_str.
assfmt(
"%d", node_list[0]);
1377 node_list_str.
appfmt(
" %d", node_list[node]);
1379 args.
put(
"node", node_list_str.
c_str());
1380 args.
put(
"abort", abort);
1381 if (check_version_ge(handle->mgmd_version(),
1382 NDB_MAKE_VERSION(7,1,8),
1383 NDB_MAKE_VERSION(7,0,19),
1385 args.
put(
"force", force);
1387 SET_ERROR(handle, NDB_MGM_STOP_FAILED,
1388 "The connected mgm server does not support 'stop --force'");
1392 reply = ndb_mgm_call_slow(handle, stop_reply_v2,
"stop v2", &args);
1394 reply = ndb_mgm_call_slow(handle, stop_reply_v1,
"stop", &args);
1395 CHECK_REPLY(handle, reply, -1);
1398 if(!reply->get(
"stopped", &stopped))
1400 SET_ERROR(handle, NDB_MGM_STOP_FAILED,
1401 "Could not get number of stopped nodes from mgm server");
1406 reply->get(
"disconnect", (Uint32*)disconnect);
1410 reply->get(
"result", result);
1411 if(strcmp(result.
c_str(),
"Ok") != 0) {
1412 SET_ERROR(handle, NDB_MGM_STOP_FAILED, result.
c_str());
1417 DBUG_RETURN(stopped);
1430 int initial,
int nostart,
int abort)
1435 abort, &disconnect);
1441 int initial,
int nostart,
int abort,
int *disconnect)
1444 nostart, abort,
false, disconnect);
1450 int initial,
int nostart,
int abort,
int force,
1453 DBUG_ENTER(
"ndb_mgm_restart");
1454 CHECK_HANDLE(handle, -1);
1455 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_restart4");
1458 MGM_CMD(
"restart reply", NULL,
""),
1459 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1460 MGM_ARG(
"restarted", Int, Optional,
"No of restarted nodes"),
1464 MGM_CMD(
"restart reply", NULL,
""),
1465 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1466 MGM_ARG(
"restarted", Int, Optional,
"No of restarted nodes"),
1467 MGM_ARG(
"disconnect", Int, Optional,
"Disconnect to apply"),
1471 CHECK_CONNECTED(handle, -1);
1473 if (!get_mgmd_version(handle))
1476 int use_v2= ((handle->mgmd_version_major==5)
1478 (handle->mgmd_version_minor==0 && handle->mgmd_version_build>=21)
1479 ||(handle->mgmd_version_minor==1 && handle->mgmd_version_build>=12)
1480 ||(handle->mgmd_version_minor>1)
1483 || (handle->mgmd_version_major>5);
1485 if(no_of_nodes < 0){
1486 SET_ERROR(handle, NDB_MGM_RESTART_FAILED,
1487 "Restart requested of negative number of nodes");
1491 if(no_of_nodes == 0) {
1493 args.
put(
"abort", abort);
1494 args.
put(
"initialstart", initial);
1495 args.
put(
"nostart", nostart);
1498 ndb_mgm_call_slow(handle, restart_reply_v1,
"restart all", &args);
1499 CHECK_REPLY(handle, reply, -1);
1502 reply->get(
"result", result);
1503 if(strcmp(result.
c_str(),
"Ok") != 0) {
1504 SET_ERROR(handle, NDB_MGM_RESTART_FAILED, result.
c_str());
1510 if(!reply->get(
"restarted", &restarted)){
1511 SET_ERROR(handle, NDB_MGM_RESTART_FAILED,
1512 "Could not get restarted number of nodes from mgm server");
1517 DBUG_RETURN(restarted);
1521 node_list_str.
assfmt(
"%d", node_list[0]);
1523 node_list_str.
appfmt(
" %d", node_list[node]);
1527 args.
put(
"node", node_list_str.
c_str());
1528 args.
put(
"abort", abort);
1529 args.
put(
"initialstart", initial);
1530 args.
put(
"nostart", nostart);
1532 if (check_version_ge(handle->mgmd_version(),
1533 NDB_MAKE_VERSION(7,1,8),
1534 NDB_MAKE_VERSION(7,0,19),
1536 args.
put(
"force", force);
1538 SET_ERROR(handle, NDB_MGM_RESTART_FAILED,
1539 "The connected mgm server does not support 'restart --force'");
1543 reply = ndb_mgm_call_slow(handle, restart_reply_v2,
1544 "restart node v2", &args);
1546 reply = ndb_mgm_call_slow(handle, restart_reply_v1,
1547 "restart node", &args);
1548 CHECK_REPLY(handle, reply, -1);
1551 reply->get(
"result", result);
1552 if(strcmp(result.
c_str(),
"Ok") != 0) {
1553 SET_ERROR(handle, NDB_MGM_RESTART_FAILED, result.
c_str());
1558 reply->get(
"restarted", &restarted);
1560 reply->get(
"disconnect", (Uint32*)disconnect);
1564 DBUG_RETURN(restarted);
1567 static const char *clusterlog_severity_names[]=
1568 {
"enabled",
"debug",
"info",
"warning",
"error",
"critical",
"alert" };
1574 } clusterlog_severities[] = {
1583 { 0, NDB_MGM_ILLEGAL_EVENT_SEVERITY },
1588 ndb_mgm_match_event_severity(
const char * name)
1591 return NDB_MGM_ILLEGAL_EVENT_SEVERITY;
1593 for(
int i = 0; clusterlog_severities[
i].name !=0 ;
i++)
1594 if(strcasecmp(name, clusterlog_severities[
i].name) == 0)
1595 return clusterlog_severities[
i].severity;
1597 return NDB_MGM_ILLEGAL_EVENT_SEVERITY;
1604 int i= (int)severity;
1606 return clusterlog_severity_names[i];
1608 if(clusterlog_severities[i].severity == severity)
1609 return clusterlog_severities[
i].name;
1617 unsigned int severity_size)
1619 DBUG_ENTER(
"ndb_mgm_get_clusterlog_severity_filter");
1620 CHECK_HANDLE(handle, -1);
1621 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_get_clusterlog_severity_filter");
1623 MGM_CMD(
"clusterlog", NULL,
""),
1624 MGM_ARG(clusterlog_severity_names[0], Int, Mandatory,
""),
1625 MGM_ARG(clusterlog_severity_names[1], Int, Mandatory,
""),
1626 MGM_ARG(clusterlog_severity_names[2], Int, Mandatory,
""),
1627 MGM_ARG(clusterlog_severity_names[3], Int, Mandatory,
""),
1628 MGM_ARG(clusterlog_severity_names[4], Int, Mandatory,
""),
1629 MGM_ARG(clusterlog_severity_names[5], Int, Mandatory,
""),
1630 MGM_ARG(clusterlog_severity_names[6], Int, Mandatory,
""),
1632 CHECK_CONNECTED(handle, -1);
1636 reply = ndb_mgm_call(handle, getinfo_reply,
"get info clusterlog", &args);
1637 CHECK_REPLY(handle, reply, -1);
1639 for(
unsigned int i=0; i < severity_size; i++) {
1640 reply->get(clusterlog_severity_names[severity[i].category], &severity[i].value);
1642 DBUG_RETURN(severity_size);
1646 const unsigned int *
1649 DBUG_ENTER(
"ndb_mgm_get_clusterlog_severity_filter_old");
1650 CHECK_HANDLE(handle, NULL);
1651 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_get_clusterlog_severity_filter");
1655 MGM_CMD(
"clusterlog", NULL,
""),
1656 MGM_ARG(clusterlog_severity_names[0], Int, Mandatory,
""),
1657 MGM_ARG(clusterlog_severity_names[1], Int, Mandatory,
""),
1658 MGM_ARG(clusterlog_severity_names[2], Int, Mandatory,
""),
1659 MGM_ARG(clusterlog_severity_names[3], Int, Mandatory,
""),
1660 MGM_ARG(clusterlog_severity_names[4], Int, Mandatory,
""),
1661 MGM_ARG(clusterlog_severity_names[5], Int, Mandatory,
""),
1662 MGM_ARG(clusterlog_severity_names[6], Int, Mandatory,
""),
1664 CHECK_CONNECTED(handle, NULL);
1668 reply = ndb_mgm_call(handle, getinfo_reply,
"get info clusterlog", &args);
1669 CHECK_REPLY(handle, reply, NULL);
1672 reply->get(clusterlog_severity_names[i], &enabled[i]);
1674 DBUG_RETURN(enabled);
1684 DBUG_ENTER(
"ndb_mgm_set_clusterlog_severity_filter");
1685 CHECK_HANDLE(handle, -1);
1686 SET_ERROR(handle, NDB_MGM_NO_ERROR,
1687 "Executing: ndb_mgm_set_clusterlog_severity_filter");
1689 MGM_CMD(
"set logfilter reply", NULL,
""),
1690 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1694 CHECK_CONNECTED(handle, -1);
1697 args.
put(
"level", severity);
1698 args.
put(
"enable", enable);
1701 reply = ndb_mgm_call(handle, filter_reply,
"set logfilter", &args);
1702 CHECK_REPLY(handle, reply, retval);
1705 reply->get(
"result", result);
1707 if (strcmp(result.
c_str(),
"1") == 0)
1709 else if (strcmp(result.
c_str(),
"0") == 0)
1713 SET_ERROR(handle, EINVAL, result.
c_str());
1716 DBUG_RETURN(retval);
1735 {
"SCHEMA", NDB_MGM_EVENT_CATEGORY_SCHEMA },
1741 ndb_mgm_match_event_category(
const char * status)
1746 for(
int i = 0; categories[
i].name !=0 ; i++)
1747 if(strcmp(status, categories[i].name) == 0)
1748 return categories[
i].category;
1758 for(i = 0; categories[
i].name != 0; i++)
1759 if(categories[i].category == status)
1760 return categories[
i].name;
1765 static const char *clusterlog_names[]=
1766 {
"startup",
"shutdown",
"statistics",
"checkpoint",
"noderestart",
"connection",
"info",
"warning",
"error",
"congestion",
"debug",
"backup" };
1772 unsigned int loglevel_size)
1774 DBUG_ENTER(
"ndb_mgm_get_clusterlog_loglevel");
1775 CHECK_HANDLE(handle, -1);
1776 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_get_clusterlog_loglevel");
1777 int loglevel_count = loglevel_size;
1779 MGM_CMD(
"get cluster loglevel", NULL,
""),
1780 MGM_ARG(clusterlog_names[0], Int, Mandatory,
""),
1781 MGM_ARG(clusterlog_names[1], Int, Mandatory,
""),
1782 MGM_ARG(clusterlog_names[2], Int, Mandatory,
""),
1783 MGM_ARG(clusterlog_names[3], Int, Mandatory,
""),
1784 MGM_ARG(clusterlog_names[4], Int, Mandatory,
""),
1785 MGM_ARG(clusterlog_names[5], Int, Mandatory,
""),
1786 MGM_ARG(clusterlog_names[6], Int, Mandatory,
""),
1787 MGM_ARG(clusterlog_names[7], Int, Mandatory,
""),
1788 MGM_ARG(clusterlog_names[8], Int, Mandatory,
""),
1789 MGM_ARG(clusterlog_names[9], Int, Mandatory,
""),
1790 MGM_ARG(clusterlog_names[10], Int, Mandatory,
""),
1791 MGM_ARG(clusterlog_names[11], Int, Mandatory,
""),
1793 CHECK_CONNECTED(handle, -1);
1797 reply = ndb_mgm_call(handle, getloglevel_reply,
"get cluster loglevel", &args);
1798 CHECK_REPLY(handle, reply, -1);
1800 for(
int i=0; i < loglevel_count; i++) {
1801 reply->get(clusterlog_names[loglevel[i].category], &loglevel[i].value);
1803 DBUG_RETURN(loglevel_count);
1807 const unsigned int *
1810 DBUG_ENTER(
"ndb_mgm_get_clusterlog_loglevel_old");
1811 CHECK_HANDLE(handle, NULL);
1812 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_get_clusterlog_loglevel");
1813 int loglevel_count = CFG_MAX_LOGLEVEL - CFG_MIN_LOGLEVEL + 1 ;
1814 static unsigned int loglevel[CFG_MAX_LOGLEVEL - CFG_MIN_LOGLEVEL + 1] = {0,0,0,0,0,0,0,0,0,0,0,0};
1816 MGM_CMD(
"get cluster loglevel", NULL,
""),
1817 MGM_ARG(clusterlog_names[0], Int, Mandatory,
""),
1818 MGM_ARG(clusterlog_names[1], Int, Mandatory,
""),
1819 MGM_ARG(clusterlog_names[2], Int, Mandatory,
""),
1820 MGM_ARG(clusterlog_names[3], Int, Mandatory,
""),
1821 MGM_ARG(clusterlog_names[4], Int, Mandatory,
""),
1822 MGM_ARG(clusterlog_names[5], Int, Mandatory,
""),
1823 MGM_ARG(clusterlog_names[6], Int, Mandatory,
""),
1824 MGM_ARG(clusterlog_names[7], Int, Mandatory,
""),
1825 MGM_ARG(clusterlog_names[8], Int, Mandatory,
""),
1826 MGM_ARG(clusterlog_names[9], Int, Mandatory,
""),
1827 MGM_ARG(clusterlog_names[10], Int, Mandatory,
""),
1828 MGM_ARG(clusterlog_names[11], Int, Mandatory,
""),
1830 CHECK_CONNECTED(handle, NULL);
1834 reply = ndb_mgm_call(handle, getloglevel_reply,
"get cluster loglevel", &args);
1835 CHECK_REPLY(handle, reply, NULL);
1837 for(
int i=0; i < loglevel_count; i++) {
1838 reply->get(clusterlog_names[i], &loglevel[i]);
1840 DBUG_RETURN(loglevel);
1850 DBUG_ENTER(
"ndb_mgm_set_clusterlog_loglevel");
1851 CHECK_HANDLE(handle, -1);
1852 SET_ERROR(handle, NDB_MGM_NO_ERROR,
1853 "Executing: ndb_mgm_set_clusterlog_loglevel");
1855 MGM_CMD(
"set cluster loglevel reply", NULL,
""),
1856 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1859 CHECK_CONNECTED(handle, -1);
1862 args.
put(
"node", nodeId);
1863 args.
put(
"category", cat);
1864 args.
put(
"level", level);
1867 reply = ndb_mgm_call(handle, clusterlog_reply,
1868 "set cluster loglevel", &args);
1869 CHECK_REPLY(handle, reply, -1);
1871 DBUG_PRINT(
"enter",(
"node=%d, category=%d, level=%d", nodeId, cat, level));
1874 reply->get(
"result", result);
1875 if(strcmp(result.
c_str(),
"Ok") != 0) {
1876 SET_ERROR(handle, EINVAL, result.
c_str());
1891 DBUG_ENTER(
"ndb_mgm_set_loglevel_node");
1892 CHECK_HANDLE(handle, -1);
1893 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_set_loglevel_node");
1895 MGM_CMD(
"set loglevel reply", NULL,
""),
1896 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
1899 CHECK_CONNECTED(handle, -1);
1902 args.
put(
"node", nodeId);
1903 args.
put(
"category", category);
1904 args.
put(
"level", level);
1906 reply = ndb_mgm_call(handle, loglevel_reply,
"set loglevel", &args);
1907 CHECK_REPLY(handle, reply, -1);
1910 reply->get(
"result", result);
1911 if(strcmp(result.
c_str(),
"Ok") != 0) {
1912 SET_ERROR(handle, EINVAL, result.
c_str());
1922 ndb_mgm_listen_event_internal(
NdbMgmHandle handle,
const int filter[],
1923 int parsable, NDB_SOCKET_TYPE* sock)
1925 DBUG_ENTER(
"ndb_mgm_listen_event_internal");
1926 CHECK_HANDLE(handle, -1);
1927 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_listen_event");
1929 MGM_CMD(
"listen event", NULL,
""),
1930 MGM_ARG(
"result", Int, Mandatory,
"Error message"),
1931 MGM_ARG(
"msg",
String, Optional,
"Error message"),
1939 s.set_connect_timeout(handle->timeout);
1942 fprintf(handle->errstream,
"Unable to create socket");
1943 setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
1944 "Unable to create socket");
1950 if ((err = s.bind(bind_address, 0)) != 0)
1952 fprintf(handle->errstream,
1953 "Unable to bind local address '%s:0' err: %d, errno: %d, "
1954 "while trying to connect with connect string: '%s:%d'\n",
1955 bind_address, err, errno, hostname, port);
1956 setError(handle, NDB_MGM_BIND_ADDRESS, __LINE__,
1957 "Unable to bind local address '%s:0' errno: %d, errno: %d, "
1958 "while trying to connect with connect string: '%s:%d'\n",
1959 bind_address, err, errno, hostname, port);
1963 const NDB_SOCKET_TYPE sockfd = s.connect(hostname, port);
1964 if (!my_socket_valid(sockfd))
1966 setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
1967 "Unable to connect to");
1974 args.
put(
"parsable", parsable);
1977 for(
int i = 0; filter[
i] != 0; i += 2){
1978 tmp.
appfmt(
"%d=%d ", filter[i+1], filter[i]);
1983 NDB_SOCKET_TYPE tmp = handle->socket;
1984 handle->socket = sockfd;
1987 reply = ndb_mgm_call(handle, stat_reply,
"listen event", &args);
1989 handle->socket = tmp;
1992 my_socket_close(sockfd);
1993 CHECK_REPLY(handle, reply, -1);
2015 if(ndb_mgm_listen_event_internal(handle,filter,0,&s)<0)
2016 my_socket_invalidate(&s);
2029 DBUG_ENTER(
"ndb_mgm_dump_state");
2030 CHECK_HANDLE(handle, -1);
2031 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_dump_state");
2033 MGM_CMD(
"dump state reply", NULL,
""),
2034 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2037 CHECK_CONNECTED(handle, -1);
2041 for (
int i = 0; i < _num_args; i++){
2042 unsigned n = strlen(buf);
2043 if (n + 20 >
sizeof(buf)) {
2044 SET_ERROR(handle, NDB_MGM_USAGE_ERROR,
"arguments too long");
2047 sprintf(buf + n,
"%s%d", i ?
" " :
"", _args[i]);
2051 args.
put(
"node", nodeId);
2052 args.
put(
"args", buf);
2055 prop = ndb_mgm_call(handle, dump_state_reply,
"dump state", &args);
2056 CHECK_REPLY(handle, prop, -1);
2059 prop->get(
"result", result);
2060 if(strcmp(result.
c_str(),
"Ok") != 0) {
2061 SET_ERROR(handle, EINVAL, result.
c_str());
2075 return ndb_mgm_get_configuration2(handle, 0,
2076 NDB_MGM_NODE_TYPE_UNKNOWN, nodeid);
2081 ndb_mgm_start_signallog(
NdbMgmHandle handle,
int nodeId,
2084 DBUG_ENTER(
"ndb_mgm_start_signallog");
2085 CHECK_HANDLE(handle, -1);
2086 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_start_signallog");
2088 MGM_CMD(
"start signallog reply", NULL,
""),
2089 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2093 CHECK_CONNECTED(handle, -1);
2096 args.
put(
"node", nodeId);
2099 prop = ndb_mgm_call(handle,
2100 start_signallog_reply,
2103 CHECK_REPLY(handle, prop, -1);
2107 prop->get(
"result", result);
2108 if(strcmp(result.
c_str(),
"Ok") == 0) {
2111 SET_ERROR(handle, EINVAL, result.
c_str());
2117 DBUG_RETURN(retval);
2122 ndb_mgm_stop_signallog(
NdbMgmHandle handle,
int nodeId,
2125 DBUG_ENTER(
"ndb_mgm_stop_signallog");
2126 CHECK_HANDLE(handle, -1);
2127 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_stop_signallog");
2129 MGM_CMD(
"stop signallog reply", NULL,
""),
2130 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2134 CHECK_CONNECTED(handle, -1);
2137 args.
put(
"node", nodeId);
2140 prop = ndb_mgm_call(handle, stop_signallog_reply,
"stop signallog", &args);
2141 CHECK_REPLY(handle, prop, -1);
2145 prop->get(
"result", result);
2146 if(strcmp(result.
c_str(),
"Ok") == 0) {
2149 SET_ERROR(handle, EINVAL, result.
c_str());
2155 DBUG_RETURN(retval);
2168 const char* blockNames,
2171 DBUG_ENTER(
"ndb_mgm_log_signals");
2172 CHECK_HANDLE(handle, -1);
2173 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_log_signals");
2175 MGM_CMD(
"log signals reply", NULL,
""),
2176 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2180 CHECK_CONNECTED(handle, -1);
2183 args.
put(
"node", nodeId);
2184 args.
put(
"blocks", blockNames);
2188 args.
put(
"in", (Uint32)1);
2189 args.
put(
"out", (Uint32)0);
2192 args.
put(
"in", (Uint32)0);
2193 args.
put(
"out", (Uint32)1);
2196 args.
put(
"in", (Uint32)1);
2197 args.
put(
"out", (Uint32)1);
2200 args.
put(
"in", (Uint32)0);
2201 args.
put(
"out", (Uint32)0);
2206 prop = ndb_mgm_call(handle, stop_signallog_reply,
"log signals", &args);
2207 CHECK_REPLY(handle, prop, -1);
2211 prop->get(
"result", result);
2212 if(strcmp(result.
c_str(),
"Ok") == 0) {
2215 SET_ERROR(handle, EINVAL, result.
c_str());
2221 DBUG_RETURN(retval);
2226 ndb_mgm_set_trace(
NdbMgmHandle handle,
int nodeId,
int traceNumber,
2229 DBUG_ENTER(
"ndb_mgm_set_trace");
2230 CHECK_HANDLE(handle, -1);
2231 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_set_trace");
2233 MGM_CMD(
"set trace reply", NULL,
""),
2234 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2238 CHECK_CONNECTED(handle, -1);
2241 args.
put(
"node", nodeId);
2242 args.
put(
"trace", traceNumber);
2245 prop = ndb_mgm_call(handle, set_trace_reply,
"set trace", &args);
2246 CHECK_REPLY(handle, prop, -1);
2250 prop->get(
"result", result);
2251 if(strcmp(result.
c_str(),
"Ok") == 0) {
2254 SET_ERROR(handle, EINVAL, result.
c_str());
2260 DBUG_RETURN(retval);
2265 ndb_mgm_insert_error(
NdbMgmHandle handle,
int nodeId,
int errorCode,
2268 DBUG_ENTER(
"ndb_mgm_insert_error");
2269 CHECK_HANDLE(handle, -1);
2270 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_insert_error");
2272 MGM_CMD(
"insert error reply", NULL,
""),
2273 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2277 CHECK_CONNECTED(handle, -1);
2280 args.
put(
"node", nodeId);
2281 args.
put(
"error", errorCode);
2284 prop = ndb_mgm_call(handle, insert_error_reply,
"insert error", &args);
2285 CHECK_REPLY(handle, prop, -1);
2289 prop->get(
"result", result);
2290 if(strcmp(result.
c_str(),
"Ok") == 0) {
2293 SET_ERROR(handle, EINVAL, result.
c_str());
2299 DBUG_RETURN(retval);
2306 DBUG_ENTER(
"ndb_mgm_start");
2307 CHECK_HANDLE(handle, -1);
2308 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_start");
2310 MGM_CMD(
"start reply", NULL,
""),
2311 MGM_ARG(
"started", Int, Optional,
"No of started nodes"),
2312 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2316 CHECK_CONNECTED(handle, -1);
2318 if(no_of_nodes < 0){
2319 SET_ERROR(handle, EINVAL,
"");
2323 if(no_of_nodes == 0){
2326 reply = ndb_mgm_call(handle, start_reply,
"start all", &args);
2327 CHECK_REPLY(handle, reply, -1);
2330 if(!reply->get(
"started", &count)){
2338 for(
int node = 0; node < no_of_nodes; node++) {
2340 args.
put(
"node", node_list[node]);
2343 reply = ndb_mgm_call(handle, start_reply,
"start", &args);
2347 reply->get(
"result", result);
2348 if(strcmp(result.
c_str(),
"Ok") == 0) {
2351 SET_ERROR(handle, EINVAL, result.
c_str());
2359 DBUG_RETURN(started);
2368 unsigned int* _backup_id,
2370 unsigned int input_backupId,
2371 unsigned int backuppoint)
2373 DBUG_ENTER(
"ndb_mgm_start_backup");
2375 CHECK_HANDLE(handle, -1);
2376 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_start_backup");
2378 MGM_CMD(
"start backup reply", NULL,
""),
2379 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2380 MGM_ARG(
"id", Int, Optional,
"Id of the started backup"),
2383 CHECK_CONNECTED(handle, -1);
2385 if (!get_mgmd_version(handle))
2388 bool sendBackupPoint = (handle->mgmd_version() >= NDB_MAKE_VERSION(6,4,0));
2391 args.
put(
"completed", wait_completed);
2392 if(input_backupId > 0)
2393 args.
put(
"backupid", input_backupId);
2394 if (sendBackupPoint)
2395 args.
put(
"backuppoint", backuppoint);
2399 int old_timeout= handle->timeout;
2400 if (wait_completed == 2)
2401 handle->timeout= 48*60*60*1000;
2402 else if (wait_completed == 1)
2403 handle->timeout= 10*60*1000;
2404 reply = ndb_mgm_call(handle, start_backup_reply,
"start backup", &args);
2405 handle->timeout= old_timeout;
2407 CHECK_REPLY(handle, reply, -1);
2410 reply->get(
"result", result);
2411 reply->get(
"id", _backup_id);
2412 if(strcmp(result.
c_str(),
"Ok") != 0) {
2413 SET_ERROR(handle, NDB_MGM_COULD_NOT_START_BACKUP, result.
c_str());
2425 unsigned int* _backup_id,
2427 unsigned int input_backupId)
2435 unsigned int* _backup_id,
2446 DBUG_ENTER(
"ndb_mgm_abort_backup");
2447 CHECK_HANDLE(handle, -1);
2448 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_abort_backup");
2450 MGM_CMD(
"abort backup reply", NULL,
""),
2451 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2454 CHECK_CONNECTED(handle, -1);
2457 args.
put(
"id", backupId);
2460 prop = ndb_mgm_call(handle, stop_backup_reply,
"abort backup", &args);
2461 CHECK_REPLY(handle, prop, -1);
2464 prop->get(
"result", &buf);
2465 if(strcmp(buf,
"Ok")!=0) {
2466 SET_ERROR(handle, NDB_MGM_COULD_NOT_ABORT_BACKUP, buf);
2477 ndb_mgm_get_configuration2(
NdbMgmHandle handle,
unsigned int version,
2480 DBUG_ENTER(
"ndb_mgm_get_configuration2");
2482 CHECK_HANDLE(handle, 0);
2483 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_get_configuration");
2484 CHECK_CONNECTED(handle, 0);
2486 if (!get_mgmd_version(handle))
2489 bool getConfigUsingNodetype =
2490 (handle->mgmd_version() >= NDB_MAKE_VERSION(6,4,0));
2493 args.
put(
"version", version);
2494 if (getConfigUsingNodetype)
2496 args.
put(
"nodetype", nodetype);
2501 if (check_version_ge(handle->mgmd_version(),
2502 NDB_MAKE_VERSION(7,1,16),
2503 NDB_MAKE_VERSION(7,0,27),
2506 args.
put(
"from_node", from_node);
2510 SET_ERROR(handle, NDB_MGM_GET_CONFIG_FAILED,
2511 "The mgm server does not support getting config from_node");
2517 MGM_CMD(
"get config reply", NULL,
""),
2518 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2519 MGM_ARG(
"Content-Length", Int, Optional,
"Content length in bytes"),
2520 MGM_ARG(
"Content-Type",
String, Optional,
"Type (octet-stream)"),
2521 MGM_ARG(
"Content-Transfer-Encoding",
String, Optional,
"Encoding(base64)"),
2526 prop = ndb_mgm_call(handle, reply,
"get config", &args);
2527 CHECK_REPLY(handle, prop, 0);
2530 const char * buf =
"<unknown error>";
2531 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0){
2532 fprintf(handle->errstream,
"ERROR Message: %s\n\n", buf);
2533 SET_ERROR(handle, NDB_MGM_GET_CONFIG_FAILED, buf);
2537 buf =
"<Unspecified>";
2538 if(!prop->get(
"Content-Type", &buf) ||
2539 strcmp(buf,
"ndbconfig/octet-stream") != 0){
2540 fprintf(handle->errstream,
"Unhandled response type: %s\n", buf);
2544 buf =
"<Unspecified>";
2545 if(!prop->get(
"Content-Transfer-Encoding", &buf)
2546 || strcmp(buf,
"base64") != 0){
2547 fprintf(handle->errstream,
"Unhandled encoding: %s\n", buf);
2551 buf =
"<Content-Length Unspecified>";
2553 if(!prop->get(
"Content-Length", &len)){
2554 fprintf(handle->errstream,
"Invalid response: %s\n\n", buf);
2560 char* buf64 =
new char[len];
2564 if((read = read_socket(handle->socket, handle->timeout,
2565 &buf64[start], len-start)) < 1){
2569 SET_ERROR(handle, ETIMEDOUT,
"Timeout reading packed config");
2571 SET_ERROR(handle, errno,
"Error reading packed config");
2572 ndb_mgm_disconnect_quiet(handle);
2576 }
while(start < len);
2580 void *tmp_data = malloc(base64_needed_decoded_length((
size_t) (len - 1)));
2581 const int res = ndb_base64_decode(buf64, len-1, tmp_data, NULL);
2584 tmp.append((
void *) tmp_data, res);
2588 fprintf(handle->errstream,
"Failed to decode buffer\n");
2593 const int res2 = cvf.unpack(tmp);
2595 fprintf(handle->errstream,
"Failed to unpack buffer\n");
2611 return ndb_mgm_get_configuration2(handle, version,
2612 NDB_MGM_NODE_TYPE_UNKNOWN);
2627 ndb_mgm_set_configuration_nodeid(
NdbMgmHandle handle,
int nodeid)
2629 DBUG_ENTER(
"ndb_mgm_set_configuration_nodeid");
2630 CHECK_HANDLE(handle, -1);
2631 handle->cfg._ownNodeId= nodeid;
2639 DBUG_ENTER(
"ndb_mgm_get_configuration_nodeid");
2640 CHECK_HANDLE(handle, 0);
2641 DBUG_RETURN(handle->cfg._ownNodeId);
2647 if (handle->cfg_i >= 0)
2648 return handle->cfg.ids[handle->cfg_i].port;
2656 if (handle->cfg_i >= 0)
2657 return handle->cfg.ids[handle->cfg_i].name.c_str();
2665 return handle->cfg.makeConnectString(buf,buf_sz);
2671 if (handle->cfg_i >= 0)
2673 if (handle->m_bindaddress)
2674 return handle->m_bindaddress;
2675 if (handle->cfg.ids[handle->cfg_i].bind_address.length())
2676 return handle->cfg.ids[handle->cfg_i].bind_address.c_str();
2683 ndb_mgm_alloc_nodeid(
NdbMgmHandle handle,
unsigned int version,
int nodetype,
2686 DBUG_ENTER(
"ndb_mgm_alloc_nodeid");
2687 CHECK_HANDLE(handle, 0);
2688 CHECK_CONNECTED(handle, 0);
2689 union {
long l;
char c[
sizeof(long)]; } endian_check;
2693 int nodeid= handle->cfg._ownNodeId;
2696 args.
put(
"version", version);
2697 args.
put(
"nodetype", nodetype);
2698 args.
put(
"nodeid", nodeid);
2699 args.
put(
"user",
"mysqld");
2700 args.
put(
"password",
"mysqld");
2701 args.
put(
"public key",
"a public key");
2702 args.
put(
"endian", (endian_check.c[
sizeof(
long)-1])?
"big":
"little");
2704 args.
put(
"name", handle->m_name);
2705 args.
put(
"log_event", log_event);
2708 MGM_CMD(
"get nodeid reply", NULL,
""),
2709 MGM_ARG(
"error_code", Int, Optional,
"Error code"),
2710 MGM_ARG(
"nodeid", Int, Optional,
"Error message"),
2711 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2716 prop= ndb_mgm_call(handle, reply,
"get nodeid", &args);
2717 CHECK_REPLY(handle, prop, -1);
2722 if (!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0)
2727 Uint32 error_code= NDB_MGM_ALLOCID_ERROR;
2728 err.
assfmt(
"Could not alloc node id at %s port %d: %s",
2729 hostname, port, buf);
2730 prop->get(
"error_code", &error_code);
2731 setError(handle, error_code, __LINE__, err.
c_str());
2735 if(!prop->get(
"nodeid", &_nodeid) != 0){
2736 fprintf(handle->errstream,
"ERROR Message: <nodeid Unspecified>\n");
2743 DBUG_RETURN(nodeid);
2753 DBUG_ENTER(
"ndb_mgm_set_int_parameter");
2754 CHECK_HANDLE(handle, 0);
2755 CHECK_CONNECTED(handle, 0);
2758 args.
put(
"node", node);
2759 args.
put(
"param", param);
2760 args.put64(
"value", value);
2763 MGM_CMD(
"set parameter reply", NULL,
""),
2764 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2769 prop= ndb_mgm_call(handle, reply,
"set parameter", &args);
2770 CHECK_REPLY(handle, prop, -1);
2775 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0){
2776 fprintf(handle->errstream,
"ERROR Message: %s\n", buf);
2791 unsigned long long value,
2793 DBUG_ENTER(
"ndb_mgm_set_int64_parameter");
2794 CHECK_HANDLE(handle, 0);
2795 CHECK_CONNECTED(handle, 0);
2798 args.
put(
"node", node);
2799 args.
put(
"param", param);
2800 args.put64(
"value", value);
2803 MGM_CMD(
"set parameter reply", NULL,
""),
2804 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2809 prop= ndb_mgm_call(handle, reply,
"set parameter", &args);
2810 CHECK_REPLY(handle, prop, 0);
2813 SET_ERROR(handle, EIO,
"Unable set parameter");
2820 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0){
2821 fprintf(handle->errstream,
"ERROR Message: %s\n", buf);
2838 DBUG_ENTER(
"ndb_mgm_set_string_parameter");
2839 CHECK_HANDLE(handle, 0);
2840 CHECK_CONNECTED(handle, 0);
2843 args.
put(
"node", node);
2844 args.
put(
"parameter", param);
2845 args.
put(
"value", value);
2848 MGM_CMD(
"set parameter reply", NULL,
""),
2849 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2854 prop= ndb_mgm_call(handle, reply,
"set parameter", &args);
2855 CHECK_REPLY(handle, prop, 0);
2858 SET_ERROR(handle, EIO,
"Unable set parameter");
2865 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0){
2866 fprintf(handle->errstream,
"ERROR Message: %s\n", buf);
2878 ndb_mgm_purge_stale_sessions(
NdbMgmHandle handle,
char **purged)
2880 DBUG_ENTER(
"ndb_mgm_purge_stale_sessions");
2881 CHECK_HANDLE(handle, 0);
2882 CHECK_CONNECTED(handle, 0);
2887 MGM_CMD(
"purge stale sessions reply", NULL,
""),
2888 MGM_ARG(
"purged",
String, Optional,
""),
2889 MGM_ARG(
"result",
String, Mandatory,
"Error message"),
2894 prop= ndb_mgm_call(handle, reply,
"purge stale sessions", &args);
2895 CHECK_REPLY(handle, prop, -1);
2898 SET_ERROR(handle, EIO,
"Unable to purge stale sessions");
2905 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0){
2906 fprintf(handle->errstream,
"ERROR Message: %s\n", buf);
2910 if (prop->get(
"purged", &buf))
2911 *purged= strdup(buf);
2925 DBUG_ENTER(
"ndb_mgm_check_connection");
2926 CHECK_HANDLE(handle, 0);
2927 CHECK_CONNECTED(handle, 0);
2931 if (out.println(
"check connection"))
2932 goto ndb_mgm_check_connection_error;
2934 if (out.println(
"%s",
""))
2935 goto ndb_mgm_check_connection_error;
2937 in.gets(buf,
sizeof(buf));
2938 if(strcmp(
"check connection reply\n", buf))
2939 goto ndb_mgm_check_connection_error;
2941 in.gets(buf,
sizeof(buf));
2942 if(strcmp(
"result: Ok\n", buf))
2943 goto ndb_mgm_check_connection_error;
2945 in.gets(buf,
sizeof(buf));
2946 if(strcmp(
"\n", buf))
2947 goto ndb_mgm_check_connection_error;
2951 ndb_mgm_check_connection_error:
2958 ndb_mgm_set_connection_int_parameter(
NdbMgmHandle handle,
2964 DBUG_ENTER(
"ndb_mgm_set_connection_int_parameter");
2965 CHECK_HANDLE(handle, 0);
2966 CHECK_CONNECTED(handle, 0);
2969 args.
put(
"node1", node1);
2970 args.
put(
"node2", node2);
2971 args.
put(
"param", param);
2972 args.
put(
"value", (Uint32)value);
2975 MGM_CMD(
"set connection parameter reply", NULL,
""),
2976 MGM_ARG(
"message",
String, Mandatory,
"Error Message"),
2977 MGM_ARG(
"result",
String, Mandatory,
"Status Result"),
2982 prop= ndb_mgm_call(handle, reply,
"set connection parameter", &args);
2983 CHECK_REPLY(handle, prop, -1);
2988 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0){
2989 fprintf(handle->errstream,
"ERROR Message: %s\n", buf);
3001 ndb_mgm_get_connection_int_parameter(
NdbMgmHandle handle,
3007 DBUG_ENTER(
"ndb_mgm_get_connection_int_parameter");
3008 CHECK_HANDLE(handle, -1);
3009 CHECK_CONNECTED(handle, -2);
3012 args.
put(
"node1", node1);
3013 args.
put(
"node2", node2);
3014 args.
put(
"param", param);
3017 MGM_CMD(
"get connection parameter reply", NULL,
""),
3018 MGM_ARG(
"value", Int, Mandatory,
"Current Value"),
3019 MGM_ARG(
"result",
String, Mandatory,
"Result"),
3024 prop = ndb_mgm_call(handle, reply,
"get connection parameter", &args);
3025 CHECK_REPLY(handle, prop, -3);
3030 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0){
3031 fprintf(handle->errstream,
"ERROR Message: %s\n", buf);
3037 if(!prop->get(
"value",(Uint32*)value)){
3038 fprintf(handle->errstream,
"Unable to get value\n");
3050 DBUG_ENTER(
"ndb_mgm_convert_to_transporter");
3055 SET_ERROR(*handle, NDB_MGM_ILLEGAL_SERVER_HANDLE,
"");
3056 my_socket_invalidate(&s);
3060 if ((*handle)->connected != 1)
3062 SET_ERROR(*handle, NDB_MGM_SERVER_NOT_CONNECTED ,
"");
3063 my_socket_invalidate(&s);
3067 (*handle)->connected= 0;
3068 s= (*handle)->socket;
3071 s_output.println(
"transporter connect");
3072 s_output.println(
"%s",
"");
3083 DBUG_ENTER(
"ndb_mgm_get_mgmd_nodeid");
3086 CHECK_HANDLE(handle, 0);
3087 CHECK_CONNECTED(handle, 0);
3092 MGM_CMD(
"get mgmd nodeid reply", NULL,
""),
3093 MGM_ARG(
"nodeid", Int, Mandatory,
"Node ID"),
3098 prop = ndb_mgm_call(handle, reply,
"get mgmd nodeid", &args);
3099 CHECK_REPLY(handle, prop, 0);
3101 if(!prop->get(
"nodeid",&nodeid)){
3102 fprintf(handle->errstream,
"Unable to get value\n");
3107 DBUG_RETURN(nodeid);
3111 int ndb_mgm_report_event(
NdbMgmHandle handle, Uint32 *data, Uint32 length)
3113 DBUG_ENTER(
"ndb_mgm_report_event");
3114 CHECK_HANDLE(handle, 0);
3115 CHECK_CONNECTED(handle, 0);
3118 args.
put(
"length", length);
3121 for (
int i = 0; i < (int) length; i++)
3122 data_string.
appfmt(
" %lu", (ulong) data[i]);
3124 args.
put(
"data", data_string.
c_str());
3127 MGM_CMD(
"report event reply", NULL,
""),
3128 MGM_ARG(
"result",
String, Mandatory,
"Result"),
3133 prop = ndb_mgm_call(handle, reply,
"report event", &args);
3134 CHECK_REPLY(handle, prop, -1);
3143 DBUG_ENTER(
"ndb_mgm_end_session");
3144 CHECK_HANDLE(handle, 0);
3145 CHECK_CONNECTED(handle, 0);
3148 s_output.println(
"end session");
3149 s_output.println(
"%s",
"");
3153 in.gets(buf,
sizeof(buf));
3154 CHECK_TIMEDOUT_RET(handle, in, s_output, -1);
3161 int *major,
int *minor,
int *build,
int len,
char* str)
3163 DBUG_ENTER(
"ndb_mgm_get_version");
3164 CHECK_HANDLE(handle, 0);
3165 CHECK_CONNECTED(handle, 0);
3170 MGM_CMD(
"version", NULL,
""),
3171 MGM_ARG(
"id", Int, Mandatory,
"ID"),
3172 MGM_ARG(
"major", Int, Mandatory,
"Major"),
3173 MGM_ARG(
"minor", Int, Mandatory,
"Minor"),
3174 MGM_ARG(
"build", Int, Optional,
"Build"),
3175 MGM_ARG(
"string",
String, Mandatory,
"String"),
3176 MGM_ARG(
"mysql_major", Int, Optional,
"MySQL major"),
3177 MGM_ARG(
"mysql_minor", Int, Optional,
"MySQL minor"),
3178 MGM_ARG(
"mysql_build", Int, Optional,
"MySQL build"),
3183 prop = ndb_mgm_call(handle, reply,
"get version", &args);
3184 CHECK_REPLY(handle, prop, 0);
3187 if(!prop->get(
"id",&
id)){
3188 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
3189 "Unable to get version id");
3192 *build= getBuild(
id);
3194 if(!prop->get(
"major",(Uint32*)major)){
3195 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
3196 "Unable to get version major");
3200 if(!prop->get(
"minor",(Uint32*)minor)){
3201 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
3202 "Unable to get version minor");
3207 if(!prop->get(
"string", result)){
3208 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
3209 "Unable to get version string");
3213 strncpy(str, result.
c_str(), len);
3223 Uint64 session_id=0;
3225 DBUG_ENTER(
"ndb_mgm_get_session_id");
3226 CHECK_HANDLE(handle, 0);
3227 CHECK_CONNECTED(handle, 0);
3232 MGM_CMD(
"get session id reply", NULL,
""),
3233 MGM_ARG(
"id", Int, Mandatory,
"Node ID"),
3238 prop = ndb_mgm_call(handle, reply,
"get session id", &args);
3239 CHECK_REPLY(handle, prop, 0);
3241 if(!prop->get(
"id",&session_id)){
3242 fprintf(handle->errstream,
"Unable to get session id\n");
3247 DBUG_RETURN(session_id);
3256 DBUG_ENTER(
"ndb_mgm_get_session");
3257 CHECK_HANDLE(handle, 0);
3258 CHECK_CONNECTED(handle, 0);
3261 args.
put(
"id", (Uint32)
id);
3264 MGM_CMD(
"get session reply", NULL,
""),
3265 MGM_ARG(
"id", Int, Mandatory,
"Node ID"),
3266 MGM_ARG(
"m_stopSelf", Int, Optional,
"m_stopSelf"),
3267 MGM_ARG(
"m_stop", Int, Optional,
"stop session"),
3268 MGM_ARG(
"nodeid", Int, Optional,
"allocated node id"),
3269 MGM_ARG(
"parser_buffer_len", Int, Optional,
"waiting in buffer"),
3270 MGM_ARG(
"parser_status", Int, Optional,
"parser status"),
3275 prop = ndb_mgm_call(handle, reply,
"get session", &args);
3276 CHECK_REPLY(handle, prop, 0);
3281 if(!prop->get(
"id",&r_id)){
3282 fprintf(handle->errstream,
"Unable to get session id\n");
3287 rlen+=
sizeof(s->id);
3289 if(prop->get(
"m_stopSelf",&(s->m_stopSelf)))
3290 rlen+=
sizeof(s->m_stopSelf);
3294 if(prop->get(
"m_stop",&(s->m_stop)))
3295 rlen+=
sizeof(s->m_stop);
3299 if(prop->get(
"nodeid",&(s->nodeid)))
3300 rlen+=
sizeof(s->nodeid);
3304 if(prop->get(
"parser_buffer_len",&(s->parser_buffer_len)))
3306 rlen+=
sizeof(s->parser_buffer_len);
3307 if(prop->get(
"parser_status",&(s->parser_status)))
3308 rlen+=
sizeof(s->parser_status);
3316 DBUG_RETURN(retval);
3323 DBUG_ENTER(
"ndb_mgm_set_configuration");
3325 SET_ERROR(h, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_set_configuration");
3326 CHECK_CONNECTED(h, 0);
3331 if (!cfg->pack(buf))
3333 SET_ERROR(h, NDB_MGM_OUT_OF_MEMORY,
"Packing config");
3338 encoded.
assfmt(
"%*s", base64_needed_encoded_length(buf.length()),
"Z");
3339 (void) base64_encode(buf.get_data(), buf.length(), (
char*)encoded.
c_str());
3342 args.
put(
"Content-Length", (Uint32)strlen(encoded.
c_str()));
3343 args.
put(
"Content-Type",
"ndbconfig/octet-stream");
3344 args.
put(
"Content-Transfer-Encoding",
"base64");
3347 MGM_CMD(
"set config reply", NULL,
""),
3348 MGM_ARG(
"result",
String, Mandatory,
"Result"),
3353 reply= ndb_mgm_call(h, set_config_reply,
"set config", &args,
3355 CHECK_REPLY(h, reply, -1);
3358 reply->get(
"result",result);
3362 if(strcmp(result.
c_str(),
"Ok") != 0) {
3363 SET_ERROR(h, NDB_MGM_CONFIG_CHANGE_FAILED, result.
c_str());
3377 DBUG_ENTER(
"ndb_mgm_create_nodegroup");
3378 CHECK_HANDLE(handle, -1);
3379 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_create_nodegroup");
3380 CHECK_CONNECTED(handle, -2);
3383 for (
int i = 0; nodes[
i] != 0; i++)
3384 nodestr.
appfmt(
"%u ", nodes[i]);
3387 args.
put(
"nodes", nodestr.
c_str());
3390 MGM_CMD(
"create nodegroup reply", NULL,
""),
3391 MGM_ARG(
"ng", Int, Mandatory,
"NG Id"),
3392 MGM_ARG(
"error_code", Int, Optional,
"error_code"),
3393 MGM_ARG(
"result",
String, Mandatory,
"Result"),
3398 prop = ndb_mgm_call(handle, reply,
"create nodegroup", &args);
3399 CHECK_REPLY(handle, prop, -3);
3402 const char * buf = 0;
3403 if (!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0)
3406 Uint32 err = NDB_MGM_ILLEGAL_SERVER_REPLY;
3407 prop->get(
"error_code", &err);
3408 setError(handle, err, __LINE__, buf ? buf :
"Illegal reply");
3410 else if (!prop->get(
"ng",(Uint32*)ng))
3413 setError(handle, NDB_MGM_ILLEGAL_SERVER_REPLY, __LINE__,
3414 "Nodegroup not sent back in reply");
3425 DBUG_ENTER(
"ndb_mgm_drop_nodegroup");
3426 CHECK_HANDLE(handle, -1);
3427 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_create_nodegroup");
3428 CHECK_CONNECTED(handle, -2);
3434 MGM_CMD(
"drop nodegroup reply", NULL,
""),
3435 MGM_ARG(
"error_code", Int, Optional,
"error_code"),
3436 MGM_ARG(
"result",
String, Mandatory,
"Result"),
3441 prop = ndb_mgm_call(handle, reply,
"drop nodegroup", &args);
3442 CHECK_REPLY(handle, prop, -3);
3445 const char * buf = 0;
3446 if(!prop->get(
"result", &buf) || strcmp(buf,
"Ok") != 0)
3449 Uint32 err = NDB_MGM_ILLEGAL_SERVER_REPLY;
3450 prop->get(
"error_code", &err);
3451 setError(handle, err, __LINE__, buf ? buf :
"Illegal reply");
3471 cmp_event(
const void *_a,
const void *_b)
3489 return (b->MemoryUsage.block - a->MemoryUsage.block);
3500 ndb_mgm_create_logevent_handle_same_socket(
NdbMgmHandle mh);
3514 int no_of_nodes,
const int * node_list)
3516 DBUG_ENTER(
"ndb_mgm_dump_events");
3517 CHECK_HANDLE(handle, NULL);
3518 SET_ERROR(handle, NDB_MGM_NO_ERROR,
"Executing: ndb_mgm_dump_events");
3519 CHECK_CONNECTED(handle, NULL);
3522 args.
put(
"type", (Uint32)type);
3526 const char* separator =
"";
3528 for(
int node = 0; node < no_of_nodes; node++)
3530 nodes.
appfmt(
"%s%d", separator, node_list[node]);
3537 MGM_CMD(
"dump events reply", NULL,
""),
3538 MGM_ARG(
"result",
String, Mandatory,
"Ok or error message"),
3539 MGM_ARG(
"events", Int, Optional,
"Number of events that follows"),
3542 const Properties *reply = ndb_mgm_call(handle, dump_events_reply,
3543 "dump events", &args);
3544 CHECK_REPLY(handle, reply, NULL);
3547 const char * result;
3548 reply->get(
"result", &result);
3549 if (strcmp(result,
"Ok") != 0) {
3550 SET_ERROR(handle, NDB_MGM_USAGE_ERROR, result);
3557 if (!reply->get(
"events", &num_events))
3559 SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
3560 "Number of events missing");
3574 SET_ERROR(handle, NDB_MGM_OUT_OF_MEMORY,
3575 "Allocating ndb_mgm_events struct");
3581 ndb_mgm_create_logevent_handle_same_socket(handle);
3584 SET_ERROR(handle, NDB_MGM_OUT_OF_MEMORY,
"Creating logevent handle");
3589 while (i < num_events)
3597 free_log_handle(log_handle);
3598 SET_ERROR(handle, ETIMEDOUT,
3599 "Time out talking to management server");
3605 free_log_handle(log_handle);
3614 free_log_handle(log_handle);
3619 sizeof(events->
events[0]), cmp_event);
3620 DBUG_RETURN(events);