📄 mgmapi.cpp
字号:
const char * buf; if (!prop->get("result", &buf) || strcmp(buf, "Ok") != 0) { const char *hostname= ndb_mgm_get_connected_host(handle); unsigned port= ndb_mgm_get_connected_port(handle); BaseString err; Uint32 error_code= NDB_MGM_ALLOCID_ERROR; err.assfmt("Could not alloc node id at %s port %d: %s", hostname, port, buf); prop->get("error_code", &error_code); setError(handle, error_code, __LINE__, err.c_str()); break; } Uint32 _nodeid; if(!prop->get("nodeid", &_nodeid) != 0){ fprintf(handle->errstream, "ERROR Message: <nodeid Unspecified>\n"); break; } nodeid= _nodeid; }while(0); delete prop; return nodeid;}/***************************************************************************** * Global Replication ******************************************************************************/extern "C"int ndb_mgm_rep_command(NdbMgmHandle handle, unsigned int request, unsigned int* replication_id, struct ndb_mgm_reply* /*reply*/) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_rep_command"); const ParserRow<ParserDummy> replication_reply[] = { MGM_CMD("global replication reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_ARG("id", Int, Optional, "Id of global replication"), MGM_END() }; CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -1); Properties args; args.put("request", request); const Properties *reply; reply = ndb_mgm_call(handle, replication_reply, "rep", &args); CHECK_REPLY(reply, -1); const char * result; reply->get("result", &result); reply->get("id", replication_id); if(strcmp(result,"Ok")!=0) { delete reply; return -1; } delete reply; return 0;}extern "C"intndb_mgm_set_int_parameter(NdbMgmHandle handle, int node, int param, unsigned value, struct ndb_mgm_reply*){ CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; args.put("node", node); args.put("param", param); args.put("value", value); const ParserRow<ParserDummy> reply[]= { MGM_CMD("set parameter reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; const Properties *prop; prop= ndb_mgm_call(handle, reply, "set parameter", &args); CHECK_REPLY(prop, -1); int res= -1; do { const char * buf; if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ fprintf(handle->errstream, "ERROR Message: %s\n", buf); break; } res= 0; } while(0); delete prop; return res;}extern "C"int ndb_mgm_set_int64_parameter(NdbMgmHandle handle, int node, int param, unsigned long long value, struct ndb_mgm_reply*){ CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; args.put("node", node); args.put("param", param); args.put("value", value); const ParserRow<ParserDummy> reply[]= { MGM_CMD("set parameter reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; const Properties *prop; prop= ndb_mgm_call(handle, reply, "set parameter", &args); if(prop == NULL) { SET_ERROR(handle, EIO, "Unable set parameter"); return -1; } int res= -1; do { const char * buf; if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ fprintf(handle->errstream, "ERROR Message: %s\n", buf); break; } res= 0; } while(0); delete prop; return res;}extern "C"intndb_mgm_set_string_parameter(NdbMgmHandle handle, int node, int param, const char * value, struct ndb_mgm_reply*){ CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; args.put("node", node); args.put("parameter", param); args.put("value", value); const ParserRow<ParserDummy> reply[]= { MGM_CMD("set parameter reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; const Properties *prop; prop= ndb_mgm_call(handle, reply, "set parameter", &args); if(prop == NULL) { SET_ERROR(handle, EIO, "Unable set parameter"); return -1; } int res= -1; do { const char * buf; if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ fprintf(handle->errstream, "ERROR Message: %s\n", buf); break; } res= 0; } while(0); delete prop; return res;}extern "C"intndb_mgm_purge_stale_sessions(NdbMgmHandle handle, char **purged){ CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; const ParserRow<ParserDummy> reply[]= { MGM_CMD("purge stale sessions reply", NULL, ""), MGM_ARG("purged", String, Optional, ""), MGM_ARG("result", String, Mandatory, "Error message"), MGM_END() }; const Properties *prop; prop= ndb_mgm_call(handle, reply, "purge stale sessions", &args); if(prop == NULL) { SET_ERROR(handle, EIO, "Unable to purge stale sessions"); return -1; } int res= -1; do { const char * buf; if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ fprintf(handle->errstream, "ERROR Message: %s\n", buf); break; } if (purged) { if (prop->get("purged", &buf)) *purged= strdup(buf); else *purged= 0; } res= 0; } while(0); delete prop; return res;}extern "C"intndb_mgm_check_connection(NdbMgmHandle handle){ CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); SocketOutputStream out(handle->socket); SocketInputStream in(handle->socket, handle->read_timeout); char buf[32]; if (out.println("check connection")) goto ndb_mgm_check_connection_error; if (out.println("")) goto ndb_mgm_check_connection_error; in.gets(buf, sizeof(buf)); if(strcmp("check connection reply\n", buf)) goto ndb_mgm_check_connection_error; in.gets(buf, sizeof(buf)); if(strcmp("result: Ok\n", buf)) goto ndb_mgm_check_connection_error; in.gets(buf, sizeof(buf)); if(strcmp("\n", buf)) goto ndb_mgm_check_connection_error; return 0;ndb_mgm_check_connection_error: ndb_mgm_disconnect(handle); return -1;}extern "C"intndb_mgm_set_connection_int_parameter(NdbMgmHandle handle, int node1, int node2, int param, int value, struct ndb_mgm_reply* mgmreply){ DBUG_ENTER("ndb_mgm_set_connection_int_parameter"); CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; args.put("node1", node1); args.put("node2", node2); args.put("param", param); args.put("value", (Uint32)value); const ParserRow<ParserDummy> reply[]= { MGM_CMD("set connection parameter reply", NULL, ""), MGM_ARG("message", String, Mandatory, "Error Message"), MGM_ARG("result", String, Mandatory, "Status Result"), MGM_END() }; const Properties *prop; prop= ndb_mgm_call(handle, reply, "set connection parameter", &args); CHECK_REPLY(prop, -1); int res= -1; do { const char * buf; if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ fprintf(handle->errstream, "ERROR Message: %s\n", buf); break; } res= 0; } while(0); delete prop; DBUG_RETURN(res);}extern "C"intndb_mgm_get_connection_int_parameter(NdbMgmHandle handle, int node1, int node2, int param, int *value, struct ndb_mgm_reply* mgmreply){ DBUG_ENTER("ndb_mgm_get_connection_int_parameter"); CHECK_HANDLE(handle, -1); CHECK_CONNECTED(handle, -2); Properties args; args.put("node1", node1); args.put("node2", node2); args.put("param", param); const ParserRow<ParserDummy> reply[]= { MGM_CMD("get connection parameter reply", NULL, ""), MGM_ARG("value", Int, Mandatory, "Current Value"), MGM_ARG("result", String, Mandatory, "Result"), MGM_END() }; const Properties *prop; prop = ndb_mgm_call(handle, reply, "get connection parameter", &args); CHECK_REPLY(prop, -3); int res= -1; do { const char * buf; if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ fprintf(handle->errstream, "ERROR Message: %s\n", buf); break; } res= 0; } while(0); if(!prop->get("value",(Uint32*)value)){ fprintf(handle->errstream, "Unable to get value\n"); res = -4; } delete prop; DBUG_RETURN(res);}extern "C"NDB_SOCKET_TYPEndb_mgm_convert_to_transporter(NdbMgmHandle *handle){ NDB_SOCKET_TYPE s; CHECK_HANDLE((*handle), NDB_INVALID_SOCKET); CHECK_CONNECTED((*handle), NDB_INVALID_SOCKET); (*handle)->connected= 0; // we pretend we're disconnected s= (*handle)->socket; SocketOutputStream s_output(s); s_output.println("transporter connect"); s_output.println(""); ndb_mgm_destroy_handle(handle); // set connected=0, so won't disconnect return s;}extern "C"Uint32ndb_mgm_get_mgmd_nodeid(NdbMgmHandle handle){ Uint32 nodeid=0; DBUG_ENTER("ndb_mgm_get_mgmd_nodeid"); CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; const ParserRow<ParserDummy> reply[]= { MGM_CMD("get mgmd nodeid reply", NULL, ""), MGM_ARG("nodeid", Int, Mandatory, "Node ID"), MGM_END() }; const Properties *prop; prop = ndb_mgm_call(handle, reply, "get mgmd nodeid", &args); CHECK_REPLY(prop, 0); if(!prop->get("nodeid",&nodeid)){ fprintf(handle->errstream, "Unable to get value\n"); return 0; } delete prop; DBUG_RETURN(nodeid);}extern "C"int ndb_mgm_report_event(NdbMgmHandle handle, Uint32 *data, Uint32 length){ DBUG_ENTER("ndb_mgm_report_event"); CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; args.put("length", length); BaseString data_string; for (int i = 0; i < length; i++) data_string.appfmt(" %u", data[i]); args.put("data", data_string.c_str()); const ParserRow<ParserDummy> reply[]= { MGM_CMD("report event reply", NULL, ""), MGM_ARG("result", String, Mandatory, "Result"), MGM_END() }; const Properties *prop; prop = ndb_mgm_call(handle, reply, "report event", &args); CHECK_REPLY(prop, -1); DBUG_RETURN(0);}extern "C"int ndb_mgm_end_session(NdbMgmHandle handle){ DBUG_ENTER("ndb_mgm_end_session"); CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); SocketOutputStream s_output(handle->socket); s_output.println("end session"); s_output.println(""); SocketInputStream in(handle->socket, handle->read_timeout); char buf[32]; in.gets(buf, sizeof(buf)); DBUG_RETURN(0);}extern "C"int ndb_mgm_get_version(NdbMgmHandle handle, int *major, int *minor, int *build, int len, char* str){ DBUG_ENTER("ndb_mgm_get_version"); CHECK_HANDLE(handle, 0); CHECK_CONNECTED(handle, 0); Properties args; const ParserRow<ParserDummy> reply[]= { MGM_CMD("version", NULL, ""), MGM_ARG("id", Int, Mandatory, "ID"), MGM_ARG("major", Int, Mandatory, "Major"), MGM_ARG("minor", Int, Mandatory, "Minor"), MGM_ARG("string", String, Mandatory, "String"), MGM_END() }; const Properties *prop; prop = ndb_mgm_call(handle, reply, "get version", &args); CHECK_REPLY(prop, 0); Uint32 id; if(!prop->get("id",&id)){ fprintf(handle->errstream, "Unable to get value\n"); return 0; } *build= getBuild(id); if(!prop->get("major",(Uint32*)major)){ fprintf(handle->errstream, "Unable to get value\n"); return 0; } if(!prop->get("minor",(Uint32*)minor)){ fprintf(handle->errstream, "Unable to get value\n"); return 0; } BaseString result; if(!prop->get("string", result)){ fprintf(handle->errstream, "Unable to get value\n"); return 0; } strncpy(str, result.c_str(), len); delete prop; DBUG_RETURN(1);}template class Vector<const ParserRow<ParserDummy>*>;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -