void doFetch(std::list<RequestInfo>::iterator iter, ServiceIterator::ErrorType reason) { /* FIXME: this does not acquire a lock--which will cause a problem * if this class is destructed while we are executing doFetch. */ RequestInfo &info = *iter; if (cleanup || !info.serviter) { SILOG(transfer,error,"None of the services registered for " << info.fileId.uri() << " were successful."); CacheLayer::getData(info.fileId, info.range, info.callback); boost::unique_lock<boost::mutex> transfer_lock(mActiveTransferLock); mActiveTransfers.erase(iter); mCleanupCV.notify_one(); return; } URI lookupUri; std::tr1::shared_ptr<DownloadHandler> handler; ServiceParams params; if (mService->getNextProtocol(info.serviter,reason,info.fileId.uri(),lookupUri,params,handler)) { // info IS GETTING FREED BEFORE download RETURNS TO SET info.httpreq!!!!!!!!! info.httpreq = DownloadHandler::TransferDataPtr(); handler->download(&info.httpreq, params, lookupUri, info.range, std::tr1::bind(&NetworkCacheLayer::httpCallback, this, iter, _1, _2)); // info may be deleted by now (not so unlikely as it sounds -- it happens if you connect to localhost) } else { info.serviter = NULL; // deleted. doFetch(iter, ServiceIterator::UNSUPPORTED); } }
StatusWith<LogicalSessionIdSet> SessionsCollectionRS::findRemovedSessions( OperationContext* opCtx, const LogicalSessionIdSet& sessions) { return dispatch(NamespaceString::kLogicalSessionsNamespace, opCtx, [&] { DBDirectClient client(opCtx); return doFetch(NamespaceString::kLogicalSessionsNamespace, sessions, makeFindFnForCommand( NamespaceString::kLogicalSessionsNamespace, &client)); }, [&](DBClientBase* client) { return doFetch(NamespaceString::kLogicalSessionsNamespace, sessions, makeFindFnForCommand( NamespaceString::kLogicalSessionsNamespace, client)); }); }
int main(int argc, char *argv[]) /* read bed 6 file, look up sequence */ { if (argc != 4) usage(); if (!fileExists(argv[1])) errAbort("can't find %s\n", argv[1]); if (!fileExists(argv[2])) errAbort("can't find %s\n", argv[2]); doFetch(argv[1], argv[2], argv[3]); return 0; }
StatusWith<LogicalSessionIdSet> SessionsCollectionSharded::findRemovedSessions( OperationContext* opCtx, const LogicalSessionIdSet& sessions) { auto send = [&](BSONObj toSend) -> StatusWith<BSONObj> { const NamespaceString nss(SessionsCollection::kSessionsFullNS); auto qr = QueryRequest::makeFromFindCommand(nss, toSend, false); if (!qr.isOK()) { return qr.getStatus(); } const boost::intrusive_ptr<ExpressionContext> expCtx; auto cq = CanonicalQuery::canonicalize(opCtx, std::move(qr.getValue()), expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kAllowAllSpecialFeatures & ~MatchExpressionParser::AllowedFeatures::kExpr); if (!cq.isOK()) { return cq.getStatus(); } // Do the work to generate the first batch of results. This blocks waiting to get responses // from the shard(s). std::vector<BSONObj> batch; BSONObj viewDefinition; auto cursorId = ClusterFind::runQuery( opCtx, *cq.getValue(), ReadPreferenceSetting::get(opCtx), &batch, &viewDefinition); if (!cursorId.isOK()) { return cursorId.getStatus(); } BSONObjBuilder result; CursorResponseBuilder firstBatch(/*firstBatch*/ true, &result); for (const auto& obj : batch) { firstBatch.append(obj); } firstBatch.done(cursorId.getValue(), nss.ns()); return result.obj(); }; return doFetch(sessions, send); }
StatusWith<LogicalSessionIdSet> SessionsCollectionSharded::findRemovedSessions( OperationContext* opCtx, const LogicalSessionIdSet& sessions) { auto send = [&](BSONObj toSend) -> StatusWith<BSONObj> { auto qr = QueryRequest::makeFromFindCommand( NamespaceString::kLogicalSessionsNamespace, toSend, false); if (!qr.isOK()) { return qr.getStatus(); } const boost::intrusive_ptr<ExpressionContext> expCtx; auto cq = CanonicalQuery::canonicalize(opCtx, std::move(qr.getValue()), expCtx, ExtensionsCallbackNoop(), MatchExpressionParser::kBanAllSpecialFeatures); if (!cq.isOK()) { return cq.getStatus(); } // Do the work to generate the first batch of results. This blocks waiting to get responses // from the shard(s). std::vector<BSONObj> batch; CursorId cursorId; try { cursorId = ClusterFind::runQuery( opCtx, *cq.getValue(), ReadPreferenceSetting::get(opCtx), &batch); } catch (const DBException& ex) { return ex.toStatus(); } rpc::OpMsgReplyBuilder replyBuilder; CursorResponseBuilder::Options options; options.isInitialResponse = true; CursorResponseBuilder firstBatch(&replyBuilder, options); for (const auto& obj : batch) { firstBatch.append(obj); } firstBatch.done(cursorId, NamespaceString::kLogicalSessionsNamespace.ns()); return replyBuilder.releaseBody(); }; return doFetch(NamespaceString::kLogicalSessionsNamespace, sessions, send); }
void CertificateFetcher::fetch(const shared_ptr<CertificateRequest>& certRequest, const shared_ptr<ValidationState>& state, const ValidationContinuation& continueValidation) { BOOST_ASSERT(m_certStorage != nullptr); auto cert = m_certStorage->getUnverifiedCertCache().find(certRequest->interest); if (cert != nullptr) { NDN_LOG_DEBUG_DEPTH("Found certificate in **un**verified key cache " << cert->getName()); continueValidation(*cert, state); return; } doFetch(certRequest, state, [continueValidation, this] (const Certificate& cert, const shared_ptr<ValidationState>& state) { m_certStorage->cacheUnverifiedCert(Certificate(cert)); continueValidation(cert, state); }); }
void httpCallback(std::list<RequestInfo>::iterator iter, DenseDataPtr recvData, bool success) { RequestInfo &info = *iter; if (recvData && success) { // Now go back through the chain! CacheLayer::populateParentCaches(info.fileId.fingerprint(), recvData); SparseData data; data.addValidData(recvData); info.serviter->finished(ServiceIterator::SUCCESS); info.serviter = NULL; // avoid double-free in RequestInfo destructor. info.callback(&data); boost::unique_lock<boost::mutex> transfer_lock(mActiveTransferLock); mActiveTransfers.erase(iter); mCleanupCV.notify_one(); } else { // todo: add a more specific error code instead of 'bool success'. doFetch(iter, ServiceIterator::GENERAL_ERROR); } }
bool DatabaseImpl::fetch(IReadBatch& readBatch) { checkBatchArgumentFor(readBatch); return doFetch(readBatch); }
bool DatabaseImpl::fetch(const boost::string_ref& key, partNum_t partNum, std::string& value) { checkSimpleArgumentFor(key, partNum); SingleRead singleRead(key, partNum, value); return doFetch(singleRead); }
void paraNode() /* paraNode - a net server. */ { char *line; char *command; struct sockaddr_in sai; /* We have to know who we are... */ hostName = getMachine(); initRandom(); getTicksToHundreths(); /* log init */ if (optionExists("log")) logOpenFile("paraNode", optionVal("log", NULL)); else logOpenSyslog("paraNode", optionVal("logFacility", NULL)); logSetMinPriority(optionVal("logMinPriority", "info")); logInfo("starting paraNode on %s", hostName); /* Make job lists. */ jobsRunning = newDlList(); jobsFinished = newDlList(); /* Set up socket and self to listen to it. */ ZeroVar(&sai); sai.sin_family = AF_INET; sai.sin_port = htons(paraNodePort); sai.sin_addr.s_addr = INADDR_ANY; mainRudp = rudpMustOpenBound(&sai); mainRudp->maxRetries = 12; /* Event loop. */ findNow(); for (;;) { /* Get next incoming message and optionally check to make * sure that it's from a host we trust, and check signature * on first bit of incoming data. */ if (pmReceive(&pmIn, mainRudp)) { findNow(); if (hubName == NULL || ntohl(pmIn.ipAddress.sin_addr.s_addr) == hubIp || ntohl(pmIn.ipAddress.sin_addr.s_addr) == localIp) { /* Host and signature look ok, read a string and * parse out first word as command. */ line = pmIn.data; logDebug("message from %s: \"%s\"", paraFormatIp(ntohl(pmIn.ipAddress.sin_addr.s_addr)), line); command = nextWord(&line); if (command != NULL) { if (sameString("quit", command)) break; else if (sameString("run", command)) doRun(line, &pmIn.ipAddress); else if (sameString("jobDone", command)) jobDone(line); else if (sameString("status", command)) doStatus(); else if (sameString("kill", command)) doKill(line); else if (sameString("check", command)) doCheck(line, &pmIn.ipAddress); else if (sameString("resurrect", command)) doResurrect(line, &pmIn.ipAddress); else if (sameString("listJobs", command)) listJobs(); else if (sameString("fetch", command)) doFetch(line); else logWarn("invalid command: \"%s\"", command); } logDebug("done command"); } else { logWarn("command from unauthorized host %s", paraFormatIp(ntohl(pmIn.ipAddress.sin_addr.s_addr))); } } } rudpClose(&mainRudp); }
void PlainHeaderIteratorTripleString::goToStart() { pos=0; doFetch(); }
hdt::TripleString * PlainHeaderIteratorTripleString::next() { returnTriple = nextTriple; doFetch(); return &returnTriple; }
/// ITERATOR PlainHeaderIteratorTripleString::PlainHeaderIteratorTripleString(PlainHeader *header, TripleString &pattern) : header(header), pos(0), pattern(pattern) { doFetch(); }
void gotServices(std::list<RequestInfo>::iterator iter, ServiceIterator *services) { (*iter).serviter = services; doFetch(iter, ServiceIterator::SUCCESS); }