From 99e56eedabfe34dbfbfd8105759403173de72d44 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 28 Aug 2015 16:55:33 -0700 Subject: MAINT-5575: Begin conversion to Singleton<> for Experience Cache. Commited on branch so that I don't trigger a build of it until I'm ready. --HG-- branch : MAINT-5575 --- indra/llmessage/llexperiencecache.cpp | 925 +++++++++++++++++----------------- 1 file changed, 465 insertions(+), 460 deletions(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 52b60a176e..d196d7da93 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -34,608 +34,613 @@ #include "boost/tokenizer.hpp" -namespace LLExperienceCache -{ +typedef std::map KeyMap; +KeyMap privateToPublicKeyMap; - typedef std::map KeyMap; - KeyMap privateToPublicKeyMap; +void mapKeys(const LLSD& legacyKeys); - void mapKeys(const LLSD& legacyKeys); +std::string sLookupURL; - std::string sLookupURL; +typedef std::map ask_queue_t; +ask_queue_t sAskQueue; - typedef std::map ask_queue_t; - ask_queue_t sAskQueue; +typedef std::map pending_queue_t; +pending_queue_t sPendingQueue; - typedef std::map pending_queue_t; - pending_queue_t sPendingQueue; +LLExperienceCache::cache_t sCache; +int sMaximumLookups = 10; - cache_t sCache; - int sMaximumLookups = 10; +LLFrameTimer sRequestTimer; - LLFrameTimer sRequestTimer; +// Periodically clean out expired entries from the cache +LLFrameTimer sEraseExpiredTimer; - // Periodically clean out expired entries from the cache - LLFrameTimer sEraseExpiredTimer; +// May have multiple callbacks for a single ID, which are +// represented as multiple slots bound to the signal. +// Avoid copying signals via pointers. +typedef std::map signal_map_t; +signal_map_t sSignalMap; - // May have multiple callbacks for a single ID, which are - // represented as multiple slots bound to the signal. - // Avoid copying signals via pointers. - typedef std::map signal_map_t; - signal_map_t sSignalMap; +bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age); +void eraseExpired(); - bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age); - void eraseExpired(); +//========================================================================= +LLExperienceCache::LLExperienceCache() +{ +} - void processExperience( const LLUUID& public_key, const LLSD& experience ) - { - sCache[public_key]=experience; - LLSD & row = sCache[public_key]; +LLExperienceCache::~LLExperienceCache() +{ +} - if(row.has(EXPIRES)) - { - row[EXPIRES] = row[EXPIRES].asReal() + LLFrameTimer::getTotalSeconds(); - } +//------------------------------------------------------------------------- +void LLExperienceCache::importFile(std::istream& istr) +{ + LLSD data; + S32 parse_count = LLSDSerialize::fromXMLDocument(data, istr); + if (parse_count < 1) return; - if(row.has(EXPERIENCE_ID)) - { - sPendingQueue.erase(row[EXPERIENCE_ID].asUUID()); - } + LLSD experiences = data["experiences"]; - //signal - signal_map_t::iterator sig_it = sSignalMap.find(public_key); - if (sig_it != sSignalMap.end()) - { - callback_signal_t* signal = sig_it->second; - (*signal)(experience); + LLUUID public_key; + LLSD::map_const_iterator it = experiences.beginMap(); + for (; it != experiences.endMap(); ++it) + { + public_key.set(it->first); + sCache[public_key] = it->second; + } - sSignalMap.erase(public_key); + LL_DEBUGS("ExperienceCache") << "importFile() loaded " << sCache.size() << LL_ENDL; +} - delete signal; - } - } +void LLExperienceCache::exportFile(std::ostream& ostr) const +{ + LLSD experiences; - void initClass( ) - { - } + cache_t::const_iterator it = sCache.begin(); + for (; it != sCache.end(); ++it) + { + if (!it->second.has(EXPERIENCE_ID) || it->second[EXPERIENCE_ID].asUUID().isNull() || + it->second.has("DoesNotExist") || (it->second.has(PROPERTIES) && it->second[PROPERTIES].asInteger() & PROPERTY_INVALID)) + continue; - const cache_t& getCached() + experiences[it->first.asString()] = it->second; + } + + LLSD data; + data["experiences"] = experiences; + + LLSDSerialize::toPrettyXML(data, ostr); +} + +// *TODO$: Rider: These three functions not seem to be used... it may be useful in testing. +void LLExperienceCache::bootstrap(const LLSD& legacyKeys, int initialExpiration) +{ + mapKeys(legacyKeys); + LLSD::array_const_iterator it = legacyKeys.beginArray(); + for (/**/; it != legacyKeys.endArray(); ++it) + { + LLSD experience = *it; + if (experience.has(EXPERIENCE_ID)) + { + if (!experience.has(EXPIRES)) + { + experience[EXPIRES] = initialExpiration; + } + processExperience(experience[EXPERIENCE_ID].asUUID(), experience); + } + else + { + LL_WARNS("ExperienceCache") + << "Skipping bootstrap entry which is missing " << EXPERIENCE_ID + << LL_ENDL; + } + } +} + +void LLExperienceCache::mapKeys(const LLSD& legacyKeys) +{ + LLSD::array_const_iterator exp = legacyKeys.beginArray(); + for (/**/; exp != legacyKeys.endArray(); ++exp) + { + if (exp->has(LLExperienceCache::EXPERIENCE_ID) && exp->has(LLExperienceCache::PRIVATE_KEY)) + { + privateToPublicKeyMap[(*exp)[LLExperienceCache::PRIVATE_KEY].asUUID()] = (*exp)[LLExperienceCache::EXPERIENCE_ID].asUUID(); + } + } +} + +LLUUID LLExperienceCache::getExperienceId(const LLUUID& private_key, bool null_if_not_found) +{ + if (private_key.isNull()) + return LLUUID::null; + + KeyMap::const_iterator it = privateToPublicKeyMap.find(private_key); + if (it == privateToPublicKeyMap.end()) + { + if (null_if_not_found) + { + return LLUUID::null; + } + return private_key; + } + LL_WARNS("LLExperience") << "converted private key " << private_key << " to experience_id " << it->second << LL_ENDL; + return it->second; +} + +//========================================================================= +void LLExperienceCache::processExperience(const LLUUID& public_key, const LLSD& experience) +{ + sCache[public_key]=experience; + LLSD & row = sCache[public_key]; + + if(row.has(EXPIRES)) { - return sCache; + row[EXPIRES] = row[EXPIRES].asReal() + LLFrameTimer::getTotalSeconds(); } - void setMaximumLookups( int maximumLookups) + if(row.has(EXPERIENCE_ID)) { - sMaximumLookups = maximumLookups; + sPendingQueue.erase(row[EXPERIENCE_ID].asUUID()); } - void bootstrap(const LLSD& legacyKeys, int initialExpiration) + //signal + signal_map_t::iterator sig_it = sSignalMap.find(public_key); + if (sig_it != sSignalMap.end()) { - mapKeys(legacyKeys); - LLSD::array_const_iterator it = legacyKeys.beginArray(); - for(/**/; it != legacyKeys.endArray(); ++it) - { - LLSD experience = *it; - if(experience.has(EXPERIENCE_ID)) - { - if(!experience.has(EXPIRES)) - { - experience[EXPIRES] = initialExpiration; - } - processExperience(experience[EXPERIENCE_ID].asUUID(), experience); - } - else - { - LL_WARNS("ExperienceCache") - << "Skipping bootstrap entry which is missing " << EXPERIENCE_ID - << LL_ENDL; - } - } + callback_signal_t* signal = sig_it->second; + (*signal)(experience); + + sSignalMap.erase(public_key); + + delete signal; } +} +const LLExperienceCache::cache_t& LLExperienceCache::getCached() +{ + return sCache; +} + +void LLExperienceCache::setMaximumLookups(int maximumLookups) +{ + sMaximumLookups = maximumLookups; +} - bool expirationFromCacheControl(LLSD headers, F64 *expires) +bool LLExperienceCache::expirationFromCacheControl(LLSD headers, F64 *expires) +{ + // Allow the header to override the default + LLSD cache_control_header = headers["cache-control"]; + if (cache_control_header.isDefined()) { - // Allow the header to override the default - LLSD cache_control_header = headers["cache-control"]; - if (cache_control_header.isDefined()) + S32 max_age = 0; + std::string cache_control = cache_control_header.asString(); + if (max_age_from_cache_control(cache_control, &max_age)) { - S32 max_age = 0; - std::string cache_control = cache_control_header.asString(); - if (max_age_from_cache_control(cache_control, &max_age)) - { - LL_WARNS("ExperienceCache") - << "got EXPIRES from headers, max_age " << max_age - << LL_ENDL; - F64 now = LLFrameTimer::getTotalSeconds(); - *expires = now + (F64)max_age; - return true; - } + LL_WARNS("ExperienceCache") + << "got EXPIRES from headers, max_age " << max_age + << LL_ENDL; + F64 now = LLFrameTimer::getTotalSeconds(); + *expires = now + (F64)max_age; + return true; } - return false; } + return false; +} - static const std::string MAX_AGE("max-age"); - static const boost::char_separator EQUALS_SEPARATOR("="); - static const boost::char_separator COMMA_SEPARATOR(","); +static const std::string MAX_AGE("max-age"); +static const boost::char_separator EQUALS_SEPARATOR("="); +static const boost::char_separator COMMA_SEPARATOR(","); + +bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age) +{ + // Split the string on "," to get a list of directives + typedef boost::tokenizer > tokenizer; + tokenizer directives(cache_control, COMMA_SEPARATOR); - bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age) + tokenizer::iterator token_it = directives.begin(); + for ( ; token_it != directives.end(); ++token_it) { - // Split the string on "," to get a list of directives - typedef boost::tokenizer > tokenizer; - tokenizer directives(cache_control, COMMA_SEPARATOR); + // Tokens may have leading or trailing whitespace + std::string token = *token_it; + LLStringUtil::trim(token); - tokenizer::iterator token_it = directives.begin(); - for ( ; token_it != directives.end(); ++token_it) + if (token.compare(0, MAX_AGE.size(), MAX_AGE) == 0) { - // Tokens may have leading or trailing whitespace - std::string token = *token_it; - LLStringUtil::trim(token); - - if (token.compare(0, MAX_AGE.size(), MAX_AGE) == 0) + // ...this token starts with max-age, so let's chop it up by "=" + tokenizer subtokens(token, EQUALS_SEPARATOR); + tokenizer::iterator subtoken_it = subtokens.begin(); + + // Must have a token + if (subtoken_it == subtokens.end()) return false; + std::string subtoken = *subtoken_it; + + // Must exactly equal "max-age" + LLStringUtil::trim(subtoken); + if (subtoken != MAX_AGE) return false; + + // Must have another token + ++subtoken_it; + if (subtoken_it == subtokens.end()) return false; + subtoken = *subtoken_it; + + // Must be a valid integer + // *NOTE: atoi() returns 0 for invalid values, so we have to + // check the string first. + // *TODO: Do servers ever send "0000" for zero? We don't handle it + LLStringUtil::trim(subtoken); + if (subtoken == "0") { - // ...this token starts with max-age, so let's chop it up by "=" - tokenizer subtokens(token, EQUALS_SEPARATOR); - tokenizer::iterator subtoken_it = subtokens.begin(); - - // Must have a token - if (subtoken_it == subtokens.end()) return false; - std::string subtoken = *subtoken_it; - - // Must exactly equal "max-age" - LLStringUtil::trim(subtoken); - if (subtoken != MAX_AGE) return false; - - // Must have another token - ++subtoken_it; - if (subtoken_it == subtokens.end()) return false; - subtoken = *subtoken_it; - - // Must be a valid integer - // *NOTE: atoi() returns 0 for invalid values, so we have to - // check the string first. - // *TODO: Do servers ever send "0000" for zero? We don't handle it - LLStringUtil::trim(subtoken); - if (subtoken == "0") - { - *max_age = 0; - return true; - } - S32 val = atoi( subtoken.c_str() ); - if (val > 0 && val < S32_MAX) - { - *max_age = val; - return true; - } - return false; + *max_age = 0; + return true; } + S32 val = atoi( subtoken.c_str() ); + if (val > 0 && val < S32_MAX) + { + *max_age = val; + return true; + } + return false; } - return false; } + return false; +} - void importFile(std::istream& istr) +class LLExperienceResponder : public LLHTTPClient::Responder +{ +public: + LLExperienceResponder(const ask_queue_t& keys) + :mKeys(keys) { - LLSD data; - S32 parse_count = LLSDSerialize::fromXMLDocument(data, istr); - if(parse_count < 1) return; - - LLSD experiences = data["experiences"]; - LLUUID public_key; - LLSD::map_const_iterator it = experiences.beginMap(); - for(; it != experiences.endMap() ; ++it) - { - public_key.set(it->first); - sCache[public_key]=it->second; - } - - LL_DEBUGS("ExperienceCache") << "importFile() loaded " << sCache.size() << LL_ENDL; } - void exportFile(std::ostream& ostr) + /*virtual*/ void httpCompleted() { - LLSD experiences; - - cache_t::const_iterator it =sCache.begin(); - for( ; it != sCache.end() ; ++it) + LLSD experiences = getContent()["experience_keys"]; + LLSD::array_const_iterator it = experiences.beginArray(); + for( /**/ ; it != experiences.endArray(); ++it) { - if(!it->second.has(EXPERIENCE_ID) || it->second[EXPERIENCE_ID].asUUID().isNull() || - it->second.has("DoesNotExist") || (it->second.has(PROPERTIES) && it->second[PROPERTIES].asInteger() & PROPERTY_INVALID)) - continue; + const LLSD& row = *it; + LLUUID public_key = row[EXPERIENCE_ID].asUUID(); - experiences[it->first.asString()] = it->second; - } - LLSD data; - data["experiences"] = experiences; + LL_DEBUGS("ExperienceCache") << "Received result for " << public_key + << " display '" << row[LLExperienceCache::NAME].asString() << "'" << LL_ENDL ; - LLSDSerialize::toPrettyXML(data, ostr); - } + processExperience(public_key, row); + } - class LLExperienceResponder : public LLHTTPClient::Responder - { - public: - LLExperienceResponder(const ask_queue_t& keys) - :mKeys(keys) + LLSD error_ids = getContent()["error_ids"]; + LLSD::array_const_iterator errIt = error_ids.beginArray(); + for( /**/ ; errIt != error_ids.endArray() ; ++errIt ) { - + LLUUID id = errIt->asUUID(); + LLSD exp; + exp[EXPIRES]=DEFAULT_EXPIRATION; + exp[EXPERIENCE_ID] = id; + exp[PROPERTIES]=PROPERTY_INVALID; + exp[MISSING]=true; + exp[QUOTA] = DEFAULT_QUOTA; + + processExperience(id, exp); + LL_WARNS("ExperienceCache") << "LLExperienceResponder::result() error result for " << id << LL_ENDL ; } - /*virtual*/ void httpCompleted() + LL_DEBUGS("ExperienceCache") << sCache.size() << " cached experiences" << LL_ENDL; + } + + /*virtual*/ void httpFailure() + { + LL_WARNS("ExperienceCache") << "Request failed "<first); + //leave the properties alone if we already have a cache entry for this xp + if(exp.isUndefined()) + { + exp[PROPERTIES]=PROPERTY_INVALID; + } + exp[EXPIRES]=retry_timestamp; + exp[EXPERIENCE_ID] = it->first; + exp["key_type"] = it->second; + exp["uuid"] = it->first; + exp["error"] = (LLSD::Integer)getStatus(); + exp[QUOTA] = DEFAULT_QUOTA; + + LLExperienceCache::processExperience(it->first, exp); + } - LL_DEBUGS("ExperienceCache") << "Received result for " << public_key - << " display '" << row[LLExperienceCache::NAME].asString() << "'" << LL_ENDL ; + } - processExperience(public_key, row); - } + // Return time to retry a request that generated an error, based on + // error type and headers. Return value is seconds-since-epoch. + F64 errorRetryTimestamp(S32 status) + { - LLSD error_ids = getContent()["error_ids"]; - LLSD::array_const_iterator errIt = error_ids.beginArray(); - for( /**/ ; errIt != error_ids.endArray() ; ++errIt ) + // Retry-After takes priority + LLSD retry_after = getResponseHeaders()["retry-after"]; + if (retry_after.isDefined()) + { + // We only support the delta-seconds type + S32 delta_seconds = retry_after.asInteger(); + if (delta_seconds > 0) { - LLUUID id = errIt->asUUID(); - LLSD exp; - exp[EXPIRES]=DEFAULT_EXPIRATION; - exp[EXPERIENCE_ID] = id; - exp[PROPERTIES]=PROPERTY_INVALID; - exp[MISSING]=true; - exp[QUOTA] = DEFAULT_QUOTA; - - processExperience(id, exp); - LL_WARNS("ExperienceCache") << "LLExperienceResponder::result() error result for " << id << LL_ENDL ; + // ...valid delta-seconds + return F64(delta_seconds); } - - LL_DEBUGS("ExperienceCache") << sCache.size() << " cached experiences" << LL_ENDL; } - /*virtual*/ void httpFailure() + // If no Retry-After, look for Cache-Control max-age + F64 expires = 0.0; + if (LLExperienceCache::expirationFromCacheControl(getResponseHeaders(), &expires)) { - LL_WARNS("ExperienceCache") << "Request failed "<first); - //leave the properties alone if we already have a cache entry for this xp - if(exp.isUndefined()) - { - exp[PROPERTIES]=PROPERTY_INVALID; - } - exp[EXPIRES]=retry_timestamp; - exp[EXPERIENCE_ID] = it->first; - exp["key_type"] = it->second; - exp["uuid"] = it->first; - exp["error"] = (LLSD::Integer)getStatus(); - exp[QUOTA] = DEFAULT_QUOTA; - - LLExperienceCache::processExperience(it->first, exp); - } - + return expires; } - // Return time to retry a request that generated an error, based on - // error type and headers. Return value is seconds-since-epoch. - F64 errorRetryTimestamp(S32 status) + // No information in header, make a guess + if (status == 503) { + // ...service unavailable, retry soon + const F64 SERVICE_UNAVAILABLE_DELAY = 600.0; // 10 min + return SERVICE_UNAVAILABLE_DELAY; + } + else if (status == 499) + { + // ...we were probably too busy, retry quickly + const F64 BUSY_DELAY = 10.0; // 10 seconds + return BUSY_DELAY; - // Retry-After takes priority - LLSD retry_after = getResponseHeaders()["retry-after"]; - if (retry_after.isDefined()) - { - // We only support the delta-seconds type - S32 delta_seconds = retry_after.asInteger(); - if (delta_seconds > 0) - { - // ...valid delta-seconds - return F64(delta_seconds); - } - } - - // If no Retry-After, look for Cache-Control max-age - F64 expires = 0.0; - if (LLExperienceCache::expirationFromCacheControl(getResponseHeaders(), &expires)) - { - return expires; - } - - // No information in header, make a guess - if (status == 503) - { - // ...service unavailable, retry soon - const F64 SERVICE_UNAVAILABLE_DELAY = 600.0; // 10 min - return SERVICE_UNAVAILABLE_DELAY; - } - else if (status == 499) - { - // ...we were probably too busy, retry quickly - const F64 BUSY_DELAY = 10.0; // 10 seconds - return BUSY_DELAY; - - } - else - { - // ...other unexpected error - const F64 DEFAULT_DELAY = 3600.0; // 1 hour - return DEFAULT_DELAY; - } } + else + { + // ...other unexpected error + const F64 DEFAULT_DELAY = 3600.0; // 1 hour + return DEFAULT_DELAY; + } + } - private: - ask_queue_t mKeys; - }; +private: + ask_queue_t mKeys; +}; - void requestExperiences() - { - if(sAskQueue.empty() || sLookupURL.empty()) - return; - F64 now = LLFrameTimer::getTotalSeconds(); +void LLExperienceCache::requestExperiences() +{ + if(sAskQueue.empty() || sLookupURL.empty()) + return; - const U32 EXP_URL_SEND_THRESHOLD = 3000; - const U32 PAGE_SIZE = EXP_URL_SEND_THRESHOLD/UUID_STR_LENGTH; + F64 now = LLFrameTimer::getTotalSeconds(); - std::ostringstream ostr; + const U32 EXP_URL_SEND_THRESHOLD = 3000; + const U32 PAGE_SIZE = EXP_URL_SEND_THRESHOLD/UUID_STR_LENGTH; - ask_queue_t keys; + std::ostringstream ostr; - ostr << sLookupURL << "?page_size=" << PAGE_SIZE; + ask_queue_t keys; + ostr << sLookupURL << "?page_size=" << PAGE_SIZE; - int request_count = 0; - while(!sAskQueue.empty() && request_count < sMaximumLookups) - { - ask_queue_t::iterator it = sAskQueue.begin(); - const LLUUID& key = it->first; - const std::string& key_type = it->second; - ostr << '&' << key_type << '=' << key.asString() ; + int request_count = 0; + while(!sAskQueue.empty() && request_count < sMaximumLookups) + { + ask_queue_t::iterator it = sAskQueue.begin(); + const LLUUID& key = it->first; + const std::string& key_type = it->second; + + ostr << '&' << key_type << '=' << key.asString() ; - keys[key]=key_type; - request_count++; + keys[key]=key_type; + request_count++; - sPendingQueue[key] = now; + sPendingQueue[key] = now; - if(ostr.tellp() > EXP_URL_SEND_THRESHOLD) - { - LL_DEBUGS("ExperienceCache") << "requestExperiences() query: " << ostr.str() << LL_ENDL; - LLHTTPClient::get(ostr.str(), new LLExperienceResponder(keys)); - ostr.clear(); - ostr.str(sLookupURL); - ostr << "?page_size=" << PAGE_SIZE; - keys.clear(); - } - sAskQueue.erase(it); - } - - if(ostr.tellp() > sLookupURL.size()) + if(ostr.tellp() > EXP_URL_SEND_THRESHOLD) { - LL_DEBUGS("ExperienceCache") << "requestExperiences() query 2: " << ostr.str() << LL_ENDL; + LL_DEBUGS("ExperienceCache") << "requestExperiences() query: " << ostr.str() << LL_ENDL; LLHTTPClient::get(ostr.str(), new LLExperienceResponder(keys)); + ostr.clear(); + ostr.str(sLookupURL); + ostr << "?page_size=" << PAGE_SIZE; + keys.clear(); } + sAskQueue.erase(it); } - bool isRequestPending(const LLUUID& public_key) + if(ostr.tellp() > sLookupURL.size()) { - bool isPending = false; - const F64 PENDING_TIMEOUT_SECS = 5.0 * 60.0; + LL_DEBUGS("ExperienceCache") << "requestExperiences() query 2: " << ostr.str() << LL_ENDL; + LLHTTPClient::get(ostr.str(), new LLExperienceResponder(keys)); + } +} - pending_queue_t::const_iterator it = sPendingQueue.find(public_key); - if(it != sPendingQueue.end()) - { - F64 expire_time = LLFrameTimer::getTotalSeconds() - PENDING_TIMEOUT_SECS; - isPending = (it->second > expire_time); - } +bool LLExperienceCache::isRequestPending(const LLUUID& public_key) +{ + bool isPending = false; + const F64 PENDING_TIMEOUT_SECS = 5.0 * 60.0; + + pending_queue_t::const_iterator it = sPendingQueue.find(public_key); - return isPending; + if(it != sPendingQueue.end()) + { + F64 expire_time = LLFrameTimer::getTotalSeconds() - PENDING_TIMEOUT_SECS; + isPending = (it->second > expire_time); } + return isPending; +} + - void setLookupURL( const std::string& lookup_url ) +void LLExperienceCache::setLookupURL(const std::string& lookup_url) +{ + sLookupURL = lookup_url; + if(!sLookupURL.empty()) { - sLookupURL = lookup_url; - if(!sLookupURL.empty()) - { - sLookupURL += "id/"; - } + sLookupURL += "id/"; } +} + +bool LLExperienceCache::hasLookupURL() +{ + return !sLookupURL.empty(); +} - bool hasLookupURL() +void LLExperienceCache::idle() +{ + + const F32 SECS_BETWEEN_REQUESTS = 0.1f; + if (!sRequestTimer.checkExpirationAndReset(SECS_BETWEEN_REQUESTS)) { - return !sLookupURL.empty(); + return; } - void idle() + // Must be large relative to above + const F32 ERASE_EXPIRED_TIMEOUT = 60.f; // seconds + if (sEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) { - - const F32 SECS_BETWEEN_REQUESTS = 0.1f; - if (!sRequestTimer.checkExpirationAndReset(SECS_BETWEEN_REQUESTS)) - { - return; - } - - // Must be large relative to above - const F32 ERASE_EXPIRED_TIMEOUT = 60.f; // seconds - if (sEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) - { - eraseExpired(); - } + eraseExpired(); + } - if(!sAskQueue.empty()) - { - requestExperiences(); - } + if(!sAskQueue.empty()) + { + requestExperiences(); } +} - void erase( const LLUUID& key ) - { - cache_t::iterator it = sCache.find(key); +void LLExperienceCache::erase(const LLUUID& key) +{ + cache_t::iterator it = sCache.find(key); - if(it != sCache.end()) - { - sCache.erase(it); - } + if(it != sCache.end()) + { + sCache.erase(it); } +} - void eraseExpired() +void LLExperienceCache::eraseExpired() +{ + F64 now = LLFrameTimer::getTotalSeconds(); + cache_t::iterator it = sCache.begin(); + while (it != sCache.end()) { - F64 now = LLFrameTimer::getTotalSeconds(); - cache_t::iterator it = sCache.begin(); - while (it != sCache.end()) - { - cache_t::iterator cur = it; - LLSD& exp = cur->second; - ++it; + cache_t::iterator cur = it; + LLSD& exp = cur->second; + ++it; - if(exp.has(EXPIRES) && exp[EXPIRES].asReal() < now) + if(exp.has(EXPIRES) && exp[EXPIRES].asReal() < now) + { + if(!exp.has(EXPERIENCE_ID)) { - if(!exp.has(EXPERIENCE_ID)) + LL_WARNS("ExperienceCache") << "Removing experience with no id " << LL_ENDL ; + sCache.erase(cur); + } + else + { + LLUUID id = exp[EXPERIENCE_ID].asUUID(); + LLUUID private_key = exp.has(LLExperienceCache::PRIVATE_KEY) ? exp[LLExperienceCache::PRIVATE_KEY].asUUID():LLUUID::null; + if(private_key.notNull() || !exp.has("DoesNotExist")) { - LL_WARNS("ExperienceCache") << "Removing experience with no id " << LL_ENDL ; - sCache.erase(cur); - } - else - { - LLUUID id = exp[EXPERIENCE_ID].asUUID(); - LLUUID private_key = exp.has(LLExperienceCache::PRIVATE_KEY) ? exp[LLExperienceCache::PRIVATE_KEY].asUUID():LLUUID::null; - if(private_key.notNull() || !exp.has("DoesNotExist")) - { - fetch(id, true); - } - else - { - LL_WARNS("ExperienceCache") << "Removing invalid experience " << id << LL_ENDL ; - sCache.erase(cur); - } + fetch(id, true); + } + else + { + LL_WARNS("ExperienceCache") << "Removing invalid experience " << id << LL_ENDL ; + sCache.erase(cur); } } } } +} - bool fetch( const LLUUID& key, bool refresh/* = true*/ ) +bool LLExperienceCache::fetch(const LLUUID& key, bool refresh/* = true*/) +{ + if(!key.isNull() && !isRequestPending(key) && (refresh || sCache.find(key)==sCache.end())) { - if(!key.isNull() && !isRequestPending(key) && (refresh || sCache.find(key)==sCache.end())) - { - LL_DEBUGS("ExperienceCache") << " queue request for " << EXPERIENCE_ID << " " << key << LL_ENDL ; - sAskQueue[key]=EXPERIENCE_ID; + LL_DEBUGS("ExperienceCache") << " queue request for " << EXPERIENCE_ID << " " << key << LL_ENDL ; + sAskQueue[key]=EXPERIENCE_ID; - return true; - } - return false; + return true; } + return false; +} - void insert(const LLSD& experience_data ) +void LLExperienceCache::insert(const LLSD& experience_data) +{ + if(experience_data.has(EXPERIENCE_ID)) { - if(experience_data.has(EXPERIENCE_ID)) - { - processExperience(experience_data[EXPERIENCE_ID].asUUID(), experience_data); - } - else - { - LL_WARNS("ExperienceCache") << ": Ignoring cache insert of experience which is missing " << EXPERIENCE_ID << LL_ENDL; - } + processExperience(experience_data[EXPERIENCE_ID].asUUID(), experience_data); } - static LLSD empty; - const LLSD& get(const LLUUID& key) + else { - if(key.isNull()) return empty; - cache_t::const_iterator it = sCache.find(key); - - if (it != sCache.end()) - { - return it->second; - } - - fetch(key); - - return empty; + LL_WARNS("ExperienceCache") << ": Ignoring cache insert of experience which is missing " << EXPERIENCE_ID << LL_ENDL; } - void get( const LLUUID& key, callback_slot_t slot ) - { - if(key.isNull()) return; - - cache_t::const_iterator it = sCache.find(key); - if (it != sCache.end()) - { - // ...name already exists in cache, fire callback now - callback_signal_t signal; - signal.connect(slot); - - signal(it->second); - return; - } +} - fetch(key); +static LLSD empty; +const LLSD& LLExperienceCache::get(const LLUUID& key) +{ + if(key.isNull()) return empty; + cache_t::const_iterator it = sCache.find(key); - // always store additional callback, even if request is pending - signal_map_t::iterator sig_it = sSignalMap.find(key); - if (sig_it == sSignalMap.end()) - { - // ...new callback for this id - callback_signal_t* signal = new callback_signal_t(); - signal->connect(slot); - sSignalMap[key] = signal; - } - else - { - // ...existing callback, bind additional slot - callback_signal_t* signal = sig_it->second; - signal->connect(slot); - } + if (it != sCache.end()) + { + return it->second; } -} - + fetch(key); -void LLExperienceCache::mapKeys( const LLSD& legacyKeys ) + return empty; +} +void LLExperienceCache::get(const LLUUID& key, callback_slot_t slot) { - LLSD::array_const_iterator exp = legacyKeys.beginArray(); - for(/**/ ; exp != legacyKeys.endArray() ; ++exp) + if(key.isNull()) return; + + cache_t::const_iterator it = sCache.find(key); + if (it != sCache.end()) { - if(exp->has(LLExperienceCache::EXPERIENCE_ID) && exp->has(LLExperienceCache::PRIVATE_KEY)) - { - privateToPublicKeyMap[(*exp)[LLExperienceCache::PRIVATE_KEY].asUUID()]=(*exp)[LLExperienceCache::EXPERIENCE_ID].asUUID(); - } + // ...name already exists in cache, fire callback now + callback_signal_t signal; + signal.connect(slot); + + signal(it->second); + return; } -} + fetch(key); -LLUUID LLExperienceCache::getExperienceId(const LLUUID& private_key, bool null_if_not_found) -{ - if (private_key.isNull()) - return LLUUID::null; - - KeyMap::const_iterator it=privateToPublicKeyMap.find(private_key); - if(it == privateToPublicKeyMap.end()) + // always store additional callback, even if request is pending + signal_map_t::iterator sig_it = sSignalMap.find(key); + if (sig_it == sSignalMap.end()) { - if(null_if_not_found) - { - return LLUUID::null; - } - return private_key; + // ...new callback for this id + callback_signal_t* signal = new callback_signal_t(); + signal->connect(slot); + sSignalMap[key] = signal; + } + else + { + // ...existing callback, bind additional slot + callback_signal_t* signal = sig_it->second; + signal->connect(slot); } - LL_WARNS("LLExperience") << "converted private key " << private_key << " to experience_id " << it->second << LL_ENDL; - return it->second; } + + -- cgit v1.2.3 From 4b3269c94d8b68c977598d2444ae04f7e1f9062c Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Mon, 31 Aug 2015 07:27:13 -0700 Subject: Some initial changes to convert the experience cache to a singleton --HG-- branch : MAINT-5575 --- indra/llmessage/llexperiencecache.cpp | 214 +++++++++++++++++++--------------- 1 file changed, 122 insertions(+), 92 deletions(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index d196d7da93..34c4210359 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -32,22 +32,18 @@ #include #include #include "boost/tokenizer.hpp" +#include typedef std::map KeyMap; KeyMap privateToPublicKeyMap; -void mapKeys(const LLSD& legacyKeys); std::string sLookupURL; -typedef std::map ask_queue_t; -ask_queue_t sAskQueue; - typedef std::map pending_queue_t; pending_queue_t sPendingQueue; -LLExperienceCache::cache_t sCache; int sMaximumLookups = 10; LLFrameTimer sRequestTimer; @@ -55,16 +51,41 @@ LLFrameTimer sRequestTimer; // Periodically clean out expired entries from the cache LLFrameTimer sEraseExpiredTimer; -// May have multiple callbacks for a single ID, which are -// represented as multiple slots bound to the signal. -// Avoid copying signals via pointers. -typedef std::map signal_map_t; -signal_map_t sSignalMap; - -bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age); -void eraseExpired(); +//========================================================================= +namespace LLExperienceCacheImpl +{ + bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age); + void mapKeys(const LLSD& legacyKeys); +} +//========================================================================= +const std::string LLExperienceCache::PRIVATE_KEY = "private_id"; +const std::string LLExperienceCache::MISSING = "DoesNotExist"; + +const std::string LLExperienceCache::AGENT_ID = "agent_id"; +const std::string LLExperienceCache::GROUP_ID = "group_id"; +const std::string LLExperienceCache::EXPERIENCE_ID = "public_id"; +const std::string LLExperienceCache::NAME = "name"; +const std::string LLExperienceCache::PROPERTIES = "properties"; +const std::string LLExperienceCache::EXPIRES = "expiration"; +const std::string LLExperienceCache::DESCRIPTION = "description"; +const std::string LLExperienceCache::QUOTA = "quota"; +const std::string LLExperienceCache::MATURITY = "maturity"; +const std::string LLExperienceCache::METADATA = "extended_metadata"; +const std::string LLExperienceCache::SLURL = "slurl"; + +// should be in sync with experience-api/experiences/models.py +const int LLExperienceCache::PROPERTY_INVALID = 1 << 0; +const int LLExperienceCache::PROPERTY_PRIVILEGED = 1 << 3; +const int LLExperienceCache::PROPERTY_GRID = 1 << 4; +const int LLExperienceCache::PROPERTY_PRIVATE = 1 << 5; +const int LLExperienceCache::PROPERTY_DISABLED = 1 << 6; +const int LLExperienceCache::PROPERTY_SUSPENDED = 1 << 7; + +// default values +const F64 LLExperienceCache::DEFAULT_EXPIRATION = 600.0; +const S32 LLExperienceCache::DEFAULT_QUOTA = 128; // this is megabytes //========================================================================= LLExperienceCache::LLExperienceCache() @@ -118,7 +139,7 @@ void LLExperienceCache::exportFile(std::ostream& ostr) const // *TODO$: Rider: These three functions not seem to be used... it may be useful in testing. void LLExperienceCache::bootstrap(const LLSD& legacyKeys, int initialExpiration) { - mapKeys(legacyKeys); + LLExperienceCacheImpl::mapKeys(legacyKeys); LLSD::array_const_iterator it = legacyKeys.beginArray(); for (/**/; it != legacyKeys.endArray(); ++it) { @@ -140,18 +161,6 @@ void LLExperienceCache::bootstrap(const LLSD& legacyKeys, int initialExpiration) } } -void LLExperienceCache::mapKeys(const LLSD& legacyKeys) -{ - LLSD::array_const_iterator exp = legacyKeys.beginArray(); - for (/**/; exp != legacyKeys.endArray(); ++exp) - { - if (exp->has(LLExperienceCache::EXPERIENCE_ID) && exp->has(LLExperienceCache::PRIVATE_KEY)) - { - privateToPublicKeyMap[(*exp)[LLExperienceCache::PRIVATE_KEY].asUUID()] = (*exp)[LLExperienceCache::EXPERIENCE_ID].asUUID(); - } - } -} - LLUUID LLExperienceCache::getExperienceId(const LLUUID& private_key, bool null_if_not_found) { if (private_key.isNull()) @@ -190,12 +199,10 @@ void LLExperienceCache::processExperience(const LLUUID& public_key, const LLSD& signal_map_t::iterator sig_it = sSignalMap.find(public_key); if (sig_it != sSignalMap.end()) { - callback_signal_t* signal = sig_it->second; + signal_ptr signal = sig_it->second; (*signal)(experience); sSignalMap.erase(public_key); - - delete signal; } } @@ -236,60 +243,6 @@ static const std::string MAX_AGE("max-age"); static const boost::char_separator EQUALS_SEPARATOR("="); static const boost::char_separator COMMA_SEPARATOR(","); -bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age) -{ - // Split the string on "," to get a list of directives - typedef boost::tokenizer > tokenizer; - tokenizer directives(cache_control, COMMA_SEPARATOR); - - tokenizer::iterator token_it = directives.begin(); - for ( ; token_it != directives.end(); ++token_it) - { - // Tokens may have leading or trailing whitespace - std::string token = *token_it; - LLStringUtil::trim(token); - - if (token.compare(0, MAX_AGE.size(), MAX_AGE) == 0) - { - // ...this token starts with max-age, so let's chop it up by "=" - tokenizer subtokens(token, EQUALS_SEPARATOR); - tokenizer::iterator subtoken_it = subtokens.begin(); - - // Must have a token - if (subtoken_it == subtokens.end()) return false; - std::string subtoken = *subtoken_it; - - // Must exactly equal "max-age" - LLStringUtil::trim(subtoken); - if (subtoken != MAX_AGE) return false; - - // Must have another token - ++subtoken_it; - if (subtoken_it == subtokens.end()) return false; - subtoken = *subtoken_it; - - // Must be a valid integer - // *NOTE: atoi() returns 0 for invalid values, so we have to - // check the string first. - // *TODO: Do servers ever send "0000" for zero? We don't handle it - LLStringUtil::trim(subtoken); - if (subtoken == "0") - { - *max_age = 0; - return true; - } - S32 val = atoi( subtoken.c_str() ); - if (val > 0 && val < S32_MAX) - { - *max_age = val; - return true; - } - return false; - } - } - return false; -} - class LLExperienceResponder : public LLHTTPClient::Responder { @@ -435,7 +388,6 @@ void LLExperienceCache::requestExperiences() ostr << sLookupURL << "?page_size=" << PAGE_SIZE; - int request_count = 0; while(!sAskQueue.empty() && request_count < sMaximumLookups) { @@ -503,7 +455,6 @@ bool LLExperienceCache::hasLookupURL() void LLExperienceCache::idle() { - const F32 SECS_BETWEEN_REQUESTS = 0.1f; if (!sRequestTimer.checkExpirationAndReset(SECS_BETWEEN_REQUESTS)) { @@ -517,7 +468,6 @@ void LLExperienceCache::idle() eraseExpired(); } - if(!sAskQueue.empty()) { requestExperiences(); @@ -568,7 +518,6 @@ void LLExperienceCache::eraseExpired() } } } - bool LLExperienceCache::fetch(const LLUUID& key, bool refresh/* = true*/) { @@ -594,10 +543,12 @@ void LLExperienceCache::insert(const LLSD& experience_data) } } -static LLSD empty; const LLSD& LLExperienceCache::get(const LLUUID& key) { - if(key.isNull()) return empty; + static const LLSD empty; + + if(key.isNull()) + return empty; cache_t::const_iterator it = sCache.find(key); if (it != sCache.end()) @@ -609,9 +560,10 @@ const LLSD& LLExperienceCache::get(const LLUUID& key) return empty; } -void LLExperienceCache::get(const LLUUID& key, callback_slot_t slot) +void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::Callback_t slot) { - if(key.isNull()) return; + if(key.isNull()) + return; cache_t::const_iterator it = sCache.find(key); if (it != sCache.end()) @@ -626,12 +578,20 @@ void LLExperienceCache::get(const LLUUID& key, callback_slot_t slot) fetch(key); + signal_ptr signal = signal_ptr(new callback_signal_t()); + + std::pair result = sSignalMap.insert(signal_map_t::value_type(key, signal)); + if (!result.second) + signal = result.first.second; + signal->connect(slot); + +#if 0 // always store additional callback, even if request is pending signal_map_t::iterator sig_it = sSignalMap.find(key); if (sig_it == sSignalMap.end()) { // ...new callback for this id - callback_signal_t* signal = new callback_signal_t(); + signal_ptr signal = signal_ptr(new callback_signal_t()); signal->connect(slot); sSignalMap[key] = signal; } @@ -641,6 +601,76 @@ void LLExperienceCache::get(const LLUUID& key, callback_slot_t slot) callback_signal_t* signal = sig_it->second; signal->connect(slot); } +#endif +} + +//========================================================================= +void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys) +{ + LLSD::array_const_iterator exp = legacyKeys.beginArray(); + for (/**/; exp != legacyKeys.endArray(); ++exp) + { + if (exp->has(LLExperienceCache::EXPERIENCE_ID) && exp->has(LLExperienceCache::PRIVATE_KEY)) + { + privateToPublicKeyMap[(*exp)[LLExperienceCache::PRIVATE_KEY].asUUID()] = (*exp)[LLExperienceCache::EXPERIENCE_ID].asUUID(); + } + } } +bool LLExperienceCacheImpl::max_age_from_cache_control(const std::string& cache_control, S32 *max_age) +{ + // Split the string on "," to get a list of directives + typedef boost::tokenizer > tokenizer; + tokenizer directives(cache_control, COMMA_SEPARATOR); + + tokenizer::iterator token_it = directives.begin(); + for ( ; token_it != directives.end(); ++token_it) + { + // Tokens may have leading or trailing whitespace + std::string token = *token_it; + LLStringUtil::trim(token); + + if (token.compare(0, MAX_AGE.size(), MAX_AGE) == 0) + { + // ...this token starts with max-age, so let's chop it up by "=" + tokenizer subtokens(token, EQUALS_SEPARATOR); + tokenizer::iterator subtoken_it = subtokens.begin(); + + // Must have a token + if (subtoken_it == subtokens.end()) return false; + std::string subtoken = *subtoken_it; + + // Must exactly equal "max-age" + LLStringUtil::trim(subtoken); + if (subtoken != MAX_AGE) return false; + + // Must have another token + ++subtoken_it; + if (subtoken_it == subtokens.end()) return false; + subtoken = *subtoken_it; + + // Must be a valid integer + // *NOTE: atoi() returns 0 for invalid values, so we have to + // check the string first. + // *TODO: Do servers ever send "0000" for zero? We don't handle it + LLStringUtil::trim(subtoken); + if (subtoken == "0") + { + *max_age = 0; + return true; + } + S32 val = atoi( subtoken.c_str() ); + if (val > 0 && val < S32_MAX) + { + *max_age = val; + return true; + } + return false; + } + } + return false; +} + + + -- cgit v1.2.3 From 96e343b49b0b5a0951ffab0beb2e1d09c37bbdc5 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Tue, 1 Sep 2015 16:13:52 -0700 Subject: MAINT-5575: Convert the Experience cache into a coro based singleton. --HG-- branch : MAINT-5575 --- indra/llmessage/llexperiencecache.cpp | 569 +++++++++++++++++----------------- 1 file changed, 277 insertions(+), 292 deletions(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 34c4210359..36a4fc8823 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -26,53 +26,51 @@ #include "llexperiencecache.h" #include "llavatarname.h" -#include "llframetimer.h" #include "llhttpclient.h" #include "llsdserialize.h" +#include "llcoros.h" +#include "lleventcoro.h" +#include "lleventfilter.h" +#include "llcoproceduremanager.h" +#include "lldir.h" #include #include -#include "boost/tokenizer.hpp" +#include #include - -typedef std::map KeyMap; -KeyMap privateToPublicKeyMap; - - -std::string sLookupURL; - -typedef std::map pending_queue_t; -pending_queue_t sPendingQueue; - -int sMaximumLookups = 10; - -LLFrameTimer sRequestTimer; - -// Periodically clean out expired entries from the cache -LLFrameTimer sEraseExpiredTimer; - - //========================================================================= namespace LLExperienceCacheImpl { - bool max_age_from_cache_control(const std::string& cache_control, S32 *max_age); void mapKeys(const LLSD& legacyKeys); + F64 getErrorRetryDeltaTime(S32 status, LLSD headers); + bool maxAgeFromCacheControl(const std::string& cache_control, S32 *max_age); + + static const std::string PRIVATE_KEY = "private_id"; + static const std::string EXPERIENCE_ID = "public_id"; + + static const std::string MAX_AGE("max-age"); + static const boost::char_separator EQUALS_SEPARATOR("="); + static const boost::char_separator COMMA_SEPARATOR(","); + + // *TODO$: this seems to be tied to mapKeys which is used by bootstrap.... but I don't think that bootstrap is used. + typedef std::map KeyMap; + KeyMap privateToPublicKeyMap; } //========================================================================= const std::string LLExperienceCache::PRIVATE_KEY = "private_id"; const std::string LLExperienceCache::MISSING = "DoesNotExist"; -const std::string LLExperienceCache::AGENT_ID = "agent_id"; -const std::string LLExperienceCache::GROUP_ID = "group_id"; +const std::string LLExperienceCache::AGENT_ID = "agent_id"; +const std::string LLExperienceCache::GROUP_ID = "group_id"; const std::string LLExperienceCache::EXPERIENCE_ID = "public_id"; const std::string LLExperienceCache::NAME = "name"; const std::string LLExperienceCache::PROPERTIES = "properties"; const std::string LLExperienceCache::EXPIRES = "expiration"; const std::string LLExperienceCache::DESCRIPTION = "description"; const std::string LLExperienceCache::QUOTA = "quota"; -const std::string LLExperienceCache::MATURITY = "maturity"; -const std::string LLExperienceCache::METADATA = "extended_metadata"; +const std::string LLExperienceCache::MATURITY = "maturity"; +const std::string LLExperienceCache::METADATA = "extended_metadata"; const std::string LLExperienceCache::SLURL = "slurl"; // should be in sync with experience-api/experiences/models.py @@ -80,20 +78,51 @@ const int LLExperienceCache::PROPERTY_INVALID = 1 << 0; const int LLExperienceCache::PROPERTY_PRIVILEGED = 1 << 3; const int LLExperienceCache::PROPERTY_GRID = 1 << 4; const int LLExperienceCache::PROPERTY_PRIVATE = 1 << 5; -const int LLExperienceCache::PROPERTY_DISABLED = 1 << 6; -const int LLExperienceCache::PROPERTY_SUSPENDED = 1 << 7; +const int LLExperienceCache::PROPERTY_DISABLED = 1 << 6; +const int LLExperienceCache::PROPERTY_SUSPENDED = 1 << 7; // default values -const F64 LLExperienceCache::DEFAULT_EXPIRATION = 600.0; +const F64 LLExperienceCache::DEFAULT_EXPIRATION = 600.0; const S32 LLExperienceCache::DEFAULT_QUOTA = 128; // this is megabytes //========================================================================= -LLExperienceCache::LLExperienceCache() +LLExperienceCache::LLExperienceCache(): + mShutdown(false) { } LLExperienceCache::~LLExperienceCache() { + +} + +void LLExperienceCache::initSingleton() +{ + mCacheFileName = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "experience_cache.xml"); + + LL_INFOS("ExperienceCache") << "Loading " << mCacheFileName << LL_ENDL; + llifstream cache_stream(mCacheFileName.c_str()); + + if (cache_stream.is_open()) + { + cache_stream >> (*this); + } + + LLCoros::instance().launch("LLExperienceCache::idleCoro", + boost::bind(&LLExperienceCache::idleCoro, this)); + +} + +void LLExperienceCache::cleanup() +{ + LL_INFOS("ExperienceCache") << "Saving " << mCacheFileName << LL_ENDL; + + llofstream cache_stream(mCacheFileName.c_str()); + if (cache_stream.is_open()) + { + cache_stream << (*this); + } + mShutdown = true; } //------------------------------------------------------------------------- @@ -110,18 +139,18 @@ void LLExperienceCache::importFile(std::istream& istr) for (; it != experiences.endMap(); ++it) { public_key.set(it->first); - sCache[public_key] = it->second; + mCache[public_key] = it->second; } - LL_DEBUGS("ExperienceCache") << "importFile() loaded " << sCache.size() << LL_ENDL; + LL_DEBUGS("ExperienceCache") << "importFile() loaded " << mCache.size() << LL_ENDL; } void LLExperienceCache::exportFile(std::ostream& ostr) const { LLSD experiences; - cache_t::const_iterator it = sCache.begin(); - for (; it != sCache.end(); ++it) + cache_t::const_iterator it = mCache.begin(); + for (; it != mCache.end(); ++it) { if (!it->second.has(EXPERIENCE_ID) || it->second[EXPERIENCE_ID].asUUID().isNull() || it->second.has("DoesNotExist") || (it->second.has(PROPERTIES) && it->second[PROPERTIES].asInteger() & PROPERTY_INVALID)) @@ -136,7 +165,7 @@ void LLExperienceCache::exportFile(std::ostream& ostr) const LLSDSerialize::toPrettyXML(data, ostr); } -// *TODO$: Rider: These three functions not seem to be used... it may be useful in testing. +// *TODO$: Rider: This method does not seem to be used... it may be useful in testing. void LLExperienceCache::bootstrap(const LLSD& legacyKeys, int initialExpiration) { LLExperienceCacheImpl::mapKeys(legacyKeys); @@ -166,8 +195,8 @@ LLUUID LLExperienceCache::getExperienceId(const LLUUID& private_key, bool null_i if (private_key.isNull()) return LLUUID::null; - KeyMap::const_iterator it = privateToPublicKeyMap.find(private_key); - if (it == privateToPublicKeyMap.end()) + LLExperienceCacheImpl::KeyMap::const_iterator it = LLExperienceCacheImpl::privateToPublicKeyMap.find(private_key); + if (it == LLExperienceCacheImpl::privateToPublicKeyMap.end()) { if (null_if_not_found) { @@ -182,8 +211,10 @@ LLUUID LLExperienceCache::getExperienceId(const LLUUID& private_key, bool null_i //========================================================================= void LLExperienceCache::processExperience(const LLUUID& public_key, const LLSD& experience) { - sCache[public_key]=experience; - LLSD & row = sCache[public_key]; + LL_INFOS("ExperienceCache") << "Processing experience \"" << experience[NAME] << "\" with key " << public_key.asString() << LL_ENDL; + + mCache[public_key]=experience; + LLSD & row = mCache[public_key]; if(row.has(EXPIRES)) { @@ -192,233 +223,148 @@ void LLExperienceCache::processExperience(const LLUUID& public_key, const LLSD& if(row.has(EXPERIENCE_ID)) { - sPendingQueue.erase(row[EXPERIENCE_ID].asUUID()); + mPendingQueue.erase(row[EXPERIENCE_ID].asUUID()); } //signal - signal_map_t::iterator sig_it = sSignalMap.find(public_key); - if (sig_it != sSignalMap.end()) + signal_map_t::iterator sig_it = mSignalMap.find(public_key); + if (sig_it != mSignalMap.end()) { signal_ptr signal = sig_it->second; (*signal)(experience); - sSignalMap.erase(public_key); + mSignalMap.erase(public_key); } } const LLExperienceCache::cache_t& LLExperienceCache::getCached() { - return sCache; -} - -void LLExperienceCache::setMaximumLookups(int maximumLookups) -{ - sMaximumLookups = maximumLookups; + return mCache; } - -bool LLExperienceCache::expirationFromCacheControl(LLSD headers, F64 *expires) +void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, std::string url, RequestQueue_t requests) { - // Allow the header to override the default - LLSD cache_control_header = headers["cache-control"]; - if (cache_control_header.isDefined()) - { - S32 max_age = 0; - std::string cache_control = cache_control_header.asString(); - if (max_age_from_cache_control(cache_control, &max_age)) - { - LL_WARNS("ExperienceCache") - << "got EXPIRES from headers, max_age " << max_age - << LL_ENDL; - F64 now = LLFrameTimer::getTotalSeconds(); - *expires = now + (F64)max_age; - return true; - } - } - return false; -} + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + //LL_INFOS("requestExperiencesCoro") << "url: " << url << LL_ENDL; -static const std::string MAX_AGE("max-age"); -static const boost::char_separator EQUALS_SEPARATOR("="); -static const boost::char_separator COMMA_SEPARATOR(","); + LLSD result = httpAdapter->getAndYield(httpRequest, url); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + if (!status) + { + F64 now = LLFrameTimer::getTotalSeconds(); -class LLExperienceResponder : public LLHTTPClient::Responder -{ -public: - LLExperienceResponder(const ask_queue_t& keys) - :mKeys(keys) - { - - } - - /*virtual*/ void httpCompleted() - { - LLSD experiences = getContent()["experience_keys"]; - LLSD::array_const_iterator it = experiences.beginArray(); - for( /**/ ; it != experiences.endArray(); ++it) - { - const LLSD& row = *it; - LLUUID public_key = row[EXPERIENCE_ID].asUUID(); - - - LL_DEBUGS("ExperienceCache") << "Received result for " << public_key - << " display '" << row[LLExperienceCache::NAME].asString() << "'" << LL_ENDL ; - - processExperience(public_key, row); - } - - LLSD error_ids = getContent()["error_ids"]; - LLSD::array_const_iterator errIt = error_ids.beginArray(); - for( /**/ ; errIt != error_ids.endArray() ; ++errIt ) - { - LLUUID id = errIt->asUUID(); - LLSD exp; - exp[EXPIRES]=DEFAULT_EXPIRATION; - exp[EXPERIENCE_ID] = id; - exp[PROPERTIES]=PROPERTY_INVALID; - exp[MISSING]=true; - exp[QUOTA] = DEFAULT_QUOTA; - - processExperience(id, exp); - LL_WARNS("ExperienceCache") << "LLExperienceResponder::result() error result for " << id << LL_ENDL ; - } - - LL_DEBUGS("ExperienceCache") << sCache.size() << " cached experiences" << LL_ENDL; - } - - /*virtual*/ void httpFailure() - { - LL_WARNS("ExperienceCache") << "Request failed "<first); + LLSD headers = httpResults[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_HEADERS]; + // build dummy entries for the failed requests + for (RequestQueue_t::const_iterator it = requests.begin(); it != requests.end(); ++it) + { + LLSD exp = get(*it); //leave the properties alone if we already have a cache entry for this xp - if(exp.isUndefined()) + if (exp.isUndefined()) { - exp[PROPERTIES]=PROPERTY_INVALID; + exp[PROPERTIES] = PROPERTY_INVALID; } - exp[EXPIRES]=retry_timestamp; - exp[EXPERIENCE_ID] = it->first; - exp["key_type"] = it->second; - exp["uuid"] = it->first; - exp["error"] = (LLSD::Integer)getStatus(); + exp[EXPIRES] = now + LLExperienceCacheImpl::getErrorRetryDeltaTime(status, headers); + exp[EXPERIENCE_ID] = *it; + exp["key_type"] = EXPERIENCE_ID; + exp["uuid"] = *it; + exp["error"] = (LLSD::Integer)status.getType(); exp[QUOTA] = DEFAULT_QUOTA; - LLExperienceCache::processExperience(it->first, exp); - } - - } - - // Return time to retry a request that generated an error, based on - // error type and headers. Return value is seconds-since-epoch. - F64 errorRetryTimestamp(S32 status) - { + processExperience(*it, exp); + } + return; + } - // Retry-After takes priority - LLSD retry_after = getResponseHeaders()["retry-after"]; - if (retry_after.isDefined()) - { - // We only support the delta-seconds type - S32 delta_seconds = retry_after.asInteger(); - if (delta_seconds > 0) - { - // ...valid delta-seconds - return F64(delta_seconds); - } - } + LLSD experiences = result["experience_keys"]; + + for (LLSD::array_const_iterator it = experiences.beginArray(); + it != experiences.endArray(); ++it) + { + const LLSD& row = *it; + LLUUID public_key = row[EXPERIENCE_ID].asUUID(); - // If no Retry-After, look for Cache-Control max-age - F64 expires = 0.0; - if (LLExperienceCache::expirationFromCacheControl(getResponseHeaders(), &expires)) - { - return expires; - } + LL_DEBUGS("ExperienceCache") << "Received result for " << public_key + << " display '" << row[LLExperienceCache::NAME].asString() << "'" << LL_ENDL; - // No information in header, make a guess - if (status == 503) - { - // ...service unavailable, retry soon - const F64 SERVICE_UNAVAILABLE_DELAY = 600.0; // 10 min - return SERVICE_UNAVAILABLE_DELAY; - } - else if (status == 499) - { - // ...we were probably too busy, retry quickly - const F64 BUSY_DELAY = 10.0; // 10 seconds - return BUSY_DELAY; + processExperience(public_key, row); + } - } - else - { - // ...other unexpected error - const F64 DEFAULT_DELAY = 3600.0; // 1 hour - return DEFAULT_DELAY; - } - } + LLSD error_ids = result["error_ids"]; + + for (LLSD::array_const_iterator errIt = error_ids.beginArray(); + errIt != error_ids.endArray(); ++errIt) + { + LLUUID id = errIt->asUUID(); + LLSD exp; + exp[EXPIRES] = DEFAULT_EXPIRATION; + exp[EXPERIENCE_ID] = id; + exp[PROPERTIES] = PROPERTY_INVALID; + exp[MISSING] = true; + exp[QUOTA] = DEFAULT_QUOTA; + + processExperience(id, exp); + LL_WARNS("ExperienceCache") << "LLExperienceResponder::result() error result for " << id << LL_ENDL; + } -private: - ask_queue_t mKeys; -}; +} void LLExperienceCache::requestExperiences() { - if(sAskQueue.empty() || sLookupURL.empty()) - return; - - F64 now = LLFrameTimer::getTotalSeconds(); + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } - const U32 EXP_URL_SEND_THRESHOLD = 3000; - const U32 PAGE_SIZE = EXP_URL_SEND_THRESHOLD/UUID_STR_LENGTH; + std::string urlBase = mCapability("GetExperienceInfo"); + if (urlBase.empty()) + { + LL_WARNS("ExperienceCache") << "No Experience capability." << LL_ENDL; + return; + } - std::ostringstream ostr; + if (*urlBase.rbegin() != '/') + { + urlBase += "/"; + } + urlBase += "id/"; - ask_queue_t keys; - ostr << sLookupURL << "?page_size=" << PAGE_SIZE; + F64 now = LLFrameTimer::getTotalSeconds(); - int request_count = 0; - while(!sAskQueue.empty() && request_count < sMaximumLookups) - { - ask_queue_t::iterator it = sAskQueue.begin(); - const LLUUID& key = it->first; - const std::string& key_type = it->second; + const U32 EXP_URL_SEND_THRESHOLD = 3000; + const U32 PAGE_SIZE = EXP_URL_SEND_THRESHOLD / UUID_STR_LENGTH; - ostr << '&' << key_type << '=' << key.asString() ; - - keys[key]=key_type; - request_count++; + std::ostringstream ostr; + ostr << urlBase << "?page_size=" << PAGE_SIZE; + RequestQueue_t requests; - sPendingQueue[key] = now; - - if(ostr.tellp() > EXP_URL_SEND_THRESHOLD) - { - LL_DEBUGS("ExperienceCache") << "requestExperiences() query: " << ostr.str() << LL_ENDL; - LLHTTPClient::get(ostr.str(), new LLExperienceResponder(keys)); - ostr.clear(); - ostr.str(sLookupURL); - ostr << "?page_size=" << PAGE_SIZE; - keys.clear(); - } - sAskQueue.erase(it); - } + while (!mRequestQueue.empty()) + { + RequestQueue_t::iterator it = mRequestQueue.begin(); + LLUUID key = (*it); + mRequestQueue.erase(it); + requests.insert(key); + + ostr << "&" << EXPERIENCE_ID << "=" << key.asString(); + mPendingQueue[key] = now; + + if (mRequestQueue.empty() || (ostr.tellp() > EXP_URL_SEND_THRESHOLD)) + { // request is placed in the coprocedure pool for the ExpCache cache. Throttling is done by the pool itself. + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Request", + boost::bind(&LLExperienceCache::requestExperiencesCoro, this, _1, ostr.str(), requests) ); + + ostr.str(std::string()); + ostr << urlBase << "?page_size=" << PAGE_SIZE; + requests.clear(); + } + } - if(ostr.tellp() > sLookupURL.size()) - { - LL_DEBUGS("ExperienceCache") << "requestExperiences() query 2: " << ostr.str() << LL_ENDL; - LLHTTPClient::get(ostr.str(), new LLExperienceResponder(keys)); - } } @@ -427,9 +373,9 @@ bool LLExperienceCache::isRequestPending(const LLUUID& public_key) bool isPending = false; const F64 PENDING_TIMEOUT_SECS = 5.0 * 60.0; - pending_queue_t::const_iterator it = sPendingQueue.find(public_key); + PendingQueue_t::const_iterator it = mPendingQueue.find(public_key); - if(it != sPendingQueue.end()) + if(it != mPendingQueue.end()) { F64 expire_time = LLFrameTimer::getTotalSeconds() - PENDING_TIMEOUT_SECS; isPending = (it->second > expire_time); @@ -438,69 +384,70 @@ bool LLExperienceCache::isRequestPending(const LLUUID& public_key) return isPending; } - -void LLExperienceCache::setLookupURL(const std::string& lookup_url) +void LLExperienceCache::setCapabilityQuery(LLExperienceCache::CapabilityQuery_t queryfn) { - sLookupURL = lookup_url; - if(!sLookupURL.empty()) - { - sLookupURL += "id/"; - } + mCapability = queryfn; } -bool LLExperienceCache::hasLookupURL() -{ - return !sLookupURL.empty(); -} -void LLExperienceCache::idle() +void LLExperienceCache::idleCoro() { - const F32 SECS_BETWEEN_REQUESTS = 0.1f; - if (!sRequestTimer.checkExpirationAndReset(SECS_BETWEEN_REQUESTS)) - { - return; - } + const F32 SECS_BETWEEN_REQUESTS = 0.5f; + const F32 ERASE_EXPIRED_TIMEOUT = 60.f; // seconds - // Must be large relative to above - const F32 ERASE_EXPIRED_TIMEOUT = 60.f; // seconds - if (sEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) - { - eraseExpired(); - } + LL_INFOS("ExperienceCache") << "Launching Experience cache idle coro." << LL_ENDL; + LLEventTimeout timeout; - if(!sAskQueue.empty()) - { - requestExperiences(); - } + do + { + timeout.eventAfter(SECS_BETWEEN_REQUESTS, LLSD()); + llcoro::waitForEventOn(timeout); + + if (mEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) + { + eraseExpired(); + } + + if (!mRequestQueue.empty()) + { + requestExperiences(); + } + + } while (!mShutdown); + + // The coroutine system will likely be shut down by the time we get to this point + // (or at least no further cycling will occur on it since the user has decided to quit.) } void LLExperienceCache::erase(const LLUUID& key) { - cache_t::iterator it = sCache.find(key); + cache_t::iterator it = mCache.find(key); - if(it != sCache.end()) + if(it != mCache.end()) { - sCache.erase(it); + mCache.erase(it); } } void LLExperienceCache::eraseExpired() { F64 now = LLFrameTimer::getTotalSeconds(); - cache_t::iterator it = sCache.begin(); - while (it != sCache.end()) + cache_t::iterator it = mCache.begin(); + while (it != mCache.end()) { cache_t::iterator cur = it; LLSD& exp = cur->second; ++it; + //LL_INFOS("ExperienceCache") << "Testing experience \"" << exp[NAME] << "\" with exp time " << exp[EXPIRES].asReal() << "(now = " << now << ")" << LL_ENDL; + if(exp.has(EXPIRES) && exp[EXPIRES].asReal() < now) { if(!exp.has(EXPERIENCE_ID)) { LL_WARNS("ExperienceCache") << "Removing experience with no id " << LL_ENDL ; - sCache.erase(cur); - } + mCache.erase(cur); + } else { LLUUID id = exp[EXPERIENCE_ID].asUUID(); @@ -512,7 +459,7 @@ void LLExperienceCache::eraseExpired() else { LL_WARNS("ExperienceCache") << "Removing invalid experience " << id << LL_ENDL ; - sCache.erase(cur); + mCache.erase(cur); } } } @@ -521,11 +468,11 @@ void LLExperienceCache::eraseExpired() bool LLExperienceCache::fetch(const LLUUID& key, bool refresh/* = true*/) { - if(!key.isNull() && !isRequestPending(key) && (refresh || sCache.find(key)==sCache.end())) + if(!key.isNull() && !isRequestPending(key) && (refresh || mCache.find(key)==mCache.end())) { - LL_DEBUGS("ExperienceCache") << " queue request for " << EXPERIENCE_ID << " " << key << LL_ENDL ; - sAskQueue[key]=EXPERIENCE_ID; + LL_DEBUGS("ExperienceCache") << " queue request for " << EXPERIENCE_ID << " " << key << LL_ENDL; + mRequestQueue.insert(key); return true; } return false; @@ -549,13 +496,12 @@ const LLSD& LLExperienceCache::get(const LLUUID& key) if(key.isNull()) return empty; - cache_t::const_iterator it = sCache.find(key); + cache_t::const_iterator it = mCache.find(key); - if (it != sCache.end()) + if (it != mCache.end()) { return it->second; } - fetch(key); return empty; @@ -565,8 +511,8 @@ void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::Callback_t slo if(key.isNull()) return; - cache_t::const_iterator it = sCache.find(key); - if (it != sCache.end()) + cache_t::const_iterator it = mCache.find(key); + if (it != mCache.end()) { // ...name already exists in cache, fire callback now callback_signal_t signal; @@ -580,28 +526,10 @@ void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::Callback_t slo signal_ptr signal = signal_ptr(new callback_signal_t()); - std::pair result = sSignalMap.insert(signal_map_t::value_type(key, signal)); + std::pair result = mSignalMap.insert(signal_map_t::value_type(key, signal)); if (!result.second) - signal = result.first.second; + signal = (*result.first).second; signal->connect(slot); - -#if 0 - // always store additional callback, even if request is pending - signal_map_t::iterator sig_it = sSignalMap.find(key); - if (sig_it == sSignalMap.end()) - { - // ...new callback for this id - signal_ptr signal = signal_ptr(new callback_signal_t()); - signal->connect(slot); - sSignalMap[key] = signal; - } - else - { - // ...existing callback, bind additional slot - callback_signal_t* signal = sig_it->second; - signal->connect(slot); - } -#endif } //========================================================================= @@ -610,14 +538,71 @@ void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys) LLSD::array_const_iterator exp = legacyKeys.beginArray(); for (/**/; exp != legacyKeys.endArray(); ++exp) { - if (exp->has(LLExperienceCache::EXPERIENCE_ID) && exp->has(LLExperienceCache::PRIVATE_KEY)) + if (exp->has(LLExperienceCacheImpl::EXPERIENCE_ID) && exp->has(LLExperienceCacheImpl::PRIVATE_KEY)) { - privateToPublicKeyMap[(*exp)[LLExperienceCache::PRIVATE_KEY].asUUID()] = (*exp)[LLExperienceCache::EXPERIENCE_ID].asUUID(); + LLExperienceCacheImpl::privateToPublicKeyMap[(*exp)[LLExperienceCacheImpl::PRIVATE_KEY].asUUID()] = + (*exp)[LLExperienceCacheImpl::EXPERIENCE_ID].asUUID(); } } } -bool LLExperienceCacheImpl::max_age_from_cache_control(const std::string& cache_control, S32 *max_age) +// Return time to retry a request that generated an error, based on +// error type and headers. Return value is seconds-since-epoch. +F64 LLExperienceCacheImpl::getErrorRetryDeltaTime(S32 status, LLSD headers) +{ + + // Retry-After takes priority + LLSD retry_after = headers["retry-after"]; + if (retry_after.isDefined()) + { + // We only support the delta-seconds type + S32 delta_seconds = retry_after.asInteger(); + if (delta_seconds > 0) + { + // ...valid delta-seconds + return F64(delta_seconds); + } + } + + // If no Retry-After, look for Cache-Control max-age + // Allow the header to override the default + LLSD cache_control_header = headers["cache-control"]; + if (cache_control_header.isDefined()) + { + S32 max_age = 0; + std::string cache_control = cache_control_header.asString(); + if (LLExperienceCacheImpl::maxAgeFromCacheControl(cache_control, &max_age)) + { + LL_WARNS("ExperienceCache") + << "got EXPIRES from headers, max_age " << max_age + << LL_ENDL; + return (F64)max_age; + } + } + + // No information in header, make a guess + if (status == 503) + { + // ...service unavailable, retry soon + const F64 SERVICE_UNAVAILABLE_DELAY = 600.0; // 10 min + return SERVICE_UNAVAILABLE_DELAY; + } + else if (status == 499) + { + // ...we were probably too busy, retry quickly + const F64 BUSY_DELAY = 10.0; // 10 seconds + return BUSY_DELAY; + + } + else + { + // ...other unexpected error + const F64 DEFAULT_DELAY = 3600.0; // 1 hour + return DEFAULT_DELAY; + } +} + +bool LLExperienceCacheImpl::maxAgeFromCacheControl(const std::string& cache_control, S32 *max_age) { // Split the string on "," to get a list of directives typedef boost::tokenizer > tokenizer; -- cgit v1.2.3 From 6c9610b4e44020bf266a5da7375fb9f2b24f4f8a Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 2 Sep 2015 11:50:26 -0700 Subject: Move associated experience fetching into the ExperienceCache as a coro remove the responder. --- indra/llmessage/llexperiencecache.cpp | 63 +++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 36a4fc8823..b65a3c59d5 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -356,7 +356,7 @@ void LLExperienceCache::requestExperiences() if (mRequestQueue.empty() || (ostr.tellp() > EXP_URL_SEND_THRESHOLD)) { // request is placed in the coprocedure pool for the ExpCache cache. Throttling is done by the pool itself. - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Request", + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "RequestExperiences", boost::bind(&LLExperienceCache::requestExperiencesCoro, this, _1, ostr.str(), requests) ); ostr.str(std::string()); @@ -506,7 +506,8 @@ const LLSD& LLExperienceCache::get(const LLUUID& key) return empty; } -void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::Callback_t slot) + +void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::ExperienceGetFn_t slot) { if(key.isNull()) return; @@ -532,6 +533,64 @@ void LLExperienceCache::get(const LLUUID& key, LLExperienceCache::Callback_t slo signal->connect(slot); } +//========================================================================= +void LLExperienceCache::fetchAssociatedExperience(const LLUUID& objectId, const LLUUID& itemId, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Fetch Associated", + boost::bind(&LLExperienceCache::fetchAssociatedExperienceCoro, this, _1, objectId, itemId, fn)); +} + +void LLExperienceCache::fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID objectId, LLUUID itemId, ExperienceGetFn_t fn) +{ + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + std::string url = mCapability("GetMetadata"); + if (url.empty()) + { + LL_WARNS("ExperienceCache") << "No Metadata capability." << LL_ENDL; + return; + } + + LLSD fields; + fields.append("experience"); + LLSD data; + data["object-id"] = objectId; + data["item-id"] = itemId; + data["fields"] = fields; + + LLSD result = httpAdapter->postAndYield(httpRequest, url, data); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if ((!status) || (!result.has("experience"))) + { + LLSD failure; + if (!status) + { + failure["error"] = (LLSD::Integer)status.getType(); + failure["message"] = status.getMessage(); + } + else + { + failure["error"] = -1; + failure["message"] = "no experience"; + } + if (fn && !fn.empty()) + fn(failure); + return; + } + + LLUUID expId = result["experience"].asUUID(); + get(expId, fn); +} + //========================================================================= void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys) { -- cgit v1.2.3 From 346f885473282a2826699c1d2c7dd624d60a1bf3 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 2 Sep 2015 15:16:37 -0700 Subject: Moved find experience into experience cache (moved cache recording into cache and out of UI) changed from responder to coroutine. --- indra/llmessage/llexperiencecache.cpp | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index b65a3c59d5..29ca0b2820 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -84,6 +84,7 @@ const int LLExperienceCache::PROPERTY_SUSPENDED = 1 << 7; // default values const F64 LLExperienceCache::DEFAULT_EXPIRATION = 600.0; const S32 LLExperienceCache::DEFAULT_QUOTA = 128; // this is megabytes +const int LLExperienceCache::SEARCH_PAGE_SIZE = 30; //========================================================================= LLExperienceCache::LLExperienceCache(): @@ -549,8 +550,8 @@ void LLExperienceCache::fetchAssociatedExperience(const LLUUID& objectId, const void LLExperienceCache::fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID objectId, LLUUID itemId, ExperienceGetFn_t fn) { LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); - std::string url = mCapability("GetMetadata"); + if (url.empty()) { LL_WARNS("ExperienceCache") << "No Metadata capability." << LL_ENDL; @@ -591,6 +592,49 @@ void LLExperienceCache::fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCorout get(expId, fn); } +//------------------------------------------------------------------------- +void LLExperienceCache::findExperienceByName(const std::string text, int page, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Search Name", + boost::bind(&LLExperienceCache::findExperienceByNameCoro, this, _1, text, page, fn)); +} + +void LLExperienceCache::findExperienceByNameCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, std::string text, int page, ExperienceGetFn_t fn) +{ + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + std::ostringstream url; + + + url << mCapability("FindExperienceByName") << "?page=" << page << "&page_size=" << SEARCH_PAGE_SIZE << "&query=" << LLURI::escape(text); + + LLSD result = httpAdapter->getAndYield(httpRequest, url.str()); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + fn(LLSD()); + return; + } + + result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS); + + const LLSD& experiences = result["experience_keys"]; + for (LLSD::array_const_iterator it = experiences.beginArray(); it != experiences.endArray(); ++it) + { + insert(*it); + } + + fn(result); +} + //========================================================================= void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys) { -- cgit v1.2.3 From c08072a0508cefc6bfc8c05937e984a095f323ce Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 3 Sep 2015 11:10:32 -0700 Subject: Moved group experiences into experience cache. Use coros and new HTTP libs. --- indra/llmessage/llexperiencecache.cpp | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 29ca0b2820..233b15dcdd 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -635,6 +635,47 @@ void LLExperienceCache::findExperienceByNameCoro(LLCoreHttpUtil::HttpCoroutineAd fn(result); } +//------------------------------------------------------------------------- +void LLExperienceCache::getGroupExperiences(const LLUUID &groupId, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Group Experiences", + boost::bind(&LLExperienceCache::getGroupExperiencesCoro, this, _1, groupId, fn)); +} + +void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID groupId, ExperienceGetFn_t fn) +{ + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + // search for experiences owned by the current group + std::string url = mCapability("GroupExperiences"); + if (url.empty()) + { + LL_WARNS("ExperienceCache") << "No Group Experiences capability" << LL_ENDL; + } + + url += "?" + groupId.asString(); + + LLSD result = httpAdapter->getAndYield(httpRequest, url); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + fn(LLSD()); + return; + } + + const LLSD& experienceIds = result["experience_ids"]; + fn(experienceIds); +} + //========================================================================= void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys) { -- cgit v1.2.3 From ec998b4c6efee0ddba48481dfba630e18c53a29c Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 3 Sep 2015 16:14:40 -0700 Subject: Region experience allow/disallow. --- indra/llmessage/llexperiencecache.cpp | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 233b15dcdd..af0bae0228 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -657,6 +657,7 @@ void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAda if (url.empty()) { LL_WARNS("ExperienceCache") << "No Group Experiences capability" << LL_ENDL; + return; } url += "?" + groupId.asString(); @@ -676,6 +677,52 @@ void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAda fn(experienceIds); } +//------------------------------------------------------------------------- +void LLExperienceCache::getRegionExperiences(CapabilityQuery_t regioncaps, ExperienceGetFn_t fn) +{ + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Region Experiences", + boost::bind(&LLExperienceCache::regionExperiencesCoro, this, _1, regioncaps, false, LLSD(), fn)); +} + +void LLExperienceCache::setRegionExperiences(CapabilityQuery_t regioncaps, const LLSD &experiences, ExperienceGetFn_t fn) +{ + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Region Experiences", + boost::bind(&LLExperienceCache::regionExperiencesCoro, this, _1, regioncaps, true, experiences, fn)); +} + +void LLExperienceCache::regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, + CapabilityQuery_t regioncaps, bool update, LLSD experiences, ExperienceGetFn_t fn) +{ + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + // search for experiences owned by the current group + std::string url = regioncaps("RegionExperiences"); + if (url.empty()) + { + LL_WARNS("ExperienceCache") << "No Region Experiences capability" << LL_ENDL; + return; + } + + LLSD result; + if (update) + result = httpAdapter->postAndYield(httpRequest, url, experiences); + else + result = httpAdapter->getAndYield(httpRequest, url); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { +// fn(LLSD()); + return; + } + + result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS); + fn(result); + +} + //========================================================================= void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys) { -- cgit v1.2.3 From a471ae72e4b48a12cfeeba544afde9d078428f0d Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 4 Sep 2015 13:13:16 -0700 Subject: Experience Profile to coroutines and Experience cache. --- indra/llmessage/llexperiencecache.cpp | 163 ++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index af0bae0228..0fd6836948 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -723,6 +723,169 @@ void LLExperienceCache::regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapt } +//------------------------------------------------------------------------- +void LLExperienceCache::getExperiencePermission(const LLUUID &experienceId, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + std::string url = mCapability("ExperiencePreferences") + "?" + experienceId.asString(); + + permissionInvoker_fn invoker(boost::bind( + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. + static_cast + //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndYield), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); + + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", + boost::bind(&LLExperienceCache::experiencePermissionCoro, this, _1, invoker, url, fn)); +} + +void LLExperienceCache::setExperiencePermission(const LLUUID &experienceId, const std::string &permission, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + std::string url = mCapability("ExperiencePreferences"); + if (url.empty()) + return; + LLSD permData; + LLSD data; + permData["permission"] = permission; + data[experienceId.asString()] = permData; + + permissionInvoker_fn invoker(boost::bind( + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. + static_cast + //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndYield), _1, _2, _3, data, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); + + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", + boost::bind(&LLExperienceCache::experiencePermissionCoro, this, _1, invoker, url, fn)); +} + +void LLExperienceCache::forgetExperiencePermission(const LLUUID &experienceId, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + std::string url = mCapability("ExperiencePreferences") + "?" + experienceId.asString(); + + + permissionInvoker_fn invoker(boost::bind( + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. + static_cast + //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); + + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", + boost::bind(&LLExperienceCache::experiencePermissionCoro, this, _1, invoker, url, fn)); +} + +void LLExperienceCache::experiencePermissionCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, permissionInvoker_fn invokerfn, std::string url, ExperienceGetFn_t fn) +{ + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + // search for experiences owned by the current group + + LLSD result = invokerfn(httpAdapter, httpRequest, url); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS); + + if (status) + { + fn(result); + } +} + +//------------------------------------------------------------------------- +void LLExperienceCache::getExperienceAdmin(const LLUUID &experienceId, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "IsAdmin", + boost::bind(&LLExperienceCache::getExperienceAdminCoro, this, _1, experienceId, fn)); +} + +void LLExperienceCache::getExperienceAdminCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID experienceId, ExperienceGetFn_t fn) +{ + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + std::string url = mCapability("IsExperienceAdmin"); + if (url.empty()) + { + LL_WARNS("ExperienceCache") << "No Region Experiences capability" << LL_ENDL; + return; + } + url += "?experience_id=" + experienceId.asString(); + + LLSD result = httpAdapter->getAndYield(httpRequest, url); +// LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; +// LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + fn(result); +} + +//------------------------------------------------------------------------- +void LLExperienceCache::updateExperience(LLSD updateData, ExperienceGetFn_t fn) +{ + if (mCapability.empty()) + { + LL_WARNS("ExperienceCache") << "Capability query method not set." << LL_ENDL; + return; + } + + LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "IsAdmin", + boost::bind(&LLExperienceCache::updateExperienceCoro, this, _1, updateData, fn)); +} + +void LLExperienceCache::updateExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLSD updateData, ExperienceGetFn_t fn) +{ + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + std::string url = mCapability("UpdateExperience"); + if (url.empty()) + { + LL_WARNS("ExperienceCache") << "No Region Experiences capability" << LL_ENDL; + return; + } + + updateData.erase(LLExperienceCache::QUOTA); + updateData.erase(LLExperienceCache::EXPIRES); + updateData.erase(LLExperienceCache::AGENT_ID); + + LLSD result = httpAdapter->postAndYield(httpRequest, url, updateData); + + fn(result); +} + //========================================================================= void LLExperienceCacheImpl::mapKeys(const LLSD& legacyKeys) { -- cgit v1.2.3 From 97236a42ca08979897d5c7b0826312345754cd67 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Mon, 14 Sep 2015 11:15:23 -0700 Subject: MAINT-5507: Remove HTTPClient and related cruft. --- indra/llmessage/llexperiencecache.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 0fd6836948..ff5f7e793d 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -26,7 +26,6 @@ #include "llexperiencecache.h" #include "llavatarname.h" -#include "llhttpclient.h" #include "llsdserialize.h" #include "llcoros.h" #include "lleventcoro.h" -- cgit v1.2.3 From 75c6549fde060e974c90636685962ee373f94202 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 18 Sep 2015 11:39:22 -0700 Subject: Set consistent terminology for yield/wait -> suspend for coroutines. --- indra/llmessage/llexperiencecache.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index ff5f7e793d..3265608582 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -248,7 +248,7 @@ void LLExperienceCache::requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdap //LL_INFOS("requestExperiencesCoro") << "url: " << url << LL_ENDL; - LLSD result = httpAdapter->getAndYield(httpRequest, url); + LLSD result = httpAdapter->getAndSuspend(httpRequest, url); LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); @@ -401,7 +401,7 @@ void LLExperienceCache::idleCoro() do { timeout.eventAfter(SECS_BETWEEN_REQUESTS, LLSD()); - llcoro::waitForEventOn(timeout); + llcoro::suspendUntilEventOn(timeout); if (mEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) { @@ -564,7 +564,7 @@ void LLExperienceCache::fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCorout data["item-id"] = itemId; data["fields"] = fields; - LLSD result = httpAdapter->postAndYield(httpRequest, url, data); + LLSD result = httpAdapter->postAndSuspend(httpRequest, url, data); LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); @@ -612,7 +612,7 @@ void LLExperienceCache::findExperienceByNameCoro(LLCoreHttpUtil::HttpCoroutineAd url << mCapability("FindExperienceByName") << "?page=" << page << "&page_size=" << SEARCH_PAGE_SIZE << "&query=" << LLURI::escape(text); - LLSD result = httpAdapter->getAndYield(httpRequest, url.str()); + LLSD result = httpAdapter->getAndSuspend(httpRequest, url.str()); LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); @@ -661,7 +661,7 @@ void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAda url += "?" + groupId.asString(); - LLSD result = httpAdapter->getAndYield(httpRequest, url); + LLSD result = httpAdapter->getAndSuspend(httpRequest, url); LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); @@ -704,9 +704,9 @@ void LLExperienceCache::regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapt LLSD result; if (update) - result = httpAdapter->postAndYield(httpRequest, url, experiences); + result = httpAdapter->postAndSuspend(httpRequest, url, experiences); else - result = httpAdapter->getAndYield(httpRequest, url); + result = httpAdapter->getAndSuspend(httpRequest, url); LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); @@ -740,7 +740,7 @@ void LLExperienceCache::getExperiencePermission(const LLUUID &experienceId, Expe // _1 -> httpAdapter // _2 -> httpRequest // _3 -> url - (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndYield), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); + (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", @@ -770,7 +770,7 @@ void LLExperienceCache::setExperiencePermission(const LLUUID &experienceId, cons // _1 -> httpAdapter // _2 -> httpRequest // _3 -> url - (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndYield), _1, _2, _3, data, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); + (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndSuspend), _1, _2, _3, data, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", @@ -795,7 +795,7 @@ void LLExperienceCache::forgetExperiencePermission(const LLUUID &experienceId, E // _1 -> httpAdapter // _2 -> httpRequest // _3 -> url - (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", @@ -845,7 +845,7 @@ void LLExperienceCache::getExperienceAdminCoro(LLCoreHttpUtil::HttpCoroutineAdap } url += "?experience_id=" + experienceId.asString(); - LLSD result = httpAdapter->getAndYield(httpRequest, url); + LLSD result = httpAdapter->getAndSuspend(httpRequest, url); // LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; // LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); @@ -880,7 +880,7 @@ void LLExperienceCache::updateExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapte updateData.erase(LLExperienceCache::EXPIRES); updateData.erase(LLExperienceCache::AGENT_ID); - LLSD result = httpAdapter->postAndYield(httpRequest, url, updateData); + LLSD result = httpAdapter->postAndSuspend(httpRequest, url, updateData); fn(result); } -- cgit v1.2.3 From cf835a80cd2bb5d02cc03034009919e0d9eb73b6 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 18 Sep 2015 16:36:49 -0700 Subject: Pref instance() over getInstance() --- indra/llmessage/llexperiencecache.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 3265608582..92fcd38d3b 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -356,7 +356,7 @@ void LLExperienceCache::requestExperiences() if (mRequestQueue.empty() || (ostr.tellp() > EXP_URL_SEND_THRESHOLD)) { // request is placed in the coprocedure pool for the ExpCache cache. Throttling is done by the pool itself. - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "RequestExperiences", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "RequestExperiences", boost::bind(&LLExperienceCache::requestExperiencesCoro, this, _1, ostr.str(), requests) ); ostr.str(std::string()); @@ -542,7 +542,7 @@ void LLExperienceCache::fetchAssociatedExperience(const LLUUID& objectId, const return; } - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Fetch Associated", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Fetch Associated", boost::bind(&LLExperienceCache::fetchAssociatedExperienceCoro, this, _1, objectId, itemId, fn)); } @@ -600,7 +600,7 @@ void LLExperienceCache::findExperienceByName(const std::string text, int page, E return; } - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Search Name", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Search Name", boost::bind(&LLExperienceCache::findExperienceByNameCoro, this, _1, text, page, fn)); } @@ -643,7 +643,7 @@ void LLExperienceCache::getGroupExperiences(const LLUUID &groupId, ExperienceGet return; } - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Group Experiences", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Group Experiences", boost::bind(&LLExperienceCache::getGroupExperiencesCoro, this, _1, groupId, fn)); } @@ -679,13 +679,13 @@ void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAda //------------------------------------------------------------------------- void LLExperienceCache::getRegionExperiences(CapabilityQuery_t regioncaps, ExperienceGetFn_t fn) { - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Region Experiences", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Region Experiences", boost::bind(&LLExperienceCache::regionExperiencesCoro, this, _1, regioncaps, false, LLSD(), fn)); } void LLExperienceCache::setRegionExperiences(CapabilityQuery_t regioncaps, const LLSD &experiences, ExperienceGetFn_t fn) { - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Region Experiences", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Region Experiences", boost::bind(&LLExperienceCache::regionExperiencesCoro, this, _1, regioncaps, true, experiences, fn)); } @@ -743,7 +743,7 @@ void LLExperienceCache::getExperiencePermission(const LLUUID &experienceId, Expe (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Preferences Set", boost::bind(&LLExperienceCache::experiencePermissionCoro, this, _1, invoker, url, fn)); } @@ -773,7 +773,7 @@ void LLExperienceCache::setExperiencePermission(const LLUUID &experienceId, cons (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndSuspend), _1, _2, _3, data, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Preferences Set", boost::bind(&LLExperienceCache::experiencePermissionCoro, this, _1, invoker, url, fn)); } @@ -798,7 +798,7 @@ void LLExperienceCache::forgetExperiencePermission(const LLUUID &experienceId, E (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, LLCore::HttpOptions::ptr_t(), LLCore::HttpHeaders::ptr_t())); - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "Preferences Set", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "Preferences Set", boost::bind(&LLExperienceCache::experiencePermissionCoro, this, _1, invoker, url, fn)); } @@ -829,7 +829,7 @@ void LLExperienceCache::getExperienceAdmin(const LLUUID &experienceId, Experienc return; } - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "IsAdmin", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "IsAdmin", boost::bind(&LLExperienceCache::getExperienceAdminCoro, this, _1, experienceId, fn)); } @@ -861,7 +861,7 @@ void LLExperienceCache::updateExperience(LLSD updateData, ExperienceGetFn_t fn) return; } - LLCoprocedureManager::getInstance()->enqueueCoprocedure("ExpCache", "IsAdmin", + LLCoprocedureManager::instance().enqueueCoprocedure("ExpCache", "IsAdmin", boost::bind(&LLExperienceCache::updateExperienceCoro, this, _1, updateData, fn)); } -- cgit v1.2.3 From 2763bbd97519d35a43aedf279751e7b1045581dc Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 4 Dec 2015 14:27:22 -0800 Subject: Initial changes for Vivox/Azumarill merge. Lots of temporary code and conditional compile switches. Begin switch from statemachine to coroutine. --- indra/llmessage/llexperiencecache.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'indra/llmessage/llexperiencecache.cpp') diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp index 92fcd38d3b..779d1d9d99 100644 --- a/indra/llmessage/llexperiencecache.cpp +++ b/indra/llmessage/llexperiencecache.cpp @@ -396,12 +396,9 @@ void LLExperienceCache::idleCoro() const F32 ERASE_EXPIRED_TIMEOUT = 60.f; // seconds LL_INFOS("ExperienceCache") << "Launching Experience cache idle coro." << LL_ENDL; - LLEventTimeout timeout; - do { - timeout.eventAfter(SECS_BETWEEN_REQUESTS, LLSD()); - llcoro::suspendUntilEventOn(timeout); + llcoro::suspendUntilTimeout(SECS_BETWEEN_REQUESTS); if (mEraseExpiredTimer.checkExpirationAndReset(ERASE_EXPIRED_TIMEOUT)) { -- cgit v1.2.3