waiter.cpp File Reference

#include <ndb_global.h>
#include <ndb_opts.h>
#include <mgmapi.h>
#include <NdbMain.h>
#include <NdbOut.hpp>
#include <NdbSleep.h>
#include <kernel/ndb_limits.h>
#include <NDBT.hpp>

Go to the source code of this file.

Defines

#define MGMERR(h)

Enumerations

enum  ndb_waiter_options { OPT_WAIT_STATUS_NOT_STARTED = NDB_STD_OPTIONS_LAST }

Functions

int getStatus ()
int main (int argc, char **argv)
static void usage ()
int waitClusterStatus (const char *_addr, ndb_mgm_node_status _status, unsigned int _timeout)

Variables

static int _no_contact = 0
static int _not_started = 0
static int _timeout = 120
Vector< ndb_mgm_node_stateapiNodes
NdbMgmHandle handle = NULL
Vector< ndb_mgm_node_statemgmNodes
static struct my_option my_long_options []
 NDB_STD_OPTS_VARS
Vector< ndb_mgm_node_statendbNodes


Define Documentation

#define MGMERR h   ) 
 

Value:

ndbout << "latest_error="<<ndb_mgm_get_latest_error(h) \
         << ", line="<<ndb_mgm_get_latest_error_line(h) \
         << endl;

Definition at line 100 of file waiter.cpp.


Enumeration Type Documentation

enum ndb_waiter_options
 

Enumerator:
OPT_WAIT_STATUS_NOT_STARTED 

Definition at line 33 of file waiter.cpp.


Function Documentation

int getStatus  ) 
 

Definition at line 112 of file waiter.cpp.

References abort(), Vector< T >::clear(), count, free, g_err, MGMERR, ndb_mgm_get_status(), NDB_MGM_NODE_STATUS_NO_CONTACT, NDB_MGM_NODE_STATUS_UNKNOWN, NDB_MGM_NODE_TYPE_API, NDB_MGM_NODE_TYPE_MGM, NDB_MGM_NODE_TYPE_NDB, ndbout(), ndb_mgm_cluster_state::no_of_nodes, ndb_mgm_cluster_state::node_states, ndb_mgm_node_state::node_status, ndb_mgm_node_state::node_type, NULL, Vector< T >::push_back(), and status.

Referenced by waitClusterStatus().

00112            {
00113   int retries = 0;
00114   struct ndb_mgm_cluster_state * status;
00115   struct ndb_mgm_node_state * node;
00116   
00117   ndbNodes.clear();
00118   mgmNodes.clear();
00119   apiNodes.clear();
00120 
00121   while(retries < 10){
00122     status = ndb_mgm_get_status(handle);
00123     if (status == NULL){
00124       ndbout << "status==NULL, retries="<<retries<<endl;
00125       MGMERR(handle);
00126       retries++;
00127       continue;
00128     }
00129     int count = status->no_of_nodes;
00130     for (int i = 0; i < count; i++){
00131       node = &status->node_states[i];      
00132       switch(node->node_type){
00133       case NDB_MGM_NODE_TYPE_NDB:
00134         ndbNodes.push_back(*node);
00135         break;
00136       case NDB_MGM_NODE_TYPE_MGM:
00137         mgmNodes.push_back(*node);
00138         break;
00139       case NDB_MGM_NODE_TYPE_API:
00140         apiNodes.push_back(*node);
00141         break;
00142       default:
00143         if(node->node_status == NDB_MGM_NODE_STATUS_UNKNOWN ||
00144            node->node_status == NDB_MGM_NODE_STATUS_NO_CONTACT){
00145           retries++;
00146           ndbNodes.clear();
00147           mgmNodes.clear();
00148           apiNodes.clear();
00149           free(status); 
00150           status = NULL;
00151           count = 0;
00152 
00153           ndbout << "kalle"<< endl;
00154           break;
00155         }
00156         abort();
00157         break;
00158       }
00159     }
00160     if(status == 0){
00161       ndbout << "status == 0" << endl;
00162       continue;
00163     }
00164     free(status);
00165     return 0;
00166   }
00167    
00168   g_err  << "getStatus failed" << endl;
00169   return -1;
00170 }

int main int  argc,
char **  argv
 

we must always load meta data, even if we will only print it to stdout

check wheater we can restore the backup (right version).

Definition at line 63 of file waiter.cpp.

References _no_contact, _not_started, _timeout, handle_options(), load_default_groups, load_defaults(), NDB_INIT, NDB_MGM_NODE_STATUS_NO_CONTACT, NDB_MGM_NODE_STATUS_NOT_STARTED, NDB_MGM_NODE_STATUS_STARTED, ndb_std_get_one_option(), NDBT_FAILED, NDBT_OK, NDBT_ProgramExit(), NDBT_WRONGARGS, NULL, opt_connect_str, opt_debug, and waitClusterStatus().

00063                                {
00064   NDB_INIT(argv[0]);
00065   const char *load_default_groups[]= { "mysql_cluster",0 };
00066   load_defaults("my",load_default_groups,&argc,&argv);
00067   const char* _hostName = NULL;
00068   int ho_error;
00069 #ifndef DBUG_OFF
00070   opt_debug= "d:t:O,/tmp/ndb_waiter.trace";
00071 #endif
00072   if ((ho_error=handle_options(&argc, &argv, my_long_options,
00073                                ndb_std_get_one_option)))
00074     return NDBT_ProgramExit(NDBT_WRONGARGS);
00075 
00076   _hostName = argv[0];
00077 
00078   if (_hostName == 0)
00079     _hostName= opt_connect_str;
00080 
00081   enum ndb_mgm_node_status wait_status;
00082   if (_no_contact)
00083   {
00084     wait_status= NDB_MGM_NODE_STATUS_NO_CONTACT;
00085   }
00086   else if (_not_started)
00087   {
00088     wait_status= NDB_MGM_NODE_STATUS_NOT_STARTED;
00089   }
00090   else 
00091   {
00092     wait_status= NDB_MGM_NODE_STATUS_STARTED;
00093   }
00094 
00095   if (waitClusterStatus(_hostName, wait_status, _timeout) != 0)
00096     return NDBT_ProgramExit(NDBT_FAILED);
00097   return NDBT_ProgramExit(NDBT_OK);
00098 }

static void usage void   )  [static]
 

Definition at line 56 of file waiter.cpp.

References my_print_help(), my_print_variables(), and ndb_std_print_version().

int waitClusterStatus const char *  _addr,
ndb_mgm_node_status  _status,
unsigned int  _timeout
 

Timeout has expired waiting for the nodes to enter the state we want

Make special check if we are waiting for cluster to become started

First check if any node is not starting then it's no idea to wait anymore

Definition at line 173 of file waiter.cpp.

References assert, g_err, g_info, getStatus(), MAX_NDB_NODES, MGMERR, n, ndb_mgm_connect(), ndb_mgm_create_handle(), ndb_mgm_get_node_status_string(), NDB_MGM_NODE_STATUS_STARTED, NDB_MGM_NODE_STATUS_STARTING, ndb_mgm_set_connectstring(), NdbSleep_SecSleep(), ndb_mgm_node_state::node_id, ndb_mgm_node_state::node_status, NULL, Vector< T >::size(), and ndb_mgm_node_state::start_phase.

Referenced by main().

00176 {
00177   int _startphase = -1;
00178 
00179   int _nodes[MAX_NDB_NODES];
00180   int _num_nodes = 0;
00181 
00182   handle = ndb_mgm_create_handle();
00183   if (handle == NULL){
00184     g_err << "handle == NULL" << endl;
00185     return -1;
00186   }
00187   g_info << "Connecting to mgmsrv at " << _addr << endl;
00188   if (ndb_mgm_set_connectstring(handle, _addr))
00189   {
00190     MGMERR(handle);
00191     g_err  << "Connectstring " << _addr << " invalid" << endl;
00192     return -1;
00193   }
00194   if (ndb_mgm_connect(handle,0,0,1)) {
00195     MGMERR(handle);
00196     g_err  << "Connection to " << _addr << " failed" << endl;
00197     return -1;
00198   }
00199 
00200   if (getStatus() != 0)
00201     return -1;
00202   
00203   // Collect all nodes into nodes
00204   for (size_t i = 0; i < ndbNodes.size(); i++){
00205     _nodes[i] = ndbNodes[i].node_id;
00206     _num_nodes++;
00207   }
00208 
00209   unsigned int attempts = 0;
00210   unsigned int resetAttempts = 0;
00211   const unsigned int MAX_RESET_ATTEMPTS = 10;
00212   bool allInState = false;    
00213   while (allInState == false){
00214     if (_timeout > 0 && attempts > _timeout){
00219       bool waitMore = false;
00224       if(_status == NDB_MGM_NODE_STATUS_STARTED){
00225         waitMore = true;
00230         for (size_t n = 0; n < ndbNodes.size(); n++){
00231           if (ndbNodes[n].node_status != NDB_MGM_NODE_STATUS_STARTED &&
00232               ndbNodes[n].node_status != NDB_MGM_NODE_STATUS_STARTING)
00233             waitMore = false;
00234 
00235         }
00236       } 
00237 
00238       if (!waitMore || resetAttempts > MAX_RESET_ATTEMPTS){
00239         g_err << "waitNodeState("
00240               << ndb_mgm_get_node_status_string(_status)
00241               <<", "<<_startphase<<")"
00242               << " timeout after " << attempts <<" attemps" << endl;
00243         return -1;
00244       } 
00245 
00246       g_err << "waitNodeState("
00247             << ndb_mgm_get_node_status_string(_status)
00248             <<", "<<_startphase<<")"
00249             << " resetting number of attempts "
00250             << resetAttempts << endl;
00251       attempts = 0;
00252       resetAttempts++;
00253       
00254     }
00255 
00256     allInState = true;
00257     if (getStatus() != 0){
00258       g_err << "getStatus != 0" << endl;
00259       return -1;
00260     }
00261 
00262     // ndbout << "waitNodeState; _num_nodes = " << _num_nodes << endl;
00263     // for (int i = 0; i < _num_nodes; i++)
00264     //   ndbout << " node["<<i<<"] =" <<_nodes[i] << endl;
00265 
00266     for (int i = 0; i < _num_nodes; i++){
00267       ndb_mgm_node_state* ndbNode = NULL;
00268       for (size_t n = 0; n < ndbNodes.size(); n++){
00269         if (ndbNodes[n].node_id == _nodes[i])
00270           ndbNode = &ndbNodes[n];
00271       }
00272 
00273       if(ndbNode == NULL){
00274         allInState = false;
00275         continue;
00276       }
00277 
00278       g_info << "State node " << ndbNode->node_id << " "
00279              << ndb_mgm_get_node_status_string(ndbNode->node_status)<< endl;
00280 
00281       assert(ndbNode != NULL);
00282 
00283       if(_status == NDB_MGM_NODE_STATUS_STARTING && 
00284          ((ndbNode->node_status == NDB_MGM_NODE_STATUS_STARTING && 
00285            ndbNode->start_phase >= _startphase) ||
00286           (ndbNode->node_status == NDB_MGM_NODE_STATUS_STARTED)))
00287         continue;
00288 
00289       if (_status == NDB_MGM_NODE_STATUS_STARTING){
00290         g_info << "status = "  
00291                << ndb_mgm_get_node_status_string(ndbNode->node_status)
00292                <<", start_phase="<<ndbNode->start_phase<<endl;
00293         if (ndbNode->node_status !=  _status) {
00294           if (ndbNode->node_status < _status)
00295             allInState = false;
00296           else 
00297             g_info << "node_status(" << (unsigned)ndbNode->node_status
00298                    << ") != _status("<< (unsigned)_status << ")" <<endl;
00299         } else if (ndbNode->start_phase < _startphase)
00300           allInState = false;
00301       } else {
00302         if (ndbNode->node_status !=  _status) 
00303           allInState = false;
00304       }
00305     }
00306     g_info << "Waiting for cluster enter state " 
00307             << ndb_mgm_get_node_status_string(_status)<< endl;
00308     NdbSleep_SecSleep(1);
00309     attempts++;
00310   }
00311   return 0;
00312 }


Variable Documentation

int _no_contact = 0 [static]
 

Definition at line 38 of file waiter.cpp.

Referenced by main().

int _not_started = 0 [static]
 

Definition at line 39 of file waiter.cpp.

Referenced by main().

int _timeout = 120 [static]
 

Definition at line 40 of file waiter.cpp.

Referenced by main().

Vector<ndb_mgm_node_state> apiNodes
 

Definition at line 109 of file waiter.cpp.

NdbMgmHandle handle = NULL
 

Definition at line 105 of file waiter.cpp.

Referenced by connect_ndb_mgm(), del_tree(), event_thread_run(), Dbdict::execCREATE_EVNT_REQ(), Cmvmi::execDUMP_STATE_ORD(), main(), os_thread_get_priority(), removef(), UT_LIST_BASE_NODE_T(), and wait_ndb().

Vector<ndb_mgm_node_state> mgmNodes
 

Definition at line 108 of file waiter.cpp.

struct my_option my_long_options[] [static]
 

Initial value:

{
  NDB_STD_OPTS("ndb_desc"),
  { "no-contact", 'n', "Wait for cluster no contact",
    (gptr*) &_no_contact, (gptr*) &_no_contact, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, 
  { "not-started", OPT_WAIT_STATUS_NOT_STARTED, "Wait for cluster not started",
    (gptr*) &_not_started, (gptr*) &_not_started, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, 
  { "timeout", 't', "Timeout to wait",
    (gptr*) &_timeout, (gptr*) &_timeout, 0,
    GET_INT, REQUIRED_ARG, 120, 0, 0, 0, 0, 0 }, 
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}

Definition at line 41 of file waiter.cpp.

NDB_STD_OPTS_VARS
 

Definition at line 36 of file waiter.cpp.

Vector<ndb_mgm_node_state> ndbNodes
 

Definition at line 107 of file waiter.cpp.


Generated on Wed Jul 20 21:10:06 2005 for MySQL 5.0.9 Beta by  doxygen 1.4.3