List:Commits« Previous MessageNext Message »
From:Magnus Svensson Date:December 16 2008 12:50pm
Subject:bzr commit into mysql-5.1 branch (msvensson:3162) WL#4350
View as plain text  
#At file:///home/msvensson/mysql/6.4-wl4350/ based on
revid:msvensson@stripped

 3162 Magnus Svensson	2008-12-16
      WL#4350 - add show config
modified:
  storage/ndb/include/util/NdbOut.hpp
  storage/ndb/src/common/util/NdbOut.cpp
  storage/ndb/src/common/util/OutputStream.cpp
  storage/ndb/src/mgmsrv/Config.cpp
  storage/ndb/src/mgmsrv/Config.hpp
  storage/ndb/src/mgmsrv/MgmtSrvr.cpp
  storage/ndb/src/mgmsrv/MgmtSrvr.hpp
  storage/ndb/src/mgmsrv/Services.cpp
  storage/ndb/src/mgmsrv/Services.hpp

per-file messages:
  storage/ndb/include/util/NdbOut.hpp
    Make it possible to turn off NdbOut's autoflush in 'endl'
  storage/ndb/src/common/util/NdbOut.cpp
    Make it possible to turn off NdbOut's autoflush in 'endl'
    Fix a bug where 'NdbOut::print' and 'NdbOut::println' does not use the output stream
  storage/ndb/src/common/util/OutputStream.cpp
    Fix bug in 'BufferOutputStream::print' causing one extra \0 byte to be added to the
buffer
  storage/ndb/src/mgmsrv/Config.cpp
    Make it possible to filter which parts of a config is printed
  storage/ndb/src/mgmsrv/Config.hpp
    Make it possible to filter which parts of a config is printed
  storage/ndb/src/mgmsrv/MgmtSrvr.cpp
    Add 'print_config'
  storage/ndb/src/mgmsrv/MgmtSrvr.hpp
    Add 'print_config'
  storage/ndb/src/mgmsrv/Services.cpp
    Add 'show config'
  storage/ndb/src/mgmsrv/Services.hpp
    Add 'show config'
=== modified file 'storage/ndb/include/util/NdbOut.hpp'
--- a/storage/ndb/include/util/NdbOut.hpp	2008-11-06 16:52:59 +0000
+++ b/storage/ndb/include/util/NdbOut.hpp	2008-12-16 11:50:38 +0000
@@ -74,7 +74,7 @@ public:
   NdbOut& flushline(void);
   NdbOut& setHexFormat(int _format);
   
-  NdbOut(OutputStream &);
+  NdbOut(OutputStream &, bool autoflush = true);
   virtual ~NdbOut();
 
   void print(const char * fmt, ...)
@@ -86,6 +86,7 @@ public:
 private:
   void choose(const char * fmt,...);
   int isHex;
+  bool m_autoflush;
 };
 
 #ifdef NDB_WIN

=== modified file 'storage/ndb/src/common/util/NdbOut.cpp'
--- a/storage/ndb/src/common/util/NdbOut.cpp	2008-01-28 02:14:29 +0000
+++ b/storage/ndb/src/common/util/NdbOut.cpp	2008-12-16 11:50:38 +0000
@@ -68,7 +68,8 @@ NdbOut& NdbOut::endline()
 {
   isHex = 0; // Reset hex to normal, if user forgot this
   m_out->println("");
-  m_out->flush();
+  if (m_autoflush)
+    m_out->flush();
   return *this;
 }
 
@@ -84,10 +85,9 @@ NdbOut& NdbOut::setHexFormat(int _format
   return *this;
 }
 
-NdbOut::NdbOut(OutputStream & out) 
-  : m_out(& out)
+NdbOut::NdbOut(OutputStream & out, bool autoflush)
+  : m_out(& out), isHex(0), m_autoflush(autoflush)
 {
-  isHex = 0;
 }
 
 NdbOut::~NdbOut()
@@ -102,7 +102,7 @@ NdbOut::print(const char * fmt, ...){
   va_start(ap, fmt);
   if (fmt != 0)
     BaseString::vsnprintf(buf, sizeof(buf)-1, fmt, ap);
-  ndbout << buf;
+  *this << buf;
   va_end(ap);
 }
 
@@ -114,7 +114,7 @@ NdbOut::println(const char * fmt, ...){
   va_start(ap, fmt);
   if (fmt != 0)
     BaseString::vsnprintf(buf, sizeof(buf)-1, fmt, ap);
-  ndbout << buf << endl;
+  *this << buf << endl;
   va_end(ap);
 }
 

=== modified file 'storage/ndb/src/common/util/OutputStream.cpp'
--- a/storage/ndb/src/common/util/OutputStream.cpp	2008-08-21 06:32:09 +0000
+++ b/storage/ndb/src/common/util/OutputStream.cpp	2008-12-16 11:50:38 +0000
@@ -122,15 +122,23 @@ BufferedSockOutputStream::print(const ch
   len = BaseString::vsnprintf(buf, sizeof(buf), fmt, ap);
   va_end(ap);
 
-  // Grow buffer so it can hold the string
-  if ((pos= (char*)m_buffer.append(len+1)) == 0)
+  // Allocate a temp buffer for the string
+  UtilBuffer tmp;
+  if (tmp.append(len+1) == 0)
     return -1;
 
-  // Print string to buffer
+  // Print to temp buffer
   va_start(ap, fmt);
-  len = BaseString::vsnprintf((char*)pos, len+1, fmt, ap);
+  len = BaseString::vsnprintf((char*)tmp.get_data(), len+1, fmt, ap);
   va_end(ap);
 
+  // Grow real buffer so it can hold the string
+  if ((pos= (char*)m_buffer.append(len)) == 0)
+    return -1;
+
+  // Move everything except ending 0 to real buffer
+  memcpy(pos, tmp.get_data(), tmp.length()-1);
+
   return 0;
 }
 

=== modified file 'storage/ndb/src/mgmsrv/Config.cpp'
--- a/storage/ndb/src/mgmsrv/Config.cpp	2008-11-13 07:57:54 +0000
+++ b/storage/ndb/src/mgmsrv/Config.cpp	2008-12-16 11:50:38 +0000
@@ -64,7 +64,9 @@ const size_t num_sections= sizeof(sectio
 static const ConfigInfo g_info;
 
 void
-Config::print() const {
+Config::print(const char* section_filter, NodeId nodeid_filter,
+              const char* param_filter,
+              NdbOut& out) const {
 
   for(unsigned i= 0; i < num_sections; i++) {
     unsigned section= sections[i];
@@ -84,7 +86,19 @@ Config::print() const {
                                            section,
                                            section_type);
 
-      ndbout_c("[%s]", g_info.sectionName(section, section_type));
+      const char* section_name= g_info.sectionName(section, section_type);
+
+      // Section name filter
+      if (section_filter &&                     // Filter is on
+          strcmp(section_filter, section_name)) // Value is different
+        continue;
+
+      // NodeId filter
+      Uint32 nodeid = 0;
+      it.get(CFG_NODE_ID, &nodeid);
+      if (nodeid_filter &&                   // Filter is on
+          nodeid_filter != nodeid)           // Value is different
+        continue;
 
       /*  Loop through the section and print those values that exist */
       Uint32 val;
@@ -92,12 +106,23 @@ Config::print() const {
       const char* val_str;
       while((pinfo= param_iter.next())){
 
+        // Param name filter
+        if (param_filter &&                      // Filter is on
+            strcmp(param_filter, pinfo->_fname)) // Value is different
+          continue;
+
+        if (section_name) // Print section name only first time
+        {
+          out << "[" << section_name << "]" << endl;
+          section_name= NULL;
+        }
+
         if (!it.get(pinfo->_paramId, &val))
-          ndbout_c("%s=%u", pinfo->_fname, val);
+          out << pinfo->_fname << "=" << val << endl;
         else if (!it.get(pinfo->_paramId, &val64))
-          ndbout_c("%s=%llu", pinfo->_fname, val64);
+          out << pinfo->_fname << "=" << val64 << endl;
         else if (!it.get(pinfo->_paramId, &val_str))
-          ndbout_c("%s=%s", pinfo->_fname, val_str);
+          out << pinfo->_fname << "=" << val_str << endl;
       }
     }
   }

=== modified file 'storage/ndb/src/mgmsrv/Config.hpp'
--- a/storage/ndb/src/mgmsrv/Config.hpp	2008-10-21 12:41:59 +0000
+++ b/storage/ndb/src/mgmsrv/Config.hpp	2008-12-16 11:50:38 +0000
@@ -36,7 +36,9 @@ public:
   Config(const Config*);
   virtual ~Config();
 
-  void print() const;
+  void print(const char* section_filter = NULL, NodeId nodeid_filter = NULL,
+             const char* param_filter = NULL,
+             NdbOut& out = ndbout) const;
 
   /*
     Returns generation of the config

=== modified file 'storage/ndb/src/mgmsrv/MgmtSrvr.cpp'
--- a/storage/ndb/src/mgmsrv/MgmtSrvr.cpp	2008-12-05 09:58:51 +0000
+++ b/storage/ndb/src/mgmsrv/MgmtSrvr.cpp	2008-12-16 11:50:38 +0000
@@ -411,8 +411,7 @@ MgmtSrvr::init()
 
   if (m_opts.print_full_config)
   {
-    Guard g(m_local_config_mutex);
-    m_local_config->print();
+    print_config();
     DBUG_RETURN(false);
   }
 
@@ -3913,6 +3912,16 @@ MgmtSrvr::change_config(Config& new_conf
 }
 
 
+void
+MgmtSrvr::print_config(const char* section_filter, NodeId nodeid_filter,
+                       const char* param_filter,
+                       NdbOut& out)
+{
+  Guard g(m_local_config_mutex);
+  m_local_config->print(section_filter, nodeid_filter,
+                        param_filter, out);
+}
+
 template class MutexVector<NodeId>;
 template class MutexVector<Ndb_mgmd_event_service::Event_listener>;
 template class Vector<EventSubscribeReq>;

=== modified file 'storage/ndb/src/mgmsrv/MgmtSrvr.hpp'
--- a/storage/ndb/src/mgmsrv/MgmtSrvr.hpp	2008-12-05 09:58:51 +0000
+++ b/storage/ndb/src/mgmsrv/MgmtSrvr.hpp	2008-12-16 11:50:38 +0000
@@ -553,6 +553,11 @@ public:
   */
   bool getPackedConfig(UtilBuffer& pack_buf);
 
+  void print_config(const char* section_filter = NULL,
+                    NodeId nodeid_filter = 0,
+                    const char* param_filter = NULL,
+                    NdbOut& out = ndbout);
+
 };
 
 

=== modified file 'storage/ndb/src/mgmsrv/Services.cpp'
--- a/storage/ndb/src/mgmsrv/Services.cpp	2008-11-17 09:22:20 +0000
+++ b/storage/ndb/src/mgmsrv/Services.cpp	2008-12-16 11:50:38 +0000
@@ -291,6 +291,11 @@ ParserRow<MgmApiSession> commands[] = {
   MGM_CMD("ndbinfo", &MgmApiSession::getNdbInfo, ""),
     MGM_ARG("query", String, Mandatory, "SQL-Like Query"),
 
+  MGM_CMD("show config", &MgmApiSession::showConfig, ""),
+    MGM_ARG("Section", String, Optional, "Section name"),
+    MGM_ARG("NodeId", Int, Optional, "Nodeid"),
+    MGM_ARG("Name", String, Optional, "Parameter name"),
+
   MGM_END()
 };
 
@@ -2067,6 +2072,25 @@ void MgmApiSession::getNdbInfo(Parser_t:
   return ;
 }
 
+
+void MgmApiSession::showConfig(Parser_t::Context &ctx, Properties const &args)
+{
+  const char* section = NULL;
+  const char* name = NULL;
+  Uint32 nodeid = 0;
+
+  args.get("Section", &section);
+  args.get("NodeId", &nodeid);
+  args.get("Name", &name);
+
+  NdbOut socket_out(*m_output, false /* turn off autoflush */);
+  m_output->println("show config reply");
+  m_mgmsrv.print_config(section, nodeid, name,
+                        socket_out);
+  m_output->println("");
+}
+
+
 #if 0
   // TODO Magnus, "get variables"
   ndbout_c("NdbConfig_get_path(0): %s", NdbConfig_get_path(0));

=== modified file 'storage/ndb/src/mgmsrv/Services.hpp'
--- a/storage/ndb/src/mgmsrv/Services.hpp	2008-10-05 07:12:28 +0000
+++ b/storage/ndb/src/mgmsrv/Services.hpp	2008-12-16 11:50:38 +0000
@@ -61,6 +61,7 @@ public:
 
   void getConfig(Parser_t::Context &ctx, const class Properties &args);
   void setConfig(Parser_t::Context &ctx, const class Properties &args);
+  void showConfig(Parser_t::Context &ctx, const class Properties &args);
 
   void get_nodeid(Parser_t::Context &ctx, const class Properties &args);
   void getVersion(Parser_t::Context &ctx, const class Properties &args);

Thread
bzr commit into mysql-5.1 branch (msvensson:3162) WL#4350Magnus Svensson16 Dec