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

📄 commandinterpreter.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
CommandInterpreter::executeLog(int processId,			       const char* parameters, bool all) {  struct ndb_mgm_reply reply;  Vector<const char *> blocks;  if (! parseBlockSpecification(parameters, blocks)) {    return;  }  int len=1;  Uint32 i;  for(i=0; i<blocks.size(); i++) {    len += strlen(blocks[i]) + 1;  }  char * blockNames = (char*)my_malloc(len,MYF(MY_WME));  My_auto_ptr<char> ap1(blockNames);    blockNames[0] = 0;  for(i=0; i<blocks.size(); i++) {    strcat(blockNames, blocks[i]);    strcat(blockNames, "|");  }    int result = ndb_mgm_log_signals(m_mgmsrv,				   processId, 				   NDB_MGM_SIGNAL_LOG_MODE_INOUT, 				   blockNames,				   &reply);  if (result != 0) {    ndbout_c("Execute LOG on node %d failed.", processId);    printError();  }}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeLogIn(int /* processId */,				 const char* parameters, bool /* all */) {  ndbout << "Command LOGIN not implemented." << endl;}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeLogOut(int /*processId*/, 				  const char* parameters, bool /*all*/) {  ndbout << "Command LOGOUT not implemented." << endl;}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeLogOff(int /*processId*/,				  const char* parameters, bool /*all*/) {  ndbout << "Command LOGOFF not implemented." << endl;}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeTestOn(int processId,				  const char* parameters, bool /*all*/) {  if (! emptyString(parameters)) {    ndbout << "No parameters expected to this command." << endl;    return;  }  struct ndb_mgm_reply reply;  int result = ndb_mgm_start_signallog(m_mgmsrv, processId, &reply);  if (result != 0) {    ndbout_c("Execute TESTON failed.");    printError();  }}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeTestOff(int processId,				   const char* parameters, bool /*all*/) {  if (! emptyString(parameters)) {    ndbout << "No parameters expected to this command." << endl;    return;  }  struct ndb_mgm_reply reply;  int result = ndb_mgm_stop_signallog(m_mgmsrv, processId, &reply);  if (result != 0) {    ndbout_c("Execute TESTOFF failed.");    printError();  }}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeSet(int /*processId*/, 			       const char* parameters, bool /*all*/) {  if (emptyString(parameters)) {    ndbout << "Missing parameter name." << endl;    return;  }#if 0  // Copy parameters since strtok will modify it  char* newpar = my_strdup(parameters,MYF(MY_WME));  My_auto_ptr<char> ap1(newpar);  char* configParameterName = strtok(newpar, " ");  char* allAfterParameterName = strtok(NULL, "\0");  if (emptyString(allAfterParameterName)) {    ndbout << "Missing parameter value." << endl;    return;  }  char* value = strtok(allAfterParameterName, " ");  char* allAfterValue = strtok(NULL, "\0");  if (! emptyString(allAfterValue)) {    ndbout << "Nothing expected after parameter value." << endl;    return;  }  bool configBackupFileUpdated;  bool configPrimaryFileUpdated;    // TODO The handling of the primary and backup config files should be   // analysed further.  // How it should be handled if only the backup is possible to write.  int result = _mgmtSrvr.updateConfigParam(processId, configParameterName, 					   value, configBackupFileUpdated, 					   configPrimaryFileUpdated);  if (result == 0) {    if (configBackupFileUpdated && configPrimaryFileUpdated) {      ndbout << "The configuration is updated." << endl;    }    else if (configBackupFileUpdated && !configPrimaryFileUpdated) {      ndbout << "The configuration is updated but it was only possible " 	     << "to update the backup configuration file, not the primary." 	     << endl;    }    else {      assert(false);    }  }  else {    ndbout << get_error_text(result) << endl;    if (configBackupFileUpdated && configPrimaryFileUpdated) {      ndbout << "The configuration files are however updated and "	     << "the value will be used next time the process is restarted." 	     << endl;    }    else if (configBackupFileUpdated && !configPrimaryFileUpdated) {      ndbout << "It was only possible to update the backup "	     << "configuration file, not the primary." << endl;    }    else if (!configBackupFileUpdated && !configPrimaryFileUpdated) {      ndbout << "The configuration files are not updated." << endl;    }    else {      // The primary is not tried to write if the write of backup file fails      abort();    }  }#endif}//*****************************************************************************//*****************************************************************************void CommandInterpreter::executeGetStat(int /*processId*/,					const char* parameters, bool /*all*/) {  if (! emptyString(parameters)) {    ndbout << "No parameters expected to this command." << endl;    return;  }#if 0  MgmtSrvr::Statistics statistics;  int result = _mgmtSrvr.getStatistics(processId, statistics);  if (result != 0) {    ndbout << get_error_text(result) << endl;    return;  }#endif  // Print statistic...  /*  ndbout << "Number of GETSTAT commands: "   << statistics._test1 << endl;  */}//*****************************************************************************//*****************************************************************************				 void CommandInterpreter::executeEventReporting(int processId,					  const char* parameters, 					  bool all) {  if (emptyString(parameters)) {    ndbout << "Expected argument" << endl;    return;  }  BaseString tmp(parameters);  Vector<BaseString> specs;  tmp.split(specs, " ");  for (int i=0; i < specs.size(); i++)  {    Vector<BaseString> spec;    specs[i].split(spec, "=");    if(spec.size() != 2){      ndbout << "Invalid loglevel specification: " << specs[i] << endl;      continue;    }    spec[0].trim().ndb_toupper();    int category = ndb_mgm_match_event_category(spec[0].c_str());    if(category == NDB_MGM_ILLEGAL_EVENT_CATEGORY){      if(!convert(spec[0].c_str(), category) ||	 category < NDB_MGM_MIN_EVENT_CATEGORY ||	 category > NDB_MGM_MAX_EVENT_CATEGORY){	ndbout << "Unknown category: \"" << spec[0].c_str() << "\"" << endl;	continue;      }    }    int level;    if (!convert(spec[1].c_str(),level))    {      ndbout << "Invalid level: " << spec[1].c_str() << endl;      continue;    }    ndbout << "Executing CLUSTERLOG " << spec[0] << "=" << spec[1]	   << " on node " << processId << flush;    struct ndb_mgm_reply reply;    int result;    result = ndb_mgm_set_loglevel_clusterlog(m_mgmsrv, 					     processId,					     (ndb_mgm_event_category)category,					     level, 					     &reply);      if (result != 0) {      ndbout_c(" failed.");       printError();    } else {      ndbout_c(" OK!");     }  }}/***************************************************************************** * Backup *****************************************************************************/intCommandInterpreter::executeStartBackup(char* parameters){  struct ndb_mgm_reply reply;  unsigned int backupId;#if 0  int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 };  int fd = ndb_mgm_listen_event(m_mgmsrv, filter);  if (fd < 0)  {    ndbout << "Initializing start of backup failed" << endl;    printError();    return fd;  }#endif  Vector<BaseString> args;  {    BaseString(parameters).split(args);    for (unsigned i= 0; i < args.size(); i++)      if (args[i].length() == 0)	args.erase(i--);      else	args[i].ndb_toupper();  }  int sz= args.size();  int result;  if (sz == 2 &&      args[1] == "NOWAIT")  {    result = ndb_mgm_start_backup(m_mgmsrv, 0, &backupId, &reply);  }  else if (sz == 1 ||	   (sz == 3 &&	    args[1] == "WAIT" &&	    args[2] == "COMPLETED"))  {    ndbout_c("Waiting for completed, this may take several minutes");    result = ndb_mgm_start_backup(m_mgmsrv, 2, &backupId, &reply);  }  else if (sz == 3 &&	   args[1] == "WAIT" &&	   args[2] == "STARTED")  {    ndbout_c("Waiting for started, this may take several minutes");    result = ndb_mgm_start_backup(m_mgmsrv, 1, &backupId, &reply);  }  else  {    invalid_command(parameters);    return -1;  }  if (result != 0) {    ndbout << "Start of backup failed" << endl;    printError();#if 0    close(fd);#endif    return result;  }#if 0  ndbout_c("Waiting for completed, this may take several minutes");  char *tmp;  char buf[1024];  {    SocketInputStream in(fd);    int count = 0;    do {      tmp = in.gets(buf, 1024);      if(tmp)      {	ndbout << tmp;	unsigned int id;	if(sscanf(tmp, "%*[^:]: Backup %d ", &id) == 1 && id == backupId){	  count++;	}      }    } while(count < 2);  }  SocketInputStream in(fd, 10);  do {    tmp = in.gets(buf, 1024);    if(tmp && tmp[0] != 0)    {      ndbout << tmp;    }  } while(tmp && tmp[0] != 0);  close(fd);#endif    return 0;}voidCommandInterpreter::executeAbortBackup(char* parameters) {  int bid = -1;  struct ndb_mgm_reply reply;  if (emptyString(parameters))    goto executeAbortBackupError1;  {    strtok(parameters, " ");    char* id = strtok(NULL, "\0");    if(id == 0 || sscanf(id, "%d", &bid) != 1)      goto executeAbortBackupError1;  }  {    int result= ndb_mgm_abort_backup(m_mgmsrv, bid, &reply);    if (result != 0) {      ndbout << "Abort of backup " << bid << " failed" << endl;      printError();    } else {      ndbout << "Abort of backup " << bid << " ordered" << endl;    }  }  return; executeAbortBackupError1:  ndbout << "Invalid arguments: expected <BackupId>" << endl;  return;}#ifdef HAVE_GLOBAL_REPLICATION/***************************************************************************** * Global Replication * * For information about the different commands, see * GrepReq::Request in file signaldata/grepImpl.cpp. * * Below are commands as of 2003-07-05 (may change!): * START = 0,            ///< Start Global Replication (all phases) * START_METALOG = 1,    ///< Start Global Replication (all phases) * START_METASCAN = 2,   ///< Start Global Replication (all phases) * START_DATALOG = 3,    ///< Start Global Replication (all phases) * START_DATASCAN = 4,   ///< Start Global Replication (all phases) * START_REQUESTOR = 5,  ///< Start Global Replication (all phases) * ABORT = 6,            ///< Immediate stop (removes subscription) * SLOW_STOP = 7,        ///< Stop after finishing applying current GCI epoch * FAST_STOP = 8,        ///< Stop after finishing applying all PS GCI epochs * START_TRANSFER = 9,   ///< Start SS-PS transfer * STOP_TRANSFER = 10,   ///< Stop SS-PS transfer * START_APPLY = 11,     ///< Start applying GCI epochs in SS * STOP_APPLY = 12,      ///< Stop applying GCI epochs in SS * STATUS = 13,           ///< Status * START_SUBSCR = 14, * REMOVE_BUFFERS = 15, * DROP_TABLE = 16 *****************************************************************************/voidCommandInterpreter::executeRep(char* parameters) {  if (emptyString(parameters)) {    ndbout << helpTextRep;    return;  }  char * line = my_strdup(parameters,MYF(MY_WME));  My_auto_ptr<char> ap1((char*)line);  char * firstToken = strtok(line, " ");    struct ndb_rep_reply  reply;  unsigned int          repId;  if (!strcasecmp(firstToken, "CONNECT")) {    char * host = strtok(NULL, "\0");    for (unsigned int i = 0; i < strlen(host); ++i) {      host[i] = tolower(host[i]);    }        if(host == NULL)    {      ndbout_c("host:port must be specified.");      return;    }        if(rep_connected) {      if(m_repserver != NULL) {	ndb_rep_disconnect(m_repserver);	rep_connected = false;      }           }              if(m_repserver == NULL)      m_repserver = ndb_rep_create_handle();    if(ndb_rep_connect(m_repserver, host) < 0)      ndbout_c("Failed to connect to %s", host);     el

⌨️ 快捷键说明

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