From 2eb2383ed022ec8ec591f4dde9565b7415f11351 Mon Sep 17 00:00:00 2001
From: unknown <tomas@poseidon.ndb.mysql.com>
Date: Wed, 16 Feb 2005 20:46:34 +0100
Subject: [PATCH 1/2] reuse nodeid if ndbd is restarted

mysql-test/mysql-test-run.pl:
  start and exit fix for ndbcluster
---
 mysql-test/mysql-test-run.pl                 | 6 +++++-
 ndb/include/mgmapi/mgmapi.h                  | 1 +
 ndb/include/mgmcommon/ConfigRetriever.hpp    | 2 ++
 ndb/src/common/mgmcommon/ConfigRetriever.cpp | 6 ++++++
 ndb/src/kernel/vm/Configuration.cpp          | 9 +++++++++
 ndb/src/mgmapi/mgmapi.cpp                    | 9 +++++++++
 6 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index f204fee50ed..ec163529ffb 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -358,6 +358,10 @@ sub main () {
 
   if ( $opt_start_and_exit )
   {
+    if ( ndbcluster_start() )
+    {
+      mtr_error("Can't start ndbcluster");
+    }
     if ( mysqld_start('master',0,[],[]) )
     {
       mtr_report("Servers started, exiting");
@@ -1054,7 +1058,7 @@ sub ndbcluster_start () {
 		"--data-dir=$glob_mysql_test_dir/var"],
 	       "", "/dev/null", "", "") )
   {
-    mtr_error("Error ndbcluster_install");
+    mtr_error("Error ndbcluster_start");
     return 1;
   }
 
diff --git a/ndb/include/mgmapi/mgmapi.h b/ndb/include/mgmapi/mgmapi.h
index 3d4a34d6488..fa0774afa06 100644
--- a/ndb/include/mgmapi/mgmapi.h
+++ b/ndb/include/mgmapi/mgmapi.h
@@ -376,6 +376,7 @@ extern "C" {
   int ndb_mgm_set_connectstring(NdbMgmHandle handle,
 				const char *connect_string);
 
+  int ndb_mgm_set_configuration_nodeid(NdbMgmHandle handle, int nodeid);
   int ndb_mgm_get_configuration_nodeid(NdbMgmHandle handle);
   int ndb_mgm_get_connected_port(NdbMgmHandle handle);
   const char *ndb_mgm_get_connected_host(NdbMgmHandle handle);
diff --git a/ndb/include/mgmcommon/ConfigRetriever.hpp b/ndb/include/mgmcommon/ConfigRetriever.hpp
index 8461658748e..be6d656e1a5 100644
--- a/ndb/include/mgmcommon/ConfigRetriever.hpp
+++ b/ndb/include/mgmcommon/ConfigRetriever.hpp
@@ -55,6 +55,8 @@ public:
    */
   Uint32 allocNodeId(int no_retries, int retry_delay_in_seconds);
 
+  int setNodeId(Uint32 nodeid);
+
   /**
    * Get config using socket
    */
diff --git a/ndb/src/common/mgmcommon/ConfigRetriever.cpp b/ndb/src/common/mgmcommon/ConfigRetriever.cpp
index db00cc1510f..fd04ad393eb 100644
--- a/ndb/src/common/mgmcommon/ConfigRetriever.cpp
+++ b/ndb/src/common/mgmcommon/ConfigRetriever.cpp
@@ -316,6 +316,12 @@ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf, Uint32
   return true;
 }
 
+int
+ConfigRetriever::setNodeId(Uint32 nodeid)
+{
+  return ndb_mgm_set_configuration_nodeid(m_handle, nodeid);
+}
+
 Uint32
 ConfigRetriever::allocNodeId(int no_retries, int retry_delay_in_seconds)
 {
diff --git a/ndb/src/kernel/vm/Configuration.cpp b/ndb/src/kernel/vm/Configuration.cpp
index f35a5859ff8..de78a4e927c 100644
--- a/ndb/src/kernel/vm/Configuration.cpp
+++ b/ndb/src/kernel/vm/Configuration.cpp
@@ -141,6 +141,8 @@ Configuration::init(int argc, char** argv)
   else
     _programName = strdup("");
   
+  globalData.ownId= 0;
+
   return true;
 }
 
@@ -215,6 +217,13 @@ Configuration::fetch_configuration(){
 
   ConfigRetriever &cr= *m_config_retriever;
   
+  /**
+   * if we have a nodeid set (e.g in a restart situation)
+   * reuse it
+   */
+  if (globalData.ownId)
+    cr.setNodeId(globalData.ownId);
+
   globalData.ownId = cr.allocNodeId(2 /*retry*/,3 /*delay*/);
   
   if(globalData.ownId == 0){
diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp
index 5a95c6e9ac1..68106c4689d 100644
--- a/ndb/src/mgmapi/mgmapi.cpp
+++ b/ndb/src/mgmapi/mgmapi.cpp
@@ -1720,6 +1720,15 @@ ndb_mgm_destroy_configuration(struct ndb_mgm_configuration *cfg)
   }
 }
 
+extern "C"
+int
+ndb_mgm_set_configuration_nodeid(NdbMgmHandle handle, int nodeid)
+{
+  CHECK_HANDLE(handle, -1);
+  handle->cfg._ownNodeId= nodeid;
+  return 0;
+}
+
 extern "C"
 int
 ndb_mgm_get_configuration_nodeid(NdbMgmHandle handle)

From 600e432143664fb90593b934123a538070a8f8a3 Mon Sep 17 00:00:00 2001
From: unknown <tomas@poseidon.ndb.mysql.com>
Date: Wed, 16 Feb 2005 21:54:35 +0100
Subject: [PATCH 2/2] bug #8556 corrupt ndb_mgm show printout for certain
 configurations

---
 ndb/src/mgmclient/CommandInterpreter.cpp | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp
index 025bed2bc09..c3b0ee7fe97 100644
--- a/ndb/src/mgmclient/CommandInterpreter.cpp
+++ b/ndb/src/mgmclient/CommandInterpreter.cpp
@@ -1069,16 +1069,19 @@ print_nodes(ndb_mgm_cluster_state *state, ndb_mgm_configuration_iterator *it,
 	}
 	ndbout << ")" << endl;
       } else {
-	if(ndb_mgm_find(it, CFG_NODE_ID, node_id) != 0){
-	  ndbout_c("Unable to find node with id: %d", node_id);
-	  return;
+	ndb_mgm_first(it);
+	if(ndb_mgm_find(it, CFG_NODE_ID, node_id) == 0){
+	  const char *config_hostname= 0;
+	  ndb_mgm_get_string_parameter(it, CFG_NODE_HOST, &config_hostname);
+	  if (config_hostname == 0 || config_hostname[0] == 0)
+	    config_hostname= "any host";
+	  ndbout_c(" (not connected, accepting connect from %s)",
+		   config_hostname);
+	}
+	else
+	{
+	  ndbout_c("Unable to find node with id: %d", node_id);
 	}
-	const char *config_hostname= 0;
-	ndb_mgm_get_string_parameter(it, CFG_NODE_HOST, &config_hostname);
-	if (config_hostname == 0 || config_hostname[0] == 0)
-	  config_hostname= "any host";
-	ndbout << " (not connected, accepting connect from "
-	       << config_hostname << ")" << endl;
       }
     }
   }