17 #include "ConfigManager.hpp"
18 #include "MgmtSrvr.hpp"
21 #include <NdbConfig.h>
23 #include <kernel/GlobalSignalNumbers.h>
24 #include <SignalSender.hpp>
25 #include <NdbApiSignal.hpp>
26 #include <signaldata/NFCompleteRep.hpp>
27 #include <signaldata/NodeFailRep.hpp>
28 #include <signaldata/ApiRegSignalData.hpp>
29 #include <ndb_version.h>
31 #include <EventLogger.hpp>
34 extern "C" const char* opt_ndb_connectstring;
35 extern "C" int opt_ndb_nodeid;
38 const char* configdir) :
45 m_config_retriever(opt_ndb_connectstring,
50 m_config_state(CS_UNINITIALIZED),
51 m_previous_state(CS_UNINITIALIZED),
52 m_prepared_config(NULL),
54 m_configdir(configdir)
59 ConfigManager::~ConfigManager()
62 delete m_prepared_config;
65 NdbMutex_Destroy(m_config_mutex);
78 alone_on_host(
Config* conf,
83 for (iter.first(); iter.valid(); iter.next())
86 if(iter.get(CFG_TYPE_OF_SECTION, &type) ||
91 if(iter.get(CFG_NODE_ID, &nodeid) ||
95 const char * hostname;
96 if(iter.get(CFG_NODE_HOST, &hostname))
102 g_eventLogger->
debug(
"Not alone on host %s, node %d " \
103 "will also run here",
121 ConfigManager::find_nodeid_from_configdir(
void)
126 if (iter.open(m_configdir) != 0)
130 unsigned found_nodeid= 0;
133 unsigned version, max_version = 0;
134 while ((name = iter.next_file()) != NULL)
137 "ndb_%u_config.bin.%u%c",
138 &nodeid, &version, &extra) == 2)
142 if (nodeid != found_nodeid)
144 if (found_nodeid != 0)
146 found_nodeid= nodeid;
149 if (version > max_version)
150 max_version = version;
154 if (max_version == 0)
157 config_name.
assfmt(
"%s%sndb_%u_config.bin.%u",
158 m_configdir, DIR_SEPARATOR, found_nodeid, max_version);
161 if (!(conf = load_saved_config(config_name)))
164 if (!m_config_retriever.
verifyConfig(conf->m_configValues,
187 find_own_nodeid(
Config* conf)
189 NodeId found_nodeid= 0;
191 for (iter.first(); iter.valid(); iter.next())
194 if(iter.get(CFG_TYPE_OF_SECTION, &type) ||
199 require(iter.get(CFG_NODE_ID, &nodeid) == 0);
201 const char * hostname;
202 if(iter.get(CFG_NODE_HOST, &hostname))
208 if (found_nodeid == 0)
209 found_nodeid = nodeid;
219 ConfigManager::find_nodeid_from_config(
void)
222 !m_opts.config_filename)
225 Config* conf = load_config();
229 NodeId found_nodeid = find_own_nodeid(conf);
230 if (found_nodeid == 0 ||
231 !m_config_retriever.
verifyConfig(conf->m_configValues, found_nodeid))
242 ConfigManager::init_nodeid(
void)
244 DBUG_ENTER(
"ConfigManager::init_nodeid");
246 NodeId nodeid = m_config_retriever.get_configuration_nodeid();
250 g_eventLogger->
debug(
"Got nodeid: %d from command line " \
251 "or NDB_CONNECTSTRING", nodeid);
256 nodeid = find_nodeid_from_configdir();
260 g_eventLogger->
debug(
"Got nodeid: %d from searching in configdir",
266 nodeid = find_nodeid_from_config();
270 g_eventLogger->
debug(
"Got nodeid: %d from config file given " \
285 g_eventLogger->
error(
"Could not determine which nodeid to use for "\
286 "this node. Specify it with --ndb-nodeid=<nodeid> "\
295 ConfigIter iter(config, CFG_SECTION_CONNECTION);
297 for(;iter.valid();iter.next()) {
299 require(iter.get(CFG_CONNECTION_SERVER_PORT, &port) == 0);
306 require(i2.set(CFG_CONNECTION_SERVER_PORT, port));
315 DBUG_ENTER(
"ConfigManager::init");
317 m_config_mutex = NdbMutex_Create();
320 g_eventLogger->
error(
"Failed to create mutex in ConfigManager!");
324 require(m_config_state == CS_UNINITIALIZED);
326 if (m_config_retriever.hasError())
328 g_eventLogger->
error(
"%s", m_config_retriever.getErrorString());
335 if (m_opts.initial && !delete_saved_configs())
338 if (failed_config_change_exists())
342 if (saved_config_exists(config_bin_name))
345 if (!(conf = load_saved_config(config_bin_name)))
348 if (!config_ok(conf))
352 m_config_state = CS_CONFIRMED;
354 g_eventLogger->
info(
"Loaded config from '%s'", config_bin_name.
c_str());
357 (m_opts.mycnf || m_opts.config_filename))
359 Config* new_conf = load_config();
360 if (new_conf == NULL)
366 m_config_change.config_loaded(new_conf);
367 g_eventLogger->
info(
"Loaded configuration from '%s', will try " \
368 "to set it once started",
369 m_opts.mycnf ?
"my.cnf" : m_opts.config_filename);
374 if (m_opts.mycnf || m_opts.config_filename)
376 Config* conf = load_config();
380 if (!config_ok(conf))
388 if (!conf->setPrimaryMgmNode(m_node_id))
390 g_eventLogger->
error(
"Failed to set primary MGM node");
397 g_eventLogger->
info(
"Got initial configuration from '%s', will try " \
398 "to set it when all ndb_mgmd(s) started",
399 m_opts.mycnf ?
"my.cnf" : m_opts.config_filename);
400 m_config_change.m_initial_config =
new Config(conf);
401 m_config_state = CS_INITIAL;
403 if (!init_checkers(m_config_change.m_initial_config))
409 if (!(conf = fetch_config()))
411 g_eventLogger->
error(
"Could not fetch config!");
420 reset_dynamic_ports_in_config(conf);
422 if (!config_ok(conf))
428 if (m_config->getGeneration() == 0)
430 g_eventLogger->
info(
"Fetched initial configuration, " \
431 "generation: %d, name: '%s'. "\
432 "Will try to set it when all ndb_mgmd(s) started",
433 m_config->getGeneration(), m_config->getName());
434 m_config_state= CS_INITIAL;
435 m_config_change.m_initial_config =
new Config(conf);
437 if (!init_checkers(m_config_change.m_initial_config))
442 g_eventLogger->
info(
"Fetched confirmed configuration, " \
443 "generation: %d, name: '%s'. " \
444 "Trying to write it to disk...",
445 m_config->getGeneration(), m_config->getName());
446 if (!prepareConfigChange(m_config))
449 g_eventLogger->
error(
"Failed to write the fetched config to disk");
452 commitConfigChange();
453 m_config_state = CS_CONFIRMED;
454 g_eventLogger->
info(
"The fetched configuration has been saved!");
459 require(m_config_state != CS_UNINITIALIZED);
465 ConfigManager::prepareConfigChange(
const Config* config)
467 if (m_prepared_config)
469 g_eventLogger->
error(
"Can't prepare configuration change " \
470 "when already prepared");
474 Uint32 generation= config->getGeneration();
477 g_eventLogger->
error(
"Can't prepare configuration change for "\
478 "configuration with generation 0");
483 m_config_name.
assfmt(
"%s%sndb_%u_config.bin.%u",
484 m_configdir, DIR_SEPARATOR, m_node_id, generation);
485 g_eventLogger->
debug(
"Preparing configuration, generation: %d name: %s",
486 generation, m_config_name.
c_str());
489 if (access(m_config_name.
c_str(), F_OK) == 0)
491 g_eventLogger->
error(
"The file '%s' already exist while preparing",
492 m_config_name.
c_str());
498 if(!config->pack(buf))
501 g_eventLogger->
error(
"Failed to pack configuration while preparing");
507 prep_config_name.append(
".tmp");
508 FILE * f = fopen(prep_config_name.c_str(), IF_WIN(
"wbc",
"w"));
511 g_eventLogger->
error(
"Failed to open file '%s' while preparing, errno: %d",
512 prep_config_name.c_str(), errno);
516 if(fwrite(buf.get_data(), 1, buf.length(), f) != (
size_t)buf.length())
518 g_eventLogger->
error(
"Failed to write file '%s' while preparing, errno: %d",
519 prep_config_name.c_str(), errno);
521 unlink(prep_config_name.c_str());
527 g_eventLogger->
error(
"Failed to flush file '%s' while preparing, errno: %d",
528 prep_config_name.c_str(), errno);
530 unlink(prep_config_name.c_str());
541 if (fsync(fileno(f)))
543 g_eventLogger->
error(
"Failed to sync file '%s' while preparing, errno: %d",
544 prep_config_name.c_str(), errno);
546 unlink(prep_config_name.c_str());
552 m_prepared_config =
new Config(config);
553 g_eventLogger->
debug(
"Configuration prepared");
560 ConfigManager::commitConfigChange(
void)
562 require(m_prepared_config != 0);
565 set_config(m_prepared_config);
566 m_prepared_config= NULL;
569 require(m_config_name.
length());
571 prep_config_name.append(
".tmp");
572 if(rename(prep_config_name.c_str(), m_config_name.
c_str()))
574 g_eventLogger->
error(
"rename from '%s' to '%s' failed while committing, " \
576 prep_config_name.c_str(), m_config_name.
c_str(),
581 m_config_name.
clear();
583 g_eventLogger->
info(
"Configuration %d commited", m_config->getGeneration());
588 check_no_dynamic_ports_in_config(
const Config* config)
591 ConfigIter iter(config, CFG_SECTION_CONNECTION);
593 for(;iter.valid();iter.next()) {
595 require(iter.get(CFG_CONNECTION_NODE_1, &n1) == 0 &&
596 iter.get(CFG_CONNECTION_NODE_2, &n2) == 0);
599 require(iter.get(CFG_CONNECTION_SERVER_PORT, &port_value) == 0);
601 int port = (int)port_value;
604 g_eventLogger->
error(
"INTERNAL ERROR: Found dynamic ports with "
605 "value in config, n1: %d, n2: %d, port: %u",
615 ConfigManager::set_config(
Config* new_config)
618 check_no_dynamic_ports_in_config(new_config);
621 m_config = new_config;
624 m_packed_config.
clear();
626 for (
unsigned i = 0;
i < m_subscribers.size();
i++)
627 m_subscribers[
i]->config_changed(m_node_id, new_config);
634 return m_subscribers.push_back(subscriber);
639 ConfigManager::config_ok(
const Config* conf)
642 if (!m_config_retriever.
verifyConfig(conf->m_configValues, m_node_id))
644 g_eventLogger->
error(
"%s", m_config_retriever.getErrorString());
650 require(iter.find(CFG_NODE_ID, m_node_id) == 0);
653 require(iter.get(CFG_NODE_DATADIR, &datadir) == 0);
655 if (strcmp(datadir,
"") != 0 &&
656 access(datadir, F_OK))
658 g_eventLogger->
error(
"Directory '%s' specified with DataDir " \
659 "in configuration does not exist.", \
668 ConfigManager::abortConfigChange(
void)
674 prep_config_name.append(
".tmp");
675 unlink(prep_config_name.c_str());
676 m_config_name.
clear();
678 delete m_prepared_config;
679 m_prepared_config= NULL;
685 ConfigManager::sendConfigChangeImplRef(
SignalSender& ss, NodeId nodeId,
686 ConfigChangeRef::ErrorCode error)
const
691 ref->errorCode = error;
693 g_eventLogger->
debug(
"Send CONFIG_CHANGE_IMPL_REF to node: %d, error: %d",
696 ss.sendSignal(nodeId, ssig,
697 MGM_CONFIG_MAN, GSN_CONFIG_CHANGE_IMPL_REF,
698 ConfigChangeImplRef::SignalLength);
706 NodeId nodeId = refToNode(sig->header.theSendersBlockRef);
710 g_eventLogger->
debug(
"Got CONFIG_CHANGE_IMPL_REQ from node: %d, "\
712 nodeId, req->requestType);
714 if (!m_defragger.defragment(sig))
717 Guard g(m_config_mutex);
719 switch(req->requestType){
720 case ConfigChangeImplReq::Prepare:{
721 if (sig->header.m_noOfSections != 1)
723 sendConfigChangeImplRef(ss, nodeId, ConfigChangeRef::NoConfigData);
728 if (!cf.unpack(sig->ptr[0].p, req->length))
730 sendConfigChangeImplRef(ss, nodeId, ConfigChangeRef::FailedToUnpack);
734 Config new_config(cf.getConfigValues());
735 Uint32 new_generation = new_config.getGeneration();
736 Uint32 curr_generation = m_config->getGeneration();
737 const char* new_name = new_config.getName();
738 const char* curr_name = m_config->getName();
740 if (m_config->illegal_change(&new_config))
742 sendConfigChangeImplRef(ss, nodeId, ConfigChangeRef::IllegalConfigChange);
749 if (m_config_state != CS_INITIAL)
751 g_eventLogger->
warning(
"Refusing to start initial " \
752 "configuration change since this node " \
753 "is not in INITIAL state");
754 sendConfigChangeImplRef(ss, nodeId,
755 ConfigChangeRef::IllegalInitialState);
760 if (new_generation != 0)
762 g_eventLogger->
warning(
"Refusing to start initial " \
763 "configuration change since new " \
764 "generation is not 0 (new_generation: %d)",
766 sendConfigChangeImplRef(ss, nodeId,
767 ConfigChangeRef::IllegalInitialGeneration);
774 if (nodeId != refToNode(ss.getOwnRef()))
776 Config new_config_copy(&new_config);
777 require(new_config_copy.setName(new_name));
778 unsigned exclude[]= {CFG_SECTION_SYSTEM, 0};
779 if (!new_config_copy.equal(m_config_change.m_initial_config, exclude))
783 (
"Refusing to start initial config " \
784 "change when nodes have different " \
786 "This is the actual diff:\n%s",
787 new_config_copy.diff2str(m_config_change.m_initial_config, buf));
788 sendConfigChangeImplRef(ss, nodeId,
789 ConfigChangeRef::DifferentInitial);
797 delete m_config_change.m_initial_config;
798 m_config_change.m_initial_config = NULL;
805 Uint32 curr_primary = m_config->getPrimaryMgmNode();
806 Uint32 new_primary = new_config.getPrimaryMgmNode();
807 if (new_primary != curr_primary)
809 g_eventLogger->
warning(
"Refusing to start configuration change " \
810 "requested by node %d, the new config uses " \
811 "different primary mgm node %d. " \
812 "Current primary mmgm node is %d.",
813 nodeId, new_primary, curr_primary);
814 sendConfigChangeImplRef(ss, nodeId,
815 ConfigChangeRef::NotPrimaryMgmNode);
819 if (new_generation == 0 ||
820 new_generation != curr_generation)
823 g_eventLogger->
warning(
"Refusing to start config change " \
824 "requested by node with different " \
825 "generation: %d. Our generation: %d\n" \
826 "This is the actual diff:\n%s",
827 new_generation, curr_generation,
828 new_config.diff2str(m_config, buf));
829 sendConfigChangeImplRef(ss, nodeId, ConfigChangeRef::InvalidGeneration);
835 if (strcmp(new_name, curr_name))
838 g_eventLogger->
warning(
"Refusing to start config change " \
839 "requested by node with different " \
840 "name: '%s'. Our name: '%s'\n" \
841 "This is the actual diff:\n%s",
843 new_config.diff2str(m_config, buf));
844 sendConfigChangeImplRef(ss, nodeId, ConfigChangeRef::InvalidConfigName);
850 if(!new_config.setGeneration(new_generation))
852 g_eventLogger->
error(
"Failed to set new generation to %d",
854 sendConfigChangeImplRef(ss, nodeId, ConfigChangeRef::InternalError);
858 if (!prepareConfigChange(&new_config))
860 sendConfigChangeImplRef(ss, nodeId, ConfigChangeRef::PrepareFailed);
866 case ConfigChangeImplReq::Commit:
867 commitConfigChange();
870 m_config_state = CS_CONFIRMED;
874 case ConfigChangeImplReq::Abort:
879 g_eventLogger->
error(
"execCONFIG_CHANGE_IMPL_REQ: unhandled state");
888 conf->requestType = req->requestType;
890 g_eventLogger->
debug(
"Sending CONFIG_CHANGE_IMPL_CONF to node: %d",
893 ss.sendSignal(nodeId, ssig,
895 GSN_CONFIG_CHANGE_IMPL_CONF,
896 ConfigChangeImplConf::SignalLength);
900 void ConfigManager::set_config_change_state(ConfigChangeState::States state)
902 if (state == ConfigChangeState::IDLE)
906 assert(m_config_change.m_error == ConfigChangeRef::OK);
910 m_config_change.m_state.m_current_state = state;
917 NodeId nodeId = refToNode(sig->header.theSendersBlockRef);
918 g_eventLogger->
debug(
"Got CONFIG_CHANGE_IMPL_REF from node: %d", nodeId);
922 g_eventLogger->
warning(
"Node %d refused configuration change, error: %d",
923 nodeId, ref->errorCode);
926 if (m_config_change.m_error == 0)
927 m_config_change.m_error = (ConfigChangeRef::ErrorCode)ref->errorCode;
929 switch(m_config_change.m_state){
930 case ConfigChangeState::ABORT:
931 case ConfigChangeState::PREPARING:{
933 m_config_change.m_contacted_nodes.clear(nodeId);
934 set_config_change_state(ConfigChangeState::ABORT);
936 m_waiting_for.
clear(nodeId);
940 startAbortConfigChange(ss);
943 case ConfigChangeState::COMITTING:
948 case ConfigChangeState::ABORTING:
954 g_eventLogger->
error(
"execCONFIG_CHANGE_IMPL_REF: unhandled state");
964 NodeId nodeId = refToNode(sig->header.theSendersBlockRef);
967 g_eventLogger->
debug(
"Got CONFIG_CHANGE_IMPL_CONF from node %d", nodeId);
969 switch(m_config_change.m_state){
970 case ConfigChangeState::PREPARING:{
971 require(conf->requestType == ConfigChangeImplReq::Prepare);
972 m_waiting_for.
clear(nodeId);
977 int res = sendConfigChangeImplReq(ss, m_config_change.m_new_config);
986 startAbortConfigChange(ss);
994 delete m_config_change.m_new_config;
995 m_config_change.m_new_config = 0;
1002 req->requestType = ConfigChangeImplReq::Commit;
1004 g_eventLogger->
debug(
"Sending CONFIG_CHANGE_IMPL_REQ(commit)");
1005 require(m_waiting_for.
isclear());
1006 m_waiting_for = ss.broadcastSignal(m_config_change.m_contacted_nodes, ssig,
1008 GSN_CONFIG_CHANGE_IMPL_REQ,
1009 ConfigChangeImplReq::SignalLength);
1010 if (m_waiting_for.isclear())
1011 set_config_change_state(ConfigChangeState::IDLE);
1013 set_config_change_state(ConfigChangeState::COMITTING);
1017 case ConfigChangeState::COMITTING:{
1018 require(conf->requestType == ConfigChangeImplReq::Commit);
1020 m_waiting_for.clear(nodeId);
1021 if (!m_waiting_for.isclear())
1024 require(m_config_change.m_client_ref != RNIL);
1025 require(m_config_change.m_error == 0);
1026 if (m_config_change.m_client_ref == ss.getOwnRef())
1028 g_eventLogger->
info(
"Config change completed! New generation: %d",
1029 m_config->getGeneration());
1034 sendConfigChangeConf(ss, m_config_change.m_client_ref);
1036 m_config_change.m_client_ref = RNIL;
1037 set_config_change_state(ConfigChangeState::IDLE);
1041 case ConfigChangeState::ABORT:{
1042 m_waiting_for.clear(nodeId);
1043 if (!m_waiting_for.isclear())
1046 startAbortConfigChange(ss);
1050 case ConfigChangeState::ABORTING:{
1051 m_waiting_for.clear(nodeId);
1052 if (!m_waiting_for.isclear())
1055 require(m_config_change.m_client_ref != RNIL);
1056 require(m_config_change.m_error);
1057 if (m_config_change.m_client_ref == ss.getOwnRef())
1060 error(
"Configuration change failed! error: %d '%s'",
1061 m_config_change.m_error,
1062 ConfigChangeRef::errorMessage(m_config_change.m_error));
1068 sendConfigChangeRef(ss, m_config_change.m_client_ref,
1069 m_config_change.m_error);
1071 m_config_change.m_error= ConfigChangeRef::OK;
1072 m_config_change.m_client_ref = RNIL;
1073 set_config_change_state(ConfigChangeState::IDLE);
1078 g_eventLogger->
error(
"execCONFIG_CHANGE_IMPL_CONF: unhandled state");
1086 ConfigManager::sendConfigChangeRef(
SignalSender& ss, BlockReference
to,
1087 ConfigChangeRef::ErrorCode error)
const
1089 NodeId nodeId = refToNode(to);
1093 ref->errorCode = error;
1095 g_eventLogger->
debug(
"Send CONFIG_CHANGE_REF to node: %d, error: %d",
1098 ss.sendSignal(nodeId, ssig, refToBlock(to),
1099 GSN_CONFIG_CHANGE_REF, ConfigChangeRef::SignalLength);
1104 ConfigManager::sendConfigChangeConf(
SignalSender& ss, BlockReference to)
const
1106 NodeId nodeId = refToNode(to);
1109 g_eventLogger->
debug(
"Send CONFIG_CHANGE_CONF to node: %d", nodeId);
1111 ss.sendSignal(nodeId, ssig, refToBlock(to),
1112 GSN_CONFIG_CHANGE_CONF, ConfigChangeConf::SignalLength);
1117 ConfigManager::startConfigChange(
SignalSender& ss, Uint32 ref)
1119 if (m_config_state == CS_INITIAL)
1121 g_eventLogger->
info(
"Starting initial configuration change");
1125 require(m_config_state == CS_CONFIRMED);
1126 g_eventLogger->
info(
"Starting configuration change, generation: %d",
1127 m_config_change.m_new_config->getGeneration());
1129 m_config_change.m_contacted_nodes.clear();
1130 m_config_change.m_client_ref = ref;
1131 if (sendConfigChangeImplReq(ss, m_config_change.m_new_config) <= 0)
1133 g_eventLogger->
error(
"Failed to start configuration change!");
1139 ConfigManager::startAbortConfigChange(
SignalSender& ss)
1145 req->requestType = ConfigChangeImplReq::Abort;
1147 g_eventLogger->
debug
1148 (
"Sending CONFIG_CHANGE_IMPL_REQ(abort) to %s",
1149 BaseString::getPrettyText(m_config_change.m_contacted_nodes).c_str());
1151 require(m_waiting_for.isclear());
1152 m_waiting_for = ss.broadcastSignal(m_config_change.m_contacted_nodes, ssig,
1154 GSN_CONFIG_CHANGE_IMPL_REQ,
1155 ConfigChangeImplReq::SignalLength);
1157 if (m_config_change.m_new_config)
1159 delete m_config_change.m_new_config;
1160 m_config_change.m_new_config = 0;
1163 if (m_waiting_for.isclear())
1168 m_waiting_for.set(ss.getOwnNodeId());
1171 conf->requestType = ConfigChangeImplReq::Abort;
1173 ss.sendSignal(ss.getOwnNodeId(), ssig,
1175 GSN_CONFIG_CHANGE_IMPL_CONF,
1176 ConfigChangeImplConf::SignalLength);
1179 set_config_change_state(ConfigChangeState::ABORTING);
1185 require(m_waiting_for.isclear());
1186 require(m_config_change.m_client_ref != RNIL);
1188 if (m_config_change.m_contacted_nodes.isclear())
1190 require(m_config_change.m_state == ConfigChangeState::IDLE);
1194 require(m_config_change.m_state == ConfigChangeState::PREPARING);
1197 set_config_change_state(ConfigChangeState::PREPARING);
1200 nodes.
bitANDC(m_config_change.m_contacted_nodes);
1214 ssig.ptr[0].p = (Uint32*)buf.get_data();
1215 ssig.ptr[0].sz = (buf.length() + 3) / 4;
1216 ssig.header.m_noOfSections = 1;
1220 req->requestType = ConfigChangeImplReq::Prepare;
1221 req->initial = (m_config_state == CS_INITIAL);
1222 req->length = buf.length();
1224 Uint32
i = nodes.
find(0);
1225 g_eventLogger->
debug(
"Sending CONFIG_CHANGE_IMPL_REQ(prepare) to %u", i);
1226 int result = ss.sendFragmentedSignal(i, ssig, MGM_CONFIG_MAN,
1227 GSN_CONFIG_CHANGE_IMPL_REQ,
1228 ConfigChangeImplReq::SignalLength);
1231 g_eventLogger->
warning(
"Failed to send configuration change "
1232 "prepare to node: %d, result: %d",
1237 m_waiting_for.set(i);
1238 m_config_change.m_contacted_nodes.set(i);
1246 BlockReference from = sig->header.theSendersBlockRef;
1250 if (!m_defragger.defragment(sig))
1253 if (!m_started.
equal(m_all_mgm))
1255 sendConfigChangeRef(ss, from, ConfigChangeRef::NotAllStarted);
1259 if (m_all_mgm.
find(0) != m_facade->ownId())
1261 sendConfigChangeRef(ss, from, ConfigChangeRef::NotMaster);
1265 if (m_config_change.m_state != ConfigChangeState::IDLE)
1267 sendConfigChangeRef(ss, from, ConfigChangeRef::ConfigChangeOnGoing);
1270 require(m_config_change.m_error == ConfigChangeRef::OK);
1272 if (sig->header.m_noOfSections != 1)
1274 sendConfigChangeRef(ss, from, ConfigChangeRef::NoConfigData);
1279 if (!cf.unpack(sig->ptr[0].p, req->length))
1281 sendConfigChangeRef(ss, from, ConfigChangeRef::FailedToUnpack);
1285 Config * new_config =
new Config(cf.getConfigValues());
1286 if (!config_ok(new_config))
1288 g_eventLogger->
warning(
"Refusing to start config change, the config "\
1290 sendConfigChangeRef(ss, from, ConfigChangeRef::ConfigNotOk);
1295 m_config_change.m_new_config = new_config;
1296 startConfigChange(ss, from);
1303 config_check_checksum(
const Config* config)
1309 copy.setName(
"CHECKSUM");
1310 copy.setPrimaryMgmNode(0);
1312 Uint32 checksum = copy.checksum();
1321 Guard g(m_config_mutex);
1322 BlockReference from = sig->header.theSendersBlockRef;
1323 NodeId nodeId = refToNode(from);
1327 Uint32 other_generation = req->generation;
1328 ConfigState other_state = (ConfigState)req->state;
1330 Uint32 generation = m_config->getGeneration();
1333 Uint32 checksum = config_check_checksum(m_config);
1334 Uint32 other_checksum = req->checksum;
1335 if (sig->header.theLength == ConfigCheckReq::SignalLengthBeforeChecksum)
1339 g_eventLogger->
debug(
"Other mgmd does not have checksum, using own");
1340 other_checksum = checksum;
1343 if (m_prepared_config || m_config_change.m_new_config)
1345 g_eventLogger->
debug(
"Got CONFIG_CHECK_REQ from node: %d while "
1346 "config change in progress (m_prepared_config). "
1347 "Returning incorrect state, causing it to be retried",
1349 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongState,
1350 generation, other_generation,
1351 m_config_state, CS_UNINITIALIZED);
1355 if (m_config_change.m_loaded_config && ss.getOwnNodeId() < nodeId)
1357 g_eventLogger->
debug(
"Got CONFIG_CHECK_REQ from node: %d while "
1358 "having a loaded config (and my node is lower: %d). "
1359 "Returning incorrect state, causing it to be retried",
1362 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongState,
1363 generation, other_generation,
1364 m_config_state, CS_UNINITIALIZED);
1368 g_eventLogger->
debug(
"Got CONFIG_CHECK_REQ from node: %d. "
1369 "Our generation: %d, other generation: %d, "
1370 "our state: %d, other state: %d, "
1371 "our checksum: 0x%.8x, other checksum: 0x%.8x",
1372 nodeId, generation, other_generation,
1373 m_config_state, other_state,
1374 checksum, other_checksum);
1376 switch (m_config_state)
1379 case CS_UNINITIALIZED:
1380 g_eventLogger->
error(
"execCONFIG_CHECK_REQ: unhandled state");
1385 if (other_state != CS_INITIAL)
1387 g_eventLogger->
warning(
"Refusing CONGIG_CHECK_REQ from %u, "
1388 " it's not CS_INITIAL (I am). "
1389 " Waiting for my check",
1391 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongState,
1392 generation, other_generation,
1393 m_config_state, other_state);
1397 require(generation == 0);
1398 if (other_generation != generation)
1400 g_eventLogger->
warning(
"Refusing other node, it has different " \
1401 "generation: %d, expected: %d",
1402 other_generation, generation);
1403 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongGeneration,
1404 generation, other_generation,
1405 m_config_state, other_state);
1409 if (other_checksum != checksum)
1411 g_eventLogger->
warning(
"Refusing other node, it has different "
1412 "checksum: 0x%.8x, expected: 0x%.8x",
1413 other_checksum, checksum);
1414 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongChecksum,
1415 generation, other_generation,
1416 m_config_state, other_state);
1423 if (other_state != CS_CONFIRMED)
1425 g_eventLogger->
warning(
"Refusing other node, it's in different " \
1426 "state: %d, expected: %d",
1427 other_state, m_config_state);
1428 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongState,
1429 generation, other_generation,
1430 m_config_state, other_state);
1434 if (other_generation == generation)
1437 if (other_checksum != checksum)
1439 g_eventLogger->
warning(
"Refusing other node, it has different "
1440 "checksum: 0x%.8x, expected: 0x%.8x",
1441 other_checksum, checksum);
1442 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongChecksum,
1443 generation, other_generation,
1444 m_config_state, other_state);
1449 else if (other_generation < generation)
1451 g_eventLogger->
warning(
"Refusing other node, it has lower " \
1452 " generation: %d, expected: %d",
1453 other_generation, generation);
1454 sendConfigCheckRef(ss, from, ConfigCheckRef::WrongGeneration,
1455 generation, other_generation,
1456 m_config_state, other_state);
1461 g_eventLogger->
error(
"Other node has higher generation: %d, this " \
1462 "node is out of sync with generation: %d",
1463 other_generation, generation);
1470 sendConfigCheckConf(ss, from);
1481 req->state = m_config_state;
1482 req->generation = m_config->getGeneration();
1483 req->checksum = config_check_checksum(m_config);
1485 g_eventLogger->
debug(
"Sending CONFIG_CHECK_REQ to %s",
1486 BaseString::getPrettyText(to).c_str());
1488 require(m_waiting_for.isclear());
1489 m_waiting_for = ss.broadcastSignal(to, ssig, MGM_CONFIG_MAN,
1490 GSN_CONFIG_CHECK_REQ,
1491 ConfigCheckReq::SignalLength);
1495 send_config_in_check_ref(Uint32 x)
1497 if (x >= NDB_MAKE_VERSION(7,0,8))
1503 ConfigManager::sendConfigCheckRef(
SignalSender& ss, BlockReference to,
1504 ConfigCheckRef::ErrorCode error,
1506 Uint32 other_generation,
1508 ConfigState other_state)
const
1511 NodeId nodeId = refToNode(to);
1516 ref->generation = other_generation;
1517 ref->expected_generation = generation;
1518 ref->state = other_state;
1519 ref->expected_state = state;
1521 g_eventLogger->
debug(
"Send CONFIG_CHECK_REF with error: %d to node: %d",
1524 if (!send_config_in_check_ref(ss.getNodeInfo(nodeId).m_info.
m_version))
1526 result = ss.sendSignal(nodeId, ssig, MGM_CONFIG_MAN,
1527 GSN_CONFIG_CHECK_REF, ConfigCheckRef::SignalLength);
1532 m_config->pack(buf);
1533 ssig.ptr[0].p = (Uint32*)buf.get_data();
1534 ssig.ptr[0].sz = (buf.length() + 3) / 4;
1535 ssig.header.m_noOfSections = 1;
1537 ref->length = buf.length();
1539 g_eventLogger->
debug(
"Sending CONFIG_CHECK_REF with config");
1541 result = ss.sendFragmentedSignal(nodeId, ssig, MGM_CONFIG_MAN,
1542 GSN_CONFIG_CHECK_REF,
1543 ConfigCheckRef::SignalLengthWithConfig);
1548 g_eventLogger->
warning(
"Failed to send CONFIG_CHECK_REF "
1549 "to node: %d, result: %d",
1555 ConfigManager::sendConfigCheckConf(
SignalSender& ss, BlockReference to)
const
1557 NodeId nodeId = refToNode(to);
1561 conf->state = m_config_state;
1562 conf->generation = m_config->getGeneration();
1564 g_eventLogger->
debug(
"Send CONFIG_CHECK_CONF to node: %d", nodeId);
1566 ss.sendSignal(nodeId, ssig, MGM_CONFIG_MAN,
1567 GSN_CONFIG_CHECK_CONF, ConfigCheckConf::SignalLength);
1574 BlockReference from = sig->header.theSendersBlockRef;
1575 NodeId nodeId = refToNode(from);
1576 assert(m_waiting_for.get(nodeId));
1577 m_waiting_for.clear(nodeId);
1578 m_checked.
set(nodeId);
1580 g_eventLogger->
debug(
"Got CONFIG_CHECK_CONF from node: %d",
1590 BlockReference from = sig->header.theSendersBlockRef;
1591 NodeId nodeId = refToNode(from);
1592 assert(m_waiting_for.get(nodeId));
1597 if (!m_defragger.defragment(sig))
1600 g_eventLogger->
debug(
"Got CONFIG_CHECK_REF from node %d, "
1601 "error: %d, message: '%s', "
1602 "generation: %d, expected generation: %d, "
1603 "state: %d, expected state: %d own-state: %u",
1605 ConfigCheckRef::errorMessage(ref->error),
1606 ref->generation, ref->expected_generation,
1607 ref->state, ref->expected_state,
1610 assert(ref->generation != ref->expected_generation ||
1611 ref->state != ref->expected_state ||
1612 ref->error == ConfigCheckRef::WrongChecksum);
1613 if((Uint32)m_config_state != ref->state)
1617 require(!m_checked.
get(nodeId));
1618 m_waiting_for.clear(nodeId);
1622 switch(m_config_state)
1625 case CS_UNINITIALIZED:
1626 g_eventLogger->
error(
"execCONFIG_CHECK_REF: unhandled state");
1631 if (ref->expected_state == CS_CONFIRMED)
1633 if (sig->header.theLength != ConfigCheckRef::SignalLengthWithConfig)
1637 assert(sig->header.m_noOfSections == 1);
1640 require(cf.unpack(sig->ptr[0].p, ref->length));
1642 Config other_config(cf.getConfigValues());
1643 assert(other_config.getGeneration() > 0);
1645 unsigned exclude[]= {CFG_SECTION_SYSTEM, 0};
1646 if (!other_config.equal(m_config, exclude))
1649 g_eventLogger->
error(
"This node was started --initial with "
1650 "a config which is _not_ equal to the one "
1651 "node %d is using. Refusing to start with "
1652 "different configurations, diff: \n%s",
1654 other_config.diff2str(m_config, buf, exclude));
1658 g_eventLogger->
info(
"This node was started --inital with "
1659 "a config equal to the one node %d is using. "
1660 "Will use the config with generation %d "
1662 nodeId, other_config.getGeneration(), nodeId);
1664 if (! prepareConfigChange(&other_config))
1666 abortConfigChange();
1667 g_eventLogger->
error(
"Failed to write the fetched config to disk");
1670 commitConfigChange();
1671 m_config_state = CS_CONFIRMED;
1672 g_eventLogger->
info(
"The fetched configuration has been saved!");
1673 m_waiting_for.clear(nodeId);
1674 m_checked.
set(nodeId);
1675 delete m_config_change.m_initial_config;
1676 m_config_change.m_initial_config = NULL;
1682 if (ref->expected_state == CS_INITIAL)
1684 g_eventLogger->
info(
"Waiting for peer");
1685 m_waiting_for.clear(nodeId);
1691 if (ref->error == ConfigCheckRef::WrongChecksum &&
1694 g_eventLogger->
warning(
"Ignoring CONFIG_CHECK_REF for wrong checksum "
1695 "other node has higher node id and should "
1700 g_eventLogger->
error(
"Terminating");
1713 ConfigManager::ConfigChange::config_loaded(
Config* config)
1715 if (m_loaded_config != 0)
1717 m_loaded_config = config;
1722 ConfigManager::prepareLoadedConfig(
Config * new_conf)
1725 if (!new_conf->setGeneration(m_config->getGeneration()))
1727 g_eventLogger->
error(
"Failed to copy generation from old config");
1732 if (!new_conf->setName(m_config->getName()))
1734 g_eventLogger->
error(
"Failed to copy name from old config");
1739 if (!new_conf->setPrimaryMgmNode(m_config->getPrimaryMgmNode()))
1741 g_eventLogger->
error(
"Failed to copy primary mgm node from old config");
1747 if (!m_config->equal(new_conf))
1751 g_eventLogger->
info(
"Detected change of %s on disk, will try to "
1753 "This is the actual diff:\n%s",
1754 m_opts.mycnf ?
"my.cnf" : m_opts.config_filename,
1755 m_config->diff2str(new_conf, buf));
1762 g_eventLogger->
info(
"Config equal!");
1769 ConfigManager::run()
1774 if (!m_opts.config_cache)
1783 m_config_change.release();
1784 m_config_state = CS_CONFIRMED;
1785 ndbout_c(
"== ConfigManager disabled -- manager thread will exit ==");
1795 m_all_mgm.
bitANDC(m_opts.nowait_nodes);
1796 m_all_mgm.
set(m_facade->ownId());
1800 while (!is_stopped())
1803 if (m_config_change.m_state == ConfigChangeState::IDLE)
1805 bool print_state =
false;
1806 if (m_previous_state != m_config_state)
1809 m_previous_state = m_config_state;
1816 switch (m_config_state){
1818 case CS_UNINITIALIZED:
1832 ndbout_c(
"==INITIAL==");
1834 if (m_config_change.m_initial_config &&
1835 m_started.
equal(m_all_mgm) &&
1836 m_checked.
equal(m_started) &&
1837 m_all_mgm.
find(0) == m_facade->ownId())
1839 Config* new_conf = m_config_change.m_initial_config;
1840 m_config_change.m_initial_config = 0;
1841 m_config_change.m_new_config = new_conf;
1842 startConfigChange(ss, ss.getOwnRef());
1848 ndbout_c(
"==CONFIRMED==");
1850 if (m_config_change.m_loaded_config != 0 &&
1851 m_config_change.m_new_config == 0 &&
1852 m_started.
equal(m_all_mgm) &&
1853 m_checked.
equal(m_started))
1855 Config* new_conf = m_config_change.m_loaded_config;
1856 m_config_change.m_loaded_config = 0;
1857 m_config_change.m_new_config = prepareLoadedConfig(new_conf);
1860 if (m_config_change.m_new_config &&
1861 m_started.
equal(m_all_mgm) &&
1862 m_checked.
equal(m_started))
1864 startConfigChange(ss, ss.getOwnRef());
1874 if (m_waiting_for.isclear() &&
1875 m_prepared_config == 0 &&
1876 !m_checked.
equal(m_started))
1879 not_checked.
assign(m_started);
1880 not_checked.
bitANDC(m_checked);
1881 sendConfigCheckReq(ss, not_checked);
1884 handle_exclude_nodes();
1891 switch (sig->readSignalNumber()) {
1893 case GSN_CONFIG_CHANGE_REQ:
1894 execCONFIG_CHANGE_REQ(ss, sig);
1897 case GSN_CONFIG_CHANGE_IMPL_REQ:
1898 execCONFIG_CHANGE_IMPL_REQ(ss, sig);
1901 case GSN_CONFIG_CHANGE_IMPL_REF:
1902 execCONFIG_CHANGE_IMPL_REF(ss, sig);
1905 case GSN_CONFIG_CHANGE_IMPL_CONF:
1906 execCONFIG_CHANGE_IMPL_CONF(ss, sig);
1909 case GSN_NF_COMPLETEREP:{
1914 if (m_all_mgm.
get(nodeId))
1917 ndbout_c(
"Node %d failed", nodeId);
1918 m_started.
clear(nodeId);
1919 m_checked.
clear(nodeId);
1920 m_defragger.node_failed(nodeId);
1922 if (m_config_change.m_state != ConfigChangeState::IDLE)
1924 g_eventLogger->
info(
"Node %d failed during config change!!",
1926 g_eventLogger->
warning(
"Node failure handling of config "
1927 "change protocol not yet implemented!! "
1928 "No more configuration changes can occur, "
1929 "but the node will continue to serve the "
1930 "last good configuration");
1936 case GSN_NODE_FAILREP:
1940 case GSN_API_REGCONF:{
1941 NodeId nodeId = refToNode(sig->header.theSendersBlockRef);
1942 if (m_all_mgm.
get(nodeId) &&
1943 !m_started.
get(nodeId))
1945 g_eventLogger->
info(
"Node %d connected", nodeId);
1946 m_started.
set(nodeId);
1951 case GSN_CONFIG_CHECK_REQ:
1952 execCONFIG_CHECK_REQ(ss, sig);
1955 case GSN_CONFIG_CHECK_REF:
1956 execCONFIG_CHECK_REF(ss, sig);
1959 case GSN_CONFIG_CHECK_CONF:
1960 execCONFIG_CHECK_CONF(ss, sig);
1963 case GSN_TAKE_OVERTCCONF:
1964 case GSN_CONNECT_REP:
1969 g_eventLogger->
error(
"Unknown signal received. SignalNumber: "
1970 "%i from (%d, 0x%x)",
1971 sig->readSignalNumber(),
1972 refToNode(sig->header.theSendersBlockRef),
1973 refToBlock(sig->header.theSendersBlockRef));
1983 #include "InitConfigFileParser.hpp"
1986 ConfigManager::load_init_config(
const char* config_filename)
1994 ConfigManager::load_init_mycnf(
void)
2002 ConfigManager::load_config(
const char* config_filename,
bool mycnf,
2006 if (mycnf && (new_conf = load_init_mycnf()) == NULL)
2008 msg.
assign(
"Could not load configuration from 'my.cnf'");
2011 else if (config_filename &&
2012 (new_conf = load_init_config(config_filename)) == NULL)
2014 msg.
assfmt(
"Could not load configuration from '%s'",
2024 ConfigManager::load_config(
void)
const
2028 if ((new_conf = load_config(m_opts.config_filename,
2029 m_opts.mycnf, msg)) == NULL)
2031 g_eventLogger->
error(msg);
2039 ConfigManager::fetch_config(
void)
2041 DBUG_ENTER(
"ConfigManager::fetch_config");
2047 g_eventLogger->
info(
"Trying to get configuration from other mgmd(s) "\
2049 m_config_retriever.get_connectstring(buf,
sizeof(buf)));
2051 if (m_config_retriever.is_connected() ||
2052 m_config_retriever.do_connect(30 ,
2056 g_eventLogger->
info(
"Connected to '%s:%d'...",
2057 m_config_retriever.get_mgmd_host(),
2058 m_config_retriever.get_mgmd_port());
2064 m_config_retriever.
getConfig(m_config_retriever.get_mgmHandle());
2067 m_config_retriever.disconnect();
2070 g_eventLogger->
error(
"%s", m_config_retriever.getErrorString());
2074 DBUG_RETURN(
new Config(tmp));
2079 delete_file(
const char* file_name)
2082 if (DeleteFile(file_name) == 0)
2084 g_eventLogger->
error(
"Failed to delete file '%s', error: %d",
2085 file_name, GetLastError());
2089 if (unlink(file_name) == -1)
2091 g_eventLogger->
error(
"Failed to delete file '%s', error: %d",
2101 ConfigManager::delete_saved_configs(
void)
const
2105 if (iter.open(m_configdir) != 0)
2114 while ((name= iter.next_file()) != NULL)
2117 "ndb_%u_config.bin.%u%c",
2118 &nodeid, &version, &extra) == 2)
2122 if (nodeid != m_node_id)
2126 full_name.
assfmt(
"%s%s%s", m_configdir, DIR_SEPARATOR, name);
2127 g_eventLogger->
debug(
"Deleting binary config file '%s'",
2129 if (!delete_file(full_name.
c_str()))
2143 ConfigManager::saved_config_exists(
BaseString& config_name)
const
2147 if (iter.open(m_configdir) != 0)
2153 unsigned version, max_version= 0;
2154 while ((name= iter.next_file()) != NULL)
2157 "ndb_%u_config.bin.%u%c",
2158 &nodeid, &version, &extra) == 2)
2162 if (nodeid != m_node_id)
2165 if (version>max_version)
2166 max_version= version;
2170 if (max_version == 0)
2173 config_name.
assfmt(
"%s%sndb_%u_config.bin.%u",
2174 m_configdir, DIR_SEPARATOR, m_node_id, max_version);
2181 ConfigManager::failed_config_change_exists()
const
2185 if (iter.open(m_configdir) != 0)
2192 while ((name= iter.next_file()) != NULL)
2197 "ndb_%u_config.bin.%u.tm%c",
2198 &nodeid, &version, &tmp) == 3 &&
2201 if (nodeid != m_node_id)
2204 g_eventLogger->
error(
"Found binary configuration file '%s%s%s' from "
2205 "previous failed attempt to change config. This "
2206 "error must be manually resolved by removing the "
2207 "file(ie. ROLLBACK) or renaming the file to it's "
2208 "name without the .tmp extension(ie COMMIT). Make "
2209 "sure to check the other nodes so that they all "
2210 "have the same configuration generation.",
2211 m_configdir, DIR_SEPARATOR, name);
2221 ConfigManager::load_saved_config(
const BaseString& config_name)
2227 g_eventLogger->
error(
"Failed to load config from '%s', error: '%s'",
2228 config_name.
c_str(),
2229 m_config_retriever.getErrorString());
2235 g_eventLogger->
error(
"Failed to load config, out of memory");
2243 Guard g(m_config_mutex);
2249 switch(m_config_state)
2256 error.
assign(
"The cluster configuration is not yet confirmed "
2257 "by all defined management servers. ");
2258 if (m_config_change.m_state != ConfigChangeState::IDLE)
2260 error.
append(
"Initial configuration change is in progress.");
2265 not_started.bitANDC(m_checked);
2266 error.
append(
"This management server is still waiting for node ");
2267 error.
append(BaseString::getPrettyText(not_started));
2268 error.
append(
" to connect.");
2279 error.
assign(
"get_packed_config, unknown config state: %d",
2286 require(m_config != 0);
2289 if (!m_packed_config.
length())
2292 Config config_copy(m_config);
2293 if (!m_dynamic_ports.set_in_config(&config_copy))
2295 error.
assign(
"get_packed_config, failed to set dynamic ports in config");
2299 if (!config_copy.pack64(m_packed_config))
2301 error.
assign(
"get_packed_config, failed to pack config_copy");
2305 buf64->
assign(m_packed_config, m_packed_config.
length());
2312 ConfigManager::init_checkers(
const Config* config)
2322 for (iter.first(); iter.valid(); iter.next())
2327 if (iter.get(CFG_TYPE_OF_SECTION, &type) ||
2328 type != NODE_TYPE_MGM)
2333 if(iter.get(CFG_NODE_ID, &nodeid) ||
2334 nodeid == m_node_id)
2337 const char* hostname;
2339 require(!iter.get(CFG_NODE_HOST, &hostname));
2340 require(!iter.get(CFG_MGM_PORT, &port));
2341 connect_string.
assfmt(
"%s:%u",hostname,port);
2343 ConfigChecker* checker =
2344 new ConfigChecker(*
this, connect_string.
c_str(),
2345 m_opts.bind_address, nodeid);
2348 g_eventLogger->
error(
"Failed to create ConfigChecker");
2352 if (!checker->init())
2355 m_checkers.push_back(checker);
2362 ConfigManager::start_checkers(
void)
2364 for (
unsigned i = 0; i < m_checkers.size(); i++)
2365 m_checkers[i]->start();
2370 ConfigManager::stop_checkers(
void)
2372 for (
unsigned i = 0; i < m_checkers.size(); i++)
2374 ConfigChecker* checker = m_checkers[
i];
2375 ndbout <<
"stop checker " << i << endl;
2382 ConfigManager::ConfigChecker::ConfigChecker(
ConfigManager& manager,
2383 const char* connect_string,
2384 const char * bindaddress,
2388 m_config_retriever(opt_ndb_connectstring, opt_ndb_nodeid, NDB_VERSION,
2390 m_connect_string(connect_string),
2399 if (m_config_retriever.hasError())
2401 g_eventLogger->
error(
"%s", m_config_retriever.getErrorString());
2410 ConfigManager::ConfigChecker::run()
2414 g_eventLogger->
debug(
"ConfigChecker, connecting to '%s'",
2415 m_connect_string.c_str());
2416 while(m_config_retriever.do_connect(0 ,
2422 g_eventLogger->
debug(
"ConfigChecker, thread is stopped");
2426 NdbSleep_SecSleep(1);
2430 g_eventLogger->
debug(
"ConfigChecker, connected to '%s'",
2431 m_connect_string.c_str());
2434 int major, minor, build;
2437 &major, &minor, &build,
2438 sizeof(ver_str), ver_str))
2440 g_eventLogger->
error(
"Could not get version from mgmd on '%s'",
2441 m_connect_string.c_str());
2444 g_eventLogger->
debug(
"mgmd on '%s' has version %d.%d.%d",
2445 m_connect_string.c_str(), major, minor, build);
2451 g_eventLogger->
info(
"Excluding node %d with version %d.%d.%d from "
2452 "config change protocol",
2453 m_nodeid, major, minor, build);
2454 m_manager.m_exclude_nodes.push_back(m_nodeid);
2462 ConfigManager::handle_exclude_nodes(
void)
2465 if (!m_waiting_for.isclear())
2468 switch (m_config_state)
2471 m_exclude_nodes.lock();
2472 for (
unsigned i = 0; i < m_exclude_nodes.size(); i++)
2474 NodeId nodeid = m_exclude_nodes[
i];
2475 g_eventLogger->
debug(
"Handle exclusion of node %d", nodeid);
2476 m_all_mgm.
clear(nodeid);
2478 m_exclude_nodes.unlock();
2484 m_exclude_nodes.clear();
2490 check_dynamic_port_configured(
const Config* config,
2491 int node1,
int node2,
2494 ConfigIter iter(config, CFG_SECTION_CONNECTION);
2496 for(;iter.valid();iter.next()) {
2498 if (iter.get(CFG_CONNECTION_NODE_1, &n1) != 0 ||
2499 iter.get(CFG_CONNECTION_NODE_2, &n2) != 0)
2501 msg.
assign(
"Could not get node1 or node2 from connection section");
2505 if((n1 == (Uint32)node1 && n2 == (Uint32)node2) ||
2506 (n1 == (Uint32)node2 && n2 == (Uint32)node1))
2510 msg.
assfmt(
"Unable to find connection between nodes %d -> %d",
2516 if(iter.get(CFG_CONNECTION_SERVER_PORT, &port) != 0) {
2517 msg.
assign(
"Unable to get current value of CFG_CONNECTION_SERVER_PORT");
2524 msg.
assfmt(
"Server port for %d -> %d is not marked as dynamic, value: %u",
2525 node1, node2, port);
2533 ConfigManager::set_dynamic_port(
int node1,
int node2,
int value,
2536 Guard g(m_config_mutex);
2537 if (!check_dynamic_port_configured(m_config,
2541 if (!m_dynamic_ports.set(node1, node2, value))
2543 msg.
assfmt(
"Could not set dynamic port for %d -> %d", node1, node2);
2549 m_packed_config.
clear();
2556 ConfigManager::get_dynamic_port(
int node1,
int node2,
int *value,
2559 Guard g(m_config_mutex);
2560 if (!check_dynamic_port_configured(m_config,
2564 if (!m_dynamic_ports.get(node1, node2, value))
2566 msg.
assfmt(
"Could not get dynamic port for %d -> %d", node1, node2);
2573 bool ConfigManager::DynamicPorts::check(
int& node1,
int& node2)
const
2584 if (node1 <= 0 || node1 >= MAX_NDB_NODES)
2586 if (node2 <= 0 || node2 >= MAX_NODES)
2595 bool ConfigManager::DynamicPorts::set(
int node1,
int node2,
int port)
2597 if (!check(node1, node2))
2600 if (!m_ports.insert(
NodePair(node1, node2), port,
true))
2607 bool ConfigManager::DynamicPorts::get(
int node1,
int node2,
int* port)
const
2609 if (!check(node1, node2))
2613 (void)m_ports.search(
NodePair(node1, node2), value);
2621 ConfigManager::DynamicPorts::set_in_config(
Config* config)
2624 ConfigIter iter(config, CFG_SECTION_CONNECTION);
2626 for(;iter.valid();iter.next()) {
2628 if (iter.get(CFG_CONNECTION_SERVER_PORT, &port) != 0 ||
2633 require(iter.get(CFG_CONNECTION_NODE_1, &n1) == 0 &&
2634 iter.get(CFG_CONNECTION_NODE_2, &n2) == 0);
2637 if (!
get(n1, n2, &dyn_port) || dyn_port == 0)
2641 port = (Uint32)dyn_port;
2644 if(i2.set(CFG_CONNECTION_SERVER_PORT, port) ==
false)