Commit 38229d74 authored by unknown's avatar unknown
Browse files

BUG#12124 ndb_mgm -e "# stop" does not allow stopping ndb_mgmd processes on other systems

WL#2703 restart for ndb_mgmd

Solving two problems with one stone.

Allows the stopping and restarting of mgm nodes other than the one the mgmclient
is connected to.


ndb/include/mgmapi/mgmapi.h:
  Add the internal ndb_mgm_end_session command.
  
  This will unreserve the nodeid we have allocated synchronously.
  
  Otherwise we can't do a restart of a node really quickly as the nodeids are cleaned
  up after the connection to mgmd is closed.
ndb/include/mgmcommon/ConfigRetriever.hpp:
  Allow configuration on if end_session is going to be called on object destruction.
  
  We need to set this to false for ndbd as we fork()
ndb/src/common/mgmcommon/ConfigRetriever.cpp:
  When destroying ConfigRetreiver, ndb_mgm_end_session - i.e. deallocate the nodeid
ndb/src/common/util/SocketServer.cpp:
  When destroying a SocketServer, close the server socket.
ndb/src/kernel/main.cpp:
  don't purge allocated resources when cleaning up in parent process (nodeid)
ndb/src/kernel/vm/Configuration.cpp:
  have option end_session to closeConfiguration
ndb/src/kernel/vm/Configuration.hpp:
  have option end_session to closeConfiguration
ndb/src/mgmapi/mgmapi.cpp:
  Implement ndb_mgm_end_session
ndb/src/mgmclient/CommandInterpreter.cpp:
  Correct output of STOP as we can now stop mgmd as well as ndbd
ndb/src/mgmsrv/MgmtSrvr.cpp:
  Add code into start for connecting to our own mgmd.
  
  Create sendStopMgmd() which does the same job as sendSTOP_REQ, but for ndb_mgmd
  
  Allow stopping of other ndb_mgmd processes by creating a connection to them
  and issuing the stop command
  
  When stopping all nodes, stop other ndb_mgmd processes as well.
  
  Remove set_connect_string. Replace with connect_to_self. This is a much better
  way of doing things.
ndb/src/mgmsrv/MgmtSrvr.hpp:
  add connect_to_self and remove set_connect_string.
ndb/src/mgmsrv/Services.cpp:
  Add endSession.
  
  - delete Allocated_resources for this connection
  - create new Allocated_resources for this connection
  
  conceivably you could keep the socket open across node restarts (and even
  possibly get a different node id). But I wouldn't try it and expect happiness.
ndb/src/mgmsrv/Services.hpp:
  Add endSession
ndb/src/mgmsrv/main.cpp:
  allow mgmd to be restarted.
  
  - add g_RestartServer flag
  - move connecting to our own mgmd into MgmtSrvr (where it belongs)
  - output correct Shutdown/Restart message on shutdown/restart
parent 3bf3bb20
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -993,6 +993,22 @@ extern "C" {
  int ndb_mgm_alloc_nodeid(NdbMgmHandle handle,
			   unsigned version, int nodetype);

  /**
   * End Session
   *
   * This function tells the mgm server to free all resources associated with
   * this connection. It will also close it.
   *
   * This differs from just disconnecting as we now synchronously clean up,
   * so that a quickly restarting server that needs the same node id can
   * get it when it restarts.
   *
   * @param  handle NDB management handle
   * @return 0 on success
   *
   * @note you still have to destroy the NdbMgmHandle.
   */
  int ndb_mgm_end_session(NdbMgmHandle handle);

  /**
   * Get the node id of the mgm server we're connected to
+3 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ public:
  const char *get_connectstring(char *buf, int buf_sz) const;
  NdbMgmHandle get_mgmHandle() { return m_handle; };
  NdbMgmHandle* get_mgmHandlePtr() { return &m_handle; };
  void end_session(bool end) { m_end_session= end; };

  Uint32 get_configuration_nodeid() const;
private:
@@ -92,6 +93,8 @@ private:
  void setError(ErrorType, const char * errorMsg);
  
  Uint32      _ownNodeId;
  bool m_end_session;

  /*
  Uint32      m_mgmd_port;
  const char *m_mgmd_host;
+3 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ ConfigRetriever::ConfigRetriever(const char * _connect_string,
  m_version = version;
  m_node_type = node_type;
  _ownNodeId= 0;
  m_end_session= true;

  m_handle= ndb_mgm_create_handle();

@@ -73,6 +74,8 @@ ConfigRetriever::~ConfigRetriever()
{
  DBUG_ENTER("ConfigRetriever::~ConfigRetriever");
  if (m_handle) {
    if(m_end_session)
      ndb_mgm_end_session(m_handle);
    ndb_mgm_disconnect(m_handle);
    ndb_mgm_destroy_handle(&m_handle);
  }
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ SocketServer::~SocketServer() {
    delete m_sessions[i].m_session;
  }
  for(i = 0; i<m_services.size(); i++){
    if(m_services[i].m_socket)
      NDB_CLOSE_SOCKET(m_services[i].m_socket);
    delete m_services[i].m_service;
  }
}
+4 −1
Original line number Diff line number Diff line
@@ -307,8 +307,11 @@ int main(int argc, char** argv)
    /**
     * We no longer need the mgm connection in this process
     * (as we are the angel, not ndb)
     *
     * We don't want to purge any allocated resources (nodeid), so
     * we set that option to false
     */
    theConfig->closeConfiguration();
    theConfig->closeConfiguration(false);

    int status = 0, error_exit = 0, signum = 0;
    while(waitpid(child, &status, 0) != child);
Loading