From 9c9ac185508260a90fcdc38c6150cb0f3553ca77 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.bredbandsbolaget.se" <> Date: Thu, 17 Jun 2004 22:18:05 +0000 Subject: [PATCH] removed need for specifying TCP connections in MySQL Cluster configuration --- mysql-test/ndb/ndb_config_2_node.ini | 60 +--------- ndb/src/common/mgmcommon/ConfigInfo.cpp | 111 ++++++++++++++++-- ndb/src/common/mgmcommon/ConfigInfo.hpp | 16 +++ .../common/mgmcommon/InitConfigFileParser.cpp | 34 ++++-- 4 files changed, 147 insertions(+), 74 deletions(-) diff --git a/mysql-test/ndb/ndb_config_2_node.ini b/mysql-test/ndb/ndb_config_2_node.ini index c4ff0aba80a..5acb757d253 100644 --- a/mysql-test/ndb/ndb_config_2_node.ini +++ b/mysql-test/ndb/ndb_config_2_node.ini @@ -73,63 +73,5 @@ ExecuteOnComputer: 6 Id: 14 ExecuteOnComputer: 7 -# Mgmtsrvr connections - -[TCP] -NodeId1: 1 -NodeId2: 2 +[TCP DEFAULT] PortNumber: CHOOSE_PORT_BASE02 - -[TCP] -NodeId1: 1 -NodeId2: 3 -PortNumber: CHOOSE_PORT_BASE03 - -# Ndb nodes connections - -[TCP] -NodeId1: 2 -NodeId2: 3 -PortNumber: CHOOSE_PORT_BASE04 - -# Api connections - -[TCP] -NodeId1: 11 -NodeId2: 2 -PortNumber: CHOOSE_PORT_BASE05 - -[TCP] -NodeId1: 11 -NodeId2: 3 -PortNumber: CHOOSE_PORT_BASE06 - -[TCP] -NodeId1: 12 -NodeId2: 2 -PortNumber: CHOOSE_PORT_BASE07 - -[TCP] -NodeId1: 12 -NodeId2: 3 -PortNumber: CHOOSE_PORT_BASE08 - -[TCP] -NodeId1: 13 -NodeId2: 2 -PortNumber: CHOOSE_PORT_BASE09 - -[TCP] -NodeId1: 13 -NodeId2: 3 -PortNumber: CHOOSE_PORT_BASE10 - -[TCP] -NodeId1: 14 -NodeId2: 2 -PortNumber: CHOOSE_PORT_BASE11 - -[TCP] -NodeId1: 14 -NodeId2: 3 -PortNumber: CHOOSE_PORT_BASE12 diff --git a/ndb/src/common/mgmcommon/ConfigInfo.cpp b/ndb/src/common/mgmcommon/ConfigInfo.cpp index c3e10dd3448..c2b5fdabf01 100644 --- a/ndb/src/common/mgmcommon/ConfigInfo.cpp +++ b/ndb/src/common/mgmcommon/ConfigInfo.cpp @@ -143,6 +143,19 @@ ConfigInfo::m_SectionRules[] = { }; const int ConfigInfo::m_NoOfRules = sizeof(m_SectionRules)/sizeof(SectionRule); +/**************************************************************************** + * Config Rules declarations + ****************************************************************************/ +bool addNodeConnections(Vector§ions, + struct InitConfigFileParser::Context &ctx, + const char * ruleData); + +const ConfigInfo::ConfigRule +ConfigInfo::m_ConfigRules[] = { + { addNodeConnections, 0 }, + { 0, 0 } +}; + struct DepricationTransform { const char * m_section; const char * m_oldName; @@ -1525,7 +1538,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ConfigInfo::USED, false, ConfigInfo::INT, - MANDATORY, + 2202, 0, 0x7FFFFFFF }, @@ -2712,13 +2725,13 @@ checkMandatory(InitConfigFileParser::Context & ctx, const char * data){ * Transform a string "NodeidX" (e.g. "uppsala.32") * into a Uint32 "NodeIdX" (e.g. 32) and a string "SystemX" (e.g. "uppsala"). */ -bool fixNodeId(InitConfigFileParser::Context & ctx, const char * data){ - +bool fixNodeId(InitConfigFileParser::Context & ctx, const char * data) +{ char buf[] = "NodeIdX"; buf[6] = data[sizeof("NodeI")]; char sysbuf[] = "SystemX"; sysbuf[6] = data[sizeof("NodeI")]; const char* nodeId; require(ctx.m_currentSection->get(buf, &nodeId)); - + char tmpLine[MAX_LINE_LENGTH]; strncpy(tmpLine, nodeId, MAX_LINE_LENGTH); char* token1 = strtok(tmpLine, "."); @@ -2739,7 +2752,6 @@ bool fixNodeId(InitConfigFileParser::Context & ctx, const char * data){ require(ctx.m_currentSection->put(buf, id, true)); require(ctx.m_currentSection->put(sysbuf, token1)); } - return true; } @@ -2862,9 +2874,9 @@ fixPortNumber(InitConfigFileParser::Context & ctx, const char * data){ Uint32 adder = 0; ctx.m_userProperties.get("PortNumberAdder", &adder); Uint32 base = 0; - if(!ctx.m_userDefaults->get("PortNumber", &base) && + if(!(ctx.m_userDefaults && ctx.m_userDefaults->get("PortNumber", &base)) && !ctx.m_systemDefaults->get("PortNumber", &base)){ - return true; + return false; } ctx.m_currentSection->put("PortNumber", base + adder); adder++; @@ -3144,3 +3156,88 @@ saveInConfigValues(InitConfigFileParser::Context & ctx, const char * data){ } while(0); return true; } + +bool +addNodeConnections(Vector§ions, + struct InitConfigFileParser::Context &ctx, + const char * ruleData) +{ + Properties * props= ctx.m_config; + Properties p_connections; + Properties p_connections2; + + for (Uint32 i = 0;; i++){ + const Properties * tmp; + Uint32 nodeId1, nodeId2; + + if(!props->get("Connection", i, &tmp)) break; + + if(!tmp->get("NodeId1", &nodeId1)) continue; + p_connections.put("", nodeId1, nodeId1); + if(!tmp->get("NodeId2", &nodeId2)) continue; + p_connections.put("", nodeId2, nodeId2); + + p_connections2.put("", nodeId1 + nodeId2<<16, nodeId1); + p_connections2.put("", nodeId2 + nodeId1<<16, nodeId2); + } + + Uint32 nNodes; + ctx.m_userProperties.get("NoOfNodes", &nNodes); + + Properties p_db_nodes; + Properties p_api_mgm_nodes; + + Uint32 i_db= 0, i_api_mgm= 0; + for (Uint32 i= 0, n= 0; n < nNodes; i++){ + const Properties * tmp; + if(!props->get("Node", i, &tmp)) continue; + n++; + + const char * type; + if(!tmp->get("Type", &type)) continue; + + if (strcmp(type,"DB") == 0) + p_db_nodes.put("", i_db++, i); + else if (strcmp(type,"API") == 0 || + strcmp(type,"MGM") == 0) + p_api_mgm_nodes.put("", i_api_mgm++, i); + } + + Uint32 nodeId1, nodeId2, dummy; + + for (Uint32 i= 0; p_db_nodes.get("", i, &nodeId1); i++){ + for (Uint32 j= i+1;; j++){ + if(!p_db_nodes.get("", j, &nodeId2)) break; + if(!p_connections2.get("", nodeId1+nodeId2<<16, &dummy)) { + ConfigInfo::ConfigRuleSection s; + s.m_sectionType= BaseString("TCP"); + s.m_sectionData= new Properties; + char buf[16]; + snprintf(buf, sizeof(buf), "%u", nodeId1); + s.m_sectionData->put("NodeId1", buf); + snprintf(buf, sizeof(buf), "%u", nodeId2); + s.m_sectionData->put("NodeId2", buf); + sections.push_back(s); + } + } + } + + for (Uint32 i= 0; p_api_mgm_nodes.get("", i, &nodeId1); i++){ + if(!p_connections.get("", nodeId1, &dummy)) { + for (Uint32 j= 0;; j++){ + if(!p_db_nodes.get("", j, &nodeId2)) break; + ConfigInfo::ConfigRuleSection s; + s.m_sectionType= BaseString("TCP"); + s.m_sectionData= new Properties; + char buf[16]; + snprintf(buf, sizeof(buf), "%u", nodeId1); + s.m_sectionData->put("NodeId1", buf); + snprintf(buf, sizeof(buf), "%u", nodeId2); + s.m_sectionData->put("NodeId2", buf); + sections.push_back(s); + } + } + } + + return true; +} diff --git a/ndb/src/common/mgmcommon/ConfigInfo.hpp b/ndb/src/common/mgmcommon/ConfigInfo.hpp index b5e011ed398..79c17b436fe 100644 --- a/ndb/src/common/mgmcommon/ConfigInfo.hpp +++ b/ndb/src/common/mgmcommon/ConfigInfo.hpp @@ -71,6 +71,21 @@ public: const char * m_ruleData; }; + /** + * Entry for config rule + */ + struct ConfigRuleSection { + BaseString m_sectionType; + Properties * m_sectionData; + }; + + struct ConfigRule { + bool (* m_configRule)(Vector&, + struct InitConfigFileParser::Context &, + const char * m_ruleData); + const char * m_ruleData; + }; + ConfigInfo(); /** @@ -113,6 +128,7 @@ private: public: static const SectionRule m_SectionRules[]; + static const ConfigRule m_ConfigRules[]; static const int m_NoOfRules; }; diff --git a/ndb/src/common/mgmcommon/InitConfigFileParser.cpp b/ndb/src/common/mgmcommon/InitConfigFileParser.cpp index f4a8e1a8cd4..c1e14104647 100644 --- a/ndb/src/common/mgmcommon/InitConfigFileParser.cpp +++ b/ndb/src/common/mgmcommon/InitConfigFileParser.cpp @@ -163,6 +163,30 @@ InitConfigFileParser::parseConfig(FILE * file) { return 0; } + for(size_t i = 0; ConfigInfo::m_ConfigRules[i].m_configRule != 0; i++){ + ctx.type = InitConfigFileParser::Undefined; + ctx.m_currentSection = 0; + ctx.m_userDefaults = 0; + ctx.m_currentInfo = 0; + ctx.m_systemDefaults = 0; + + Vector tmp; + if(!(* ConfigInfo::m_ConfigRules[i].m_configRule)(tmp, ctx, + ConfigInfo::m_ConfigRules[i].m_ruleData)) + return 0; + + for(size_t j = 0; jgetInfo(ctx.fname); + ctx.m_systemDefaults = m_info->getDefaults(ctx.fname); + if(!storeSection(ctx)) + return 0; + } + } + Uint32 nConnections = 0; Uint32 nComputers = 0; Uint32 nNodes = 0; @@ -499,28 +523,22 @@ bool InitConfigFileParser::storeSection(Context& ctx){ if(ctx.m_currentSection == NULL) return true; - for(int i = strlen(ctx.fname) - 1; i>=0; i--){ ctx.fname[i] = toupper(ctx.fname[i]); } - snprintf(ctx.pname, sizeof(ctx.pname), ctx.fname); - char buf[255]; if(ctx.type == InitConfigFileParser::Section) snprintf(buf, sizeof(buf), "%s", ctx.fname); if(ctx.type == InitConfigFileParser::DefaultSection) snprintf(buf, sizeof(buf), "%s DEFAULT", ctx.fname); - snprintf(ctx.fname, sizeof(ctx.fname), buf); if(ctx.type == InitConfigFileParser::Section){ for(int i = 0; im_NoOfRules; i++){ const ConfigInfo::SectionRule & rule = m_info->m_SectionRules[i]; - if(!strcmp(rule.m_section, "*") || !strcmp(rule.m_section, ctx.fname)){ - if(!(* rule.m_sectionRule)(ctx, rule.m_ruleData)){ + if(!strcmp(rule.m_section, "*") || !strcmp(rule.m_section, ctx.fname)) + if(!(* rule.m_sectionRule)(ctx, rule.m_ruleData)) return false; - } - } } }