/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include int waitClusterStarted(const char* _addr, unsigned int _timeout= 120); int main(int argc, const char** argv){ const char* _hostName = NULL; int _help = 0; struct getargs args[] = { { "usage", '?', arg_flag, &_help, "Print help", "" } }; int num_args = sizeof(args) / sizeof(args[0]); int optind = 0; char desc[] = "hostname:port\n"\ "This program will connect to the mgmsrv of a NDB cluster.\n"\ "It will then wait for all nodes to be started\n"; if(getarg(args, num_args, argc, argv, &optind) || _help) { arg_printusage(args, num_args, argv[0], desc); return NDBT_ProgramExit(NDBT_WRONGARGS); } _hostName = argv[optind]; // NdbRestarter restarter(_hostName); if (waitClusterStarted(_hostName) != 0) return NDBT_ProgramExit(NDBT_FAILED); return NDBT_ProgramExit(NDBT_OK); } #define MGMERR(h) \ ndbout << "latest_error="< 0 && attempts > _timeout){ /** * Timeout has expired waiting for the nodes to enter * the state we want */ bool waitMore = false; /** * Make special check if we are waiting for * cluster to become started */ if(_status == NDB_MGM_NODE_STATUS_STARTED){ waitMore = true; /** * First check if any node is not starting * then it's no idea to wait anymore */ for (size_t n = 0; n < ndbNodes.size(); n++){ if (ndbNodes[n].node_status != NDB_MGM_NODE_STATUS_STARTED && ndbNodes[n].node_status != NDB_MGM_NODE_STATUS_STARTING) waitMore = false; } } if (!waitMore || resetAttempts > MAX_RESET_ATTEMPTS){ g_err << "waitNodeState(" << ndb_mgm_get_node_status_string(_status) <<", "<<_startphase<<")" << " timeout after " << attempts <<" attemps" << endl; return -1; } g_err << "waitNodeState(" << ndb_mgm_get_node_status_string(_status) <<", "<<_startphase<<")" << " resetting number of attempts " << resetAttempts << endl; attempts = 0; resetAttempts++; } allInState = true; if (getStatus() != 0){ g_err << "getStatus != 0" << endl; return -1; } // ndbout << "waitNodeState; _num_nodes = " << _num_nodes << endl; // for (int i = 0; i < _num_nodes; i++) // ndbout << " node["<node_id << " " << ndb_mgm_get_node_status_string(ndbNode->node_status)<< endl; assert(ndbNode != NULL); if(_status == NDB_MGM_NODE_STATUS_STARTING && ((ndbNode->node_status == NDB_MGM_NODE_STATUS_STARTING && ndbNode->start_phase >= _startphase) || (ndbNode->node_status == NDB_MGM_NODE_STATUS_STARTED))) continue; if (_status == NDB_MGM_NODE_STATUS_STARTING){ g_info << "status = " << ndb_mgm_get_node_status_string(ndbNode->node_status) <<", start_phase="<start_phase<node_status != _status) { if (ndbNode->node_status < _status) allInState = false; else g_info << "node_status(" << ndbNode->node_status <<") != _status("<<_status<<")"<start_phase < _startphase) allInState = false; } else { if (ndbNode->node_status != _status) allInState = false; } } g_info << "Waiting for cluster enter state" << ndb_mgm_get_node_status_string(_status)<< endl; NdbSleep_SecSleep(1); attempts++; } return 0; }