List:Commits« Previous MessageNext Message »
From:Stewart Smith Date:June 20 2006 7:33am
Subject:bk commit into 5.1 tree (stewart:1.2225)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of stewart. When stewart does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2225 06/06/20 17:33:14 stewart@stripped +5 -0
  Merge mysql.com:/home/stewart/Documents/MySQL/5.0/bugsmerge
  into  mysql.com:/home/stewart/Documents/MySQL/5.1/main

  storage/ndb/src/mgmsrv/MgmtSrvr.cpp
    1.100 06/06/20 17:33:10 stewart@stripped +0 -1
    manual merge (n/a in 5.1)

  storage/ndb/src/mgmsrv/ConfigInfo.cpp
    1.77 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Auto merged

  storage/ndb/src/mgmapi/mgmapi.cpp
    1.66 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Auto merged

  storage/ndb/src/common/util/ConfigValues.cpp
    1.10 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Auto merged

  storage/ndb/include/util/ConfigValues.hpp
    1.5 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Auto merged

  storage/ndb/src/mgmsrv/MgmtSrvr.cpp
    1.73.26.2 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Merge rename: ndb/src/mgmsrv/MgmtSrvr.cpp -> storage/ndb/src/mgmsrv/MgmtSrvr.cpp

  storage/ndb/src/mgmsrv/ConfigInfo.cpp
    1.60.9.4 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Merge rename: ndb/src/mgmsrv/ConfigInfo.cpp -> storage/ndb/src/mgmsrv/ConfigInfo.cpp

  storage/ndb/src/mgmapi/mgmapi.cpp
    1.44.16.2 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Merge rename: ndb/src/mgmapi/mgmapi.cpp -> storage/ndb/src/mgmapi/mgmapi.cpp

  storage/ndb/src/common/util/ConfigValues.cpp
    1.8.1.2 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Merge rename: ndb/src/common/util/ConfigValues.cpp -> storage/ndb/src/common/util/ConfigValues.cpp

  storage/ndb/include/util/ConfigValues.hpp
    1.3.1.2 06/06/20 17:30:17 stewart@willster.(none) +0 -0
    Merge rename: ndb/include/util/ConfigValues.hpp -> storage/ndb/include/util/ConfigValues.hpp

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	stewart
# Host:	willster.(none)
# Root:	/home/stewart/Documents/MySQL/5.1/main/RESYNC

--- 1.60.9.3/ndb/src/mgmsrv/ConfigInfo.cpp	2006-06-08 02:31:53 +10:00
+++ 1.77/storage/ndb/src/mgmsrv/ConfigInfo.cpp	2006-06-20 17:30:17 +10:00
@@ -761,6 +761,30 @@
     STR_VALUE(MAX_INT_RNIL)},
 
   {
+    CFG_DB_DISK_PAGE_BUFFER_MEMORY,
+    "DiskPageBufferMemory",
+    DB_TOKEN,
+    "Number bytes on each "DB_TOKEN_PRINT" node allocated for disk page buffer cache",
+    ConfigInfo::CI_USED,
+    false,
+    ConfigInfo::CI_INT64,
+    "64M",
+    "4M",
+    "1024G" },
+
+  {
+    CFG_DB_SGA,
+    "SharedGlobalMemory",
+    DB_TOKEN,
+    "Total number bytes on each "DB_TOKEN_PRINT" node allocated for any use",
+    ConfigInfo::CI_USED,
+    false,
+    ConfigInfo::CI_INT64,
+    "20M",
+    "0",
+    "65536G" }, // 32k pages * 32-bit i value
+  
+  {
     CFG_DB_START_PARTIAL_TIMEOUT,
     "StartPartialTimeout",
     DB_TOKEN,
@@ -869,6 +893,18 @@
     STR_VALUE(MAX_INT_RNIL) },
   
   {
+    CFG_DB_INITIAL_OPEN_FILES,
+    "InitialNoOfOpenFiles",
+    DB_TOKEN,
+    "Initial number of files open per "DB_TOKEN_PRINT" node.(One thread is created per file)",
+    ConfigInfo::CI_USED,
+    false,
+    ConfigInfo::CI_INT,
+    "27",
+    "20",
+    STR_VALUE(MAX_INT_RNIL) },
+  
+  {
     CFG_DB_TRANSACTION_CHECK_INTERVAL,
     "TimeBetweenInactiveTransactionAbortCheck",
     DB_TOKEN,
@@ -1199,9 +1235,33 @@
     false,
     ConfigInfo::CI_INT,
     "32K",
-    "0",
+    "2K",
+    STR_VALUE(MAX_INT_RNIL) },
+
+  { 
+    CFG_DB_BACKUP_MAX_WRITE_SIZE,
+    "BackupMaxWriteSize",
+    DB_TOKEN,
+    "Max size of filesystem writes made by backup (in bytes)",
+    ConfigInfo::CI_USED,
+    false,
+    ConfigInfo::CI_INT,
+    "256K",
+    "2K",
     STR_VALUE(MAX_INT_RNIL) },
 
+  { 
+    CFG_DB_STRING_MEMORY,
+    "StringMemory",
+    DB_TOKEN,
+    "Default size of string memory (0 -> 5% of max 1-100 -> %of max, >100 -> actual bytes)",
+    ConfigInfo::CI_USED,
+    false,
+    ConfigInfo::CI_INT,
+    "0",
+    "0",
+    STR_VALUE(MAX_INT_RNIL) },
+  
   /***************************************************************************
    * API
    ***************************************************************************/

--- 1.44.16.1/ndb/src/mgmapi/mgmapi.cpp	2006-04-25 08:59:30 +10:00
+++ 1.66/storage/ndb/src/mgmapi/mgmapi.cpp	2006-06-20 17:30:17 +10:00
@@ -27,6 +27,7 @@
 #include <mgmapi_debug.h>
 #include "mgmapi_configuration.hpp"
 #include <socket_io.h>
+#include <version.h>
 
 #include <NdbOut.hpp>
 #include <SocketServer.hpp>
@@ -103,6 +104,9 @@
 #endif
   FILE *errstream;
   char *m_name;
+  int mgmd_version_major;
+  int mgmd_version_minor;
+  int mgmd_version_build;
 };
 
 #define SET_ERROR(h, e, s) setError(h, e, __LINE__, s)
@@ -138,6 +142,12 @@
     return ret; \
   }
 
+#define DBUG_CHECK_REPLY(reply, ret) \
+  if (reply == NULL) { \
+    SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY, ""); \
+    DBUG_RETURN(ret);                                    \
+  }
+
 /*****************************************************************************
  * Handles
  *****************************************************************************/
@@ -168,6 +178,10 @@
   h->logfile = 0;
 #endif
 
+  h->mgmd_version_major= -1;
+  h->mgmd_version_minor= -1;
+  h->mgmd_version_build= -1;
+
   DBUG_PRINT("info", ("handle=0x%x", (UintPtr)h));
   DBUG_RETURN(h);
 }
@@ -194,7 +208,7 @@
     handle->cfg.~LocalConfig();
     new (&(handle->cfg)) LocalConfig;
     handle->cfg.init(0, 0); /* reset the LocalConfig */
-    SET_ERROR(handle, NDB_MGM_ILLEGAL_CONNECT_STRING, "");
+    SET_ERROR(handle, NDB_MGM_ILLEGAL_CONNECT_STRING, mgmsrv ? mgmsrv : "");
     DBUG_RETURN(-1);
   }
   handle->cfg_i= -1;
@@ -361,8 +375,9 @@
        * Print some info about why the parser returns NULL
        */
       fprintf(handle->errstream,
-	      "Error in mgm protocol parser. cmd: >%s< status: %d curr: %d\n",
-	      cmd, (Uint32)ctx.m_status, ctx.m_currentToken);
+	      "Error in mgm protocol parser. cmd: >%s< status: %d curr: %s\n",
+	      cmd, (Uint32)ctx.m_status,
+              (ctx.m_currentToken)?ctx.m_currentToken:"NULL");
       DBUG_PRINT("info",("ctx.status: %d, ctx.m_currentToken: %s",
 		         ctx.m_status, ctx.m_currentToken));
     }
@@ -678,7 +693,11 @@
   out.println("");
 
   char buf[1024];
-  in.gets(buf, sizeof(buf));
+  if(!in.gets(buf, sizeof(buf)))
+  {
+    SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY, "Probably disconnected");
+    return NULL;
+  }
   if(buf[strlen(buf)-1] == '\n')
     buf[strlen(buf)-1] = '\0';
 
@@ -687,7 +706,11 @@
     return NULL;
   }
 
-  in.gets(buf, sizeof(buf));
+  if(!in.gets(buf, sizeof(buf)))
+  {
+    SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY, "Probably disconnected");
+    return NULL;
+  }
   if(buf[strlen(buf)-1] == '\n')
     buf[strlen(buf)-1] = '\0';
   
@@ -695,10 +718,12 @@
   Vector<BaseString> split;
   tmp.split(split, ":");
   if(split.size() != 2){
+    SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf);
     return NULL;
   }
  
   if(!(split[0].trim() == "nodes")){
+    SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, buf);
     return NULL;
   }
 
@@ -708,6 +733,13 @@
     malloc(sizeof(ndb_mgm_cluster_state)+
 	   noOfNodes*(sizeof(ndb_mgm_node_state)+sizeof("000.000.000.000#")));
 
+  if(!state)
+  {
+    SET_ERROR(handle, NDB_MGM_OUT_OF_MEMORY,
+              "Allocating ndb_mgm_cluster_state");
+    return NULL;
+  }
+
   state->no_of_nodes= noOfNodes;
   ndb_mgm_node_state * ptr = &state->node_states[0];
   int nodeId = 0;
@@ -717,7 +749,13 @@
   }
   i = -1; ptr--;
   for(; i<noOfNodes; ){
-    in.gets(buf, sizeof(buf));
+    if(!in.gets(buf, sizeof(buf)))
+    {
+      free(state);
+      SET_ERROR(handle, NDB_MGM_ILLEGAL_SERVER_REPLY,
+                "Probably disconnected");
+      return NULL;
+    }
     tmp.assign(buf);
 
     if(tmp.trim() == ""){
@@ -746,6 +784,7 @@
 
   if(i+1 != noOfNodes){
     free(state);
+    SET_ERROR(handle, NDB_MGM_ILLEGAL_NODE_STATUS, "Node count mismatch");
     return NULL;
   }
 
@@ -826,37 +865,81 @@
   return ndb_mgm_stop2(handle, no_of_nodes, node_list, 0);
 }
 
-
 extern "C"
-int 
+int
 ndb_mgm_stop2(NdbMgmHandle handle, int no_of_nodes, const int * node_list,
 	      int abort)
 {
-  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_stop2");
-  const ParserRow<ParserDummy> stop_reply[] = {
+  int disconnect;
+  return ndb_mgm_stop3(handle, no_of_nodes, node_list, abort, &disconnect);
+}
+
+
+extern "C"
+int
+ndb_mgm_stop3(NdbMgmHandle handle, int no_of_nodes, const int * node_list,
+	      int abort, int *disconnect)
+{
+  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_stop3");
+  const ParserRow<ParserDummy> stop_reply_v1[] = {
     MGM_CMD("stop reply", NULL, ""),
     MGM_ARG("stopped", Int, Optional, "No of stopped nodes"),
     MGM_ARG("result", String, Mandatory, "Error message"),
     MGM_END()
   };
+  const ParserRow<ParserDummy> stop_reply_v2[] = {
+    MGM_CMD("stop reply", NULL, ""),
+    MGM_ARG("stopped", Int, Optional, "No of stopped nodes"),
+    MGM_ARG("result", String, Mandatory, "Error message"),
+    MGM_ARG("disconnect", Int, Mandatory, "Need to disconnect"),
+    MGM_END()
+  };
+
   CHECK_HANDLE(handle, -1);
   CHECK_CONNECTED(handle, -1);
 
-  if(no_of_nodes < 0){
+  if(handle->mgmd_version_build==-1)
+  {
+    char verstr[50];
+    if(!ndb_mgm_get_version(handle,
+                        &(handle->mgmd_version_major),
+                        &(handle->mgmd_version_minor),
+                        &(handle->mgmd_version_build),
+                        sizeof(verstr),
+                            verstr))
+    {
+      return -1;
+    }
+  }
+  int use_v2= ((handle->mgmd_version_major==5)
+    && (
+        (handle->mgmd_version_minor==0 && handle->mgmd_version_build>=21)
+        ||(handle->mgmd_version_minor==1 && handle->mgmd_version_build>=12)
+        ||(handle->mgmd_version_minor>1)
+        )
+               )
+    || (handle->mgmd_version_major>5);
+
+  if(no_of_nodes < -1){
     SET_ERROR(handle, NDB_MGM_ILLEGAL_NUMBER_OF_NODES, 
 	      "Negative number of nodes requested to stop");
     return -1;
   }
 
   Uint32 stoppedNoOfNodes = 0;
-  if(no_of_nodes == 0){
+  if(no_of_nodes <= 0){
     /**
-     * All database nodes should be stopped
+     * All nodes should be stopped (all or just db)
      */
     Properties args;
     args.put("abort", abort);
+    if(use_v2)
+      args.put("stop", (no_of_nodes==-1)?"mgm,db":"db");
     const Properties *reply;
-    reply = ndb_mgm_call(handle, stop_reply, "stop all", &args);
+    if(use_v2)
+      reply = ndb_mgm_call(handle, stop_reply_v2, "stop all", &args);
+    else
+      reply = ndb_mgm_call(handle, stop_reply_v1, "stop all", &args);
     CHECK_REPLY(reply, -1);
 
     if(!reply->get("stopped", &stoppedNoOfNodes)){
@@ -865,6 +948,10 @@
       delete reply;
       return -1;
     }
+    if(use_v2)
+      reply->get("disconnect", (Uint32*)disconnect);
+    else
+      *disconnect= 0;
     BaseString result;
     reply->get("result", result);
     if(strcmp(result.c_str(), "Ok") != 0) {
@@ -890,7 +977,11 @@
   args.put("abort", abort);
 
   const Properties *reply;
-  reply = ndb_mgm_call(handle, stop_reply, "stop", &args);
+  if(use_v2)
+    reply = ndb_mgm_call(handle, stop_reply_v2, "stop v2", &args);
+  else
+    reply = ndb_mgm_call(handle, stop_reply_v1, "stop", &args);
+
   CHECK_REPLY(reply, stoppedNoOfNodes);
   if(!reply->get("stopped", &stoppedNoOfNodes)){
     SET_ERROR(handle, NDB_MGM_STOP_FAILED, 
@@ -898,6 +989,10 @@
     delete reply;
     return -1;
   }
+  if(use_v2)
+    reply->get("disconnect", (Uint32*)disconnect);
+  else
+    *disconnect= 0;
   BaseString result;
   reply->get("result", result);
   if(strcmp(result.c_str(), "Ok") != 0) {
@@ -911,20 +1006,69 @@
 
 extern "C"
 int
+ndb_mgm_restart(NdbMgmHandle handle, int no_of_nodes, const int *node_list) 
+{
+  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_restart");
+  return ndb_mgm_restart2(handle, no_of_nodes, node_list, 0, 0, 0);
+}
+
+extern "C"
+int
 ndb_mgm_restart2(NdbMgmHandle handle, int no_of_nodes, const int * node_list,
 		 int initial, int nostart, int abort)
 {
-  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_restart2");
+  int disconnect;
+
+  return ndb_mgm_restart3(handle, no_of_nodes, node_list, initial, nostart,
+                          abort, &disconnect);
+}
+
+extern "C"
+int
+ndb_mgm_restart3(NdbMgmHandle handle, int no_of_nodes, const int * node_list,
+		 int initial, int nostart, int abort, int *disconnect)
+{
+  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_restart3");
   Uint32 restarted = 0;
-  const ParserRow<ParserDummy> restart_reply[] = {
+  const ParserRow<ParserDummy> restart_reply_v1[] = {
+    MGM_CMD("restart reply", NULL, ""),
+    MGM_ARG("result", String, Mandatory, "Error message"),
+    MGM_ARG("restarted", Int, Optional, "No of restarted nodes"),
+    MGM_END()
+  };
+  const ParserRow<ParserDummy> restart_reply_v2[] = {
     MGM_CMD("restart reply", NULL, ""),
     MGM_ARG("result", String, Mandatory, "Error message"),
     MGM_ARG("restarted", Int, Optional, "No of restarted nodes"),
+    MGM_ARG("disconnect", Int, Optional, "Disconnect to apply"),
     MGM_END()
   };
+
   CHECK_HANDLE(handle, -1);
   CHECK_CONNECTED(handle, -1);
-  
+
+  if(handle->mgmd_version_build==-1)
+  {
+    char verstr[50];
+    if(!ndb_mgm_get_version(handle,
+                        &(handle->mgmd_version_major),
+                        &(handle->mgmd_version_minor),
+                        &(handle->mgmd_version_build),
+                        sizeof(verstr),
+                            verstr))
+    {
+      return -1;
+    }
+  }
+  int use_v2= ((handle->mgmd_version_major==5)
+    && (
+        (handle->mgmd_version_minor==0 && handle->mgmd_version_build>=21)
+        ||(handle->mgmd_version_minor==1 && handle->mgmd_version_build>=12)
+        ||(handle->mgmd_version_minor>1)
+        )
+               )
+    || (handle->mgmd_version_major>5);
+
   if(no_of_nodes < 0){
     SET_ERROR(handle, NDB_MGM_RESTART_FAILED, 
 	      "Restart requested of negative number of nodes");
@@ -939,7 +1083,7 @@
     const Properties *reply;
     const int timeout = handle->read_timeout;
     handle->read_timeout= 5*60*1000; // 5 minutes
-    reply = ndb_mgm_call(handle, restart_reply, "restart all", &args);
+    reply = ndb_mgm_call(handle, restart_reply_v1, "restart all", &args);
     handle->read_timeout= timeout;
     CHECK_REPLY(reply, -1);
 
@@ -975,7 +1119,10 @@
   const Properties *reply;
   const int timeout = handle->read_timeout;
   handle->read_timeout= 5*60*1000; // 5 minutes
-  reply = ndb_mgm_call(handle, restart_reply, "restart node", &args);
+  if(use_v2)
+    reply = ndb_mgm_call(handle, restart_reply_v2, "restart node v2", &args);
+  else
+    reply = ndb_mgm_call(handle, restart_reply_v1, "restart node", &args);
   handle->read_timeout= timeout;
   if(reply != NULL) {
     BaseString result;
@@ -986,20 +1133,16 @@
       return -1;
     }
     reply->get("restarted", &restarted);
+    if(use_v2)
+      reply->get("disconnect", (Uint32*)disconnect);
+    else
+      *disconnect= 0;
     delete reply;
   } 
   
   return restarted;
 }
 
-extern "C"
-int
-ndb_mgm_restart(NdbMgmHandle handle, int no_of_nodes, const int *node_list) 
-{
-  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_restart");
-  return ndb_mgm_restart2(handle, no_of_nodes, node_list, 0, 0, 0);
-}
-
 static const char *clusterlog_severity_names[]=
   { "enabled", "debug", "info", "warning", "error", "critical", "alert" };
 
@@ -1299,33 +1442,6 @@
 
 extern "C"
 int 
-ndb_mgm_get_stat_port(NdbMgmHandle handle, struct ndb_mgm_reply* /*reply*/)
-{
-  SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_get_stat_port");
-  const ParserRow<ParserDummy> stat_reply[] = {
-    MGM_CMD("error", NULL, ""),
-    MGM_ARG("result", String, Mandatory, "Error message"),
-    MGM_CMD("get statport reply", NULL, ""),
-    MGM_ARG("tcpport", Int, Mandatory, "TCP port for statistics"),
-    MGM_END()
-  };
-  CHECK_HANDLE(handle, -1);
-  CHECK_CONNECTED(handle, -1);
-  
-  Properties args;
-  const Properties *reply;
-  reply = ndb_mgm_call(handle, stat_reply, "get statport", &args);
-  CHECK_REPLY(reply, -1);
-
-  Uint32 port;
-  reply->get("tcpport", &port);
-
-  delete reply;
-  return port;
-}
-
-extern "C"
-int 
 ndb_mgm_dump_state(NdbMgmHandle handle, int nodeId, int* _args,
 		   int _num_args, struct ndb_mgm_reply* /* reply */) 
 {
@@ -1868,7 +1984,8 @@
 
 extern "C"
 int
-ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, int nodetype)
+ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, int nodetype,
+                     int log_event)
 {
   CHECK_HANDLE(handle, 0);
   CHECK_CONNECTED(handle, 0);
@@ -1888,9 +2005,11 @@
   args.put("endian", (endian_check.c[sizeof(long)-1])?"big":"little");
   if (handle->m_name)
     args.put("name", handle->m_name);
+  args.put("log_event", log_event);
 
   const ParserRow<ParserDummy> reply[]= {
     MGM_CMD("get nodeid reply", NULL, ""),
+      MGM_ARG("error_code", Int, Optional, "Error code"),
       MGM_ARG("nodeid", Int, Optional, "Error message"),
       MGM_ARG("result", String, Mandatory, "Error message"),
     MGM_END()
@@ -1903,14 +2022,16 @@
   nodeid= -1;
   do {
     const char * buf;
-    if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){
+    if (!prop->get("result", &buf) || strcmp(buf, "Ok") != 0)
+    {
       const char *hostname= ndb_mgm_get_connected_host(handle);
       unsigned port=  ndb_mgm_get_connected_port(handle);
       BaseString err;
+      Uint32 error_code= NDB_MGM_ALLOCID_ERROR;
       err.assfmt("Could not alloc node id at %s port %d: %s",
 		 hostname, port, buf);
-      setError(handle, NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET, __LINE__,
-	       err.c_str());
+      prop->get("error_code", &error_code);
+      setError(handle, error_code, __LINE__, err.c_str());
       break;
     }
     Uint32 _nodeid;
@@ -2171,9 +2292,9 @@
 				     int param,
 				     int value,
 				     struct ndb_mgm_reply* mgmreply){
-  DBUG_ENTER("ndb_mgm_set_connection_int_parameter");
   CHECK_HANDLE(handle, 0);
   CHECK_CONNECTED(handle, 0);
+  DBUG_ENTER("ndb_mgm_set_connection_int_parameter");
   
   Properties args;
   args.put("node1", node1);
@@ -2190,7 +2311,7 @@
   
   const Properties *prop;
   prop= ndb_mgm_call(handle, reply, "set connection parameter", &args);
-  CHECK_REPLY(prop, -1);
+  DBUG_CHECK_REPLY(prop, -1);
 
   int res= -1;
   do {
@@ -2214,9 +2335,9 @@
 				     int param,
 				     int *value,
 				     struct ndb_mgm_reply* mgmreply){
-  DBUG_ENTER("ndb_mgm_get_connection_int_parameter");
   CHECK_HANDLE(handle, -1);
   CHECK_CONNECTED(handle, -2);
+  DBUG_ENTER("ndb_mgm_get_connection_int_parameter");
   
   Properties args;
   args.put("node1", node1);
@@ -2232,7 +2353,7 @@
   
   const Properties *prop;
   prop = ndb_mgm_call(handle, reply, "get connection parameter", &args);
-  CHECK_REPLY(prop, -3);
+  DBUG_CHECK_REPLY(prop, -3);
 
   int res= -1;
   do {
@@ -2280,9 +2401,9 @@
 {
   Uint32 nodeid=0;
 
-  DBUG_ENTER("ndb_mgm_get_mgmd_nodeid");
   CHECK_HANDLE(handle, 0);
   CHECK_CONNECTED(handle, 0);
+  DBUG_ENTER("ndb_mgm_get_mgmd_nodeid");
   
   Properties args;
 
@@ -2294,7 +2415,7 @@
   
   const Properties *prop;
   prop = ndb_mgm_call(handle, reply, "get mgmd nodeid", &args);
-  CHECK_REPLY(prop, 0);
+  DBUG_CHECK_REPLY(prop, 0);
 
   if(!prop->get("nodeid",&nodeid)){
     fprintf(handle->errstream, "Unable to get value\n");
@@ -2308,9 +2429,9 @@
 extern "C"
 int ndb_mgm_report_event(NdbMgmHandle handle, Uint32 *data, Uint32 length)
 {
-  DBUG_ENTER("ndb_mgm_report_event");
   CHECK_HANDLE(handle, 0);
   CHECK_CONNECTED(handle, 0);
+  DBUG_ENTER("ndb_mgm_report_event");
 
   Properties args;
   args.put("length", length);
@@ -2329,7 +2450,7 @@
   
   const Properties *prop;
   prop = ndb_mgm_call(handle, reply, "report event", &args);
-  CHECK_REPLY(prop, -1);
+  DBUG_CHECK_REPLY(prop, -1);
 
   DBUG_RETURN(0);
 }
@@ -2337,9 +2458,9 @@
 extern "C"
 int ndb_mgm_end_session(NdbMgmHandle handle)
 {
-  DBUG_ENTER("ndb_mgm_end_session");
   CHECK_HANDLE(handle, 0);
   CHECK_CONNECTED(handle, 0);
+  DBUG_ENTER("ndb_mgm_end_session");
 
   SocketOutputStream s_output(handle->socket);
   s_output.println("end session");
@@ -2351,6 +2472,58 @@
   in.gets(buf, sizeof(buf));
 
   DBUG_RETURN(0);
+}
+
+extern "C"
+int ndb_mgm_get_version(NdbMgmHandle handle,
+                        int *major, int *minor, int *build, int len, char* str)
+{
+  DBUG_ENTER("ndb_mgm_get_version");
+  CHECK_HANDLE(handle, 0);
+  CHECK_CONNECTED(handle, 0);
+
+  Properties args;
+
+  const ParserRow<ParserDummy> reply[]= {
+    MGM_CMD("version", NULL, ""),
+    MGM_ARG("id", Int, Mandatory, "ID"),
+    MGM_ARG("major", Int, Mandatory, "Major"),
+    MGM_ARG("minor", Int, Mandatory, "Minor"),
+    MGM_ARG("string", String, Mandatory, "String"),
+    MGM_END()
+  };
+
+  const Properties *prop;
+  prop = ndb_mgm_call(handle, reply, "get version", &args);
+  CHECK_REPLY(prop, 0);
+
+  Uint32 id;
+  if(!prop->get("id",&id)){
+    fprintf(handle->errstream, "Unable to get value\n");
+    return 0;
+  }
+  *build= getBuild(id);
+
+  if(!prop->get("major",(Uint32*)major)){
+    fprintf(handle->errstream, "Unable to get value\n");
+    return 0;
+  }
+
+  if(!prop->get("minor",(Uint32*)minor)){
+    fprintf(handle->errstream, "Unable to get value\n");
+    return 0;
+  }
+
+  BaseString result;
+  if(!prop->get("string", result)){
+    fprintf(handle->errstream, "Unable to get value\n");
+    return 0;
+  }
+
+  strncpy(str, result.c_str(), len);
+
+  delete prop;
+  DBUG_RETURN(1);
 }
 
 template class Vector<const ParserRow<ParserDummy>*>;

--- 1.73.26.1/ndb/src/mgmsrv/MgmtSrvr.cpp	2006-06-20 17:28:58 +10:00
+++ 1.100/storage/ndb/src/mgmsrv/MgmtSrvr.cpp	2006-06-20 17:33:10 +10:00
@@ -37,10 +37,10 @@
 #include <signaldata/EventReport.hpp>
 #include <signaldata/DumpStateOrd.hpp>
 #include <signaldata/BackupSignalData.hpp>
-#include <signaldata/GrepImpl.hpp>
 #include <signaldata/ManagementServer.hpp>
 #include <signaldata/NFCompleteRep.hpp>
 #include <signaldata/NodeFailRep.hpp>
+#include <signaldata/AllocNodeId.hpp>
 #include <NdbSleep.h>
 #include <EventLogger.hpp>
 #include <DebuggerNames.hpp>
@@ -60,9 +60,6 @@
 
 #include <SignalSender.hpp>
 
-extern bool g_StopServer;
-extern bool g_RestartServer;
-
 //#define MGM_SRV_DEBUG
 #ifdef MGM_SRV_DEBUG
 #define DEBUG(x) do ndbout << x << endl; while(0)
@@ -122,41 +119,50 @@
     /**
      * Handle started nodes
      */
-    EventSubscribeReq req;
-    req = m_event_listner[0].m_logLevel;
-    req.blockRef = _ownReference;
-
-    SetLogLevelOrd ord;
-    
     m_started_nodes.lock();
-    while(m_started_nodes.size() > 0){
-      Uint32 node = m_started_nodes[0];
-      m_started_nodes.erase(0, false);
-      m_started_nodes.unlock();
+    if (m_started_nodes.size() > 0)
+    {
+      // calculate max log level
+      EventSubscribeReq req;
+      {
+        LogLevel tmp;
+        m_event_listner.lock();
+        for(int i = m_event_listner.m_clients.size() - 1; i >= 0; i--)
+          tmp.set_max(m_event_listner[i].m_logLevel);
+        m_event_listner.unlock();
+        req = tmp;
+      }
+      req.blockRef = _ownReference;
+      while (m_started_nodes.size() > 0)
+      {
+        Uint32 node = m_started_nodes[0];
+        m_started_nodes.erase(0, false);
+        m_started_nodes.unlock();
 
-      setEventReportingLevelImpl(node, req);
-      
-      ord = m_nodeLogLevel[node];
-      setNodeLogLevelImpl(node, ord);
-      
-      m_started_nodes.lock();
-    }				 
+        setEventReportingLevelImpl(node, req);
+
+        SetLogLevelOrd ord;
+        ord = m_nodeLogLevel[node];
+        setNodeLogLevelImpl(node, ord);
+
+        m_started_nodes.lock();
+      }
+    }
     m_started_nodes.unlock();
     
     m_log_level_requests.lock();
-    while(m_log_level_requests.size() > 0){
-      req = m_log_level_requests[0];
+    while (m_log_level_requests.size() > 0)
+    {
+      EventSubscribeReq req = m_log_level_requests[0];
       m_log_level_requests.erase(0, false);
       m_log_level_requests.unlock();
-      
-      LogLevel tmp;
-      tmp = req;
-      
+
       if(req.blockRef == 0){
 	req.blockRef = _ownReference;
 	setEventReportingLevelImpl(0, req);
       } else {
-	ord = req;
+        SetLogLevelOrd ord;
+        ord = req;
 	setNodeLogLevelImpl(req.blockRef, ord);
       }
       m_log_level_requests.lock();
@@ -485,10 +491,6 @@
       case NODE_TYPE_MGM:
 	nodeTypes[id] = NDB_MGM_NODE_TYPE_MGM;
 	break;
-      case NODE_TYPE_REP:
-	nodeTypes[id] = NDB_MGM_NODE_TYPE_REP;
-	break;
-      case NODE_TYPE_EXT_REP:
       default:
 	break;
       }
@@ -507,9 +509,10 @@
   if (_ownNodeId == 0) // we did not get node id from other server
   {
     NodeId tmp= m_config_retriever->get_configuration_nodeid();
+    int error_code;
 
     if (!alloc_node_id(&tmp, NDB_MGM_NODE_TYPE_MGM,
-		       0, 0, error_string)){
+		       0, 0, error_code, error_string)){
       ndbout << "Unable to obtain requested nodeid: "
 	     << error_string.c_str() << endl;
       require(false);
@@ -570,8 +573,7 @@
       DBUG_RETURN(false);
     }
   }
-  theFacade= TransporterFacade::theFacadeInstance
-    = new TransporterFacade();
+  theFacade= new TransporterFacade();
   
   if(theFacade == 0) {
     DEBUG("MgmtSrvr.cpp: theFacade is NULL.");
@@ -932,6 +934,13 @@
  * client connection to that mgmd and stop it that way.
  * This allows us to stop mgm servers when there isn't any real
  * distributed communication up.
+ *
+ * node_ids.size()==0 means to stop all DB nodes.
+ *                    MGM nodes will *NOT* be stopped.
+ *
+ * If we work out we should be stopping or restarting ourselves,
+ * we return <0 in stopSelf for restart, >0 for stop
+ * and 0 for do nothing.
  */
 
 int MgmtSrvr::sendSTOP_REQ(const Vector<NodeId> &node_ids,
@@ -941,7 +950,8 @@
 			   bool stop,
 			   bool restart,
 			   bool nostart,
-			   bool initialStart)
+			   bool initialStart,
+                           int* stopSelf)
 {
   int error = 0;
   DBUG_ENTER("MgmtSrvr::sendSTOP_REQ");
@@ -990,12 +1000,13 @@
   NodeId nodeId= 0;
   int use_master_node= 0;
   int do_send= 0;
-  int do_stop_self= 0;
+  *stopSelf= 0;
   NdbNodeBitmask nodes_to_stop;
   {
     for (unsigned i= 0; i < node_ids.size(); i++)
     {
       nodeId= node_ids[i];
+      ndbout << "asked to stop " << nodeId << endl;
       if (getNodeType(nodeId) != NDB_MGM_NODE_TYPE_MGM)
         nodes_to_stop.set(nodeId);
       else if (nodeId != getOwnNodeId())
@@ -1006,7 +1017,11 @@
           stoppedNodes.set(nodeId);
       }
       else
-        do_stop_self= 1;;
+      {
+        ndbout << "which is me" << endl;
+        *stopSelf= (restart)? -1 : 1;
+        stoppedNodes.set(nodeId);
+      }
     }
   }
   int no_of_nodes_to_stop= nodes_to_stop.count();
@@ -1039,14 +1054,6 @@
 	  nodes.set(nodeId);
       }
     }
-    nodeId= 0;
-    while(getNextNodeId(&nodeId, NDB_MGM_NODE_TYPE_MGM))
-    {
-      if(nodeId==getOwnNodeId())
-        continue;
-      if(sendStopMgmd(nodeId, abort, stop, restart, nostart, initialStart)==0)
-        stoppedNodes.set(nodeId);
-    }
   }
 
   // now wait for the replies
@@ -1118,31 +1125,16 @@
       const NFCompleteRep * const rep =
 	CAST_CONSTPTR(NFCompleteRep, signal->getDataPtr());
 #ifdef VM_TRACE
-      ndbout_c("Node %d fail completed", rep->failedNodeId);
+      ndbout_c("sendSTOP_REQ Node %d fail completed", rep->failedNodeId);
 #endif
+      nodes.clear(rep->failedNodeId); // clear the failed node
+      if (singleUserNodeId == 0)
+        stoppedNodes.set(rep->failedNodeId);
       break;
     }
     case GSN_NODE_FAILREP:{
       const NodeFailRep * const rep =
 	CAST_CONSTPTR(NodeFailRep, signal->getDataPtr());
-      NodeBitmask failedNodes;
-      failedNodes.assign(NodeBitmask::Size, rep->theNodes);
-#ifdef VM_TRACE
-      {
-	ndbout << "Failed nodes:";
-	for (unsigned i = 0; i < 32*NodeBitmask::Size; i++)
-	  if(failedNodes.get(i))
-	    ndbout << " " << i;
-	ndbout << endl;
-      }
-#endif
-      failedNodes.bitAND(nodes);
-      if (!failedNodes.isclear())
-      {
-	nodes.bitANDC(failedNodes); // clear the failed nodes
-	if (singleUserNodeId == 0)
-	  stoppedNodes.bitOR(failedNodes);
-      }
       break;
     }
     default:
@@ -1153,11 +1145,9 @@
       DBUG_RETURN(SEND_OR_RECEIVE_FAILED);
     }
   }
-  if (!error && do_stop_self)
+  if (error && *stopSelf)
   {
-    if (restart)
-      g_RestartServer= true;
-    g_StopServer= true;
+    *stopSelf= 0;
   }
   DBUG_RETURN(error);
 }
@@ -1167,7 +1157,7 @@
  */
 
 int MgmtSrvr::stopNodes(const Vector<NodeId> &node_ids,
-                        int *stopCount, bool abort)
+                        int *stopCount, bool abort, int* stopSelf)
 {
   if (!abort)
   {
@@ -1189,20 +1179,46 @@
                         false,
                         false,
                         false,
-                        false);
+                        false,
+                        stopSelf);
   if (stopCount)
     *stopCount= nodes.count();
   return ret;
 }
 
+int MgmtSrvr::shutdownMGM(int *stopCount, bool abort, int *stopSelf)
+{
+  NodeId nodeId = 0;
+  int error;
+
+  while(getNextNodeId(&nodeId, NDB_MGM_NODE_TYPE_MGM))
+  {
+    if(nodeId==getOwnNodeId())
+      continue;
+    error= sendStopMgmd(nodeId, abort, true, false,
+                        false, false);
+    if (error == 0)
+      *stopCount++;
+  }
+
+  *stopSelf= 1;
+  *stopCount++;
+
+  return 0;
+}
+
 /*
- * Perform system shutdown
+ * Perform DB nodes shutdown.
+ * MGM servers are left in their current state
  */
 
-int MgmtSrvr::stop(int * stopCount, bool abort)
+int MgmtSrvr::shutdownDB(int * stopCount, bool abort)
 {
   NodeBitmask nodes;
   Vector<NodeId> node_ids;
+
+  int tmp;
+
   int ret = sendSTOP_REQ(node_ids,
 			 nodes,
 			 0,
@@ -1210,7 +1226,8 @@
 			 true,
 			 false,
 			 false,
-			 false);
+			 false,
+                         &tmp);
   if (stopCount)
     *stopCount = nodes.count();
   return ret;
@@ -1235,6 +1252,7 @@
   }
   NodeBitmask nodes;
   Vector<NodeId> node_ids;
+  int stopSelf;
   int ret = sendSTOP_REQ(node_ids,
 			 nodes,
 			 singleUserNodeId,
@@ -1242,7 +1260,8 @@
 			 false,
 			 false,
 			 false,
-			 false);
+			 false,
+                         &stopSelf);
   if (stopCount)
     *stopCount = nodes.count();
   return ret;
@@ -1254,7 +1273,8 @@
 
 int MgmtSrvr::restartNodes(const Vector<NodeId> &node_ids,
                            int * stopCount, bool nostart,
-                           bool initialStart, bool abort)
+                           bool initialStart, bool abort,
+                           int *stopSelf)
 {
   NodeBitmask nodes;
   int ret= sendSTOP_REQ(node_ids,
@@ -1263,22 +1283,61 @@
                         abort,
                         false,
                         true,
-                        nostart,
-                        initialStart);
+                        true,
+                        initialStart,
+                        stopSelf);
+
+  if (ret)
+    return ret;
+
   if (stopCount)
     *stopCount = nodes.count();
-  return ret;
+  
+  // start up the nodes again
+  int waitTime = 12000;
+  NDB_TICKS maxTime = NdbTick_CurrentMillisecond() + waitTime;
+  for (unsigned i = 0; i < node_ids.size(); i++)
+  {
+    NodeId nodeId= node_ids[i];
+    enum ndb_mgm_node_status s;
+    s = NDB_MGM_NODE_STATUS_NO_CONTACT;
+#ifdef VM_TRACE
+    ndbout_c("Waiting for %d not started", nodeId);
+#endif
+    while (s != NDB_MGM_NODE_STATUS_NOT_STARTED && waitTime > 0)
+    {
+      Uint32 startPhase = 0, version = 0, dynamicId = 0, nodeGroup = 0;
+      Uint32 connectCount = 0;
+      bool system;
+      const char *address;
+      status(nodeId, &s, &version, &startPhase, 
+             &system, &dynamicId, &nodeGroup, &connectCount, &address);
+      NdbSleep_MilliSleep(100);  
+      waitTime = (maxTime - NdbTick_CurrentMillisecond());
+    }
+  }
+
+  if (nostart)
+    return 0;
+
+  for (unsigned i = 0; i < node_ids.size(); i++)
+  {
+    int result = start(node_ids[i]);
+  }
+  return 0;
 }
 
 /*
- * Perform system restart
+ * Perform restart of all DB nodes
  */
 
-int MgmtSrvr::restart(bool nostart, bool initialStart, 
-		      bool abort, int * stopCount )
+int MgmtSrvr::restartDB(bool nostart, bool initialStart,
+                        bool abort, int * stopCount)
 {
   NodeBitmask nodes;
   Vector<NodeId> node_ids;
+  int tmp;
+
   int ret = sendSTOP_REQ(node_ids,
 			 nodes,
 			 0,
@@ -1286,7 +1345,8 @@
 			 true,
 			 true,
 			 true,
-			 initialStart);
+			 initialStart,
+                         &tmp);
 
   if (ret)
     return ret;
@@ -1482,7 +1542,8 @@
 MgmtSrvr::setEventReportingLevelImpl(int nodeId, 
 				     const EventSubscribeReq& ll)
 {
-  INIT_SIGNAL_SENDER(ss,nodeId);
+  SignalSender ss(theFacade);
+  ss.lock();
 
   SimpleSignal ssig;
   EventSubscribeReq * dst = 
@@ -1491,41 +1552,54 @@
 	   EventSubscribeReq::SignalLength);
   *dst = ll;
 
-  send(ss,ssig,nodeId,NODE_TYPE_DB);
+  NodeBitmask nodes;
+  nodes.clear();
+  Uint32 max = (nodeId == 0) ? (nodeId = 1, MAX_NDB_NODES) : nodeId;
+  for(; nodeId <= max; nodeId++)
+  {
+    if (nodeTypes[nodeId] != NODE_TYPE_DB)
+      continue;
+    if (okToSendTo(nodeId, true))
+      continue;
+    if (ss.sendSignal(nodeId, &ssig) == SEND_OK)
+    {
+      nodes.set(nodeId);
+    }
+  }
 
-#if 0
-  while (1)
+  int error = 0;
+  while (!nodes.isclear())
   {
     SimpleSignal *signal = ss.waitFor();
     int gsn = signal->readSignalNumber();
-    switch (gsn) { 
+    nodeId = refToNode(signal->header.theSendersBlockRef);
+    switch (gsn) {
     case GSN_EVENT_SUBSCRIBE_CONF:{
+      nodes.clear(nodeId);
       break;
     }
     case GSN_EVENT_SUBSCRIBE_REF:{
-      return SEND_OR_RECEIVE_FAILED;
+      nodes.clear(nodeId);
+      error = 1;
+      break;
     }
     case GSN_NF_COMPLETEREP:{
       const NFCompleteRep * const rep =
 	CAST_CONSTPTR(NFCompleteRep, signal->getDataPtr());
-      if (rep->failedNodeId == nodeId)
-	return SEND_OR_RECEIVE_FAILED;
+      nodes.clear(rep->failedNodeId);
       break;
     }
     case GSN_NODE_FAILREP:{
-      const NodeFailRep * const rep =
-	CAST_CONSTPTR(NodeFailRep, signal->getDataPtr());
-      if (NodeBitmask::get(rep->theNodes,nodeId))
-	return SEND_OR_RECEIVE_FAILED;
+      // ignore, NF_COMPLETEREP will arrive later
       break;
     }
     default:
       report_unknown_signal(signal);
       return SEND_OR_RECEIVE_FAILED;
     }
-
   }
-#endif
+  if (error)
+    return SEND_OR_RECEIVE_FAILED;
   return 0;
 }
 
@@ -1545,19 +1619,6 @@
   return ss.sendSignal(nodeId, &ssig) == SEND_OK ? 0 : SEND_OR_RECEIVE_FAILED;
 }
 
-int
-MgmtSrvr::send(SignalSender &ss, SimpleSignal &ssig, Uint32 node, Uint32 node_type){
-  Uint32 max = (node == 0) ? MAX_NODES : node + 1;
-  
-  for(; node < max; node++){
-    while(nodeTypes[node] != (int)node_type && node < max) node++;
-    if(nodeTypes[node] != (int)node_type)
-      break;
-    ss.sendSignal(node, &ssig);
-  }
-  return 0;
-}
-
 //****************************************************************************
 //****************************************************************************
 
@@ -1797,9 +1858,6 @@
     break;
   case GSN_EVENT_REP:
   {
-    EventReport *rep = (EventReport*) signal->getDataPtr();
-    if (rep->getNodeId() == 0)
-      rep->setNodeId(refToNode(signal->theSendersBlockRef));
     eventReport(signal->getDataPtr());
     break;
   }
@@ -1840,7 +1898,6 @@
       DBUG_VOID_RETURN;
     }
   }
-  
   rep->setNodeId(_ownNodeId);
   eventReport(theData);
   DBUG_VOID_RETURN;
@@ -1913,12 +1970,96 @@
   }
 }
 
+int
+MgmtSrvr::alloc_node_id_req(NodeId free_node_id, enum ndb_mgm_node_type type)
+{
+  SignalSender ss(theFacade);
+  ss.lock(); // lock will be released on exit
+
+  SimpleSignal ssig;
+  AllocNodeIdReq* req = CAST_PTR(AllocNodeIdReq, ssig.getDataPtrSend());
+  ssig.set(ss, TestOrd::TraceAPI, QMGR, GSN_ALLOC_NODEID_REQ,
+	   AllocNodeIdReq::SignalLength);
+  
+  req->senderRef = ss.getOwnRef();
+  req->senderData = 19;
+  req->nodeId = free_node_id;
+  req->nodeType = type;
+
+  int do_send = 1;
+  NodeId nodeId = 0;
+  while (1)
+  {
+    if (nodeId == 0)
+    {
+      bool next;
+      while((next = getNextNodeId(&nodeId, NDB_MGM_NODE_TYPE_NDB)) == true &&
+            theFacade->get_node_alive(nodeId) == false);
+      if (!next)
+        return NO_CONTACT_WITH_DB_NODES;
+      do_send = 1;
+    }
+    if (do_send)
+    {
+      if (ss.sendSignal(nodeId, &ssig) != SEND_OK) {
+        return SEND_OR_RECEIVE_FAILED;
+      }
+      do_send = 0;
+    }
+    
+    SimpleSignal *signal = ss.waitFor();
+
+    int gsn = signal->readSignalNumber();
+    switch (gsn) {
+    case GSN_ALLOC_NODEID_CONF:
+    {
+      const AllocNodeIdConf * const conf =
+        CAST_CONSTPTR(AllocNodeIdConf, signal->getDataPtr());
+      return 0;
+    }
+    case GSN_ALLOC_NODEID_REF:
+    {
+      const AllocNodeIdRef * const ref =
+        CAST_CONSTPTR(AllocNodeIdRef, signal->getDataPtr());
+      if (ref->errorCode == AllocNodeIdRef::NotMaster ||
+          ref->errorCode == AllocNodeIdRef::Busy)
+      {
+        do_send = 1;
+        nodeId = refToNode(ref->masterRef);
+        continue;
+      }
+      return ref->errorCode;
+    }
+    case GSN_NF_COMPLETEREP:
+    {
+      const NFCompleteRep * const rep =
+        CAST_CONSTPTR(NFCompleteRep, signal->getDataPtr());
+#ifdef VM_TRACE
+      ndbout_c("Node %d fail completed", rep->failedNodeId);
+#endif
+      if (rep->failedNodeId == nodeId)
+        nodeId = 0;
+      continue;
+    }
+    case GSN_NODE_FAILREP:{
+      // ignore NF_COMPLETEREP will come
+      continue;
+    }
+    default:
+      report_unknown_signal(signal);
+      return SEND_OR_RECEIVE_FAILED;
+    }
+  }
+  return 0;
+}
+
 bool
 MgmtSrvr::alloc_node_id(NodeId * nodeId, 
 			enum ndb_mgm_node_type type,
 			struct sockaddr *client_addr, 
 			SOCKET_SIZE_TYPE *client_addr_len,
-			BaseString &error_string)
+			int &error_code, BaseString &error_string,
+                        int log_event)
 {
   DBUG_ENTER("MgmtSrvr::alloc_node_id");
   DBUG_PRINT("enter", ("nodeid=%d, type=%d, client_addr=%d",
@@ -1927,6 +2068,7 @@
     if (*nodeId == 0) {
       error_string.appfmt("no-nodeid-checks set in management server.\n"
 			  "node id must be set explicitly in connectstring");
+      error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
       DBUG_RETURN(false);
     }
     DBUG_RETURN(true);
@@ -1951,8 +2093,10 @@
 
   if(NdbMutex_Lock(m_configMutex))
   {
+    // should not happen
     error_string.appfmt("unable to lock configuration mutex");
-    return false;
+    error_code = NDB_MGM_ALLOCID_ERROR;
+    DBUG_RETURN(false);
   }
   ndb_mgm_configuration_iterator
     iter(* _config->m_configValues, CFG_SECTION_NODE);
@@ -2023,6 +2167,7 @@
 			  "or specifying unique host names in config file.",
 			  id_found, tmp);
       NdbMutex_Unlock(m_configMutex);
+      error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
       DBUG_RETURN(false);
     }
     if (config_hostname == 0) {
@@ -2031,12 +2176,46 @@
 			  "or specifying unique host names in config file,\n"
 			  "or specifying just one mgmt server in config file.",
 			  tmp);
+      error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
       DBUG_RETURN(false);
     }
     id_found= tmp; // mgmt server matched, check for more matches
   }
   NdbMutex_Unlock(m_configMutex);
 
+  if (id_found && client_addr != 0)
+  {
+    int res = alloc_node_id_req(id_found, type);
+    unsigned save_id_found = id_found;
+    switch (res)
+    {
+    case 0:
+      // ok continue
+      break;
+    case NO_CONTACT_WITH_DB_NODES:
+      // ok continue
+      break;
+    default:
+      // something wrong
+      id_found = 0;
+      break;
+
+    }
+    if (id_found == 0)
+    {
+      char buf[128];
+      ndb_error_string(res, buf, sizeof(buf));
+      error_string.appfmt("Cluster refused allocation of id %d. Error: %d (%s).",
+			  save_id_found, res, buf);
+      g_eventLogger.warning("Cluster refused allocation of id %d. "
+                            "Connection from ip %s. "
+                            "Returned error string \"%s\"", save_id_found,
+                            inet_ntoa(((struct sockaddr_in *)(client_addr))->sin_addr),
+                            error_string.c_str());
+      DBUG_RETURN(false);
+    }
+  }
+
   if (id_found)
   {
     *nodeId= id_found;
@@ -2072,8 +2251,9 @@
     
     char tmp_str[128];
     m_reserved_nodes.getText(tmp_str);
-    g_eventLogger.info("Mgmt server state: nodeid %d reserved for ip %s, m_reserved_nodes %s.",
-		       id_found, get_connect_address(id_found), tmp_str);
+    g_eventLogger.info("Mgmt server state: nodeid %d reserved for ip %s, "
+                       "m_reserved_nodes %s.",
+                       id_found, get_connect_address(id_found), tmp_str);
     DBUG_RETURN(true);
   }
 
@@ -2093,26 +2273,48 @@
     type_c_string.assfmt("%s(%s)", alias, str);
   }
 
-  if (*nodeId == 0) {
+  if (*nodeId == 0)
+  {
     if (found_matching_id)
+    {
       if (found_matching_type)
+      {
 	if (found_free_node)
+        {
 	  error_string.appfmt("Connection done from wrong host ip %s.",
 			      (client_addr)?
-			        inet_ntoa(((struct sockaddr_in *)
+                              inet_ntoa(((struct sockaddr_in *)
 					 (client_addr))->sin_addr):"");
+          error_code = NDB_MGM_ALLOCID_ERROR;
+        }
 	else
+        {
 	  error_string.appfmt("No free node id found for %s.",
 			      type_string.c_str());
+          error_code = NDB_MGM_ALLOCID_ERROR;
+        }
+      }
       else
+      {
 	error_string.appfmt("No %s node defined in config file.",
 			    type_string.c_str());
+        error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
+      }
+    }
     else
+    {
       error_string.append("No nodes defined in config file.");
-  } else {
+      error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
+    }
+  }
+  else
+  {
     if (found_matching_id)
+    {
       if (found_matching_type)
-	if (found_free_node) {
+      {
+	if (found_free_node)
+        {
 	  // have to split these into two since inet_ntoa overwrites itself
 	  error_string.appfmt("Connection with id %d done from wrong host ip %s,",
 			      *nodeId, inet_ntoa(((struct sockaddr_in *)
@@ -2120,27 +2322,44 @@
 	  error_string.appfmt(" expected %s(%s).", config_hostname,
 			      r_config_addr ?
 			      "lookup failed" : inet_ntoa(config_addr));
-	} else
+          error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
+	}
+        else
+        {
 	  error_string.appfmt("Id %d already allocated by another node.",
 			      *nodeId);
+          error_code = NDB_MGM_ALLOCID_ERROR;
+        }
+      }
       else
+      {
 	error_string.appfmt("Id %d configured as %s, connect attempted as %s.",
 			    *nodeId, type_c_string.c_str(),
 			    type_string.c_str());
+        error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
+      }
+    }
     else
+    {
       error_string.appfmt("No node defined with id=%d in config file.",
 			  *nodeId);
+      error_code = NDB_MGM_ALLOCID_CONFIG_MISMATCH;
+    }
   }
 
-  g_eventLogger.warning("Allocate nodeid (%d) failed. Connection from ip %s. "
-			"Returned error string \"%s\"",
-			*nodeId,
-			client_addr != 0 ? inet_ntoa(((struct sockaddr_in *)(client_addr))->sin_addr) : "<none>",
-			error_string.c_str());
-
-  NodeBitmask connected_nodes2;
-  get_connected_nodes(connected_nodes2);
+  if (log_event || error_code == NDB_MGM_ALLOCID_CONFIG_MISMATCH)
   {
+    g_eventLogger.warning("Allocate nodeid (%d) failed. Connection from ip %s."
+                          " Returned error string \"%s\"",
+                          *nodeId,
+                          client_addr != 0
+                          ? inet_ntoa(((struct sockaddr_in *)
+                                       (client_addr))->sin_addr)
+                          : "<none>",
+                          error_string.c_str());
+
+    NodeBitmask connected_nodes2;
+    get_connected_nodes(connected_nodes2);
     BaseString tmp_connected, tmp_not_connected;
     for(Uint32 i = 0; i < MAX_NODES; i++)
     {
@@ -2340,6 +2559,7 @@
 MgmtSrvr::abortBackup(Uint32 backupId)
 {
   SignalSender ss(theFacade);
+  ss.lock(); // lock will be released on exit
 
   bool next;
   NodeId nodeId = 0;
@@ -2364,20 +2584,11 @@
 }
 
 
-/*****************************************************************************
- * Global Replication
- *****************************************************************************/
-
-int
-MgmtSrvr::repCommand(Uint32* repReqId, Uint32 request, bool waitCompleted)
-{
-  require(false);
-  return 0;
-}
-
 MgmtSrvr::Allocated_resources::Allocated_resources(MgmtSrvr &m)
   : m_mgmsrv(m)
 {
+  m_reserved_nodes.clear();
+  m_alloc_timeout= 0;
 }
 
 MgmtSrvr::Allocated_resources::~Allocated_resources()
@@ -2396,9 +2607,22 @@
 }
 
 void
-MgmtSrvr::Allocated_resources::reserve_node(NodeId id)
+MgmtSrvr::Allocated_resources::reserve_node(NodeId id, NDB_TICKS timeout)
 {
   m_reserved_nodes.set(id);
+  m_alloc_timeout= NdbTick_CurrentMillisecond() + timeout;
+}
+
+bool
+MgmtSrvr::Allocated_resources::is_timed_out(NDB_TICKS tick)
+{
+  if (m_alloc_timeout && tick > m_alloc_timeout)
+  {
+    g_eventLogger.info("Mgmt server state: nodeid %d timed out.",
+                       get_nodeid());
+    return true;
+  }
+  return false;
 }
 
 NodeId
Thread
bk commit into 5.1 tree (stewart:1.2225)Stewart Smith20 Jun