当前位置: 首页>>代码示例>>C++>>正文


C++ SectorMsg::setData方法代码示例

本文整理汇总了C++中SectorMsg::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ SectorMsg::setData方法的具体用法?C++ SectorMsg::setData怎么用?C++ SectorMsg::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SectorMsg的用法示例。


在下文中一共展示了SectorMsg::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: move

int Client::move(const string& oldpath, const string& newpath)
{
   string src = Metadata::revisePath(oldpath);
   string dst = Metadata::revisePath(newpath);

   SectorMsg msg;
   msg.setType(104);
   msg.setKey(m_iKey);

   int32_t size = src.length() + 1;
   msg.setData(0, (char*)&size, 4);
   msg.setData(4, src.c_str(), src.length() + 1);
   size = dst.length() + 1;
   msg.setData(4 + src.length() + 1, (char*)&size, 4);
   msg.setData(4 + src.length() + 1 + 4, dst.c_str(), dst.length() + 1);

   Address serv;
   m_Routing.lookup(src, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:28,代码来源:client.cpp

示例2: copy

int Client::copy(const string& src, const string& dst)
{
   string rsrc = Metadata::revisePath(src);
   string rdst = Metadata::revisePath(dst);

   SectorMsg msg;
   msg.setType(106);
   msg.setKey(m_iKey);

   int32_t size = rsrc.length() + 1;
   msg.setData(0, (char*)&size, 4);
   msg.setData(4, rsrc.c_str(), rsrc.length() + 1);
   size = rdst.length() + 1;
   msg.setData(4 + rsrc.length() + 1, (char*)&size, 4);
   msg.setData(4 + rsrc.length() + 1 + 4, rdst.c_str(), rdst.length() + 1);

   Address serv;
   m_Routing.lookup(rsrc, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:28,代码来源:client.cpp

示例3: reportSphere

int Slave::reportSphere(const string& master_ip, const int& master_port, const int& transid, const vector<Address>* bad)
{
   SectorMsg msg;
   msg.setType(4);
   msg.setKey(0);
   msg.setData(0, (char*)&transid, 4);
   msg.setData(4, (char*)&m_iSlaveID, 4);

   int num = (NULL == bad) ? 0 : bad->size();
   msg.setData(8, (char*)&num, 4);
   for (int i = 0; i < num; ++ i)
   {
      msg.setData(12 + 68 * i, (*bad)[i].m_strIP.c_str(), (*bad)[i].m_strIP.length() + 1);
      msg.setData(12 + 68 * i + 64, (char*)&((*bad)[i].m_iPort), 4);
   }

   cout << "reportSphere " << master_ip << " " << master_port << " " << transid << endl;

   if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
      return -1;

   if (msg.getType() < 0)
      return *(int32_t*)msg.getData();

   return 1;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:26,代码来源:slave.cpp

示例4: list

int Client::list(const string& path, vector<SNode>& attr)
{
   string revised_path = Metadata::revisePath(path);

   SectorMsg msg;
   msg.resize(65536);
   msg.setType(101);
   msg.setKey(m_iKey);
   msg.setData(0, revised_path.c_str(), revised_path.length() + 1);

   Address serv;
   m_Routing.lookup(revised_path, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   string filelist = msg.getData();

   unsigned int s = 0;
   while (s < filelist.length())
   {
      int t = filelist.find(';', s);
      SNode sn;
      sn.deserialize(filelist.substr(s, t - s).c_str());
      attr.insert(attr.end(), sn);
      s = t + 1;
   }

   return attr.size();
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:34,代码来源:client.cpp

示例5: reopen

int FSClient::reopen()
{
   if (0 == m_strFileName.length())
      return -1;

   // currently re-open only works on read
   if (m_bWrite)
      return -1;

   // close connection to the current slave
   int32_t cmd = 5;
   m_pClient->m_DataChn.send(m_strSlaveIP, m_iSlaveDataPort, m_iSession, (char*)&cmd, 4);
   int response;
   m_pClient->m_DataChn.recv4(m_strSlaveIP, m_iSlaveDataPort, m_iSession, response);
   m_pClient->m_DataChn.remove(m_strSlaveIP, m_iSlaveDataPort);


   SectorMsg msg;
   msg.setType(112); // open the file
   msg.setKey(m_pClient->m_iKey);
   msg.setData(0, (char*)&m_iSession, 4);
   int32_t port = m_pClient->m_DataChn.getPort();
   msg.setData(4, (char*)&port, 4);

   Address serv;
   m_pClient->lookup(m_strFileName, serv);
   if (m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   m_strSlaveIP = msg.getData();
   m_iSlaveDataPort = *(int*)(msg.getData() + 64);

   if (m_pClient->m_DataChn.connect(m_strSlaveIP, m_iSlaveDataPort) < 0)
      return SectorError::E_CONNECTION;

   memcpy(m_pcKey, m_pClient->m_pcCryptoKey, 16);
   memcpy(m_pcIV, m_pClient->m_pcCryptoIV, 8);
   m_pClient->m_DataChn.setCryptoKey(m_strSlaveIP, m_iSlaveDataPort, m_pcKey, m_pcIV);

   return 0;
}
开发者ID:heshucheng,项目名称:sector,代码行数:44,代码来源:fsclient.cpp

示例6: dataInfo

int DCClient::dataInfo(const vector<string>& files, vector<string>& info)
{
   SectorMsg msg;
   msg.setType(201);
   msg.setKey(m_pClient->m_iKey);

   int offset = 0;
   int32_t size = -1;
   for (vector<string>::const_iterator i = files.begin(); i != files.end(); ++ i)
   {
      string path = Metadata::revisePath(*i);
      size = path.length() + 1;
      msg.setData(offset, (char*)&size, 4);
      msg.setData(offset + 4, path.c_str(), size);
      offset += 4 + size;
   }

   size = -1;
   msg.setData(offset, (char*)&size, 4);

   Address serv;
   m_pClient->m_Routing.getPrimaryMaster(serv);
   if (m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   char* buf = msg.getData();
   size = msg.m_iDataLength - SectorMsg::m_iHdrSize;

   while (size > 0)
   {
      info.insert(info.end(), buf);
      size -= strlen(buf) + 1;
      buf += strlen(buf) + 1;
   }

   return info.size();
}
开发者ID:norouzi4d,项目名称:sector,代码行数:40,代码来源:dcclient.cpp

示例7: connectSPE

int DCClient::connectSPE(SPE& s)
{
   if (s.m_iStatus != 0)
      return -1;

   SectorMsg msg;
   msg.setType(203); // start processing engine
   msg.setKey(m_pClient->m_iKey);
   msg.setData(0, s.m_strIP.c_str(), s.m_strIP.length() + 1);
   msg.setData(64, (char*)&(s.m_iPort), 4);
   // leave a 4-byte blank spot for data port
   msg.setData(72, (char*)&(s.m_iID), 4);
   msg.setData(76, (char*)&m_pClient->m_iKey, 4);
   msg.setData(80, m_strOperator.c_str(), m_strOperator.length() + 1);
   int offset = 80 + m_strOperator.length() + 1;
   msg.setData(offset, (char*)&m_iRows, 4);
   msg.setData(offset + 4, (char*)&m_iParamSize, 4);
   msg.setData(offset + 8, m_pcParam, m_iParamSize);
   offset += 4 + 8 + m_iParamSize;
   msg.setData(offset, (char*)&m_iProcType, 4);

   Address serv;
   m_pClient->m_Routing.getPrimaryMaster(serv);
   if ((m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0) || (msg.getType() < 0))
      return SectorError::E_CONNECTION;

   s.m_iSession = *(int32_t*)msg.getData();

   m_pClient->m_DataChn.connect(s.m_strIP, s.m_iDataPort);

   cout << "connect SPE " << s.m_strIP.c_str() << " " << *(int*)(msg.getData()) << endl;

   // send output information
   m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, (char*)&m_iOutputType, 4);
   if (m_iOutputType > 0)
   {
      int bnum = m_mBucket.size();
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, (char*)&bnum, 4);
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, m_pOutputLoc, bnum * 80);
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, (char*)m_pOutput->m_piLocID, m_iOutputType * 4);
   }
   else if (m_iOutputType < 0)
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, m_pOutputLoc, strlen(m_pOutputLoc) + 1);

   loadOperator(s.m_strIP, s.m_iPort, s.m_iDataPort, s.m_iSession);

   s.m_iStatus = 1;

   return 0;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:50,代码来源:dcclient.cpp

示例8: utime

int Client::utime(const string& path, const int64_t& ts)
{
   string revised_path = Metadata::revisePath(path);

   SectorMsg msg;
   msg.setType(107);
   msg.setKey(m_iKey);
   msg.setData(0, revised_path.c_str(), revised_path.length() + 1);
   msg.setData(revised_path.length() + 1, (char*)&ts, 8);

   Address serv;
   m_Routing.lookup(revised_path, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:22,代码来源:client.cpp

示例9: report

int Slave::report(const string& master_ip, const int& master_port, const int32_t& transid, const vector<string>& filelist, const int& change)
{
   vector<string> serlist;
   for (vector<string>::const_iterator i = filelist.begin(); i != filelist.end(); ++ i)
   {
      struct stat s;
      if (-1 == stat((m_strHomeDir + *i).c_str(), &s))
         continue;

      SNode sn;
      sn.m_strName = *i;
      sn.m_bIsDir = S_ISDIR(s.st_mode) ? 1 : 0;
      sn.m_llTimeStamp = s.st_mtime;
      sn.m_llSize = s.st_size;

      char buf[1024];
      sn.serialize(buf);

      //update local
      Address addr;
      addr.m_strIP = "127.0.0.1";
      addr.m_iPort = 0;
      m_pLocalFile->update(buf, addr, change);

      serlist.push_back(buf);
   }

   if (serlist.empty())
      return 0;

   SectorMsg msg;
   msg.setType(1);
   msg.setKey(0);
   msg.setData(0, (char*)&transid, 4);
   msg.setData(4, (char*)&m_iSlaveID, 4);
   msg.setData(8, (char*)&change, 4);
   int32_t num = serlist.size();
   msg.setData(12, (char*)&num, 4);
   int pos = 16;
   for (vector<string>::iterator i = serlist.begin(); i != serlist.end(); ++ i)
   {
      int32_t bufsize = i->length() + 1;
      msg.setData(pos, (char*)&bufsize, 4);
      msg.setData(pos + 4, i->c_str(), bufsize);
      pos += bufsize + 4;
   }

   cout << "report " << master_ip << " " << master_port << " " << num << endl;

   if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
      return -1;

   if (msg.getType() < 0)
      return *(int32_t*)msg.getData();

   return 1;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:57,代码来源:slave.cpp

示例10: stat

int Client::stat(const string& path, SNode& attr)
{
   string revised_path = Metadata::revisePath(path);

   SectorMsg msg;
   msg.resize(65536);
   msg.setType(102);
   msg.setKey(m_iKey);
   msg.setData(0, revised_path.c_str(), revised_path.length() + 1);

   Address serv;
   m_Routing.lookup(revised_path, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   attr.deserialize(msg.getData());

   int n = (msg.m_iDataLength - SectorMsg::m_iHdrSize - 128) / 68;
   char* al = msg.getData() + 128;

   for (int i = 0; i < n; ++ i)
   {
      Address addr;
      addr.m_strIP = al + 68 * i;
      addr.m_iPort = *(int32_t*)(al + 68 * i + 64);
      attr.m_sLocation.insert(addr);
   }

   // check local cache: updated files may not be sent to the master yet
   m_StatCache.stat(path, attr);

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:38,代码来源:client.cpp

示例11: open

int FSClient::open(const string& filename, int mode, const string& hint)
{
   m_strFileName = Metadata::revisePath(filename);

   SectorMsg msg;
   msg.setType(110); // open the file
   msg.setKey(m_pClient->m_iKey);

   int32_t m = mode;
   msg.setData(0, (char*)&m, 4);
   int32_t port = m_pClient->m_DataChn.getPort();
   msg.setData(4, (char*)&port, 4);
   msg.setData(8, hint.c_str(), hint.length() + 1);
   msg.setData(72, m_strFileName.c_str(), m_strFileName.length() + 1);

   Address serv;
   m_pClient->m_Routing.lookup(m_strFileName, serv);
   if (m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   m_llSize = *(int64_t*)(msg.getData() + 72);
   m_llCurReadPos = m_llCurWritePos = 0;

   m_bRead = mode & 1;
   m_bWrite = mode & 2;
   m_bSecure = mode & 16;

   // check APPEND
   if (mode & 8)
      m_llCurWritePos = m_llSize;

   m_strSlaveIP = msg.getData();
   m_iSlaveDataPort = *(int*)(msg.getData() + 64);
   m_iSession = *(int*)(msg.getData() + 68);

   cerr << "open file " << filename << " " << m_strSlaveIP << " " << m_iSlaveDataPort << endl;
   if (m_pClient->m_DataChn.connect(m_strSlaveIP, m_iSlaveDataPort) < 0)
      return SectorError::E_CONNECTION;

   string localip;
   int localport;
   m_pClient->m_DataChn.getSelfAddr(m_strSlaveIP, m_iSlaveDataPort, localip, localport);

   if (m_strSlaveIP == localip)
   {
      // the file is on the same node, check if the file can be read directly
      int32_t cmd = 6;
      m_pClient->m_DataChn.send(m_strSlaveIP, m_iSlaveDataPort, m_iSession, (char*)&cmd, 4);
      int size = 0;
      if (m_pClient->m_DataChn.recv(m_strSlaveIP, m_iSlaveDataPort, m_iSession, m_pcLocalPath, size) > 0)
      {
         fstream test((m_pcLocalPath + filename).c_str(), ios::binary | ios::in);
         if (!test.bad() && !test.fail())
            m_bLocal = true;
      }
   }

   memcpy(m_pcKey, m_pClient->m_pcCryptoKey, 16);
   memcpy(m_pcIV, m_pClient->m_pcCryptoIV, 8);
   m_pClient->m_DataChn.setCryptoKey(m_strSlaveIP, m_iSlaveDataPort, m_pcKey, m_pcIV);

   if (m_bWrite)
      m_pClient->m_StatCache.insert(filename);

   return 0;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:69,代码来源:fsclient.cpp

示例12: prepareOutput

int DCClient::prepareOutput(const char* spenodes)
{
   m_pOutputLoc = NULL;
   m_pOutput->m_llSize = 0;
   m_pOutput->m_llRecNum = 0;

   // prepare output stream locations
   if (m_iOutputType > 0)
   {
      SectorMsg msg;
      msg.setType(204);
      msg.setKey(m_pClient->m_iKey);

      for (int i = 0; i < m_iSPENum; ++ i)
      {
         msg.setData(0, spenodes + i * 72, strlen(spenodes + i * 72) + 1);
         msg.setData(64, spenodes + i * 72 + 64, 4);
         msg.setData(68, (char*)&(m_pOutput->m_iFileNum), 4);
         msg.setData(72, (char*)&i, 4);
         int size = m_pOutput->m_strPath.length() + 1;
         int offset = 76;
         msg.setData(offset, (char*)&size, 4);
         msg.setData(offset + 4, m_pOutput->m_strPath.c_str(), m_pOutput->m_strPath.length() + 1);
         offset += 4 + size;
         size = m_pOutput->m_strName.length() + 1;
         msg.setData(offset, (char*)&size, 4);
         msg.setData(offset + 4, m_pOutput->m_strName.c_str(), m_pOutput->m_strName.length() + 1);
         offset += 4 + size;
         msg.setData(offset, (char*)&m_pClient->m_iKey, 4);
         offset += 4;
         msg.setData(offset, (char*)&m_iProcType, 4);
         if (m_iProcType == 1)
         {
            offset += 4;
            size = m_strOperator.length() + 1;
            msg.setData(offset, (char*)&size, 4);
            msg.setData(offset + 4, m_strOperator.c_str(), m_strOperator.length() + 1);
         }

         cout << "request shuffler " << spenodes + i * 72 << " " << *(int*)(spenodes + i * 72 + 64) << endl;
         Address serv;
         m_pClient->m_Routing.getPrimaryMaster(serv);
         if (m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
            continue;

         if (msg.getType() < 0)
         {
            if (*(int32_t*)msg.getData() == SectorError::E_PERMISSION)
               break;
            else
               continue;
         }

         BUCKET b;
         b.m_iID = i;
         b.m_strIP = spenodes + i * 72;
         b.m_iPort = *(int32_t*)(spenodes + i * 72 + 64);
         b.m_iDataPort = *(int32_t*)(spenodes + i * 72 + 68);
         b.m_iShufflerPort = *(int32_t*)msg.getData();
         b.m_iSession = *(int32_t*)(msg.getData() + 4);
         b.m_iProgress = 0;
         b.m_LastUpdateTime = CTimer::getTime();
         m_mBucket[b.m_iID] = b;

         // set up data connection, not for data transfter, but for keep-alive
         m_pClient->m_DataChn.connect(b.m_strIP, b.m_iDataPort);

         // upload library files for MapReduce processing
         if (m_iProcType == 1)
            loadOperator(b.m_strIP, b.m_iPort, b.m_iDataPort, b.m_iSession);
      }

      if (m_mBucket.empty())
         return SectorError::E_NOBUCKET;

      m_pOutputLoc = new char[m_mBucket.size() * 80];
      int l = 0;
      for (map<int, BUCKET>::iterator b = m_mBucket.begin(); b != m_mBucket.end(); ++ b)
      {
         strcpy(m_pOutputLoc + l * 80, b->second.m_strIP.c_str());
         *(int32_t*)(m_pOutputLoc + l * 80 + 64) = b->second.m_iPort;
         *(int32_t*)(m_pOutputLoc + l * 80 + 68) = b->second.m_iDataPort;
         *(int32_t*)(m_pOutputLoc + l * 80 + 72) = b->second.m_iShufflerPort;
         *(int32_t*)(m_pOutputLoc + l * 80 + 76) = b->second.m_iSession;
         ++ l;
      }

      // result locations
      map<int, BUCKET>::iterator b = m_mBucket.begin();
      for (int i = 0; i < m_pOutput->m_iFileNum; ++ i)
      {
         char* tmp = new char[m_pOutput->m_strPath.length() + m_pOutput->m_strName.length() + 64];
         sprintf(tmp, "%s/%s.%d", m_pOutput->m_strPath.c_str(), m_pOutput->m_strName.c_str(), i);
         m_pOutput->m_vFiles[i] = tmp;
         delete [] tmp;

         if (m_pOutput->m_vLocation[i].empty())
         {
            // if user didn't specify output location, simply pick the next bucket location and rotate
            // this should be the normal case
//.........这里部分代码省略.........
开发者ID:norouzi4d,项目名称:sector,代码行数:101,代码来源:dcclient.cpp

示例13: run


//.........这里部分代码省略.........
         if (errsize > 0)
         {
            s->second.m_pDS->m_pResult->m_pcData = new char[errsize];
            strcpy(s->second.m_pDS->m_pResult->m_pcData, msg.getData() + 12);
         }

         ++ self->m_iProgress;

#ifndef WIN32
         pthread_mutex_lock(&self->m_ResLock);
         ++ self->m_iAvailRes;
         pthread_cond_signal(&self->m_ResCond);
         pthread_mutex_unlock(&self->m_ResLock);
#else
         ++ self->m_iAvailRes;
         SetEvent(self->m_ResCond);
#endif

         if (progress == -2)
         {
            // error occured to this SPE
            s->second.m_iStatus = -1;
         }

         continue;
      }

      if (progress > s->second.m_iProgress)
         s->second.m_iProgress = progress;

      if (progress < 100)
         continue;

      self->readResult(&(s->second));

      // one SPE completes!
	  int64_t t = CTimer::getTime();
      if (self->m_iAvgRunTime <= 0)
         self->m_iAvgRunTime = (t - s->second.m_StartTime) / 1000000;
      else
         self->m_iAvgRunTime = (self->m_iAvgRunTime * 7 + (t - s->second.m_StartTime) / 1000000) / 8;
   }

   self->m_dRunningProgress = 0;

   // release all SPEs and close all Shufflers
   for (map<int, SPE>::iterator i = self->m_mSPE.begin(); i != self->m_mSPE.end(); ++ i)
   {
      // an offset of -1 will tell the SPE to release itself
      int64_t cmd = -1;
      self->m_pClient->m_DataChn.send(i->second.m_strIP, i->second.m_iDataPort, i->second.m_iSession, (char*)&cmd, 8);
   }

   for(map<int, BUCKET>::iterator i = self->m_mBucket.begin(); i != self->m_mBucket.end(); ++ i)
   {
      SectorMsg msg;
      int32_t cmd = -1;
      msg.setData(0, (char*)&cmd, 4);
      int id = 0;
      self->m_pClient->m_GMP.sendto(i->second.m_strIP.c_str(), i->second.m_iShufflerPort, id, &msg);
   }

   //TODO: need to detect lost slaves
   while (self->checkBucket() > 0)
   {
      string ip;
      int port;
      int tmp;
      SectorMsg msg;
      if (self->m_pClient->m_GMP.recvfrom(ip, port, tmp, &msg, false) < 0)
         continue;

      int32_t bucketid = *(int32_t*)(msg.getData());
      map<int, BUCKET>::iterator b = self->m_mBucket.find(bucketid);
      if (b == self->m_mBucket.end())
         continue;
      b->second.m_iProgress = 100;

#ifndef WIN32
      pthread_cond_signal(&self->m_ResCond);
#else
      SetEvent(self->m_ResCond);
#endif
   }

   // some buckets may be left empty because no value was sent to them. remove these from the output stream
   self->postProcessOutput();

   // set totalSPE = 0, so that read() will return error immediately
   if (self->m_iProgress < 100)
      self->m_iTotalSPE = 0;

   CGuard::leaveCS(self->m_RunLock);

#ifndef WIN32
   return NULL;
#else
   return 0;
#endif
}
开发者ID:norouzi4d,项目名称:sector,代码行数:101,代码来源:dcclient.cpp

示例14: SPEShuffler


//.........这里部分代码省略.........
#ifndef WIN32
      pthread_create(&shufflerex, NULL, SPEShufflerEx, p);
#else
      DWORD ThreadID;
      shufflerex = CreateThread(NULL, 0, SPEShufflerEx, p, NULL, &ThreadID);
#endif

      self->m_SectorLog << LogStart(LogLevel::SCREEN) << "SPE Shuffler " << path << " " << localfile << " " << bucketnum << LogEnd();
   }

   while (init_success)
   {
      string speip;
      int speport;
      SectorMsg msg;
      int msgid;
      int r = gmp->recvfrom(speip, speport, msgid, &msg, false);

      // client releases the task or client has already been shutdown
      if (((r > 0) && (speip == client_ip) && (speport == client_port))
         || ((r < 0) && (!self->m_DataChn.isConnected(client_ip, client_data_port))))
      {
         Bucket b;
         b.totalnum = -1;
         b.totalsize = 0;
         bqlock->acquire();
         bq->push(b);
         bqcond->signal();
         bqlock->release();

         break;
      }

      if (r < 0)
         continue;

      if (*pendingSize > 256000000)
      {
         // too many incoming results, ask the sender to wait
         // the receiver buffer size threshold is set to 256MB. This prevents the shuffler from being overflowed
         // it also helps direct the traffic to less congested shuffler and leads to better load balance
         msg.setType(-msg.getType());
         gmp->sendto(speip, speport, msgid, &msg);
      }
      else
      {
         Bucket b;
         b.totalnum = *(int32_t*)(msg.getData() + 8);;
         b.totalsize = *(int32_t*)(msg.getData() + 12);
         b.src_ip = speip;
         b.src_dataport = *(int32_t*)msg.getData();
         b.session = *(int32_t*)(msg.getData() + 4);

         gmp->sendto(speip, speport, msgid, &msg);

         if (!self->m_DataChn.isConnected(speip, b.src_dataport))
            self->m_DataChn.connect(speip, b.src_dataport);

         bqlock->acquire();
         bq->push(b);
         *pendingSize += b.totalsize;
         bqcond->signal();
         bqlock->release();
      }
   }

   if (init_success)
   {
#ifndef WIN32
      pthread_join(shufflerex, NULL);
#else
      WaitForSingleObject(shufflerex, INFINITE);
#endif

      delete bqlock;
      delete bqcond;
      delete pendingSize;

      SectorMsg msg;
      msg.setType(1); // success, return result
      msg.setData(0, (char*)&(bucketid), 4);
      int progress = 100;
      msg.setData(4, (char*)&progress, 4);
      msg.m_iDataLength = SectorMsg::m_iHdrSize + 8;
      int id = 0;
      self->m_GMP.sendto(client_ip.c_str(), client_port, id, &msg);

      self->m_SectorLog << LogStart(LogLevel::LEVEL_3) << "bucket completed 100 " << client_ip << " " << client_port << LogEnd();
   }

   gmp->close();
   delete gmp;

   self->reportSphere(master_ip, master_port, transid);

   // clear this transaction
   self->m_TransManager.updateSlave(transid, self->m_iSlaveID);

   return NULL;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:101,代码来源:serv_spe.cpp

示例15: sendResultToBuckets

int Slave::sendResultToBuckets(const int& buckets, const SPEResult& result, const SPEDestination& dest)
{
   map<int, set<int> > ResByLoc;
   map<int, int> SizeByLoc;

   for (int i = 0; i < dest.m_iLocNum; ++ i)
   {
      ResByLoc[i].clear();
      SizeByLoc[i] = 0;
   }

   // summarize information for each bucket, ignore empty buckets
   for (int r = 0; r < buckets; ++ r)
   {
      int i = dest.m_piLocID[r];
      if (0 != result.m_vDataLen[r])
      {
         ResByLoc[i].insert(r);
         SizeByLoc[i] += result.m_vDataLen[r] + (result.m_vIndexLen[r] - 1) * 8;
      }
   }

   unsigned int tn = 0;
   map<int, set<int> >::iterator p = ResByLoc.begin();

   while(!ResByLoc.empty())
   {
      int i = p->first;
      if (++ p == ResByLoc.end())
         p = ResByLoc.begin();

      if (ResByLoc[i].empty())
      {
         //skip empty buckets
         ResByLoc.erase(i);
         SizeByLoc.erase(i);
         continue;
      }

      // retrieve bucket location/address
      char* dstip = dest.m_pcOutputLoc + i * 80;
      int32_t dstport = *(int32_t*)(dest.m_pcOutputLoc + i * 80 + 68);
      int32_t shufflerport = *(int32_t*)(dest.m_pcOutputLoc + i * 80 + 72);
      int32_t session = *(int32_t*)(dest.m_pcOutputLoc + i * 80 + 76);

      SectorMsg msg;
      int32_t srcport = m_DataChn.getPort();
      msg.setData(0, (char*)&srcport, 4);
      msg.setData(4, (char*)&session, 4);
      int totalnum = ResByLoc[i].size();
      msg.setData(8, (char*)&totalnum, 4);
      int totalsize = SizeByLoc[i];
      msg.setData(12, (char*)&totalsize, 4);
      msg.m_iDataLength = SectorMsg::m_iHdrSize + 16;

      // request to send results to the slave node
      msg.setType(1);
      if (m_GMP.rpc(dstip, shufflerport, &msg, &msg) < 0)
         return -1;

      if (msg.getType() < 0)
      {
         // if all shufflers are busy, wait here a little while
         if (++ tn >= ResByLoc.size())
         {
            tn = 0;
            #ifndef WIN32
            usleep(100000);
            #else
            Sleep(100);
            #endif
         }
         continue;
      }

      if (!m_DataChn.isConnected(dstip, dstport))
      {
         if (m_DataChn.connect(dstip, dstport) < 0)
            return -1;
      }

      // send results for one bucket a time
      for (set<int>::iterator r = ResByLoc[i].begin(); r != ResByLoc[i].end(); ++ r)
      {
         int32_t id = *r;
         m_DataChn.send(dstip, dstport, session, (char*)&id, 4);
         m_DataChn.send(dstip, dstport, session, result.m_vData[id], result.m_vDataLen[id]);
         m_DataChn.send(dstip, dstport, session, (char*)(result.m_vIndex[id] + 1), (result.m_vIndexLen[id] - 1) * 8);
      }

      // update total sent data
      m_SlaveStat.updateIO(dstip, SizeByLoc[i], +SlaveStat::SYS_OUT);

      ResByLoc.erase(i);
      SizeByLoc.erase(i);
   }

   return 1;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:99,代码来源:serv_spe.cpp


注:本文中的SectorMsg::setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。