📄 mgmapi.cpp
字号:
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) { BaseString result; prop->get("result", result); if(strcmp(result.c_str(), "Ok") == 0) { retval = 0; } else { SET_ERROR(handle, EINVAL, result.c_str()); retval = -1; } delete prop; } return retval;}extern "C"int ndb_mgm_stop_signallog(NdbMgmHandle handle, int nodeId, struct ndb_mgm_reply* reply) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_stop_signallog"); const ParserRow<ParserDummy> stop_signallog_reply[] = { MGM_CMD("stop 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, stop_signallog_reply, "stop signallog", &args); if(prop != NULL) { BaseString result; prop->get("result", result); if(strcmp(result.c_str(), "Ok") == 0) { retval = 0; } else { SET_ERROR(handle, EINVAL, result.c_str()); retval = -1; } delete prop; } return retval;}struct ndb_mgm_signal_log_modes { const char* name; enum ndb_mgm_signal_log_mode mode;};extern "C"int ndb_mgm_log_signals(NdbMgmHandle handle, int nodeId, enum ndb_mgm_signal_log_mode mode, const char* blockNames, struct ndb_mgm_reply* reply) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_log_signals"); const ParserRow<ParserDummy> stop_signallog_reply[] = { MGM_CMD("log signals 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); args.put("blocks", blockNames); switch(mode) { case NDB_MGM_SIGNAL_LOG_MODE_IN: args.put("in", (Uint32)1); args.put("out", (Uint32)0); break; case NDB_MGM_SIGNAL_LOG_MODE_OUT: args.put("in", (Uint32)0); args.put("out", (Uint32)1); break; case NDB_MGM_SIGNAL_LOG_MODE_INOUT: args.put("in", (Uint32)1); args.put("out", (Uint32)1); break; case NDB_MGM_SIGNAL_LOG_MODE_OFF: args.put("in", (Uint32)0); args.put("out", (Uint32)0); break; } const Properties *prop; prop = ndb_mgm_call(handle, stop_signallog_reply, "log signals", &args); if(prop != NULL) { BaseString result; prop->get("result", result); if(strcmp(result.c_str(), "Ok") == 0) { retval = 0; } else { SET_ERROR(handle, EINVAL, result.c_str()); retval = -1; } delete prop; } return retval;}extern "C"int ndb_mgm_set_trace(NdbMgmHandle handle, int nodeId, int traceNumber, struct ndb_mgm_reply* reply) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_set_trace"); const ParserRow<ParserDummy> set_trace_reply[] = { MGM_CMD("set trace 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); args.put("trace", traceNumber); const Properties *prop; prop = ndb_mgm_call(handle, set_trace_reply, "set trace", &args); if(prop != NULL) { BaseString result; prop->get("result", result); if(strcmp(result.c_str(), "Ok") == 0) { retval = 0; } else { SET_ERROR(handle, EINVAL, result.c_str()); retval = -1; } delete prop; } return retval;}extern "C"int ndb_mgm_insert_error(NdbMgmHandle handle, int nodeId, int errorCode, struct ndb_mgm_reply* reply) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_insert_error"); const ParserRow<ParserDummy> insert_error_reply[] = { MGM_CMD("insert error 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); args.put("error", errorCode); const Properties *prop; prop = ndb_mgm_call(handle, insert_error_reply, "insert error", &args); if(prop != NULL) { BaseString result; prop->get("result", result); if(strcmp(result.c_str(), "Ok") == 0) { retval = 0; } else { SET_ERROR(handle, EINVAL, result.c_str()); retval = -1; } delete prop; } return retval;}extern "C"int ndb_mgm_start(NdbMgmHandle handle, int no_of_nodes, const int * node_list){ SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_start"); const ParserRow<ParserDummy> start_reply[] = { MGM_CMD("start reply", NULL, ""), MGM_ARG("started", Int, Optional, "No of started nodes"), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; int started = 0; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); if(no_of_nodes < 0){ SET_ERROR(handle, EINVAL, ""); return -1; } if(no_of_nodes == 0){ Properties args; const Properties *reply; reply = ndb_mgm_call(handle, start_reply, "start all", &args); CHECK_REPLY(reply, -1); Uint32 count = 0; if(!reply->get("started", &count)){ delete reply; return -1; } delete reply; return count; } for(int node = 0; node < no_of_nodes; node++) { Properties args; args.put("node", node_list[node]); const Properties *reply; reply = ndb_mgm_call(handle, start_reply, "start", &args); if(reply != NULL) { BaseString result; reply->get("result", result); if(strcmp(result.c_str(), "Ok") == 0) { started++; } else { SET_ERROR(handle, EINVAL, result.c_str()); delete reply; return -1; } } delete reply; } return started;}/***************************************************************************** * Backup *****************************************************************************/extern "C"int ndb_mgm_start_backup(NdbMgmHandle handle, int wait_completed, unsigned int* _backup_id, struct ndb_mgm_reply* /*reply*/) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_start_backup"); const ParserRow<ParserDummy> start_backup_reply[] = { MGM_CMD("start backup reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_ARG("id", Int, Optional, "Id of the started backup"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; args.put("completed", wait_completed); const Properties *reply; { // start backup can take some time, set timeout high Uint64 old_timeout= handle->read_timeout; if (wait_completed == 2) handle->read_timeout= 48*60*60*1000; // 48 hours else if (wait_completed == 1) handle->read_timeout= 10*60*1000; // 10 minutes reply = ndb_mgm_call(handle, start_backup_reply, "start backup", &args); handle->read_timeout= old_timeout; } CHECK_REPLY(reply, -1); BaseString result; reply->get("result", result); reply->get("id", _backup_id); if(strcmp(result.c_str(), "Ok") != 0) { SET_ERROR(handle, NDB_MGM_COULD_NOT_START_BACKUP, result.c_str()); delete reply; return -1; } delete reply; return 0;}extern "C"intndb_mgm_abort_backup(NdbMgmHandle handle, unsigned int backupId, struct ndb_mgm_reply* /*reply*/) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_abort_backup"); const ParserRow<ParserDummy> stop_backup_reply[] = { MGM_CMD("abort backup reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; args.put("id", backupId); const Properties *prop; prop = ndb_mgm_call(handle, stop_backup_reply, "abort backup", &args); CHECK_REPLY(prop, -1); const char * buf; prop->get("result", &buf); if(strcmp(buf,"Ok")!=0) { SET_ERROR(handle, NDB_MGM_COULD_NOT_ABORT_BACKUP, buf); delete prop; return -1; } delete prop; return 0;}extern "C"struct ndb_mgm_configuration *ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) { CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; args.put("version", version); const ParserRow<ParserDummy> reply[] = { MGM_CMD("get config reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_ARG("Content-Length", Int, Optional, "Content length in bytes"), MGM_ARG("Content-Type", String, Optional, "Type (octet-stream)"), MGM_ARG("Content-Transfer-Encoding", String, Optional, "Encoding(base64)"), MGM_END() }; const Properties *prop; prop = ndb_mgm_call(handle, reply, "get config", &args); CHECK_REPLY(prop, 0); do { const char * buf; if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ fprintf(handle->errstream, "ERROR Message: %s\n\n", buf); break; } buf = "<Unspecified>"; if(!prop->get("Content-Type", &buf) || strcmp(buf, "ndbconfig/octet-stream") != 0){ fprintf(handle->errstream, "Unhandled response type: %s\n", buf); break; } buf = "<Unspecified>"; if(!prop->get("Content-Transfer-Encoding", &buf) || strcmp(buf, "base64") != 0){ fprintf(handle->errstream, "Unhandled encoding: %s\n", buf); break; } buf = "<Content-Length Unspecified>"; Uint32 len = 0; if(!prop->get("Content-Length", &len)){ fprintf(handle->errstream, "Invalid response: %s\n\n", buf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -