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

📄 configuration.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2003 MySQL AB   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <ndb_global.h>#include <ndb_opts.h>#include "Configuration.hpp"#include <ErrorHandlingMacros.hpp>#include "GlobalData.hpp"#include <ConfigRetriever.hpp>#include <IPCConfig.hpp>#include <ndb_version.h>#include <NdbMem.h>#include <NdbOut.hpp>#include <WatchDog.hpp>#include <mgmapi_configuration.hpp>#include <mgmapi_config_parameters_debug.h>#include <kernel_config_parameters.h>#include <kernel_types.h>#include <ndb_limits.h>#include <ndbapi_limits.h>#include "pc.hpp"#include <LogLevel.hpp>#include <NdbSleep.h>extern "C" {  void ndbSetOwnVersion();}#include <EventLogger.hpp>extern EventLogger g_eventLogger;enum ndbd_options {  OPT_INITIAL = NDB_STD_OPTIONS_LAST,  OPT_NODAEMON,  OPT_FOREGROUND};NDB_STD_OPTS_VARS;// XXX should be my_bool ???static int _daemon, _no_daemon, _foreground,  _initial, _no_start;static int _initialstart;static const char* _nowait_nodes;extern Uint32 g_start_type;extern NdbNodeBitmask g_nowait_nodes;/** * Arguments to NDB process */ static struct my_option my_long_options[] ={  NDB_STD_OPTS("ndbd"),  { "initial", OPT_INITIAL,    "Perform initial start of ndbd, including cleaning the file system. "    "Consult documentation before using this",    (gptr*) &_initial, (gptr*) &_initial, 0,    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },  { "nostart", 'n',    "Don't start ndbd immediately. Ndbd will await command from ndb_mgmd",    (gptr*) &_no_start, (gptr*) &_no_start, 0,    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },  { "daemon", 'd', "Start ndbd as daemon (default)",    (gptr*) &_daemon, (gptr*) &_daemon, 0,    GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },  { "nodaemon", OPT_NODAEMON,    "Do not start ndbd as daemon, provided for testing purposes",    (gptr*) &_no_daemon, (gptr*) &_no_daemon, 0,    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },  { "foreground", OPT_FOREGROUND,    "Run real ndbd in foreground, provided for debugging purposes"    " (implies --nodaemon)",    (gptr*) &_foreground, (gptr*) &_foreground, 0,    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },  { "nowait-nodes", NO_ARG,     "Nodes that will not be waited for during start",    (gptr*) &_nowait_nodes, (gptr*) &_nowait_nodes, 0,    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },  { "initial-start", NO_ARG,     "Perform initial start",    (gptr*) &_initialstart, (gptr*) &_initialstart, 0,    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}};static void short_usage_sub(void){  printf("Usage: %s [OPTIONS]\n", my_progname);}static void usage(){  short_usage_sub();  ndb_std_print_version();  my_print_help(my_long_options);  my_print_variables(my_long_options);}boolConfiguration::init(int argc, char** argv){    const char *load_default_groups[]= { "mysql_cluster","ndbd",0 };  load_defaults("my",load_default_groups,&argc,&argv);  int ho_error;#ifndef DBUG_OFF  opt_debug= "d:t:O,/tmp/ndbd.trace";#endif  if ((ho_error=handle_options(&argc, &argv, my_long_options,			       ndb_std_get_one_option)))    exit(ho_error);  if (_no_daemon || _foreground) {    _daemon= 0;  }  DBUG_PRINT("info", ("no_start=%d", _no_start));  DBUG_PRINT("info", ("initial=%d", _initial));  DBUG_PRINT("info", ("daemon=%d", _daemon));  DBUG_PRINT("info", ("foreground=%d", _foreground));  DBUG_PRINT("info", ("connect_str=%s", opt_connect_str));  ndbSetOwnVersion();  // Check the start flag  if (_no_start)    globalData.theRestartFlag = initial_state;  else     globalData.theRestartFlag = perform_start;  // Check the initial flag  if (_initial)    _initialStart = true;    // Check connectstring  if (opt_connect_str)    _connectString = strdup(opt_connect_str);    // Check daemon flag  if (_daemon)    _daemonMode = true;  if (_foreground)    _foregroundMode = true;  // Save programname  if(argc > 0 && argv[0] != 0)    _programName = strdup(argv[0]);  else    _programName = strdup("");    globalData.ownId= 0;  if (_nowait_nodes)  {    BaseString str(_nowait_nodes);    Vector<BaseString> arr;    str.split(arr, ",");    for (Uint32 i = 0; i<arr.size(); i++)    {      char *endptr = 0;      long val = strtol(arr[i].c_str(), &endptr, 10);      if (*endptr)      {	ndbout_c("Unable to parse nowait-nodes argument: %s : %s", 		 arr[i].c_str(), _nowait_nodes);	exit(-1);      }      if (! (val > 0 && val < MAX_NDB_NODES))      {	ndbout_c("Invalid nodeid specified in nowait-nodes: %d : %s", 		 val, _nowait_nodes);	exit(-1);      }      g_nowait_nodes.set(val);    }  }  if (_initialstart)  {    _initialStart = true;    g_start_type |= (1 << NodeState::ST_INITIAL_START);  }    return true;}Configuration::Configuration(){  _programName = 0;  _connectString = 0;  _fsPath = 0;  _backupPath = 0;  _initialStart = false;  _daemonMode = false;  _foregroundMode = false;  m_config_retriever= 0;  m_clusterConfig= 0;  m_clusterConfigIter= 0;  m_logLevel= 0;}Configuration::~Configuration(){  if (opt_connect_str)    free(_connectString);  if(_programName != NULL)    free(_programName);  if(_fsPath != NULL)    free(_fsPath);  if(_backupPath != NULL)    free(_backupPath);  if (m_config_retriever) {    delete m_config_retriever;  }  if(m_logLevel) {    delete m_logLevel;  }}voidConfiguration::closeConfiguration(bool end_session){  m_config_retriever->end_session(end_session);  if (m_config_retriever) {    delete m_config_retriever;  }  m_config_retriever= 0;}voidConfiguration::fetch_configuration(){  /**   * Fetch configuration from management server   */  if (m_config_retriever) {    delete m_config_retriever;  }  m_mgmd_port= 0;  m_config_retriever= new ConfigRetriever(getConnectString(),					  NDB_VERSION, NODE_TYPE_DB);  if (m_config_retriever->hasError())  {    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG,	      "Could not connect initialize handle to management server",	      m_config_retriever->getErrorString());  }  if(m_config_retriever->do_connect(12,5,1) == -1){    const char * s = m_config_retriever->getErrorString();    if(s == 0)      s = "No error given!";    /* Set stop on error to true otherwise NDB will       go into an restart loop...    */    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Could not connect to ndb_mgmd", s);  }    m_mgmd_port= m_config_retriever->get_mgmd_port();  m_mgmd_host.assign(m_config_retriever->get_mgmd_host());  ConfigRetriever &cr= *m_config_retriever;    /**   * if we have a nodeid set (e.g in a restart situation)   * reuse it   */  if (globalData.ownId)    cr.setNodeId(globalData.ownId);  globalData.ownId = cr.allocNodeId(2 /*retry*/,3 /*delay*/);    if(globalData.ownId == 0){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, 	      "Unable to alloc node id", m_config_retriever->getErrorString());  }    ndb_mgm_configuration * p = cr.getConfig();  if(p == 0){    const char * s = cr.getErrorString();    if(s == 0)      s = "No error given!";        /* Set stop on error to true otherwise NDB will       go into an restart loop...    */        ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Could not fetch configuration"	      "/invalid configuration", s);  }  if(m_clusterConfig)    free(m_clusterConfig);    m_clusterConfig = p;    ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);  if (iter.find(CFG_NODE_ID, globalData.ownId)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", "DB missing");  }    if(iter.get(CFG_DB_STOP_ON_ERROR, &_stopOnError)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", 	      "StopOnError missing");  }  m_mgmds.clear();  for(ndb_mgm_first(&iter); ndb_mgm_valid(&iter); ndb_mgm_next(&iter))  {    Uint32 nodeType, port;    char const *hostname;    ndb_mgm_get_int_parameter(&iter,CFG_TYPE_OF_SECTION,&nodeType);    if (nodeType != NodeInfo::MGM)      continue;    if (ndb_mgm_get_string_parameter(&iter,CFG_NODE_HOST, &hostname) ||	ndb_mgm_get_int_parameter(&iter,CFG_MGM_PORT, &port) ||	hostname == 0 || hostname[0] == 0)    {      continue;    }    BaseString connectstring(hostname);    connectstring.appfmt(":%d", port);    m_mgmds.push_back(connectstring);  }}static char * get_and_validate_path(ndb_mgm_configuration_iterator &iter,				    Uint32 param, const char *param_string){   const char* path = NULL;  if(iter.get(param, &path)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched missing ", 	      param_string);  }     if(path == 0 || strlen(path) == 0){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG,	      "Invalid configuration fetched. Configuration does not contain valid ",	      param_string);  }    // check that it is pointing on a valid directory  //   char buf2[PATH_MAX];  memset(buf2, 0,sizeof(buf2));#ifdef NDB_WIN32  char* szFilePart;  if(!GetFullPathName(path, sizeof(buf2), buf2, &szFilePart) ||     (GetFileAttributes(buf2) & FILE_ATTRIBUTE_READONLY))#else  if((::realpath(path, buf2) == NULL)||       (::access(buf2, W_OK) != 0))#endif  {    ERROR_SET(fatal, NDBD_EXIT_AFS_INVALIDPATH, path, param_string);  }    if (strcmp(&buf2[strlen(buf2) - 1], DIR_SEPARATOR))    strcat(buf2, DIR_SEPARATOR);    return strdup(buf2);}voidConfiguration::setupConfiguration(){  DBUG_ENTER("Configuration::setupConfiguration");  ndb_mgm_configuration * p = m_clusterConfig;  /**   * Configure transporters   */  {      int res = IPCConfig::configureTransporters(globalData.ownId,					       * p, 					       globalTransporterRegistry);    if(res <= 0){      ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", 		"No transporters configured");    }  }  /**   * Setup cluster configuration data   */  ndb_mgm_configuration_iterator iter(* p, CFG_SECTION_NODE);  if (iter.find(CFG_NODE_ID, globalData.ownId)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", "DB missing");  }  unsigned type;  if(!(iter.get(CFG_TYPE_OF_SECTION, &type) == 0 && type == NODE_TYPE_DB)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched",	      "I'm wrong type of node");  }    if(iter.get(CFG_DB_NO_SAVE_MSGS, &_maxErrorLogs)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", 	      "MaxNoOfSavedMessages missing");  }    if(iter.get(CFG_DB_MEMLOCK, &_lockPagesInMainMemory)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", 	      "LockPagesInMainMemory missing");  }  if(iter.get(CFG_DB_WATCHDOG_INTERVAL, &_timeBetweenWatchDogCheck)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", 	      "TimeBetweenWatchDogCheck missing");  }  /**   * Get paths   */    if (_fsPath)    free(_fsPath);  _fsPath= get_and_validate_path(iter, CFG_DB_FILESYSTEM_PATH, "FileSystemPath");  if (_backupPath)    free(_backupPath);  _backupPath= get_and_validate_path(iter, CFG_DB_BACKUP_DATADIR, "BackupDataDir");  if(iter.get(CFG_DB_STOP_ON_ERROR_INSERT, &m_restartOnErrorInsert)){    ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Invalid configuration fetched", 

⌨️ 快捷键说明

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