📄 mgmapi.cpp
字号:
int initial, int nostart, int abort, int *disconnect){ SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_restart3"); Uint32 restarted = 0; const ParserRow<ParserDummy> restart_reply_v1[] = { MGM_CMD("restart reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_ARG("restarted", Int, Optional, "No of restarted nodes"), MGM_END() }; const ParserRow<ParserDummy> restart_reply_v2[] = { MGM_CMD("restart reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_ARG("restarted", Int, Optional, "No of restarted nodes"), MGM_ARG("disconnect", Int, Optional, "Disconnect to apply"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); if(handle->mgmd_version_build==-1) { char verstr[50]; if(!ndb_mgm_get_version(handle, &(handle->mgmd_version_major), &(handle->mgmd_version_minor), &(handle->mgmd_version_build), sizeof(verstr), verstr)) { return -1; } } int use_v2= ((handle->mgmd_version_major==5) && ( (handle->mgmd_version_minor==0 && handle->mgmd_version_build>=21) ||(handle->mgmd_version_minor==1 && handle->mgmd_version_build>=12) ||(handle->mgmd_version_minor>1) ) ) || (handle->mgmd_version_major>5); if(no_of_nodes < 0){ SET_ERROR(handle, NDB_MGM_RESTART_FAILED, "Restart requested of negative number of nodes"); return -1; } if(no_of_nodes == 0) { Properties args; args.put("abort", abort); args.put("initialstart", initial); args.put("nostart", nostart); const Properties *reply; const int timeout = handle->read_timeout; handle->read_timeout= 5*60*1000; // 5 minutes reply = ndb_mgm_call(handle, restart_reply_v1, "restart all", &args); handle->read_timeout= timeout; CHECK_REPLY(reply, -1); BaseString result; reply->get("result", result); if(strcmp(result.c_str(), "Ok") != 0) { SET_ERROR(handle, NDB_MGM_RESTART_FAILED, result.c_str()); delete reply; return -1; } if(!reply->get("restarted", &restarted)){ SET_ERROR(handle, NDB_MGM_RESTART_FAILED, "Could not get restarted number of nodes from mgm server"); delete reply; return -1; } delete reply; return restarted; } BaseString node_list_str; node_list_str.assfmt("%d", node_list[0]); for(int node = 1; node < no_of_nodes; node++) node_list_str.appfmt(" %d", node_list[node]); Properties args; args.put("node", node_list_str.c_str()); args.put("abort", abort); args.put("initialstart", initial); args.put("nostart", nostart); const Properties *reply; const int timeout = handle->read_timeout; handle->read_timeout= 5*60*1000; // 5 minutes if(use_v2) reply = ndb_mgm_call(handle, restart_reply_v2, "restart node v2", &args); else reply = ndb_mgm_call(handle, restart_reply_v1, "restart node", &args); handle->read_timeout= timeout; if(reply != NULL) { BaseString result; reply->get("result", result); if(strcmp(result.c_str(), "Ok") != 0) { SET_ERROR(handle, NDB_MGM_RESTART_FAILED, result.c_str()); delete reply; return -1; } reply->get("restarted", &restarted); if(use_v2) reply->get("disconnect", (Uint32*)disconnect); else *disconnect= 0; delete reply; } return restarted;}static const char *clusterlog_severity_names[]= { "enabled", "debug", "info", "warning", "error", "critical", "alert" };struct ndb_mgm_event_severities { const char* name; enum ndb_mgm_event_severity severity;} clusterlog_severities[] = { { clusterlog_severity_names[0], NDB_MGM_EVENT_SEVERITY_ON }, { clusterlog_severity_names[1], NDB_MGM_EVENT_SEVERITY_DEBUG }, { clusterlog_severity_names[2], NDB_MGM_EVENT_SEVERITY_INFO }, { clusterlog_severity_names[3], NDB_MGM_EVENT_SEVERITY_WARNING }, { clusterlog_severity_names[4], NDB_MGM_EVENT_SEVERITY_ERROR }, { clusterlog_severity_names[5], NDB_MGM_EVENT_SEVERITY_CRITICAL }, { clusterlog_severity_names[6], NDB_MGM_EVENT_SEVERITY_ALERT }, { "all", NDB_MGM_EVENT_SEVERITY_ALL }, { 0, NDB_MGM_ILLEGAL_EVENT_SEVERITY },};extern "C"ndb_mgm_event_severityndb_mgm_match_event_severity(const char * name){ if(name == 0) return NDB_MGM_ILLEGAL_EVENT_SEVERITY; for(int i = 0; clusterlog_severities[i].name !=0 ; i++) if(strcasecmp(name, clusterlog_severities[i].name) == 0) return clusterlog_severities[i].severity; return NDB_MGM_ILLEGAL_EVENT_SEVERITY;}extern "C"const char * ndb_mgm_get_event_severity_string(enum ndb_mgm_event_severity severity){ int i= (int)severity; if (i >= 0 && i < (int)NDB_MGM_EVENT_SEVERITY_ALL) return clusterlog_severity_names[i]; for(i = (int)NDB_MGM_EVENT_SEVERITY_ALL; clusterlog_severities[i].name != 0; i++) if(clusterlog_severities[i].severity == severity) return clusterlog_severities[i].name; return 0;}extern "C"const unsigned int *ndb_mgm_get_clusterlog_severity_filter(NdbMgmHandle handle) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_get_clusterlog_severity_filter"); static unsigned int enabled[(int)NDB_MGM_EVENT_SEVERITY_ALL]= {0,0,0,0,0,0,0}; const ParserRow<ParserDummy> getinfo_reply[] = { MGM_CMD("clusterlog", NULL, ""), MGM_ARG(clusterlog_severity_names[0], Int, Mandatory, ""), MGM_ARG(clusterlog_severity_names[1], Int, Mandatory, ""), MGM_ARG(clusterlog_severity_names[2], Int, Mandatory, ""), MGM_ARG(clusterlog_severity_names[3], Int, Mandatory, ""), MGM_ARG(clusterlog_severity_names[4], Int, Mandatory, ""), MGM_ARG(clusterlog_severity_names[5], Int, Mandatory, ""), MGM_ARG(clusterlog_severity_names[6], Int, Mandatory, ""), }; CHECK_HANDLE(handle, NULL); CHECK_CONNECTED(handle, NULL); Properties args; const Properties *reply; reply = ndb_mgm_call(handle, getinfo_reply, "get info clusterlog", &args); CHECK_REPLY(reply, NULL); for(int i=0; i < (int)NDB_MGM_EVENT_SEVERITY_ALL; i++) { reply->get(clusterlog_severity_names[i], &enabled[i]); } return enabled;}extern "C"int ndb_mgm_set_clusterlog_severity_filter(NdbMgmHandle handle, enum ndb_mgm_event_severity severity, int enable, struct ndb_mgm_reply* /*reply*/) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_set_clusterlog_severity_filter"); const ParserRow<ParserDummy> filter_reply[] = { MGM_CMD("set logfilter reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; int retval = -1; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; args.put("level", severity); args.put("enable", enable); const Properties *reply; reply = ndb_mgm_call(handle, filter_reply, "set logfilter", &args); CHECK_REPLY(reply, retval); BaseString result; reply->get("result", result); if (strcmp(result.c_str(), "1") == 0) retval = 1; else if (strcmp(result.c_str(), "0") == 0) retval = 0; else { SET_ERROR(handle, EINVAL, result.c_str()); } delete reply; return retval;}struct ndb_mgm_event_categories { const char* name; enum ndb_mgm_event_category category;} categories[] = { { "STARTUP", NDB_MGM_EVENT_CATEGORY_STARTUP }, { "SHUTDOWN", NDB_MGM_EVENT_CATEGORY_SHUTDOWN }, { "STATISTICS", NDB_MGM_EVENT_CATEGORY_STATISTIC }, { "NODERESTART", NDB_MGM_EVENT_CATEGORY_NODE_RESTART }, { "CONNECTION", NDB_MGM_EVENT_CATEGORY_CONNECTION }, { "CHECKPOINT", NDB_MGM_EVENT_CATEGORY_CHECKPOINT }, { "DEBUG", NDB_MGM_EVENT_CATEGORY_DEBUG }, { "INFO", NDB_MGM_EVENT_CATEGORY_INFO }, { "ERROR", NDB_MGM_EVENT_CATEGORY_ERROR }, { "BACKUP", NDB_MGM_EVENT_CATEGORY_BACKUP }, { "CONGESTION", NDB_MGM_EVENT_CATEGORY_CONGESTION }, { 0, NDB_MGM_ILLEGAL_EVENT_CATEGORY }};extern "C"ndb_mgm_event_categoryndb_mgm_match_event_category(const char * status){ if(status == 0) return NDB_MGM_ILLEGAL_EVENT_CATEGORY; for(int i = 0; categories[i].name !=0 ; i++) if(strcmp(status, categories[i].name) == 0) return categories[i].category; return NDB_MGM_ILLEGAL_EVENT_CATEGORY;}extern "C"const char * ndb_mgm_get_event_category_string(enum ndb_mgm_event_category status){ int i; for(i = 0; categories[i].name != 0; i++) if(categories[i].category == status) return categories[i].name; return 0;}extern "C"int ndb_mgm_set_clusterlog_loglevel(NdbMgmHandle handle, int nodeId, enum ndb_mgm_event_category cat, int level, struct ndb_mgm_reply* /*reply*/) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_set_clusterlog_loglevel"); const ParserRow<ParserDummy> clusterlog_reply[] = { MGM_CMD("set cluster loglevel reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; args.put("node", nodeId); args.put("category", cat); args.put("level", level); const Properties *reply; reply = ndb_mgm_call(handle, clusterlog_reply, "set cluster loglevel", &args); CHECK_REPLY(reply, -1); DBUG_ENTER("ndb_mgm_set_clusterlog_loglevel"); DBUG_PRINT("enter",("node=%d, category=%d, level=%d", nodeId, cat, level)); BaseString result; reply->get("result", result); if(strcmp(result.c_str(), "Ok") != 0) { SET_ERROR(handle, EINVAL, result.c_str()); delete reply; DBUG_RETURN(-1); } delete reply; DBUG_RETURN(0);}extern "C"int ndb_mgm_set_loglevel_node(NdbMgmHandle handle, int nodeId, enum ndb_mgm_event_category category, int level, struct ndb_mgm_reply* /*reply*/) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_set_loglevel_node"); const ParserRow<ParserDummy> loglevel_reply[] = { MGM_CMD("set loglevel reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; args.put("node", nodeId); args.put("category", category); args.put("level", level); const Properties *reply; reply = ndb_mgm_call(handle, loglevel_reply, "set loglevel", &args); CHECK_REPLY(reply, -1); BaseString result; reply->get("result", result); if(strcmp(result.c_str(), "Ok") != 0) { SET_ERROR(handle, EINVAL, result.c_str()); delete reply; return -1; } delete reply; return 0;}intndb_mgm_listen_event_internal(NdbMgmHandle handle, const int filter[], int parsable){ SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_listen_event"); const ParserRow<ParserDummy> stat_reply[] = { MGM_CMD("listen event", NULL, ""), MGM_ARG("result", Int, Mandatory, "Error message"), MGM_ARG("msg", String, Optional, "Error message"), MGM_END() }; CHECK_HANDLE(handle, -1); const char *hostname= ndb_mgm_get_connected_host(handle); int port= ndb_mgm_get_connected_port(handle); SocketClient s(hostname, port); const NDB_SOCKET_TYPE sockfd = s.connect(); if (sockfd == NDB_INVALID_SOCKET) { setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__, "Unable to connect to"); return -1; } Properties args; if (parsable) args.put("parsable", parsable); { BaseString tmp; for(int i = 0; filter[i] != 0; i += 2){ tmp.appfmt("%d=%d ", filter[i+1], filter[i]); } args.put("filter", tmp.c_str()); } int tmp = handle->socket; handle->socket = sockfd; const Properties *reply; reply = ndb_mgm_call(handle, stat_reply, "listen event", &args); handle->socket = tmp; if(reply == NULL) { close(sockfd); CHECK_REPLY(reply, -1); } return sockfd;}extern "C"intndb_mgm_listen_event(NdbMgmHandle handle, const int filter[]){ return ndb_mgm_listen_event_internal(handle,filter,0);}extern "C"int ndb_mgm_get_stat_port(NdbMgmHandle handle, struct ndb_mgm_reply* /*reply*/){ SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_get_stat_port"); const ParserRow<ParserDummy> stat_reply[] = { MGM_CMD("error", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_CMD("get statport reply", NULL, ""), MGM_ARG("tcpport", Int, Mandatory, "TCP port for statistics"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; const Properties *reply; reply = ndb_mgm_call(handle, stat_reply, "get statport", &args); CHECK_REPLY(reply, -1); Uint32 port; reply->get("tcpport", &port); delete reply; return port;}extern "C"int ndb_mgm_dump_state(NdbMgmHandle handle, int nodeId, int* _args, int _num_args, struct ndb_mgm_reply* /* reply */) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_dump_state"); const ParserRow<ParserDummy> dump_state_reply[] = { MGM_CMD("dump state reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); char buf[256]; buf[0] = 0; for (int i = 0; i < _num_args; i++){ unsigned n = strlen(buf); if (n + 20 > sizeof(buf)) { SET_ERROR(handle, NDB_MGM_USAGE_ERROR, "arguments too long"); return -1; } sprintf(buf + n, "%s%d", i ? " " : "", _args[i]); } Properties args; args.put("node", nodeId); args.put("args", buf); const Properties *prop; prop = ndb_mgm_call(handle, dump_state_reply, "dump state", &args); CHECK_REPLY(prop, -1); BaseString result; prop->get("result", result); if(strcmp(result.c_str(), "Ok") != 0) { SET_ERROR(handle, EINVAL, result.c_str()); delete prop; return -1; } delete prop; return 0;}extern "C"int ndb_mgm_start_signallog(NdbMgmHandle handle, int nodeId, struct ndb_mgm_reply* reply) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_start_signallog"); const ParserRow<ParserDummy> start_signallog_reply[] = { MGM_CMD("start signallog reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; int retval = -1; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; args.put("node", nodeId); const Properties *prop; prop = ndb_mgm_call(handle, start_signallog_reply, "start signallog", &args); if(prop != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -