Commit 86d2906b authored by joreland@mysql.com's avatar joreland@mysql.com

Initial support for updating configuration "on the fly"

Only updates values mgmsrv's on main memory
to be used in test prg's
parent 2082e8b9
......@@ -106,6 +106,31 @@ extern "C" {
struct ndb_mgm_reply* reply);
/**
*
* @param handle the NDB management handle.
* @param nodeId the node id. 0 = all db nodes
* @param errrorCode the errorCode.
* @param reply the reply message.
* @return 0 if successful or an error code.
*/
int ndb_mgm_set_int_parameter(NdbMgmHandle handle,
int node,
int param,
unsigned value,
struct ndb_mgm_reply* reply);
int ndb_mgm_set_int64_parameter(NdbMgmHandle handle,
int node,
int param,
unsigned long long value,
struct ndb_mgm_reply* reply);
int ndb_mgm_set_string_parameter(NdbMgmHandle handle,
int node,
int param,
const char * value,
struct ndb_mgm_reply* reply);
#ifdef __cplusplus
}
#endif
......
......@@ -32,9 +32,8 @@ public:
class ConstIterator {
friend class ConfigValuesFactory;
const ConfigValues & m_cfg;
protected:
Uint32 m_currentSection;
public:
Uint32 m_currentSection;
ConstIterator(const ConfigValues&c) : m_cfg(c) { m_currentSection = 0;}
bool openSection(Uint32 key, Uint32 no);
......@@ -57,6 +56,9 @@ public:
ConfigValues & m_cfg;
public:
Iterator(ConfigValues&c) : ConstIterator(c), m_cfg(c) {}
Iterator(ConfigValues&c, const ConstIterator& i):ConstIterator(c),m_cfg(c){
m_currentSection = i.m_currentSection;
}
bool set(Uint32 key, Uint32 value);
bool set(Uint32 key, Uint64 value);
......
......@@ -283,6 +283,7 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow<ParserDummy> *command_reply,
while((name = iter.next()) != NULL) {
PropertiesType t;
Uint32 val_i;
Uint64 val_64;
BaseString val_s;
cmd_args->getTypeOf(name, &t);
......@@ -291,11 +292,15 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow<ParserDummy> *command_reply,
cmd_args->get(name, &val_i);
out.println("%s: %d", name, val_i);
break;
case PropertiesType_Uint64:
cmd_args->get(name, &val_64);
out.println("%s: %Ld", name, val_64);
break;
case PropertiesType_char:
cmd_args->get(name, val_s);
out.println("%s: %s", name, val_s.c_str());
break;
default:
case PropertiesType_Properties:
/* Ignore */
break;
}
......@@ -1591,3 +1596,132 @@ ndb_mgm_rep_command(NdbMgmHandle handle, unsigned int request,
delete reply;
return 0;
}
extern "C"
int
ndb_mgm_set_int_parameter(NdbMgmHandle handle,
int node,
int param,
unsigned value,
struct ndb_mgm_reply*){
CHECK_HANDLE(handle, 0);
CHECK_CONNECTED(handle, 0);
Properties args;
args.put("node: ", node);
args.put("param: ", param);
args.put("value: ", value);
const ParserRow<ParserDummy> reply[]= {
MGM_CMD("set parameter reply", NULL, ""),
MGM_ARG("result", String, Mandatory, "Error message"),
MGM_END()
};
const Properties *prop;
prop= ndb_mgm_call(handle, reply, "set parameter", &args);
if(prop == NULL) {
SET_ERROR(handle, EIO, "Unable set parameter");
return -1;
}
int res= -1;
do {
const char * buf;
if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){
ndbout_c("ERROR Message: %s\n", buf);
break;
}
res= 0;
} while(0);
delete prop;
return res;
}
extern "C"
int
ndb_mgm_set_int64_parameter(NdbMgmHandle handle,
int node,
int param,
unsigned long long value,
struct ndb_mgm_reply*){
CHECK_HANDLE(handle, 0);
CHECK_CONNECTED(handle, 0);
Properties args;
args.put("node: ", node);
args.put("param: ", param);
args.put("value: ", value);
const ParserRow<ParserDummy> reply[]= {
MGM_CMD("set parameter reply", NULL, ""),
MGM_ARG("result", String, Mandatory, "Error message"),
MGM_END()
};
const Properties *prop;
prop= ndb_mgm_call(handle, reply, "set parameter", &args);
if(prop == NULL) {
SET_ERROR(handle, EIO, "Unable set parameter");
return -1;
}
int res= -1;
do {
const char * buf;
if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){
ndbout_c("ERROR Message: %s\n", buf);
break;
}
res= 0;
} while(0);
delete prop;
return res;
}
extern "C"
int
ndb_mgm_set_string_parameter(NdbMgmHandle handle,
int node,
int param,
const char * value,
struct ndb_mgm_reply*){
CHECK_HANDLE(handle, 0);
CHECK_CONNECTED(handle, 0);
Properties args;
args.put("node: ", node);
args.put("parameter: ", param);
args.put("value: ", value);
const ParserRow<ParserDummy> reply[]= {
MGM_CMD("set parameter reply", NULL, ""),
MGM_ARG("result", String, Mandatory, "Error message"),
MGM_END()
};
const Properties *prop;
prop= ndb_mgm_call(handle, reply, "set parameter", &args);
if(prop == NULL) {
SET_ERROR(handle, EIO, "Unable set parameter");
return -1;
}
int res= -1;
do {
const char * buf;
if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){
ndbout_c("ERROR Message: %s\n", buf);
break;
}
res= 0;
} while(0);
delete prop;
return res;
}
......@@ -2777,3 +2777,104 @@ MgmtSrvr::Allocated_resources::reserve_node(NodeId id)
m_mgmsrv.m_reserved_nodes.set(id);
}
int
MgmtSrvr::setDbParameter(int node, int param, const char * value,
BaseString& msg){
/**
* Check parameter
*/
ndb_mgm_configuration_iterator iter(* _config->m_configValues,
CFG_SECTION_NODE);
if(iter.first() != 0){
msg.assign("Unable to find node section (iter.first())");
return -1;
}
Uint32 type = NODE_TYPE_DB + 1;
if(node != 0){
if(iter.find(CFG_NODE_ID, node) != 0){
msg.assign("Unable to find node (iter.find())");
return -1;
}
if(iter.get(CFG_TYPE_OF_SECTION, &type) != 0){
msg.assign("Unable to get node type(iter.get(CFG_TYPE_OF_SECTION))");
return -1;
}
} else {
do {
if(iter.get(CFG_TYPE_OF_SECTION, &type) != 0){
msg.assign("Unable to get node type(iter.get(CFG_TYPE_OF_SECTION))");
return -1;
}
if(type == NODE_TYPE_DB)
break;
} while(iter.next() == 0);
}
if(type != NODE_TYPE_DB){
msg.assfmt("Invalid node type or no such node (%d %d)",
type, NODE_TYPE_DB);
return -1;
}
int p_type;
unsigned val_32;
unsigned long long val_64;
const char * val_char;
do {
p_type = 0;
if(iter.get(param, &val_32) == 0){
val_32 = atoi(value);
break;
}
p_type++;
if(iter.get(param, &val_64) == 0){
val_64 = atoll(value);
break;
}
p_type++;
if(iter.get(param, &val_char) == 0){
val_char = value;
break;
}
msg.assign("Could not get parameter");
return -1;
} while(0);
bool res = false;
do {
int ret = iter.get(CFG_TYPE_OF_SECTION, &type);
assert(ret == 0);
if(type != NODE_TYPE_DB)
continue;
Uint32 node;
ret = iter.get(CFG_NODE_ID, &node);
assert(ret == 0);
ConfigValues::Iterator i2(_config->m_configValues->m_config,
iter.m_config);
switch(p_type){
case 0:
res = i2.set(param, val_32);
ndbout_c("Updateing node %d param: %d to %d", node, param, val_32);
break;
case 1:
res = i2.set(param, val_64);
ndbout_c("Updateing node %d param: %d to %Ld", node, param, val_32);
break;
case 2:
res = i2.set(param, val_char);
ndbout_c("Updateing node %d param: %d to %s", node, param, val_char);
break;
default:
abort();
}
assert(res);
} while(node == 0 && iter.next() == 0);
msg.assign("Success");
return 0;
}
......@@ -517,6 +517,8 @@ public:
*/
int getPort() const;
int setDbParameter(int node, int parameter, const char * value, BaseString&);
//**************************************************************************
private:
//**************************************************************************
......
......@@ -225,6 +225,16 @@ ParserRow<MgmApiSession> commands[] = {
MGM_ARG("parameter", String, Mandatory, "Parameter"),
MGM_ARG("value", String, Mandatory, "Value"),
MGM_CMD("config lock", &MgmApiSession::configLock, ""),
MGM_CMD("config unlock", &MgmApiSession::configUnlock, ""),
MGM_ARG("commit", Int, Mandatory, "Commit changes"),
MGM_CMD("set parameter", &MgmApiSession::setParameter, ""),
MGM_ARG("node", String, Mandatory, "Node"),
MGM_ARG("parameter", String, Mandatory, "Parameter"),
MGM_ARG("value", String, Mandatory, "Value"),
MGM_END()
};
......@@ -1248,5 +1258,24 @@ MgmStatService::stopSessions(){
NDB_CLOSE_SOCKET(m_sockets[i]);
m_sockets.erase(i);
}
}
void
MgmApiSession::setParameter(Parser_t::Context &,
Properties const &args) {
BaseString node, param, value;
args.get("node", node);
args.get("parameter", param);
args.get("value", value);
BaseString result;
int ret = m_mgmsrv.setDbParameter(atoi(node.c_str()),
atoi(param.c_str()),
value.c_str(),
result);
m_output->println("set parameter reply");
m_output->println("message: %s", result.c_str());
m_output->println("result: %d", ret);
m_output->println("");
}
......@@ -82,6 +82,8 @@ public:
void configUnlock(Parser_t::Context &ctx, const class Properties &args);
void configChange(Parser_t::Context &ctx, const class Properties &args);
void setParameter(Parser_t::Context &ctx, const class Properties &args);
void repCommand(Parser_t::Context &ctx, const class Properties &args);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment