The world's most popular open source database
#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>Include dependency graph for waiter.cpp:

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 | waitClusterStatus (const char *_addr, ndb_mgm_node_status _status, unsigned int _timeout) |
| static void | usage () |
| int | main (int argc, char **argv) |
| int | getStatus () |
Variables | |
| NDB_STD_OPTS_VARS | |
| static int | _no_contact = 0 |
| static int | _not_started = 0 |
| static int | _timeout = 120 |
| static struct my_option | my_long_options [] |
| NdbMgmHandle | handle = NULL |
| Vector< ndb_mgm_node_state > | ndbNodes |
| Vector< ndb_mgm_node_state > | mgmNodes |
| Vector< ndb_mgm_node_state > | apiNodes |
| #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.
Referenced by getStatus(), and waitClusterStatus().
| enum ndb_waiter_options |
Definition at line 33 of file waiter.cpp.
00033 { 00034 OPT_WAIT_STATUS_NOT_STARTED = NDB_STD_OPTIONS_LAST 00035 };
| int getStatus | ( | ) |
Definition at line 112 of file waiter.cpp.
References abort(), apiNodes, count, free, handle, MGMERR, mgmNodes, ndb_mgm_connect(), ndb_mgm_disconnect(), 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, ndbNodes, ndbout(), ndb_mgm_node_state::node_type, NULL, 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 ndb_mgm_disconnect(handle); 00128 if (ndb_mgm_connect(handle,0,0,1)) { 00129 MGMERR(handle); 00130 g_err << "Reconnect failed" << endl; 00131 break; 00132 } 00133 continue; 00134 } 00135 int count = status->no_of_nodes; 00136 for (int i = 0; i < count; i++){ 00137 node = &status->node_states[i]; 00138 switch(node->node_type){ 00139 case NDB_MGM_NODE_TYPE_NDB: 00140 ndbNodes.push_back(*node); 00141 break; 00142 case NDB_MGM_NODE_TYPE_MGM: 00143 mgmNodes.push_back(*node); 00144 break; 00145 case NDB_MGM_NODE_TYPE_API: 00146 apiNodes.push_back(*node); 00147 break; 00148 default: 00149 if(node->node_status == NDB_MGM_NODE_STATUS_UNKNOWN || 00150 node->node_status == NDB_MGM_NODE_STATUS_NO_CONTACT){ 00151 retries++; 00152 ndbNodes.clear(); 00153 mgmNodes.clear(); 00154 apiNodes.clear(); 00155 free(status); 00156 status = NULL; 00157 count = 0; 00158 00159 ndbout << "kalle"<< endl; 00160 break; 00161 } 00162 abort(); 00163 break; 00164 } 00165 } 00166 if(status == 0){ 00167 ndbout << "status == 0" << endl; 00168 continue; 00169 } 00170 free(status); 00171 return 0; 00172 } 00173 00174 g_err << "getStatus failed" << endl; 00175 return -1; 00176 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 63 of file waiter.cpp.
References _no_contact, _not_started, _timeout, handle_options(), load_default_groups, load_defaults(), my_long_options, NDB_INIT, NDB_MGM_NODE_STATUS_NO_CONTACT, NDB_MGM_NODE_STATUS_NOT_STARTED, NDB_MGM_NODE_STATUS_STARTED, ndb_std_get_one_option(), 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*10) != 0) 00096 return NDBT_ProgramExit(NDBT_FAILED); 00097 return NDBT_ProgramExit(NDBT_OK); 00098 }
Here is the call graph for this function:

| static void usage | ( | void | ) | [static] |
Definition at line 56 of file waiter.cpp.
References my_long_options, my_print_help(), my_print_variables(), and ndb_std_print_version().
00057 { 00058 ndb_std_print_version(); 00059 my_print_help(my_long_options); 00060 my_print_variables(my_long_options); 00061 }
Here is the call graph for this function:

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

Here is the caller graph for this function:

int _no_contact = 0 [static] |
int _not_started = 0 [static] |
int _timeout = 120 [static] |
| NdbMgmHandle handle = NULL |
Definition at line 105 of file waiter.cpp.
Referenced by event_thread_run(), Dbdict::execCREATE_EVNT_REQ(), Cmvmi::execDUMP_STATE_ORD(), getStatus(), ndb_mgm_abort_backup(), ndb_mgm_alloc_nodeid(), ndb_mgm_call(), ndb_mgm_check_connection(), ndb_mgm_connect(), ndb_mgm_convert_to_transporter(), ndb_mgm_destroy_handle(), ndb_mgm_disconnect(), ndb_mgm_dump_state(), ndb_mgm_end_session(), ndb_mgm_enter_single_user(), ndb_mgm_exit_single_user(), ndb_mgm_get_clusterlog_severity_filter(), ndb_mgm_get_configuration(), ndb_mgm_get_configuration_nodeid(), ndb_mgm_get_connected_host(), ndb_mgm_get_connected_port(), ndb_mgm_get_connection_int_parameter(), ndb_mgm_get_connectstring(), ndb_mgm_get_mgmd_nodeid(), ndb_mgm_get_status(), ndb_mgm_get_version(), ndb_mgm_insert_error(), ndb_mgm_is_connected(), ndb_mgm_listen_event(), ndb_mgm_listen_event_internal(), ndb_mgm_log_signals(), ndb_mgm_purge_stale_sessions(), ndb_mgm_rep_command(), ndb_mgm_report_event(), ndb_mgm_restart(), ndb_mgm_restart2(), ndb_mgm_restart3(), ndb_mgm_set_clusterlog_loglevel(), ndb_mgm_set_clusterlog_severity_filter(), ndb_mgm_set_configuration_nodeid(), ndb_mgm_set_connection_int_parameter(), ndb_mgm_set_connectstring(), ndb_mgm_set_error_stream(), ndb_mgm_set_int64_parameter(), ndb_mgm_set_int_parameter(), ndb_mgm_set_loglevel_node(), ndb_mgm_set_name(), ndb_mgm_set_string_parameter(), ndb_mgm_set_trace(), ndb_mgm_start(), ndb_mgm_start_backup(), ndb_mgm_start_signallog(), ndb_mgm_stop(), ndb_mgm_stop2(), ndb_mgm_stop3(), ndb_mgm_stop_signallog(), os_thread_get_priority(), Suma::Table::parseTable(), SafeCounter::SafeCounter(), UT_LIST_BASE_NODE_T(), and waitClusterStatus().
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.
Definition at line 36 of file waiter.cpp.
1.4.7

