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

📄 mgmapi.cpp

📁 mysql-5.0.24源码包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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);      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.getConfigValues();  } 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,                     int log_event){  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);  args.put("log_event", log_event);  const ParserRow<ParserDummy> reply[]= {    MGM_CMD("get nodeid reply", NULL, ""),      MGM_ARG("error_code", Int, Optional, "Error code"),      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 {

⌨️ 快捷键说明

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