本文整理汇总了C++中SectorMsg::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ SectorMsg::getType方法的具体用法?C++ SectorMsg::getType怎么用?C++ SectorMsg::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SectorMsg
的用法示例。
在下文中一共展示了SectorMsg::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void Slave::run()
{
string ip;
int port;
int32_t id;
SectorMsg* msg = new SectorMsg;
msg->resize(65536);
cout << "slave process: " << "GMP " << m_iLocalPort << " DATA " << m_DataChn.getPort() << endl;
while (true)
{
if (m_GMP.recvfrom(ip, port, id, msg) < 0)
break;
cout << "recv cmd " << ip << " " << port << " type " << msg->getType() << endl;
// a slave only accepts commands from the masters
Address addr;
addr.m_strIP = ip;
addr.m_iPort = port;
if (m_Routing.getRouterID(addr) < 0)
continue;
switch (msg->getType() / 100)
{
case 0:
processSysCmd(ip, port, id, msg);
break;
case 1:
processFSCmd(ip, port, id, msg);
break;
case 2:
processDCCmd(ip, port, id, msg);
break;
case 10:
processMCmd(ip, port, id, msg);
break;
default:
break;
}
}
delete msg;
}
示例2: 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;
}
示例3: 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();
}
示例4: 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;
}
示例5: 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;
}
示例6: sysinfo
int Client::sysinfo(SysStat& sys)
{
SectorMsg msg;
msg.setKey(m_iKey);
msg.setType(3);
msg.m_iDataLength = SectorMsg::m_iHdrSize;
Address serv;
m_Routing.lookup(m_iKey, 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());
deserializeSysStat(sys, msg.getData(), msg.m_iDataLength);
for (vector<Address>::iterator i = sys.m_vMasterList.begin(); i != sys.m_vMasterList.end(); ++ i)
{
if (i->m_strIP.length() == 0)
{
i->m_strIP = serv.m_strIP;
break;
}
}
return 0;
}
示例7: 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;
}
示例8: 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;
}
示例9: remove
int Client::remove(const string& path)
{
string revised_path = Metadata::revisePath(path);
SectorMsg msg;
msg.setType(105);
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());
return 0;
}
示例10: 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();
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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
//.........这里部分代码省略.........
示例15: run
int DCClient::run(const SphereStream& input, SphereStream& output, const string& op, const int& rows, const char* param, const int& size, const int& type)
{
CGuard::enterCS(m_RunLock);
CGuard::leaveCS(m_RunLock);
m_iProcType = type;
m_strOperator = op;
m_pcParam = new char[size];
memcpy(m_pcParam, param, size);
m_iParamSize = size;
m_pInput = (SphereStream*)&input;
m_pOutput = &output;
m_iRows = rows;
m_iOutputType = m_pOutput->m_iFileNum;
// when processing files, data will not be moved
if (rows == 0)
m_bDataMove = false;
m_mpDS.clear();
m_mBucket.clear();
m_mSPE.clear();
int result = prepareInput();
if (result < 0)
return result;
cout << "JOB " << m_pInput->m_iFileNum << " " << m_pInput->m_llSize << " " << m_pInput->m_llRecNum << endl;
SectorMsg msg;
msg.setType(202); // locate available SPE
msg.setKey(m_pClient->m_iKey);
msg.m_iDataLength = SectorMsg::m_iHdrSize;
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();
m_iSPENum = (msg.m_iDataLength - 4) / 72;
if (0 == m_iSPENum)
return SectorError::E_RESOURCE;
result = prepareSPE(msg.getData());
if (result < 0)
return result;
result = segmentData();
if (result <= 0)
return result;
if (m_iOutputType == -1)
m_pOutput->init(m_mpDS.size());
result = prepareOutput(msg.getData());
if (result < 0)
return result;
m_iProgress = 0;
m_iAvgRunTime = -1;
m_iTotalDS = m_mpDS.size();
m_iTotalSPE = m_mSPE.size();
m_iAvailRes = 0;
m_bBucketHealth = true;
cout << m_mSPE.size() << " spes found! " << m_mpDS.size() << " data seg total." << endl;
// starting...
#ifndef WIN32
pthread_t scheduler;
pthread_create(&scheduler, NULL, run, this);
pthread_detach(scheduler);
#else
DWORD ThreadID;
CreateThread(NULL, 0, run, this, NULL, &ThreadID);
#endif
m_bOpened = true;
return 0;
}