⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgmapi.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 4 页
字号:
      break;    }    len += 1; // Trailing \n            char* buf64 = new char[len];    int read = 0;    size_t start = 0;    do {      if((read = read_socket(handle->socket, handle->read_timeout, 			     &buf64[start], len-start)) == -1){	delete[] buf64; 	buf64 = 0;	break;      }      start += read;    } while(start < len);    if(buf64 == 0)      break;    void *tmp_data = malloc(base64_needed_decoded_length((size_t) (len - 1)));    const int res = base64_decode(buf64, len-1, tmp_data);    delete[] buf64;    UtilBuffer tmp;    tmp.append((void *) tmp_data, res);    free(tmp_data);    if (res < 0)    {      fprintf(handle->errstream, "Failed to decode buffer\n");      break;    }    ConfigValuesFactory cvf;    const int res2 = cvf.unpack(tmp);    if(!res2){      fprintf(handle->errstream, "Failed to unpack buffer\n");      break;    }    delete prop;    return (ndb_mgm_configuration*)cvf.m_cfg;  } while(0);  delete prop;  return 0;}extern "C"voidndb_mgm_destroy_configuration(struct ndb_mgm_configuration *cfg){  if (cfg) {    ((ConfigValues *)cfg)->~ConfigValues();    free((void *)cfg);  }}extern "C"intndb_mgm_set_configuration_nodeid(NdbMgmHandle handle, int nodeid){  CHECK_HANDLE(handle, -1);  handle->cfg._ownNodeId= nodeid;  return 0;}extern "C"intndb_mgm_get_configuration_nodeid(NdbMgmHandle handle){  CHECK_HANDLE(handle, 0);  return handle->cfg._ownNodeId;}extern "C"int ndb_mgm_get_connected_port(NdbMgmHandle handle){  if (handle->cfg_i >= 0)    return handle->cfg.ids[handle->cfg_i].port;  else    return 0;}extern "C"const char *ndb_mgm_get_connected_host(NdbMgmHandle handle){  if (handle->cfg_i >= 0)    return handle->cfg.ids[handle->cfg_i].name.c_str();  else    return 0;}extern "C"const char *ndb_mgm_get_connectstring(NdbMgmHandle handle, char *buf, int buf_sz){  return handle->cfg.makeConnectString(buf,buf_sz);}extern "C"intndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, int nodetype){  CHECK_HANDLE(handle, 0);  CHECK_CONNECTED(handle, 0);  union { long l; char c[sizeof(long)]; } endian_check;  endian_check.l = 1;  int nodeid= handle->cfg._ownNodeId;  Properties args;  args.put("version", version);  args.put("nodetype", nodetype);  args.put("nodeid", nodeid);  args.put("user", "mysqld");  args.put("password", "mysqld");  args.put("public key", "a public key");  args.put("endian", (endian_check.c[sizeof(long)-1])?"big":"little");  if (handle->m_name)    args.put("name", handle->m_name);  const ParserRow<ParserDummy> reply[]= {    MGM_CMD("get nodeid reply", NULL, ""),      MGM_ARG("nodeid", Int, Optional, "Error message"),      MGM_ARG("result", String, Mandatory, "Error message"),    MGM_END()  };    const Properties *prop;  prop= ndb_mgm_call(handle, reply, "get nodeid", &args);  CHECK_REPLY(prop, -1);  nodeid= -1;  do {    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;      err.assfmt("Could not alloc node id at %s port %d: %s",		 hostname, port, buf);      setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __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);}template class Vector<const ParserRow<ParserDummy>*>;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -