Example #1
0
void NDBT_Context::wait_timeout(int msec){
  NdbMutex_Lock(propertyMutexPtr);
  NdbCondition_WaitTimeout(propertyCondPtr,
			   propertyMutexPtr,
			   msec);
  NdbMutex_Unlock(propertyMutexPtr);
}
Example #2
0
void
ArbitMgr::threadMain()
{
    ArbitSignal aSignal;
    aSignal = theInputBuffer;
    threadStart(aSignal);
    bool stop = false;
    while (! stop) {
        NdbMutex_Lock(theInputMutex);
        while (! theInputFull) {
            NdbCondition_WaitTimeout(theInputCond, theInputMutex, theInputTimeout);
            threadTimeout();
        }
        aSignal = theInputBuffer;
        theInputFull = false;
        NdbCondition_Signal(theInputCond);
        NdbMutex_Unlock(theInputMutex);
        switch (aSignal.gsn) {
        case GSN_ARBIT_CHOOSEREQ:
            threadChoose(aSignal);
            break;
        case GSN_ARBIT_STOPORD:
            stop = true;
            break;
        }
    }
    threadStop(aSignal);
}
Example #3
0
inline
void
NdbWaiter::wait(int waitTime)
{
  assert(!m_poll_owner);
  NdbCondition_WaitTimeout(m_condition, m_mutex, waitTime);
}
Example #4
0
Ndb*
NdbPool::wait_free_ndb(Uint32 &id)
{
  int res;
  int time_out = 3500;
  do {
    NdbCondition* tmp = input_pool_cond;
    m_waiting++;
    m_input_queue++;
    time_out -= 500;
    res = NdbCondition_WaitTimeout(input_pool_cond, pool_mutex, time_out);
    if (tmp == input_pool_cond) {
      m_input_queue--;
    } else {
      m_output_queue--;
      if (m_output_queue == 0) {
        switch_condition_queue();
      }
    }
    m_waiting--;
  } while (res == 0 && m_first_wait == NULL_POOL);
  if (res != 0 && m_first_wait == NULL_POOL) {
    return NULL;
  }
  id = m_first_wait;
  remove_wait_list();
  assert(m_waiting != 0 || m_first_wait == NULL_POOL);
  return m_pool_reference[id].ndb_reference;
}
Example #5
0
NdbTableImpl *
GlobalDictCache::get(const char * name, int *error)
{
  DBUG_ENTER("GlobalDictCache::get");
  DBUG_PRINT("enter", ("name: %s", name));

  const Uint32 len = strlen(name);
  Vector<TableVersion> * versions = 0;
  versions = m_tableHash.getData(name, len);
  if(versions == 0){
    versions = new Vector<TableVersion>(2);
    if (versions == NULL)
    {
      *error = -1;
      DBUG_RETURN(0);
    }
    m_tableHash.insertKey(name, len, 0, versions);
  }

  int waitTime = 100;

  bool retreive = false;
  while(versions->size() > 0 && !retreive){
    TableVersion * ver = & versions->back();
    switch(ver->m_status){
    case OK:
      ver->m_refCount++;
      DBUG_RETURN(ver->m_impl);
    case DROPPED:
      retreive = true; // Break loop
      break;
    case RETREIVING:
      NdbCondition_WaitTimeout(m_waitForTableCondition, m_mutex, waitTime);
      continue;
    }
  }
  
  /**
   * Create new...
   */
  TableVersion tmp;
  tmp.m_version = 0;
  tmp.m_impl = 0;
  tmp.m_status = RETREIVING;
  tmp.m_refCount = 1; // The one retreiving it
  if (versions->push_back(tmp))
  {
    *error = -1;
    DBUG_RETURN(0);
  }
  DBUG_RETURN(0);
}
Example #6
0
void
ClusterMgr::startThread() {
  Guard g(clusterMgrThreadMutex);

  theStop = -1;
  theClusterMgrThread = NdbThread_Create(runClusterMgr_C,
                                         (void**)this,
                                         0, // default stack size
                                         "ndb_clustermgr",
                                         NDB_THREAD_PRIO_HIGH);
  Uint32 cnt = 0;
  while (theStop == -1 && cnt < 60)
  {
    NdbCondition_WaitTimeout(waitForHBCond, clusterMgrThreadMutex, 1000);
  }

  assert(theStop == 0);
}
Example #7
0
NdbApiSignal *
SignalQueue::waitFor(int gsn, NodeId nodeid, Uint32 timeout) {
  Guard g(m_mutex);

  if(m_signalQueueHead == NULL)
    NdbCondition_WaitTimeout(m_cond, m_mutex, timeout);

  if(m_signalQueueHead == NULL)
    return NULL;

  if(gsn != 0 && 
     m_signalQueueHead->signal->readSignalNumber() != gsn)
    return NULL;

  if(nodeid != 0 &&
     refToNode(m_signalQueueHead->signal->theSendersBlockRef) != nodeid)
    return NULL;

  return pop();
}
Example #8
0
void
CPCD::Monitor::run() {
  while(1) {
    NdbMutex_Lock(m_changeMutex);
    NdbCondition_WaitTimeout(m_changeCondition,
			     m_changeMutex,
			     m_pollingInterval * 1000);

    MutexVector<CPCD::Process *> &proc = *m_cpcd->getProcessList();

    proc.lock();

    for(size_t i = 0; i < proc.size(); i++) {
      proc[i]->monitor();
    }

    proc.unlock();

    NdbMutex_Unlock(m_changeMutex);
  }
}
Example #9
0
void
ClusterMgr::startThread()
{
    /**
     * We use the clusterMgrThreadMutex as a signalling object between this
     * thread and the main thread of the ClusterMgr.
     * The clusterMgrThreadMutex also protects the theStop-variable.
     */
    Guard g(clusterMgrThreadMutex);

    theStop = -1;
    theClusterMgrThread = NdbThread_Create(runClusterMgr_C,
                                           (void**)this,
                                           0, // default stack size
                                           "ndb_clustermgr",
                                           NDB_THREAD_PRIO_HIGH);
    Uint32 cnt = 0;
    while (theStop == -1 && cnt < 60)
    {
        NdbCondition_WaitTimeout(waitForHBCond, clusterMgrThreadMutex, 1000);
    }

    assert(theStop == 0);
}
Example #10
0
void
ArbitMgr::sendSignalToThread(ArbitSignal& aSignal)
{
#ifdef DEBUG_ARBIT
    char buf[17] = "";
    ndbout << "arbit recv: ";
    ndbout << " gsn=" << aSignal.gsn;
    ndbout << " send=" << aSignal.data.sender;
    ndbout << " code=" << aSignal.data.code;
    ndbout << " node=" << aSignal.data.node;
    ndbout << " ticket=" << aSignal.data.ticket.getText(buf, sizeof(buf));
    ndbout << " mask=" << aSignal.data.mask.getText(buf, sizeof(buf));
    ndbout << endl;
#endif
    aSignal.setTimestamp();       // signal arrival time
    NdbMutex_Lock(theInputMutex);
    while (theInputFull) {
        NdbCondition_WaitTimeout(theInputCond, theInputMutex, 1000);
    }
    theInputBuffer = aSignal;
    theInputFull = true;
    NdbCondition_Signal(theInputCond);
    NdbMutex_Unlock(theInputMutex);
}
Example #11
0
void
ClusterMgr::forceHB()
{
    theFacade.lock_mutex();

    if(waitingForHB)
    {
      NdbCondition_WaitTimeout(waitForHBCond, theFacade.theMutexPtr, 1000);
      theFacade.unlock_mutex();
      return;
    }

    waitingForHB= true;

    NodeBitmask ndb_nodes;
    ndb_nodes.clear();
    waitForHBFromNodes.clear();
    for(Uint32 i = 0; i < MAX_NODES; i++)
    {
      if(!theNodes[i].defined)
        continue;
      if(theNodes[i].m_info.m_type == NodeInfo::DB)
      {
        ndb_nodes.set(i);
        const ClusterMgr::Node &node= getNodeInfo(i);
        waitForHBFromNodes.bitOR(node.m_state.m_connected_nodes);
      }
    }
    waitForHBFromNodes.bitAND(ndb_nodes);

#ifdef DEBUG_REG
    char buf[128];
    ndbout << "Waiting for HB from " << waitForHBFromNodes.getText(buf) << endl;
#endif
    NdbApiSignal signal(numberToRef(API_CLUSTERMGR, theFacade.ownId()));

    signal.theVerId_signalNumber   = GSN_API_REGREQ;
    signal.theReceiversBlockNumber = QMGR;
    signal.theTrace                = 0;
    signal.theLength               = ApiRegReq::SignalLength;

    ApiRegReq * req = CAST_PTR(ApiRegReq, signal.getDataPtrSend());
    req->ref = numberToRef(API_CLUSTERMGR, theFacade.ownId());
    req->version = NDB_VERSION;

    int nodeId= 0;
    for(int i=0;
        (int) NodeBitmask::NotFound != (nodeId= waitForHBFromNodes.find(i));
        i= nodeId+1)
    {
#ifdef DEBUG_REG
      ndbout << "FORCE HB to " << nodeId << endl;
#endif
      theFacade.sendSignalUnCond(&signal, nodeId);
    }

    /* Wait for nodes to reply - if any heartbeats was sent */
    if (!waitForHBFromNodes.isclear())
      NdbCondition_WaitTimeout(waitForHBCond, theFacade.theMutexPtr, 1000);

    waitingForHB= false;
#ifdef DEBUG_REG
    ndbout << "Still waiting for HB from " << waitForHBFromNodes.getText(buf) << endl;
#endif
    theFacade.unlock_mutex();
}