List:Commits« Previous MessageNext Message »
From:Stewart Smith Date:June 16 2008 3:01pm
Subject:bzr commit into mysql-5.1-telco-6.4 branch (stewart:2656) WL#4278
View as plain text  
#At file:///home/stewart/mysql/stew-wl4278-disabled-nodes/

 2656 stewart@stripped	2008-06-17
      [patch 01/20] WL#4278 add ndb_mgm_set_configuration()pass a binary representation of the config to and from the mgm server
modified:
  storage/ndb/include/mgmapi/mgmapi.h
  storage/ndb/src/mgmapi/mgmapi.cpp
  storage/ndb/src/mgmsrv/MgmtSrvr.cpp
  storage/ndb/src/mgmsrv/MgmtSrvr.hpp
  storage/ndb/src/mgmsrv/Services.cpp
  storage/ndb/src/mgmsrv/Services.hpp
  storage/ndb/test/ndbapi/testMgm.cpp
  storage/ndb/test/run-test/daily-basic-tests.txt

=== modified file 'storage/ndb/include/mgmapi/mgmapi.h'
--- a/storage/ndb/include/mgmapi/mgmapi.h	2008-04-07 10:26:34 +0000
+++ b/storage/ndb/include/mgmapi/mgmapi.h	2008-06-16 15:00:55 +0000
@@ -1101,6 +1101,10 @@ extern "C" {
 							   unsigned version);
   void ndb_mgm_destroy_configuration(struct ndb_mgm_configuration *);
 
+  /* Pure, pure evil */
+  int ndb_mgm_set_configuration(NdbMgmHandle h, ndb_mgm_configuration *c);
+
+
   int ndb_mgm_alloc_nodeid(NdbMgmHandle handle,
 			   unsigned version, int nodetype, int log_event);
 

=== modified file 'storage/ndb/src/mgmapi/mgmapi.cpp'
--- a/storage/ndb/src/mgmapi/mgmapi.cpp	2008-03-13 14:09:32 +0000
+++ b/storage/ndb/src/mgmapi/mgmapi.cpp	2008-06-16 15:00:55 +0000
@@ -2935,4 +2935,66 @@ err:
   DBUG_RETURN(retval);
 }
 
+int ndb_mgm_set_configuration(NdbMgmHandle h, ndb_mgm_configuration *c)
+{
+  SocketOutputStream out(h->socket);
+  SocketInputStream in(h->socket, h->timeout);
+
+  const ConfigValues * cfg = (ConfigValues*)c;
+  UtilBuffer src;
+  cfg->pack(src);
+
+  char *tmp_str = (char *) malloc(base64_needed_encoded_length(src.length()));
+  (void) base64_encode(src.get_data(), src.length(), tmp_str);
+
+  out.println("set config");
+  out.println("Content-Length: %u", strlen(tmp_str));
+  out.println("Content-Type: ndbconfig/octet-stream");
+  out.println("Content-Transfer-Encoding: base64");
+
+  out.println("");
+
+  out.println(tmp_str);
+
+  const ParserRow<ParserDummy> reply[]= {
+    MGM_CMD("set config reply", NULL, ""),
+    MGM_ARG("result", String, Mandatory, "Result"),
+    MGM_END()
+  };
+
+  Parser_t::Context ctx;
+  ParserDummy session(h->socket);
+  Parser_t parser(reply, in, true, true, true);
+
+  const Properties* p = parser.parse(ctx, session);
+  if (p == NULL){
+    if(!ndb_mgm_is_connected(h)) {
+      return(-1);
+    }
+    else
+    {
+      if(ctx.m_status==Parser_t::Eof
+	 || ctx.m_status==Parser_t::NoLine)
+      {
+	ndb_mgm_disconnect(h);
+	return(-2);
+      }
+      /**
+       * Print some info about why the parser returns NULL
+       */
+      fprintf(h->errstream,
+	      "Error in mgm protocol parser. cmd: >%s< status: %d curr: %s\n",
+	      "set config", (Uint32)ctx.m_status,
+              (ctx.m_currentToken)?ctx.m_currentToken:"NULL");
+    }
+  }
+
+  BaseString result;
+  p->get("result",result);
+
+  delete p;
+
+  return atoi(result.c_str());
+}
+
 template class Vector<const ParserRow<ParserDummy>*>;

=== modified file 'storage/ndb/src/mgmsrv/MgmtSrvr.cpp'
--- a/storage/ndb/src/mgmsrv/MgmtSrvr.cpp	2008-06-09 10:52:24 +0000
+++ b/storage/ndb/src/mgmsrv/MgmtSrvr.cpp	2008-06-16 15:00:55 +0000
@@ -2930,6 +2930,21 @@ MgmtSrvr::setConnectionDbParameter(int n
   DBUG_RETURN(1);
 }
 
+int MgmtSrvr::set_config(ConfigValues* config)
+{
+  Guard g(m_configMutex);
+
+  /* gently with a chainsaw
+
+     This is in no way nice, sane or safe.
+
+     Puppies die here.
+   */
+  free(_config->m_configValues);
+  _config->m_configValues= (ndb_mgm_configuration*)config;
+
+  return 0;
+}
 
 int
 MgmtSrvr::getConnectionDbParameter(int node1, 

=== modified file 'storage/ndb/src/mgmsrv/MgmtSrvr.hpp'
--- a/storage/ndb/src/mgmsrv/MgmtSrvr.hpp	2008-06-09 10:52:24 +0000
+++ b/storage/ndb/src/mgmsrv/MgmtSrvr.hpp	2008-06-16 15:00:55 +0000
@@ -451,6 +451,8 @@ private:
   int check_nodes_starting();
   int check_nodes_stopping();
 
+  int set_config(ConfigValues* config);
+
   //**************************************************************************
   
   int _blockNumber;
@@ -459,7 +461,7 @@ private:
 
   BlockReference _ownReference; 
   NdbMutex *m_configMutex;
-  const Config * _config;
+  Config * _config;
   BaseString m_configFilename;
 
   NodeBitmask m_reserved_nodes;

=== modified file 'storage/ndb/src/mgmsrv/Services.cpp'
--- a/storage/ndb/src/mgmsrv/Services.cpp	2008-06-09 10:52:24 +0000
+++ b/storage/ndb/src/mgmsrv/Services.cpp	2008-06-16 15:00:55 +0000
@@ -278,6 +278,11 @@ ParserRow<MgmApiSession> commands[] = {
   MGM_CMD("get session", &MgmApiSession::getSession, ""),
     MGM_ARG("id", Int, Mandatory, "SessionID"),
 
+  MGM_CMD("set config", &MgmApiSession::set_config, ""),
+    MGM_ARG("Content-Length", Int, Mandatory, "Length of config"),
+    MGM_ARG("Content-Type", String, Mandatory, "Type of config"),
+    MGM_ARG("Content-Transfer-Encoding", String, Mandatory, "encoding"),
+
   MGM_END()
 };
 
@@ -1839,5 +1844,93 @@ MgmApiSession::getSession(Parser_t::Cont
   m_output->println("");
 }
 
+void MgmApiSession::set_config(Parser_t::Context &ctx, Properties const &args)
+{
+  int result= 0;
+  Uint32 content_length= 0;
+  char *config_str= NULL;
+  void *decoded= NULL;
+  const char *content_type;
+  const char *content_encoding;
+  int res= 0;
+  UtilBuffer tmp;
+  ConfigValuesFactory cvf;
+  int r = 0;
+  size_t start = 0;
+
+
+  args.get("Content-Length", &content_length);
+  args.get("Content-Type", &content_type);
+  args.get("Content-Transfer-Encoding", &content_encoding);
+
+  if(content_length ==0 || content_length > (1024*1024))
+  {
+    result= -1; //FIXME: wrong config length size
+    goto done;
+  }
+
+  if(!content_type || strcmp(content_type,"ndbconfig/octet-stream"))
+  {
+    result= -2; // FIXME: wrong content type
+    goto done;
+  }
+
+  if(!content_encoding || strcmp(content_encoding,"base64"))
+  {
+    result= -3;
+    goto done;
+  }
+
+  config_str= (char *) malloc(content_length+1);
+  if(!config_str)
+  {
+    result= -5; // FIXME no mem
+    goto done;
+  }
+
+  do {
+    if((r= read_socket(m_socket,30000,&config_str[start],content_length-start))
+       <0)
+    {
+      result= -(content_length-start); // FIXME
+      goto done;
+    }
+    start += r;
+  } while(start < content_length);
+
+  config_str[content_length]= 0;
+
+  decoded= malloc(base64_needed_decoded_length((size_t)(content_length)));
+
+  res= base64_decode(config_str, content_length, decoded, NULL);
+
+  ndbout << config_str << endl;
+
+  if (res < 0)
+  {
+    result= -6;
+    goto done;
+  }
+
+  tmp.append((void *) decoded, res);
+  res= cvf.unpack(tmp);
+  if(!res){
+    result= -7;
+    goto done;
+  }
+
+  m_mgmsrv.set_config(cvf.getConfigValues());
+
+done:
+
+  if(config_str)
+    free(config_str);
+  if(decoded)
+    free(decoded);
+  m_output->println("set config reply");
+  m_output->println("result: %u",result);
+  m_output->println("");
+}
+
 template class MutexVector<int>;
 template class Vector<ParserRow<MgmApiSession> const*>;

=== modified file 'storage/ndb/src/mgmsrv/Services.hpp'
--- a/storage/ndb/src/mgmsrv/Services.hpp	2007-03-22 11:33:07 +0000
+++ b/storage/ndb/src/mgmsrv/Services.hpp	2008-06-16 15:00:55 +0000
@@ -112,6 +112,8 @@ public:
 
   void getSessionId(Parser_t::Context &ctx, Properties const &args);
   void getSession(Parser_t::Context &ctx, Properties const &args);
+
+  void set_config(Parser_t::Context &ctx, Properties const &args);
 };
 
 class MgmApiService : public SocketServer::Service {

=== modified file 'storage/ndb/test/ndbapi/testMgm.cpp'
--- a/storage/ndb/test/ndbapi/testMgm.cpp	2007-06-13 12:54:00 +0000
+++ b/storage/ndb/test/ndbapi/testMgm.cpp	2008-06-16 15:00:55 +0000
@@ -91,6 +91,24 @@ int drop_index_on_pk(Ndb* pNdb, const ch
   return result;
 }
 
+int runTestApiSetConfig(NDBT_Context* ctx, NDBT_Step* step)
+{
+  char *mgm= ctx->getRemoteMgm();
+  ndb_mgm_configuration *fetched_config;
+
+  NdbMgmHandle h;
+  h= ndb_mgm_create_handle();
+  ndb_mgm_set_connectstring(h, mgm);
+  ndb_mgm_connect(h,0,0,0);
+
+  fetched_config = ndb_mgm_get_configuration(h, 0);
+
+  int r= ndb_mgm_set_configuration(h,fetched_config);
+
+  ndbout << "ndb_mgm_set_coniguration returned: " << r << endl;
+
+  return (r==0)?NDBT_OK:NDBT_FAILED;
+}
 
 #define CHECK(b) if (!(b)) { \
   g_err << "ERR: "<< step->getName() \
@@ -828,6 +846,11 @@ TESTCASE("ApiMgmStructEventTimeout",
   INITIALIZER(runTestMgmApiStructEventTimeout);
 
 }
+TESTCASE("ApiSetConfig",
+	 "Tests the ndb_mgm_set_configuration"){
+  INITIALIZER(runTestApiSetConfig);
+
+}
 NDBT_TESTSUITE_END(testMgm);
 
 int main(int argc, const char** argv){

=== modified file 'storage/ndb/test/run-test/daily-basic-tests.txt'
--- a/storage/ndb/test/run-test/daily-basic-tests.txt	2008-06-11 20:48:24 +0000
+++ b/storage/ndb/test/run-test/daily-basic-tests.txt	2008-06-16 15:00:55 +0000
@@ -982,6 +982,10 @@ max-time: 120
 cmd: testMgm
 args: -n ApiMgmStructEventTimeout T1
 
+max-time: 120
+cmd: testMgm
+args: -n ApiSetConfig T1
+
 max-time: 5000
 cmd: testNodeRestart
 args: -n GCP T1

Thread
bzr commit into mysql-5.1-telco-6.4 branch (stewart:2656) WL#4278Stewart Smith16 Jun