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

📄 commandinterpreter.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	ndbout << BaseString(str).ndb_toupper() << " ";    }    ndbout << endl;    DBUG_VOID_RETURN;  }   else if (strcasecmp(item, "FILTER") == 0 ||	   strcasecmp(item, "TOGGLE") == 0)  {    DBUG_PRINT("info",("TOGGLE"));    enable= -1;  }   else if (strcasecmp(item, "OFF") == 0)   {    DBUG_PRINT("info",("OFF"));    enable= 0;  } else if (strcasecmp(item, "ON") == 0) {    DBUG_PRINT("info",("ON"));    enable= 1;  } else {    ndbout << "Invalid argument." << endl;    DBUG_VOID_RETURN;  }  int res_enable;  item = strtok_r(NULL, " ", &tmpPtr);  if (item == NULL) {    res_enable=      ndb_mgm_set_clusterlog_severity_filter(m_mgmsrv,					     NDB_MGM_EVENT_SEVERITY_ON,					     enable, NULL);    if (res_enable < 0)    {      ndbout << "Couldn't set filter" << endl;      printError();      DBUG_VOID_RETURN;    }    ndbout << "Cluster logging is " << (res_enable ? "enabled.":"disabled") << endl;    DBUG_VOID_RETURN;  }  do {    severity= NDB_MGM_ILLEGAL_EVENT_SEVERITY;    if (strcasecmp(item, "ALL") == 0) {      severity = NDB_MGM_EVENT_SEVERITY_ALL;	    } else if (strcasecmp(item, "ALERT") == 0) {      severity = NDB_MGM_EVENT_SEVERITY_ALERT;    } else if (strcasecmp(item, "CRITICAL") == 0) {       severity = NDB_MGM_EVENT_SEVERITY_CRITICAL;    } else if (strcasecmp(item, "ERROR") == 0) {      severity = NDB_MGM_EVENT_SEVERITY_ERROR;    } else if (strcasecmp(item, "WARNING") == 0) {      severity = NDB_MGM_EVENT_SEVERITY_WARNING;    } else if (strcasecmp(item, "INFO") == 0) {      severity = NDB_MGM_EVENT_SEVERITY_INFO;    } else if (strcasecmp(item, "DEBUG") == 0) {      severity = NDB_MGM_EVENT_SEVERITY_DEBUG;    } else if (strcasecmp(item, "OFF") == 0 ||	       strcasecmp(item, "ON") == 0) {      if (enable < 0) // only makes sense with toggle	severity = NDB_MGM_EVENT_SEVERITY_ON;    }    if (severity == NDB_MGM_ILLEGAL_EVENT_SEVERITY) {      ndbout << "Invalid severity level: " << item << endl;      DBUG_VOID_RETURN;    }    res_enable= ndb_mgm_set_clusterlog_severity_filter(m_mgmsrv, severity,						       enable, NULL);    if (res_enable < 0)    {      ndbout << "Couldn't set filter" << endl;      printError();      DBUG_VOID_RETURN;    }    ndbout << BaseString(item).ndb_toupper().c_str() << " " << (res_enable ? "enabled":"disabled") << endl;    item = strtok_r(NULL, " ", &tmpPtr);	  } while(item != NULL);  DBUG_VOID_RETURN;} //*****************************************************************************//*****************************************************************************voidCommandInterpreter::executeStop(int processId, const char *parameters,                                bool all) {  Vector<BaseString> command_list;  if (parameters)  {    BaseString tmp(parameters);    tmp.split(command_list);    for (unsigned i= 0; i < command_list.size();)      command_list[i].c_str()[0] ? i++ : (command_list.erase(i),0);  }  if (all)    executeStop(command_list, 0, 0, 0);  else    executeStop(command_list, 0, &processId, 1);}voidCommandInterpreter::executeStop(Vector<BaseString> &command_list,                                unsigned command_pos,                                int *node_ids, int no_of_nodes){  int abort= 0;  for (; command_pos < command_list.size(); command_pos++)  {    const char *item= command_list[command_pos].c_str();    if (strcasecmp(item, "-A") == 0)    {      abort= 1;      continue;    }    ndbout_c("Invalid option: %s. Expecting -A after STOP",             item);    return;  }  int result= ndb_mgm_stop2(m_mgmsrv, no_of_nodes, node_ids, abort);  if (result < 0)  {    ndbout_c("Shutdown failed.");    printError();  }  else  {    if (node_ids == 0)      ndbout_c("NDB Cluster has shutdown.");    else    {      ndbout << "Node";      for (int i= 0; i < no_of_nodes; i++)        ndbout << " " << node_ids[i];      ndbout_c(" has shutdown.");    }  }}voidCommandInterpreter::executeEnterSingleUser(char* parameters) {  strtok(parameters, " ");  struct ndb_mgm_reply reply;  char* id = strtok(NULL, " ");  id = strtok(NULL, " ");  id = strtok(NULL, "\0");  int nodeId = -1;  if(id == 0 || sscanf(id, "%d", &nodeId) != 1){    ndbout_c("Invalid arguments: expected <NodeId>");    ndbout_c("Use SHOW to see what API nodes are configured");    return;  }  int result = ndb_mgm_enter_single_user(m_mgmsrv, nodeId, &reply);    if (result != 0) {    ndbout_c("Entering single user mode for node %d failed", nodeId);    printError();  } else {    ndbout_c("Single user mode entered");    ndbout_c("Access is granted for API node %d only.", nodeId);  }}void CommandInterpreter::executeExitSingleUser(char* parameters) {  int result = ndb_mgm_exit_single_user(m_mgmsrv, 0);  if (result != 0) {    ndbout_c("Exiting single user mode failed.");    printError();  } else {    ndbout_c("Exiting single user mode in progress.");    ndbout_c("Use ALL STATUS or SHOW to see when single user mode has been exited.");  }}voidCommandInterpreter::executeStart(int processId, const char* parameters,				 bool all) {  int result;  if(all) {    result = ndb_mgm_start(m_mgmsrv, 0, 0);  } else {    result = ndb_mgm_start(m_mgmsrv, 1, &processId);  }  if (result <= 0) {    ndbout << "Start failed." << endl;    printError();  } else    {      if(all)	ndbout_c("NDB Cluster is being started.");      else	ndbout_c("Database node %d is being started.", processId);    }}voidCommandInterpreter::executeRestart(int processId, const char* parameters,				   bool all){  Vector<BaseString> command_list;  if (parameters)  {    BaseString tmp(parameters);    tmp.split(command_list);    for (unsigned i= 0; i < command_list.size();)      command_list[i].c_str()[0] ? i++ : (command_list.erase(i),0);  }  if (all)    executeRestart(command_list, 0, 0, 0);  else    executeRestart(command_list, 0, &processId, 1);}voidCommandInterpreter::executeRestart(Vector<BaseString> &command_list,                                   unsigned command_pos,                                   int *node_ids, int no_of_nodes){  int result;  int nostart= 0;  int initialstart= 0;  int abort= 0;  for (; command_pos < command_list.size(); command_pos++)  {    const char *item= command_list[command_pos].c_str();    if (strcasecmp(item, "-N") == 0)    {      nostart= 1;      continue;    }    if (strcasecmp(item, "-I") == 0)    {      initialstart= 1;      continue;    }    if (strcasecmp(item, "-A") == 0)    {      abort= 1;      continue;    }    ndbout_c("Invalid option: %s. Expecting -A,-N or -I after RESTART",             item);    return;  }  result= ndb_mgm_restart2(m_mgmsrv, no_of_nodes, node_ids,                           initialstart, nostart, abort);    if (result <= 0) {    ndbout_c("Restart failed.");    printError();  }  else  {    if (node_ids == 0)      ndbout_c("NDB Cluster is being restarted.");    else    {      ndbout << "Node";      for (int i= 0; i < no_of_nodes; i++)        ndbout << " " << node_ids[i];      ndbout_c(" is being restarted");    }  }}voidCommandInterpreter::executeDumpState(int processId, const char* parameters,				     bool all) {  if(emptyString(parameters)){    ndbout << "Expected argument" << endl;    return;  }  Uint32 no = 0;  int pars[25];    char * tmpString = my_strdup(parameters,MYF(MY_WME));  My_auto_ptr<char> ap1(tmpString);  char * tmpPtr = 0;  char * item = strtok_r(tmpString, " ", &tmpPtr);  while(item != NULL){    if (0x0 <= strtoll(item, NULL, 0) && strtoll(item, NULL, 0) <= 0xffffffff){      pars[no] = strtoll(item, NULL, 0);     } else {      ndbout << "Illegal value in argument to signal." << endl	     << "(Value must be between 0 and 0xffffffff.)" 	     << endl;      return;    }    no++;    item = strtok_r(NULL, " ", &tmpPtr);  }  ndbout << "Sending dump signal with data:" << endl;  for (Uint32 i=0; i<no; i++) {    ndbout.setHexFormat(1) << pars[i] << " ";    if (!(i+1 & 0x3)) ndbout << endl;  }    struct ndb_mgm_reply reply;  ndb_mgm_dump_state(m_mgmsrv, processId, pars, no, &reply);}void CommandInterpreter::executeStatus(int processId, 				  const char* parameters, bool all) {  if (! emptyString(parameters)) {    ndbout_c("No parameters expected to this command.");    return;  }  ndb_mgm_node_status status;  Uint32 startPhase, version;  bool system;    struct ndb_mgm_cluster_state *cl;  cl = ndb_mgm_get_status(m_mgmsrv);  if(cl == NULL) {    ndbout_c("Cannot get status of node %d.", processId);    printError();    return;  }  NdbAutoPtr<char> ap1((char*)cl);  int i = 0;  while((i < cl->no_of_nodes) && cl->node_states[i].node_id != processId)    i++;  if(cl->node_states[i].node_id != processId) {    ndbout << processId << ": Node not found" << endl;    return;  }  status = cl->node_states[i].node_status;  startPhase = cl->node_states[i].start_phase;  version = cl->node_states[i].version;  ndbout << "Node " << processId << ": " << status_string(status);  switch(status){  case NDB_MGM_NODE_STATUS_STARTING:    ndbout << " (Phase " << startPhase << ")";    break;  case NDB_MGM_NODE_STATUS_SHUTTING_DOWN:    ndbout << " (Phase " << startPhase << ")";    break;  default:    break;  }  if(status != NDB_MGM_NODE_STATUS_NO_CONTACT)    ndbout_c(" (Version %d.%d.%d)", 	     getMajor(version) ,	     getMinor(version),	     getBuild(version));  else    ndbout << endl;}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeLogLevel(int processId, const char* parameters, 				    bool all) {  (void) all;  if (emptyString(parameters)) {    ndbout << "Expected argument" << endl;    return;  }   BaseString tmp(parameters);  Vector<BaseString> spec;  tmp.split(spec, "=");  if(spec.size() != 2){    ndbout << "Invalid loglevel specification: " << parameters << endl;    return;  }  spec[0].trim().ndb_toupper();  int category = ndb_mgm_match_event_category(spec[0].c_str());  if(category == NDB_MGM_ILLEGAL_EVENT_CATEGORY){    category = atoi(spec[0].c_str());    if(category < NDB_MGM_MIN_EVENT_CATEGORY ||       category > NDB_MGM_MAX_EVENT_CATEGORY){      ndbout << "Unknown category: \"" << spec[0].c_str() << "\"" << endl;      return;    }  }    int level = atoi(spec[1].c_str());  if(level < 0 || level > 15){    ndbout << "Invalid level: " << spec[1].c_str() << endl;    return;  }    ndbout << "Executing LOGLEVEL on node " << processId << flush;  struct ndb_mgm_reply reply;  int result;  result = ndb_mgm_set_loglevel_node(m_mgmsrv, 				     processId,				     (ndb_mgm_event_category)category,				     level, 				     &reply);    if (result < 0) {    ndbout_c(" failed.");    printError();  } else {    ndbout_c(" OK!");  }    }//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeError(int processId, 				      const char* parameters, bool /* all */) {  if (emptyString(parameters)) {    ndbout << "Missing error number." << endl;    return;  }  // Copy parameters since strtok will modify it  char* newpar = my_strdup(parameters,MYF(MY_WME));   My_auto_ptr<char> ap1(newpar);  char* firstParameter = strtok(newpar, " ");  int errorNo;  if (! convert(firstParameter, errorNo)) {    ndbout << "Expected an integer." << endl;    return;  }  char* allAfterFirstParameter = strtok(NULL, "\0");  if (! emptyString(allAfterFirstParameter)) {    ndbout << "Nothing expected after error number." << endl;    return;  }  ndb_mgm_insert_error(m_mgmsrv, processId, errorNo, NULL);}//*****************************************************************************//*****************************************************************************void 

⌨️ 快捷键说明

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