IFvDataSource * createRemoteFileDataSource(const SocketEndpoint & server, const char * username, const char * password, const char * logicalName) { Owned<INode> serverNode = createINode(server); CMessageBuffer msg; msg.setEndian(__BIG_ENDIAN); msg.append((byte)FVCMDcreatefile); msg.append(myProcessSession()); msg.append(username); msg.append(password); msg.append(logicalName); sendReceive(serverNode, msg); unsigned short version; unique_id_t id; __int64 numRows; bool isIndex; msg.read(version); msg.read(id); msg.read(numRows); Owned<IFvDataSourceMetaData> meta = deserializeDataSourceMeta(msg); msg.read(isIndex); if (id) return new RemoteDataSource(server, id, meta, numRows, isIndex); return 0; }
bool RemoteDataSource::getARow(MemoryBuffer & out, RowCache & cache, byte cmd, __int64 row) { RowLocation location; if (cache.getCacheRow(row, location)) { out.append(location.matchLength, location.matchRow); return true; } CMessageBuffer msg; msg.setEndian(__BIG_ENDIAN); msg.append(cmd); msg.append(id); msg.append(row); sendReceive(msg); bool ok; msg.read(ok); if (!ok) return false; __int64 start; msg.read(start); VariableRowBlock * next = new VariableRowBlock(msg, start); cache.addRowsOwn(next); if (!cache.getCacheRow(row, location)) assertex(!"Internal Error!"); out.append(location.matchLength, location.matchRow); return true; }
rowcount_t SortSlaveMP::GetMinMax(size32_t &keybuffsize,void *&keybuff, size32_t &avrecsizesize) { CMessageBuffer mb; mb.append((byte)FN_GetMinMax); sendRecv(mb); deserializeblk(mb,keybuffsize,keybuff); mb.read(avrecsizesize); rowcount_t ret; mb.read(ret); return ret; }
void process() { if (!container.queryLocal() && container.queryJob().querySlaves() > 1) { CMessageBuffer msg; unsigned nslaves = container.queryJob().querySlaves(); unsigned s = 1; rowcount_t totalCount = 0, slaveCount; for (; s<=nslaves; s++) { if (!receiveMsg(msg, s, mpTag)) return; msg.read(slaveCount); if (RCUNSET == slaveCount) { totalCount = RCUNSET; break; // unknown } totalCount += slaveCount; } s=1; msg.clear().append(totalCount); for (; s<=nslaves; s++) container.queryJob().queryJobComm().send(msg, s, mpTag); } }
void process() { CMessageBuffer msg; unsigned inputs = container.getInputs(); unsigned slaves = container.queryJob().querySlaves(); unsigned s; bool readSome=false, slaveReadSome; IntArray replyTags; for (s=0; s<slaves; s++) replyTags.append(0); while (inputs>1) { inputs--; for (s=0; s<slaves; s++) { rank_t sender; if (!receiveMsg(msg, RANK_ALL, replyTag, &sender)) return; replyTags.replace(msg.getReplyTag(), ((int)sender)-1); msg.read(slaveReadSome); if (slaveReadSome) readSome = true; } msg.clear().append(readSome); for (s=0; s<slaves; s++) { if (!queryJobChannel().queryJobComm().send(msg, ((rank_t) s+1), (mptag_t) replyTags.item(s), LONGTIMEOUT)) throw MakeActivityException(this, 0, "Failed to give result to slave"); } if (readSome) // got some, have told slaves to ignore rest, so finish break; } }
virtual void main() { running = true; loop { INode *senderNode; CMessageBuffer msg; if (!queryWorldCommunicator().recv(msg, NULL, MPTAG_THORREGISTRATION, &senderNode)) return; rank_t sender = queryClusterGroup().rank(senderNode); SocketEndpoint ep = senderNode->endpoint(); ep.port -= THOR_MP_INC; StringBuffer url; ep.getUrlStr(url); if (RANK_NULL == sender) { PROGLOG("Node %s trying to deregister is not part of this cluster", url.str()); continue; } RegistryCode code; msg.read((int &)code); if (!rc_deregister == code) throwUnexpected(); registry.deregisterNode(sender); } running = false; }
virtual void main() { running = true; loop { INode *senderNode; CMessageBuffer msg; if (!queryWorldCommunicator().recv(msg, NULL, MPTAG_THORREGISTRATION, &senderNode)) return; rank_t sender = queryNodeGroup().rank(senderNode); SocketEndpoint ep = senderNode->endpoint(); StringBuffer url; ep.getUrlStr(url); if (RANK_NULL == sender) { PROGLOG("Node %s trying to deregister is not part of this cluster", url.str()); continue; } RegistryCode code; msg.read((int &)code); if (rc_deregister != code) throwUnexpected(); Owned<IException> e = deserializeException(msg); if (e.get()) EXCLOG(e, "Slave unregistered with exception"); registry.deregisterNode(sender-1); } running = false; }
void process() { ActPrintLog("ReDistributeActivityMaster::process"); HashDistributeMasterBase::process(); IHThorHashDistributeArg *helper = (IHThorHashDistributeArg *)queryHelper(); unsigned n = container.queryJob().querySlaves(); MemoryAttr ma; offset_t *sizes = (offset_t *)ma.allocate(sizeof(offset_t)*n); unsigned i; try { for (i=0;i<n;i++) { if (abortSoon) return; CMessageBuffer mb; #ifdef _TRACE ActPrintLog("ReDistribute process, Receiving on tag %d",statstag); #endif rank_t sender; if (!receiveMsg(mb, RANK_ALL, statstag, &sender)||abortSoon) return; #ifdef _TRACE ActPrintLog("ReDistribute process, Received size from %d",sender); #endif sender--; assertex((unsigned)sender<n); mb.read(sizes[sender]); } ActPrintLog("ReDistributeActivityMaster::process sizes got"); for (i=0;i<n;i++) { CMessageBuffer mb; mb.append(n*sizeof(offset_t),sizes); #ifdef _TRACE ActPrintLog("ReDistribute process, Replying to node %d tag %d",i+1,statstag); #endif if (!container.queryJob().queryJobComm().send(mb, (rank_t)i+1, statstag)) return; } // check if any max skew broken double maxskew = helper->getTargetSkew(); if (maxskew>helper->getSkew()) { offset_t tot = 0; for (i=0;i<n;i++) tot += sizes[i]; offset_t avg = tot/n; for (i=0;i<n;i++) { double r = ((double)sizes[i]-(double)avg)/(double)avg; if ((r>=maxskew)||(-r>maxskew)) { throw MakeActivityException(this, TE_DistributeFailedSkewExceeded, "DISTRIBUTE maximum skew exceeded (node %d has %"I64F"d, average is %"I64F"d)",i+1,sizes[i],avg); } } } } catch (IException *e) { ActPrintLog(e,"ReDistribute"); throw; } ActPrintLog("ReDistributeActivityMaster::process exit"); }
rowcount_t getFinalCount(CSlaveActivity &activity) { rowcount_t totalCount = 0; CMessageBuffer mb; if (activity.receiveMsg(mb, 0, activity.queryMpTag())) mb.read(totalCount); return totalCount; }
void SortSlaveMP::MultiBinChopStop(unsigned num,rowcount_t *pos) { CMessageBuffer mb; mb.append((byte)FN_MultiBinChopStop); mb.append(num); sendRecv(mb); mb.read(num*sizeof(rowcount_t),pos); }
void SortSlaveMP::MultiBinChop(size32_t keybuffsize,const byte *keybuff, unsigned num,rowcount_t *pos,byte cmpfn) { CMessageBuffer mb; mb.append((byte)FN_MultiBinChop); serializeblk(mb,keybuffsize,keybuff).append(num).append(cmpfn); sendRecv(mb); mb.read(num*sizeof(rowcount_t),pos); }
void SortSlaveMP::GetGatherInfo(rowcount_t &numlocal, offset_t &totalsize, unsigned &overflowscale, bool hasserializer) { CMessageBuffer mb; mb.append((byte)FN_GetGatherInfo); mb.append(hasserializer); sendRecv(mb); mb.read(numlocal).read(totalsize).read(overflowscale); }
bool RemoteDataSource::fetchRawRow(MemoryBuffer & out, __int64 offset) { CMessageBuffer msg; msg.setEndian(__BIG_ENDIAN); msg.append(FVCMDfetchraw); msg.append(id); msg.append(offset); sendReceive(msg); bool ok; msg.read(ok); if (!ok) return false; size32_t len; msg.read(len); out.append(len, msg.readDirect(len)); return true; }
StringBuffer & getDaliDiagnosticValue(const char *name,StringBuffer &ret) { CMessageBuffer mb; mb.append((int)MDR_GET_VALUE).append(name); queryCoven().sendRecv(mb,RANK_RANDOM,MPTAG_DALI_DIAGNOSTICS_REQUEST); StringAttr str; mb.read(str); ret.append(str); return ret; }
bool SortSlaveMP::Connect(unsigned _part, unsigned _numnodes) { CMessageBuffer mb; mb.append((byte)FN_Connect); mb.append(_part).append(_numnodes); sendRecv(mb); bool ret; mb.read(ret); return ret; }
rowcount_t SortSlaveMP::OverflowAdjustMapStop( unsigned mapsize, rowcount_t *map) { CMessageBuffer mb; mb.append((byte)FN_OverflowAdjustMapStop); mb.append(mapsize); sendRecv(mb); rowcount_t ret; mb.read(ret).read(mapsize*sizeof(rowcount_t),map); return ret; }
bool SortSlaveMP::sendRecv(CMessageBuffer &mb, unsigned timeout) { if (!comm->sendRecv(mb,rank,tag,timeout)) return false; byte ok = 255; if (mb.length()) { mb.read(ok); if (ok==1) return true; if (ok==0) { int err; mb.read(err); StringAttr errstr; mb.read(errstr); throw MakeStringException(err, "%s", errstr.get()); } } throw MakeStringException(-1,"SortSlaveMP::sendRecv() protocol error %d",(int)ok); return false; }
bool SortSlaveMP::FirstRowOfFile(const char *filename,size32_t &rowbuffsize, byte * &rowbuf) { CMessageBuffer mb; mb.append((byte)FN_FirstRowOfFile); mb.append(filename); sendRecv(mb); deserializeblk(mb,rowbuffsize,rowbuf); bool ret; mb.read(ret); return ret; }
const void *getFirst() // for global, not called on 1st slave { CMessageBuffer msg; if (!queryJobChannel().queryJobComm().recv(msg, queryJobChannel().queryMyRank()-1, mpTag)) // previous node return NULL; msg.read(count); size32_t r = msg.remaining(); OwnedConstThorRow firstRow; if (r) firstRow.deserialize(inrowif, r, msg.readDirect(r)); return firstRow.getClear(); }
const void *getResult(const void *firstRow) { IHThorAggregateArg *helper = (IHThorAggregateArg *)baseHelper.get(); unsigned numPartialResults = container.queryJob().querySlaves(); if (1 == numPartialResults) return firstRow; CThorExpandingRowArray partialResults(*this, this, true, stableSort_none, true, numPartialResults); if (hadElement) partialResults.setRow(0, firstRow); --numPartialResults; size32_t sz; while (numPartialResults--) { CMessageBuffer msg; rank_t sender; if (!receiveMsg(msg, RANK_ALL, mpTag, &sender)) return NULL; if (abortSoon) return NULL; msg.read(sz); if (sz) { assertex(NULL == partialResults.query(sender-1)); CThorStreamDeserializerSource mds(sz, msg.readDirect(sz)); RtlDynamicRowBuilder rowBuilder(queryRowAllocator()); size32_t sz = queryRowDeserializer()->deserialize(rowBuilder, mds); partialResults.setRow(sender-1, rowBuilder.finalizeRowClear(sz)); } } RtlDynamicRowBuilder rowBuilder(queryRowAllocator(), false); bool first = true; numPartialResults = container.queryJob().querySlaves(); unsigned p=0; for (;p<numPartialResults; p++) { const void *row = partialResults.query(p); if (row) { if (first) { first = false; sz = cloneRow(rowBuilder, row, queryRowMetaData()); } else sz = helper->mergeAggregate(rowBuilder, row); } } if (first) sz = helper->clearAggregate(rowBuilder); return rowBuilder.finalizeRowClear(sz); }
__int64 RemoteDataSource::numRows(bool force) { if (!force) return cachedNumRows; CMessageBuffer msg; msg.setEndian(__BIG_ENDIAN); msg.append((byte)FVCMDnumrows); msg.append(id); sendReceive(msg); __int64 result; msg.read(result); return result; }
void CLogMsgLinkToChild::connect() { CMessageBuffer out; out.append('A').append(cid); try { queryWorldCommunicator().sendRecv(out, childNode, MPTAG_JLOG_CONNECT_TO_CHILD); } catch(IException * e) { e->Release(); } out.read(pid); connected = true; }
const void * getResult() { CMessageBuffer mb; if (receiveMsg(mb, 0, mpTag)) { size32_t sz; mb.read(sz); if (sz) { CThorStreamDeserializerSource ds(sz,mb.readDirect(sz)); RtlDynamicRowBuilder rowBuilder(queryRowAllocator()); size32_t sz = queryRowDeserializer()->deserialize(rowBuilder,ds); return rowBuilder.finalizeRowClear(sz); } } return NULL; }
rowcount_t getCount(CActivityBase &activity, unsigned partialResults, rowcount_t limit, mptag_t mpTag) { rowcount_t totalCount = 0; CMessageBuffer msg; while (partialResults--) { rank_t sender; msg.clear(); if (!activity.receiveMsg(msg, RANK_ALL, mpTag, &sender)) return 0; if (activity.queryAbortSoon()) return 0; rowcount_t partialCount; msg.read(partialCount); totalCount += (rowcount_t)partialCount; if (totalCount > limit) break; } return totalCount; }
void process() { CWorkUnitWriteMasterBase::process(); unsigned nslaves = container.queryJob().querySlaves(); CMessageBuffer mb; unsigned s=0; for (; s<nslaves; s++) { loop { if (!container.queryJob().queryJobComm().send(mb, s+1, mpTag)) return; if (!receiveMsg(mb, s+1, mpTag)) return; if (0 == mb.length()) break; unsigned numGot; mb.read(numGot); unsigned l=mb.remaining(); if (workunitWriteLimit && totalSize+resultData.length()+l > workunitWriteLimit) { StringBuffer errMsg("Dataset too large to output to workunit (limit is set to "); errMsg.append(workunitWriteLimit/0x100000).append(") megabytes, in result ("); if (resultName.length()) errMsg.append("name=").append(resultName); else errMsg.append("sequence=").append(resultSeq); errMsg.append(")"); throw MakeThorException(TE_WorkUnitWriteLimitExceeded, "%s", errMsg.str()); } resultData.append(l, mb.readDirect(l)); mb.clear(); numResults += numGot; if (-1 != flushThreshold && resultData.length() >= (unsigned)flushThreshold) flushResults(); } } flushResults(true); }
void process() { unsigned slaves = container.queryJob().querySlaves(); IHThorLimitArg *helper = (IHThorLimitArg *)queryHelper(); rowcount_t rowLimit = (rowcount_t)helper->getRowLimit(); rowcount_t total = 0; while (slaves--) { CMessageBuffer mb; if (!receiveMsg(mb, RANK_ALL, mpTag, NULL)) return; if (abortSoon) return; rowcount_t count; mb.read(count); total += count; if (total > rowLimit) break; } switch (container.getKind()) { case TAKcreaterowlimit: case TAKskiplimit: { unsigned slaves = container.queryJob().querySlaves(); CMessageBuffer mb; mb.append(total); queryJobChannel().queryJobComm().send(mb, RANK_ALL_OTHER, mpTag); break; } case TAKlimit: { if (total > rowLimit) helper->onLimitExceeded(); break; } } }
rowcount_t aggregateToLimit() { rowcount_t total = 0; ICommunicator &comm = queryJobChannel().queryJobComm(); unsigned slaves = container.queryJob().querySlaves(); unsigned s; for (s=0; s<slaves; s++) { CMessageBuffer msg; rank_t sender; if (!receiveMsg(msg, RANK_ALL, mpTag, &sender)) return 0; if (abortSoon) return 0; rowcount_t count; msg.read(count); total += count; if (total > limit) break; } return total; }
virtual void process() { CMasterActivity::process(); bool results = false; unsigned nslaves = container.queryJob().querySlaves(); while (nslaves--) { CMessageBuffer mb; if (abortSoon || !receiveMsg(mb, RANK_ALL, replyTag, NULL)) break; StringBuffer str; mb.getSender().getUrlStr(str); size32_t sz; mb.read(sz); if (sz) { if (results) throw MakeThorException(TE_UnexpectedMultipleSlaveResults, "Received greater than one result from slaves"); IHThorRemoteResultArg *helper = (IHThorRemoteResultArg *)queryHelper(); Owned<IThorRowInterfaces> resultRowIf = createRowInterfaces(helper->queryOutputMeta()); CThorStreamDeserializerSource mds(sz, mb.readDirect(sz)); RtlDynamicRowBuilder rowBuilder(resultRowIf->queryRowAllocator()); size32_t sz = resultRowIf->queryRowDeserializer()->deserialize(rowBuilder, mds); OwnedConstThorRow result = rowBuilder.finalizeRowClear(sz); helper->sendResult(result); results = true; } } if (!results && !abortSoon) { ActPrintLog("WARNING: no results"); IHThorRemoteResultArg *helper = (IHThorRemoteResultArg *)queryHelper(); //helper->sendResult(NULL); // Jake I think this always cores (so raise exception instead) throw MakeThorException(TE_UnexpectedMultipleSlaveResults, "Received no results from slaves"); } }
bool sendLoopingCount(unsigned n, unsigned emptyIterations) { if (!container.queryLocalOrGrouped()) { if (global || (lastMaxEmpty && (0 == emptyIterations)) || (!lastMaxEmpty && (emptyIterations>maxEmptyLoopIterations)) || ((0 == n) && (0 == emptyIterations))) { CMessageBuffer msg; // inform master starting msg.append(n); msg.append(emptyIterations); queryJobChannel().queryJobComm().send(msg, 0, mpTag); if (!global) { lastMaxEmpty = emptyIterations>maxEmptyLoopIterations; return true; } receiveMsg(msg, 0, mpTag); bool ok; msg.read(ok); return ok; } } return true; }
void processMessage(CMessageBuffer &mb) { ICoven &coven=queryCoven(); SessionId id; int fn; mb.read(fn); switch (fn) { case MSR_REGISTER_PROCESS_SESSION: { acceptConnections.wait(); acceptConnections.signal(); Owned<INode> node(deserializeINode(mb)); Owned<INode> servernode(deserializeINode(mb)); // hopefully me, but not if forwarded int role=0; if (mb.length()-mb.getPos()>=sizeof(role)) { // a capability block present mb.read(role); if (!manager.authorizeConnection(role,false)) { SocketEndpoint sender = mb.getSender(); mb.clear(); coven.reply(mb); MilliSleep(100+getRandom()%1000); // Causes client to 'work' for a short time. Owned<INode> node = createINode(sender); coven.disconnect(node); break; } #ifdef _DEBUG StringBuffer eps; PROGLOG("Connection to %s authorized",mb.getSender().getUrlStr(eps).str()); #endif } IGroup *covengrp; id = manager.registerClientProcess(node.get(),covengrp,(DaliClientRole)role); mb.clear().append(id); if (covengrp->rank(servernode)==RANK_NULL) { // must have been redirected covengrp->Release(); // no good, so just use one we know about (may use something more sophisticated later) INode *na = servernode.get(); covengrp = createIGroup(1, &na); } covengrp->serialize(mb); covengrp->Release(); coven.reply(mb); } break; case MSR_SECONDARY_REGISTER_PROCESS_SESSION: { mb.read(id); Owned<INode> node (deserializeINode(mb)); int role; mb.read(role); manager.addProcessSession(id,node.get(),(DaliClientRole)role); mb.clear(); coven.reply(mb); } break; case MSR_REGISTER_SESSION: { SecurityToken tok; SessionId parentid; mb.read(tok).read(parentid); SessionId id = manager.registerSession(tok,parentid); mb.clear().append(id); coven.reply(mb); } break; case MSR_SECONDARY_REGISTER_SESSION: { mb.read(id); manager.addSession(id); mb.clear(); coven.reply(mb); } break; case MSR_LOOKUP_PROCESS_SESSION: { // looks up from node or from id Owned<INode> node (deserializeINode(mb)); if (node->endpoint().isNull()&&(mb.length()-mb.getPos()>=sizeof(id))) { mb.read(id); INode *n = manager.getProcessSessionNode(id); if (n) node.setown(n); node->serialize(mb.clear()); } else { id = manager.lookupProcessSession(node.get()); mb.clear().append(id); } coven.reply(mb); } break; case MSR_STOP_SESSION: { SessionId sessid; bool failed; mb.read(sessid).read(failed); manager.stopSession(sessid,failed); mb.clear(); coven.reply(mb); } break; case MSR_LOOKUP_LDAP_PERMISSIONS: { StringAttr key; StringAttr obj; Owned<IUserDescriptor> udesc=createUserDescriptor(); StringAttr username; StringAttr passwordenc; mb.read(key).read(obj); udesc->deserialize(mb); #ifndef _NO_DALIUSER_STACKTRACE //following debug code to be removed StringBuffer sb; udesc->getUserName(sb); if (0==sb.length()) { DBGLOG("UNEXPECTED USER (NULL) in dasess.cpp CSessionRequestServer::processMessage() line %d", __LINE__); } #endif unsigned auditflags = 0; if (mb.length()-mb.getPos()>=sizeof(auditflags)) mb.read(auditflags); int err = 0; int ret=manager.getPermissionsLDAP(key,obj,udesc,auditflags,&err); mb.clear().append(ret); if (err) mb.append(err); coven.reply(mb); } break; } }