From c07901e29ed545bbb02e3bddf148fe1104b94e9f Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:56 -0500 Subject: Second Life viewer sources 1.15.1.3 --- linden/indra/llmessage/llcachename.cpp | 95 ++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 16 deletions(-) (limited to 'linden/indra/llmessage/llcachename.cpp') diff --git a/linden/indra/llmessage/llcachename.cpp b/linden/indra/llmessage/llcachename.cpp index 5df62b3..1cc7e09 100644 --- a/linden/indra/llmessage/llcachename.cpp +++ b/linden/indra/llmessage/llcachename.cpp @@ -52,6 +52,10 @@ const char* CN_NONE = "(none)"; const char* CN_HIPPOS = "(hippos)"; const F32 HIPPO_PROBABILITY = 0.01f; +// We track name requests in flight for up to this long. +// We won't re-request a name during this time +const U32 PENDING_TIMEOUT_SECS = 5 * 60; + // File version number const S32 CN_FILE_VERSION = 2; @@ -182,8 +186,9 @@ namespace { } - typedef std::vector AskQueue; + typedef std::set AskQueue; typedef std::vector ReplyQueue; + typedef std::map PendingQueue; typedef std::map Cache; typedef std::vector Observers; }; @@ -200,6 +205,9 @@ public: AskQueue mAskNameQueue; AskQueue mAskGroupQueue; // UUIDs to ask our upstream host about + + PendingQueue mPendingQueue; + // UUIDs that have been requested but are not in cache yet. ReplyQueue mReplyQueue; // requests awaiting replies from us @@ -214,6 +222,7 @@ public: void processPendingAsks(); void processPendingReplies(); void sendRequest(const char* msg_name, const AskQueue& queue); + bool isRequestPending(const LLUUID& id); // Message system callbacks. void processUUIDRequest(LLMessageSystem* msg, bool isGroup); @@ -456,7 +465,10 @@ BOOL LLCacheName::getName(const LLUUID& id, char* first, char* last) : CN_WAITING); strcpy(last, ""); /*Flawfinder: ignore*/ - impl.mAskNameQueue.push_back(id); + if (!impl.isRequestPending(id)) + { + impl.mAskNameQueue.insert(id); + } return FALSE; } @@ -496,8 +508,10 @@ BOOL LLCacheName::getGroupName(const LLUUID& id, char* group) // The function signature needs to change to pass in the length // of first and last. strcpy(group, CN_WAITING); /*Flawfinder: ignore*/ - - impl.mAskGroupQueue.push_back(id); + if (!impl.isRequestPending(id)) + { + impl.mAskGroupQueue.insert(id); + } return FALSE; } } @@ -525,13 +539,16 @@ void LLCacheName::get(const LLUUID& id, BOOL is_group, LLCacheNameCallback callb } else { - if (!is_group) - { - impl.mAskNameQueue.push_back(id); - } - else + if (!impl.isRequestPending(id)) { - impl.mAskGroupQueue.push_back(id); + if (!is_group) + { + impl.mAskNameQueue.insert(id); + } + else + { + impl.mAskGroupQueue.insert(id); + } } impl.mReplyQueue.push_back(PendingReply(id, callback, user_data)); } @@ -570,6 +587,19 @@ void LLCacheName::deleteEntriesOlderThan(S32 secs) impl.mCache.erase(curiter); } } + + // These are pending requests that we never heard back from. + U32 pending_expire_time = now - PENDING_TIMEOUT_SECS; + for(PendingQueue::iterator p_iter = impl.mPendingQueue.begin(); + p_iter != impl.mPendingQueue.end(); ) + { + PendingQueue::iterator p_curitor = p_iter++; + + if (p_curitor->second < pending_expire_time) + { + impl.mPendingQueue.erase(p_curitor); + } + } } @@ -599,6 +629,18 @@ void LLCacheName::dump() } } +void LLCacheName::dumpStats() +{ + llinfos << "Queue sizes: " + << " Cache=" << impl.mCache.size() + << " AskName=" << impl.mAskNameQueue.size() + << " AskGroup=" << impl.mAskGroupQueue.size() + << " Pending=" << impl.mPendingQueue.size() + << " Reply=" << impl.mReplyQueue.size() + << " Observers=" << impl.mObservers.size() + << llendl; +} + void LLCacheName::Impl::processPendingAsks() { sendRequest(_PREHASH_UUIDNameRequest, mAskNameQueue); @@ -702,7 +744,23 @@ void LLCacheName::Impl::notifyObservers(const LLUUID& id, } } +bool LLCacheName::Impl::isRequestPending(const LLUUID& id) +{ + U32 now = (U32)time(NULL); + U32 expire_time = now - PENDING_TIMEOUT_SECS; + PendingQueue::iterator iter = mPendingQueue.find(id); + + if (iter == mPendingQueue.end() + || (iter->second < expire_time) ) + { + mPendingQueue[id] = now; + return false; + } + + return true; +} + void LLCacheName::Impl::processUUIDRequest(LLMessageSystem* msg, bool isGroup) { // You should only get this message if the cache is at the simulator @@ -740,13 +798,16 @@ void LLCacheName::Impl::processUUIDRequest(LLMessageSystem* msg, bool isGroup) } else { - if (isGroup) + if (!isRequestPending(id)) { - mAskGroupQueue.push_back(id); - } - else - { - mAskNameQueue.push_back(id); + if (isGroup) + { + mAskGroupQueue.insert(id); + } + else + { + mAskNameQueue.insert(id); + } } mReplyQueue.push_back(PendingReply(id, fromHost)); @@ -770,6 +831,8 @@ void LLCacheName::Impl::processUUIDReply(LLMessageSystem* msg, bool isGroup) mCache[id] = entry; } + mPendingQueue.erase(id); + entry->mIsGroup = isGroup; entry->mCreateTime = (U32)time(NULL); if (!isGroup) -- cgit v1.1