23 #include "ConfigInfo.hpp"
25 #include <HashMap.hpp>
28 m_configValues(config_values)
38 Config::Config(
const Config* conf)
52 ndb_mgm_destroy_configuration(m_configValues);
59 CFG_SECTION_CONNECTION
61 const size_t num_sections=
sizeof(sections)/
sizeof(
unsigned);
66 Config::print(
const char* section_filter, NodeId nodeid_filter,
67 const char* param_filter,
70 for(
unsigned i= 0;
i < num_sections;
i++) {
71 unsigned section= sections[
i];
77 for(;it.valid();it.next()) {
80 if(it.get(CFG_TYPE_OF_SECTION, §ion_type) != 0)
88 const char* section_name= g_info.sectionName(section, section_type);
92 strcmp(section_filter, section_name))
97 it.get(CFG_NODE_ID, &nodeid);
99 nodeid_filter != nodeid)
106 while((pinfo= param_iter.next())){
110 strcmp(param_filter, pinfo->_fname))
115 out <<
"[" << section_name <<
"]" << endl;
120 out << pinfo->_fname <<
"=" << val << endl;
121 else if (!it.get(pinfo->
_paramId, &val64))
122 out << pinfo->_fname <<
"=" << val64 << endl;
123 else if (!it.get(pinfo->
_paramId, &val_str))
124 out << pinfo->_fname <<
"=" << val_str << endl;
133 Config::getGeneration()
const
138 if (iter.get(CFG_SYS_CONFIG_GENERATION, &generation))
146 Config::getPrimaryMgmNode()
const
148 Uint32 primaryMgmNode;
151 if (iter.get(CFG_SYS_PRIMARY_MGM_NODE, &primaryMgmNode))
154 return primaryMgmNode;
159 Config::getName()
const
164 if (iter.get(CFG_SYS_NAME, &name))
172 Config::setValue(Uint32 section, Uint32 section_no,
173 Uint32
id, Uint32 new_val)
176 if (!iter.openSection(section, section_no))
179 if (!iter.set(
id, new_val))
187 Config::setValue(Uint32 section, Uint32 section_no,
188 Uint32
id,
const char* new_val)
191 if (!iter.openSection(section, section_no))
194 if (!iter.set(
id, new_val))
202 Config::setGeneration(Uint32 new_gen)
204 return setValue(CFG_SECTION_SYSTEM, 0,
205 CFG_SYS_CONFIG_GENERATION,
211 Config::setPrimaryMgmNode(Uint32 new_primary)
213 return setValue(CFG_SECTION_SYSTEM, 0,
214 CFG_SYS_PRIMARY_MGM_NODE,
220 Config::setName(
const char* new_name)
222 return setValue(CFG_SECTION_SYSTEM, 0,
231 return m_configValues->m_config.pack(buf);
235 #include <ndb_base64.h>
241 if (m_configValues->m_config.pack(buf) == 0)
246 base64_needed_encoded_length(buf.length()),
249 if (base64_encode(buf.get_data(),
251 (
char*)encoded.
c_str()))
266 add_diff(
const char* name,
const char* key,
272 if (!diff.getCopy(key, §ion)){
274 new_section.put(
"Key", key);
275 new_section.put(
"Name", name);
277 require(diff.
put(key, &new_section));
280 require(diff.getCopy(key, §ion));
285 require(value->get(
"Type", &type));
287 require(value->
put(
"Name", value_name));
291 if (!section->
put(value_name, value))
292 require(section->getPropertiesErrno() ==
293 E_PROPERTIES_ELEMENT_ALREADY_EXISTS);
296 require(diff.
put(key, section,
true));
303 compare_value(
const char* name,
const char* key,
312 if (it.get(pid, &val) ==
true) {
314 if (it2.get(pid, &val2) ==
true) {
317 info.put(
"Type", DT_DIFF);
318 info.put(
"New", val2);
319 info.put(
"Old", val);
322 pinfo->_fname, &info);
328 info.put(
"Type", DT_MISSING_VALUE);
329 info.put(
"Old", val);
332 pinfo->_fname, &info);
340 if (it.get(pid, &val) ==
true) {
342 if (it2.get(pid, &val2) ==
true) {
345 info.put(
"Type", DT_DIFF);
346 info.put64(
"New", Uint64(val2));
347 info.put64(
"Old", Uint64(val));
350 pinfo->_fname, &info);
356 info.put(
"Type", DT_MISSING_VALUE);
357 info.put64(
"Old", Uint64(val));
360 pinfo->_fname, &info);
368 if (it.get(pid, &val) ==
true) {
370 if (it2.get(pid, &val2) ==
true) {
371 if (strcmp(val, val2)) {
373 info.put(
"Type", DT_DIFF);
374 info.put(
"New", val2);
375 info.put(
"Old", val);
378 pinfo->_fname, &info);
384 info.put(
"Type", DT_MISSING_VALUE);
385 info.put(
"Old", val);
388 pinfo->_fname, &info);
407 while((pinfo= param_iter.next())) {
409 compare_value(
"SYSTEM",
"", pinfo, itA.m_config, itB.m_config, diff);
419 for(;itA.valid(); itA.next())
424 require(itA.get(CFG_TYPE_OF_SECTION, &nodeType) == 0);
430 require(itA.get(CFG_NODE_ID, &nodeId) == 0);
433 key.
assfmt(
"NodeId=%d", nodeId);
437 if (itB.find(CFG_NODE_ID, nodeId) != 0)
441 info.put(
"Type", DT_MISSING_SECTION);
442 info.put(
"Why",
"Node removed");
443 add_diff(name.c_str(), key.c_str(),
445 "Node removed", &info);
452 require(itB.get(CFG_TYPE_OF_SECTION, &nodeType2) == 0);
453 if ((nodeType == NODE_TYPE_DB || nodeType == NODE_TYPE_MGM) &&
454 nodeType != nodeType2)
458 info.put(
"Type", DT_ILLEGAL_CHANGE);
459 info.put(
"Why",
"Node has changed type");
460 add_diff(name.c_str(), key.c_str(),
462 "Node type changed", &info);
469 while((pinfo= param_iter.next())) {
471 compare_value(name.c_str(), key.c_str(), pinfo,
472 itA.m_config, itB.m_config, diff);
481 NodePair(Uint32 n1, Uint32 n2) : nodeId1(n1), nodeId2(n2) {};
493 Uint32 nodeId1, nodeId2;
495 for(; itB.valid(); itB.next())
497 require(itB.get(CFG_CONNECTION_NODE_1, &nodeId1) == 0);
498 require(itB.get(CFG_CONNECTION_NODE_2, &nodeId2) == 0);
500 require(lookup.insert(
NodePair(nodeId1, nodeId2), itB.m_sectionNo));
506 for(;itA.valid(); itA.next())
509 Uint32 connectionType;
510 require(itA.get(CFG_TYPE_OF_SECTION, &connectionType) == 0);
512 BaseString name(g_info.sectionName(CFG_SECTION_CONNECTION, connectionType));
515 Uint32 nodeId1_A, nodeId2_A;
516 require(itA.get(CFG_CONNECTION_NODE_1, &nodeId1_A) == 0);
517 require(itA.get(CFG_CONNECTION_NODE_2, &nodeId2_A) == 0);
520 key.
assfmt(
"NodeId1=%d;NodeId2=%d", nodeId1_A, nodeId2_A);
524 if (!lookup.search(
NodePair(nodeId1_A, nodeId2_A), sectionNo))
528 info.put(
"Type", DT_MISSING_SECTION);
529 info.put(
"Why",
"Connection removed");
530 add_diff(name.c_str(), key.c_str(),
532 "Connection removed", &info);
539 require(itB.openSection(CFG_SECTION_CONNECTION, sectionNo) ==
true);
541 Uint32 nodeId1_B, nodeId2_B;
542 require(itB.get(CFG_CONNECTION_NODE_1, &nodeId1_B) ==
true);
543 require(itB.get(CFG_CONNECTION_NODE_2, &nodeId2_B) ==
true);
544 require(nodeId1_A == nodeId1_B && nodeId2_A == nodeId2_B);
549 CFG_SECTION_CONNECTION,
551 while((pinfo= param_iter.next())) {
553 compare_value(name.c_str(), key.c_str(), pinfo, itA.m_config, itB, diff);
560 include_section(
const unsigned* exclude,
unsigned section){
565 if (*exclude == section)
578 const unsigned* exclude)
const {
580 if (include_section(exclude, CFG_SECTION_SYSTEM)) {
581 diff_system(
this, other, diff);
582 diff_system(other,
this, diff);
584 if (include_section(exclude, CFG_SECTION_NODE)) {
585 diff_nodes(
this, other, diff);
586 diff_nodes(other,
this, diff);
588 if (include_section(exclude, CFG_SECTION_CONNECTION)) {
589 diff_connections(
this, other, diff);
590 diff_connections(other,
this, diff);
598 require(prop->getTypeOf(name, &type));
600 case PropertiesType_Uint32:
603 require(prop->get(name, &val));
607 case PropertiesType_Uint64:
610 require(prop->get(name, &val));
614 case PropertiesType_char:
616 require(prop->get(name, buf));
632 while ((name= prop_it.next())){
635 require(diff_list.get(name, &node));
637 require(node->get(
"Name", &name));
638 str.
appfmt(
"[%s]\n", name);
641 require(node->get(
"Key", key));
644 key.
split(keys,
";");
645 for (
unsigned i= 0;
i < keys.size();
i++)
646 str.
appfmt(
"%s\n", keys[
i].c_str());
651 while ((name= prop_it2.next())){
654 if (!node->get(name, &what))
658 require(what->get(
"Type", &type));
659 require(what->get(
"Name", &name));
663 str.
appfmt(
"-%s=%s\n", name, p2s(what,
"Old", buf));
664 str.
appfmt(
"+%s=%s\n", name, p2s(what,
"New", buf));
668 case DT_MISSING_VALUE:
670 str.
appfmt(
"-%s=%s\n", name, p2s(what,
"Old", buf));
674 case DT_MISSING_SECTION:
677 if (what->get(
"Why", &why))
682 case DT_ILLEGAL_CHANGE:
685 str.
appfmt(
"Illegal change\n");
686 if (what->get(
"Why", &why))
692 str.
appfmt(
"Illegal 'type' found in diff_list\n");
703 void Config::print_diff(
const Config* other)
const {
705 diff(other, diff_list);
707 ndbout_c(
"%s", diff2str(diff_list, str));
712 Config::diff2str(
const Config* other,
BaseString& str,
const unsigned * exclude)
const {
714 diff(other, diff_list, exclude);
715 return diff2str(diff_list, str);
719 bool Config::equal(
const Properties& diff_list)
const {
722 while ((prop_it.next()))
728 bool Config::equal(
const Config* other,
const unsigned * exclude)
const {
730 diff(other, diff_list, exclude);
731 return equal(diff_list);
736 bool Config::illegal_change(
const Properties& diff_list)
const {
740 while ((name= prop_it.next())){
743 require(diff_list.get(name, &node));
746 while ((name= prop_it2.next())){
749 if (!node->get(name, &what))
753 require(what->get(
"Type", &type));
754 if (type == DT_ILLEGAL_CHANGE)
762 bool Config::illegal_change(
const Config* other)
const {
764 diff(other, diff_list);
765 return illegal_change(diff_list);
769 void Config::getConnectString(
BaseString& connectstring,
775 for(;it.valid(); it.next())
779 require(it.get(CFG_TYPE_OF_SECTION, &nodeType) == 0);
781 if (nodeType != NODE_TYPE_MGM)
785 const char* hostname;
786 require(it.get(CFG_NODE_HOST, &hostname) == 0);
787 require(it.get(CFG_MGM_PORT, &port) == 0);
790 connectstring.
append(separator);
793 connectstring.
appfmt(
"%s:%d", hostname, port);
796 ndbout << connectstring << endl;
806 for (; it.valid(); it.next())
809 require(it.get(CFG_TYPE_OF_SECTION, &node_type) == 0);
811 if (type == NDB_MGM_NODE_TYPE_UNKNOWN ||
815 require(it.get(CFG_NODE_ID, &nodeid) == 0);
823 Config::checksum(
void)
const {
830 const char* chk_ptr = (
const char*)buf.get_data();
831 chk_ptr += buf.length() -
sizeof(Uint32);
832 chk = *(Uint32*) chk_ptr;