List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:March 15 2010 8:20am
Subject:bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3437) WL#4523
View as plain text  
#At file:///home/msvensson/mysql/7.0-angel/ based on revid:magnus.blaudd@stripped0pnpclnaq3mt6m1s

 3437 Magnus Blåudd	2010-03-15
      WL#4523  Run ndbd as Windows Service

       - Extract the hosts to report to directly from ndb_mgm_configuration
         passed as parameter to function - only angel uses reportShutDown
         function now
       - Remove the m_mgmds vector from the global configuration
         previsouly used by reportShutdown
       - Remove friend declarations of reportShutdown
       - Make reportShutdown static

    modified:
      storage/ndb/src/kernel/angel.cpp
      storage/ndb/src/kernel/vm/Configuration.cpp
      storage/ndb/src/kernel/vm/Configuration.hpp
=== modified file 'storage/ndb/src/kernel/angel.cpp'
--- a/storage/ndb/src/kernel/angel.cpp	2009-06-04 19:10:46 +0000
+++ b/storage/ndb/src/kernel/angel.cpp	2010-03-15 08:20:23 +0000
@@ -28,9 +28,6 @@
 #include <EventLogger.hpp>
 extern EventLogger * g_eventLogger;
 
-#include "vm/SimBlockList.hpp"
-
-
 #define MAX_FAILED_STARTUPS 3
 // Flag set by child through SIGUSR1 to signal a failed startup
 static bool failed_startup_flag=false;
@@ -108,9 +105,18 @@ get_int_property(Properties &info,
   return true;
 }
 
-int reportShutdown(class Configuration *config, int error_exit, int restart, Uint32 sphase=256)
+#include "../mgmapi/mgmapi_configuration.hpp"
+
+static void
+reportShutdown(const ndb_mgm_configuration* config,
+               NodeId nodeid, int error_exit,
+               bool restart, bool nostart, bool initial)
 {
-  Uint32 error=0, signum=0;
+  // Only allow "initial" and "nostart" to be set if "restart" is set
+  assert(restart ||
+         (!restart && !initial && !nostart));
+
+  Uint32 error=0, signum=0, sphase=256;
 #ifndef NDB_WIN
   Properties info;
   readChildInfo(info);
@@ -122,11 +128,11 @@ int reportShutdown(class Configuration *
   Uint32 length, theData[25];
   EventReport *rep=(EventReport *) theData;
 
-  rep->setNodeId(globalData.ownId);
+  rep->setNodeId(nodeid);
   if (restart)
     theData[1]=1 |
-          (globalData.theRestartFlag == initial_state ? 2 : 0) |
-    (config->getInitialStart() ? 4 : 0);
+      (nostart ? 2 : 0) |
+      (initial ? 4 : 0);
   else
     theData[1]=0;
 
@@ -145,51 +151,53 @@ int reportShutdown(class Configuration *
     length=6;
   }
 
-  { // Log event
-    const EventReport * const eventReport=(EventReport *) & theData[0];
-    g_eventLogger->log(eventReport->getEventType(), theData, length,
-                       eventReport->getNodeId(), 0);
-  }
-
-  for (unsigned n=0; n < config->m_mgmds.size(); n++)
+  // Log event locally
+  g_eventLogger->log(rep->getEventType(), theData, length,
+                     rep->getNodeId(), 0);
+
+  // Log event to cluster log
+  ndb_mgm_configuration_iterator iter(*config, CFG_SECTION_NODE);
+  for (iter.first(); iter.valid(); iter.next())
   {
-    NdbMgmHandle h=ndb_mgm_create_handle();
-    if (h == 0 ||
-        ndb_mgm_set_connectstring(h, config->m_mgmds[n].c_str()) ||
-        ndb_mgm_connect(h,
-                        1, //no_retries
-                        0, //retry_delay_in_seconds
-                        0 //verbose
-                        ))
-      goto handle_error;
-
-    {
-      if (ndb_mgm_report_event(h, theData, length))
-        goto handle_error;
+    Uint32 type;
+    if (iter.get(CFG_TYPE_OF_SECTION, &type) ||
+       type != NODE_TYPE_MGM)
+      continue;
+
+    Uint32 port;
+    if (iter.get(CFG_MGM_PORT, &port))
+      continue;
+
+    const char* hostname;
+    if (iter.get(CFG_NODE_HOST, &hostname))
+      continue;
+
+    BaseString connect_str;
+    connect_str.assfmt("%s:%d", hostname, port);
+
+
+    NdbMgmHandle h = ndb_mgm_create_handle();
+    if (h == 0)
+    {
+      g_eventLogger->warning("Unable to report shutdown reason "
+                             "to '%s'(failed to create mgm handle)",
+                             connect_str.c_str());
+      continue;
     }
-    goto do_next;
 

-handle_error:
-    if (h)
-    {
-      BaseString tmp(ndb_mgm_get_latest_error_msg(h));
-      tmp.append(" : ");
-      tmp.append(ndb_mgm_get_latest_error_desc(h));
-      g_eventLogger->warning("Unable to report shutdown reason to %s: %s",
-                             config->m_mgmds[n].c_str(), tmp.c_str());
-    } else
-    {
-      g_eventLogger->error("Unable to report shutdown reason to %s",
-                           config->m_mgmds[n].c_str());
-    }
-do_next:
-    if (h)
-    {
-      ndb_mgm_disconnect(h);
-      ndb_mgm_destroy_handle(&h);
+    if (ndb_mgm_set_connectstring(h, connect_str.c_str()) ||
+        ndb_mgm_connect(h, 1, 0, 0) ||
+        ndb_mgm_report_event(h, theData, length))
+    {
+      g_eventLogger->warning("Unable to report shutdown reason "
+                             "to '%s'(error: %s - %s)",
+                             connect_str.c_str(),
+                             ndb_mgm_get_latest_error_msg(h),
+                             ndb_mgm_get_latest_error_desc(h));
     }
+
+    ndb_mgm_destroy_handle(&h);
   }
-  return 0;
 }
 
 
@@ -243,6 +251,8 @@ ignore_signals(void)
 void
 childReportSignal(int signum);
 
+#include "vm/SimBlockList.hpp"
+
 int
 angel_run(const char* connect_str,
           const char* bind_address,
@@ -320,7 +330,8 @@ angel_run(const char* connect_str,
       switch (WEXITSTATUS(status)) {
       case NRT_Default:
         g_eventLogger->info("Angel shutting down");
-        reportShutdown(theConfig, 0, 0);
+        reportShutdown(theConfig->getClusterConfig(),
+                       globalData.ownId, 0, 0, false, false);
         angel_exit(0);
         break;
       case NRT_NoStart_Restart:
@@ -342,7 +353,8 @@ angel_run(const char* connect_str,
           /**
            * Error shutdown && stopOnError()
            */
-          reportShutdown(theConfig, error_exit, 0);
+          reportShutdown(theConfig->getClusterConfig(), globalData.ownId,
+                         error_exit, 0, false, false);
           angel_exit(0);
         }
         // Fall-through
@@ -368,7 +380,8 @@ angel_run(const char* connect_str,
         /**
          * Error shutdown && stopOnError()
          */
-        reportShutdown(theConfig, error_exit, 0);
+        reportShutdown(theConfig->getClusterConfig(), globalData.ownId,
+                       error_exit, 0, false, false);
         angel_exit(0);
       }
     }
@@ -384,11 +397,15 @@ angel_run(const char* connect_str,
        */
       g_eventLogger->alert("Ndbd has failed %u consecutive startups. "
                            "Not restarting", failed_startups);
-      reportShutdown(theConfig, error_exit, 0);
+      reportShutdown(theConfig->getClusterConfig(), globalData.ownId,
+                     error_exit, 0, false, false);
       angel_exit(0);
     }
     failed_startup_flag=false;
-    reportShutdown(theConfig, error_exit, 1);
+    reportShutdown(theConfig->getClusterConfig(), globalData.ownId,
+                   error_exit, 1,
+                   (globalData.theRestartFlag == initial_state), /* nostart */
+                   theConfig->getInitialStart() /* initial */ );
     g_eventLogger->info("Ndb has terminated (pid %d) restarting", child);
     theConfig->fetch_configuration(connect_str, bind_address);
   }

=== modified file 'storage/ndb/src/kernel/vm/Configuration.cpp'
--- a/storage/ndb/src/kernel/vm/Configuration.cpp	2010-02-02 09:01:11 +0000
+++ b/storage/ndb/src/kernel/vm/Configuration.cpp	2010-03-15 08:20:23 +0000
@@ -216,28 +216,6 @@ Configuration::fetch_configuration(const
   }
   NdbConfig_SetPath(datadir);
 
-  m_mgmds.clear();
-  for(ndb_mgm_first(&iter); ndb_mgm_valid(&iter); ndb_mgm_next(&iter))
-  {
-    Uint32 nodeType, port;
-    char const *hostname;
-
-    ndb_mgm_get_int_parameter(&iter,CFG_TYPE_OF_SECTION,&nodeType);
-
-    if (nodeType != NodeInfo::MGM)
-      continue;
-
-    if (ndb_mgm_get_string_parameter(&iter,CFG_NODE_HOST, &hostname) ||
-	ndb_mgm_get_int_parameter(&iter,CFG_MGM_PORT, &port) ||
-	hostname == 0 || hostname[0] == 0)
-    {
-      continue;
-    }
-    BaseString connectstring(hostname);
-    connectstring.appfmt(":%d", port);
-
-    m_mgmds.push_back(connectstring);
-  }
 }
 
 static char * get_and_validate_path(ndb_mgm_configuration_iterator &iter,

=== modified file 'storage/ndb/src/kernel/vm/Configuration.hpp'
--- a/storage/ndb/src/kernel/vm/Configuration.hpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/src/kernel/vm/Configuration.hpp	2010-03-15 08:20:23 +0000
@@ -135,7 +135,6 @@ public:
 private:
   friend class Cmvmi;
   friend class Qmgr;
-  friend int reportShutdown(class Configuration *config, int error, int restart, Uint32 sphase);
 
   Uint32 _stopOnError;
   Uint32 m_restartOnErrorInsert;
@@ -160,8 +159,6 @@ private:
   
   ConfigRetriever *m_config_retriever;
 
-  Vector<BaseString> m_mgmds;
-
   /**
    * arguments to NDB process
    */

Attachment: [text/bzr-bundle] bzr/magnus.blaudd@sun.com-20100315082023-2w48hj8n5iaatymq.bundle
Thread
bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3437) WL#4523Magnus Blåudd15 Mar