📄 configinfo.cpp
字号:
pinfo.put64("Min", tmp_uint64); require(InitConfigFileParser::convertStringToUint64(param._max, tmp_uint64)); pinfo.put64("Max", tmp_uint64); break; } case CI_SECTION: pinfo.put("SectionType", (Uint32)UintPtr(param._default)); break; case CI_STRING: break; } // Check that pinfo is really new if (section->get(param._fname, &oldpinfo)) { ndbout << "Error: Parameter " << param._fname << " defined twice in section " << param._section << "." << endl; require(false); } // Add new pinfo to section section->put(param._fname, &pinfo); // Replace section with modified section m_info.put(param._section, section, true); if(param._type != ConfigInfo::CI_SECTION){ Properties * p; if(!m_systemDefaults.getCopy(param._section, &p)){ p = new Properties(true); } if(param._default != UNDEFINED && param._default != MANDATORY){ switch (param._type) { case CI_SECTION: break; case CI_STRING: require(p->put(param._fname, param._default)); break; case CI_BOOL: { bool tmp_bool; require(InitConfigFileParser::convertStringToBool(param._default, default_bool)); require(p->put(param._fname, default_bool)); break; } case CI_INT: case CI_INT64: { Uint64 tmp_uint64; require(InitConfigFileParser::convertStringToUint64(param._default, default_uint64)); require(p->put(param._fname, default_uint64)); break; } } } require(m_systemDefaults.put(param._section, p, true)); delete p; } } for (i=0; i<m_NoOfParams; i++) { if(m_ParamInfo[i]._section == NULL){ ndbout << "Check that each entry has a section failed." << endl; ndbout << "Parameter \"" << m_ParamInfo[i]._fname << endl; ndbout << "Edit file " << __FILE__ << "." << endl; require(false); } if(m_ParamInfo[i]._type == ConfigInfo::CI_SECTION) continue; const Properties * p = getInfo(m_ParamInfo[i]._section); if (!p || !p->contains(m_ParamInfo[i]._fname)) { ndbout << "Check that each pname has an fname failed." << endl; ndbout << "Parameter \"" << m_ParamInfo[i]._fname << "\" does not exist in section \"" << m_ParamInfo[i]._section << "\"." << endl; ndbout << "Edit file " << __FILE__ << "." << endl; require(false); } }}/**************************************************************************** * Getters ****************************************************************************/inline void warning(const char * src, const char * arg){ ndbout << "Illegal call to ConfigInfo::" << src << "() - " << arg << endl; require(false);}const Properties * ConfigInfo::getInfo(const char * section) const { const Properties * p; if(!m_info.get(section, &p)){ return 0; // warning("getInfo", section); } return p;}const Properties * ConfigInfo::getDefaults(const char * section) const { const Properties * p; if(!m_systemDefaults.get(section, &p)){ return 0; //warning("getDefaults", section); } return p;}staticUint64getInfoInt(const Properties * section, const char* fname, const char * type){ Uint32 val32; const Properties * p; if (section->get(fname, &p) && p->get(type, &val32)) { return val32; } Uint64 val64; if(p && p->get(type, &val64)){ return val64; } section->print(); if(section->get(fname, &p)){ p->print(); } warning(type, fname); return 0;}staticconst char *getInfoString(const Properties * section, const char* fname, const char * type){ const char* val; const Properties * p; if (section->get(fname, &p) && p->get(type, &val)) { return val; } warning(type, fname); return val;}Uint64ConfigInfo::getMax(const Properties * section, const char* fname) const { return getInfoInt(section, fname, "Max");}Uint64ConfigInfo::getMin(const Properties * section, const char* fname) const { return getInfoInt(section, fname, "Min");}Uint64ConfigInfo::getDefault(const Properties * section, const char* fname) const { return getInfoInt(section, fname, "Default");}const char*ConfigInfo::getDescription(const Properties * section, const char* fname) const { return getInfoString(section, fname, "Description");}boolConfigInfo::isSection(const char * section) const { for (int i = 0; i<m_noOfSectionNames; i++) { if(!strcasecmp(section, m_sectionNames[i])) return true; } return false;}const char*ConfigInfo::nameToAlias(const char * name) { for (int i = 0; m_sectionNameAliases[i].name != 0; i++) if(!strcasecmp(name, m_sectionNameAliases[i].name)) return m_sectionNameAliases[i].alias; return 0;}const char*ConfigInfo::getAlias(const char * section) { for (int i = 0; m_sectionNameAliases[i].name != 0; i++) if(!strcasecmp(section, m_sectionNameAliases[i].alias)) return m_sectionNameAliases[i].name; return 0;}boolConfigInfo::verify(const Properties * section, const char* fname, Uint64 value) const { Uint64 min, max; min = getInfoInt(section, fname, "Min"); max = getInfoInt(section, fname, "Max"); if(min > max){ warning("verify", fname); } if (value >= min && value <= max) return true; else return false;}ConfigInfo::Type ConfigInfo::getType(const Properties * section, const char* fname) const { return (ConfigInfo::Type) getInfoInt(section, fname, "Type");}ConfigInfo::StatusConfigInfo::getStatus(const Properties * section, const char* fname) const { return (ConfigInfo::Status) getInfoInt(section, fname, "Status");}/**************************************************************************** * Printers ****************************************************************************/void ConfigInfo::print() const { Properties::Iterator it(&m_info); for (const char* n = it.first(); n != NULL; n = it.next()) { print(n); }}void ConfigInfo::print(const char* section) const { ndbout << "****** " << section << " ******" << endl << endl; const Properties * sec = getInfo(section); Properties::Iterator it(sec); for (const char* n = it.first(); n != NULL; n = it.next()) { // Skip entries with different F- and P-names if (getStatus(sec, n) == ConfigInfo::CI_INTERNAL) continue; if (getStatus(sec, n) == ConfigInfo::CI_DEPRICATED) continue; if (getStatus(sec, n) == ConfigInfo::CI_NOTIMPLEMENTED) continue; print(sec, n); }}void ConfigInfo::print(const Properties * section, const char* parameter) const { ndbout << parameter; // ndbout << getDescription(section, parameter) << endl; switch (getType(section, parameter)) { case ConfigInfo::CI_BOOL: ndbout << " (Boolean value)" << endl; ndbout << getDescription(section, parameter) << endl; if (getDefault(section, parameter) == false) { ndbout << "Default: N (Legal values: Y, N)" << endl; } else if (getDefault(section, parameter) == true) { ndbout << "Default: Y (Legal values: Y, N)" << endl; } else if (getDefault(section, parameter) == (UintPtr)MANDATORY) { ndbout << "MANDATORY (Legal values: Y, N)" << endl; } else { ndbout << "UNKNOWN" << endl; } ndbout << endl; break; case ConfigInfo::CI_INT: case ConfigInfo::CI_INT64: ndbout << " (Non-negative Integer)" << endl; ndbout << getDescription(section, parameter) << endl; if (getDefault(section, parameter) == (UintPtr)MANDATORY) { ndbout << "MANDATORY ("; } else if (getDefault(section, parameter) == (UintPtr)UNDEFINED) { ndbout << "UNDEFINED ("; } else { ndbout << "Default: " << getDefault(section, parameter) << " ("; } ndbout << "Min: " << getMin(section, parameter) << ", "; ndbout << "Max: " << getMax(section, parameter) << ")" << endl; ndbout << endl; break; case ConfigInfo::CI_STRING: ndbout << " (String)" << endl; ndbout << getDescription(section, parameter) << endl; if (getDefault(section, parameter) == (UintPtr)MANDATORY) { ndbout << "MANDATORY" << endl; } else { ndbout << "No default value" << endl; } ndbout << endl; break; case ConfigInfo::CI_SECTION: break; }}/**************************************************************************** * Section Rules ****************************************************************************//** * Node rule: Add "Type" and update "NoOfNodes" */booltransformNode(InitConfigFileParser::Context & ctx, const char * data){ Uint32 id, line; if(!ctx.m_currentSection->get("NodeId", &id) && !ctx.m_currentSection->get("Id", &id)){ Uint32 nextNodeId= 1; ctx.m_userProperties.get("NextNodeId", &nextNodeId); id= nextNodeId; while (ctx.m_userProperties.get("AllocatedNodeId_", id, &line)) id++; if (id != nextNodeId) { fprintf(stderr,"Cluster configuration warning line %d: " "Could not use next node id %d for section [%s], " "using next unused node id %d.\n", ctx.m_sectionLineno, nextNodeId, ctx.fname, id); } ctx.m_currentSection->put("NodeId", id); } else if(ctx.m_userProperties.get("AllocatedNodeId_", id, &line)) { ctx.reportError("Duplicate nodeid in section " "[%s] starting at line: %d. Previously used on line %d.", ctx.fname, ctx.m_sectionLineno, line); return false; } // next node id _always_ next numbers after last used id ctx.m_userProperties.put("NextNodeId", id+1, true); ctx.m_userProperties.put("AllocatedNodeId_", id, ctx.m_sectionLineno); BaseString::snprintf(ctx.pname, sizeof(ctx.pname), "Node_%d", id); ctx.m_currentSection->put("Type", ctx.fname); Uint32 nodes = 0; ctx.m_userProperties.get("NoOfNodes", &nodes); ctx.m_userProperties.put("NoOfNodes", ++nodes, true); /** * Update count (per type) */ nodes = 0; ctx.m_userProperties.get(ctx.fname, &nodes); ctx.m_userProperties.put(ctx.fname, ++nodes, true); return true;}static bool checkLocalhostHostnameMix(InitConfigFileParser::Context & ctx, const char * data){ DBUG_ENTER("checkLocalhostHostnameMix"); const char * hostname= 0; ctx.m_currentSection->get("HostName", &hostname); if (hostname == 0 || hostname[0] == 0) DBUG_RETURN(true); Uint32 localhost_used= 0; if(!strcmp(hostname, "localhost") || !strcmp(hostname, "127.0.0.1")){ localhost_used= 1; ctx.m_userProperties.put("$computer-localhost-used", localhost_used); if(!ctx.m_userProperties.get("$computer-localhost", &hostname)) DBUG_RETURN(true); } else { ctx.m_userProperties.get("$computer-localhost-used", &localhost_used); ctx.m_userProperties.put("$computer-localhost", hostname); } if (localhost_used) { ctx.reportError("Mixing of localhost (default for [NDBD]HostName) with other hostname(%s) is illegal", hostname); DBUG_RETURN(false); } DBUG_RETURN(true);}boolfixNodeHostname(InitConfigFileParser::Context & ctx, const char * data){ const char * hostname; DBUG_ENTER("fixNodeHostname"); if (ctx.m_currentSection->get("HostName", &hostname)) DBUG_RETURN(checkLocalhostHostnameMix(ctx,0)); const char * compId; if(!ctx.m_currentSection->get("ExecuteOnComputer", &compId)) DBUG_RETURN(true); const Properties * computer; char tmp[255]; BaseString::snprintf(tmp, sizeof(tmp), "Computer_%s", compId); if(!ctx.m_config->get(tmp, &computer)){ ctx.reportError("Computer \"%s\" not declared" "- [%s] starting at line: %d", compId, ctx.fname, ctx.m_sectionLineno); DBUG_RETURN(false); } if(!computer->get("HostName", &hostname)){ ctx.reportError("HostName missing in [COMPUTER] (Id: %d) " " - [%s] starting at line: %d", compId, ctx.fname, ctx.m_sectionLineno); DBUG_RETURN(false); } require(ctx.m_currentSection->put("HostName", hostname)); DBUG_RETURN(checkLocalhostHostnameMix(ctx,0));}boolfixFileSystemPath(InitConfigFileParser::Context & ctx, const char * data){ DBUG_ENTER("fixFileSystemPath"); const char * path; if (ctx.m_currentSection->get("FileSystemPath", &path)) DBUG_RETURN(true); if (ctx.m_currentSection->get("DataDir", &path)) { require(ctx.m_currentSection->put("FileSystemPath", path)); DBUG_RETURN(true); } require(false); DBUG_RETURN(false);}boolfixBackupDataDir(InitConfigFileParser::Context & ctx, const char * data){ const char * path; if (ctx.m_currentSection->get("BackupDataDir", &path)) return true; if (ctx.m_currentSection->get("FileSystemPath", &path)) { require(ctx.m_currentSection->put("BackupDataDir", path)); return true; } require(false); return false;}/** * Connection rule: Check support of connection */boolcheckConnectionSupport(InitConfigFileParser::Context & ctx, const char * data){ int error= 0; if (strcasecmp("TCP",ctx.fname) == 0) { // always enabled } else if (strcasecmp("SHM",ctx.fname) == 0) {#ifndef NDB_SHM_TRANSPORTER error= 1;#endif } else if (strcasecmp("SCI",ctx.fname) == 0) {#ifndef NDB_SCI_TRANSPORTER error= 1;#endif } else if (strcasecmp("OSE",ctx.fname) == 0) {#ifndef NDB_OSE_TRANSPORTER error= 1;#endif } if (error) { ctx.reportError("Binary not compiled with this connection support, " "[%s] starting at line: %d", ctx.fname, ctx.m_sectionLineno); return false; } return true;}/** * Connection rule: Update "NoOfConnections" */booltransformConnection(InitConfigFileParser::Context & ctx, const char * data){ Uint32 connections = 0; ctx.m_userProperties.get("NoOfConnections", &connections); BaseString::snprintf(ctx.pname, sizeof(ctx.pname), "Connection_%d", connections); ctx.m_userProperties.put("NoOfConnections", ++connections, true); ctx.m_currentSection->put("Type", ctx.fname); return true;}/** * System rule: Just add it */booltransformSystem(InitConfigFileParser::Context & ctx, const char * data){ const char * name; if(!ctx.m_currentSection->get("Name", &name)){ ctx.reportError("Mandatory parameter Name missing from section " "[%s] starting at line: %d", ctx.fname, ctx.m_sectionLineno); return false; } ndbout << "transformSystem " << name << endl; BaseString::snprintf(ctx.pname, sizeof(ctx.pname), "SYSTEM_%s", name); return true;}/** * Computer rule: Update "NoOfComputers", add "Type" */booltransformComputer(InitConfigFileParser::Context & ctx, const char * data){ const char * id; if(!ctx.m_currentSection->get("Id", &id)){ ctx.reportError("Mandatory parameter Id missing from section " "[%s] starting at line: %d", ctx.fname, ctx.m_sectionLineno); return false; } BaseString::snprintf(ctx.pname, sizeof(ctx.pname), "Computer_%s", id); Uint32 computers = 0; ctx.m_userProperties.get("NoOfComputers", &computers); ctx.m_userProperties.put("NoOfComputers", ++computers, true); const char * hostname = 0; ctx.m_currentSection->get("HostName", &hostname); if(!hostname){ return true; } return checkLocalhostHostnameMix(ctx,0);}/** * Apply default values */void applyDefaultValues(InitConfigFileParser::Context & ctx, const Properties * defaults){ DBUG_ENTER("applyDefaultValues"); if(defaults != NULL){ Properties::Iterator it(defaults); for(const char * name = it.first(); name != NULL; name = it.next()){ ConfigInfo::Status st = ctx.m_info->getStatus(ctx.m_currentInfo, name); if(!ctx.m_currentSection->contains(name)){ switch (ctx.m_info->getType(ctx.m_currentInfo, name)){ case ConfigInfo::CI_INT: case ConfigInfo::CI_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -