int Ndb_cluster_connection::wait_until_ready(int timeout, int timeout_after_first_alive) { DBUG_ENTER("Ndb_cluster_connection::wait_until_ready"); TransporterFacade *tp = TransporterFacade::instance(); if (tp == 0) { DBUG_RETURN(-1); } if (tp->ownId() == 0) { DBUG_RETURN(-1); } int secondsCounter = 0; int milliCounter = 0; int noChecksSinceFirstAliveFound = 0; do { unsigned int foundAliveNode = 0; tp->lock_mutex(); for(unsigned i= 0; i < no_db_nodes(); i++) { //************************************************ // If any node is answering, ndb is answering //************************************************ if (tp->get_node_alive(m_impl.m_all_nodes[i].id) != 0) { foundAliveNode++; } } tp->unlock_mutex(); if (foundAliveNode == no_db_nodes()) { DBUG_RETURN(0); } else if (foundAliveNode > 0) { noChecksSinceFirstAliveFound++; // 100 ms delay -> 10* if (noChecksSinceFirstAliveFound > 10*timeout_after_first_alive) DBUG_RETURN(1); } else if (secondsCounter >= timeout) { // no alive nodes and timed out DBUG_RETURN(-1); } NdbSleep_MilliSleep(100); milliCounter += 100; if (milliCounter >= 1000) { secondsCounter++; milliCounter = 0; }//if } while (1); }
int Ndb_cluster_connection::get_no_ready() { TransporterFacade *tp = m_impl.m_transporter_facade; if (tp == 0 || tp->ownId() == 0) return -1; unsigned int foundAliveNode = 0; tp->lock_mutex(); for(unsigned i= 0; i < no_db_nodes(); i++) { //************************************************ // If any node is answering, ndb is answering //************************************************ if (tp->get_node_alive(m_impl.m_all_nodes[i].id) != 0) { foundAliveNode++; } } tp->unlock_mutex(); return foundAliveNode; }
Uint32 Ndb_cluster_connection_impl::get_next_alive_node(Ndb_cluster_connection_node_iter &iter) { Uint32 id; TransporterFacade *tp = m_impl.m_transporter_facade; if (tp == 0 || tp->ownId() == 0) return 0; while ((id = get_next_node(iter))) { tp->lock_mutex(); if (tp->get_node_alive(id) != 0) { tp->unlock_mutex(); return id; } tp->unlock_mutex(); } return 0; }