covered situation in which cache entries are invalidated when messages expire

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-cacheopt@4459 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2011-07-17 22:25:41 +00:00
parent c1a9ed9e25
commit bea5f2250f
2 changed files with 69 additions and 5 deletions

View file

@ -476,6 +476,54 @@ void p3GroupDistrib::updateCacheDocument()
return; return;
} }
struct by_cacheid
{
bool operator()(pugi::xml_node node) const
{
bool cachIdEqual = true;
cachIdEqual &= (node.child_value("subId") == subId);
cachIdEqual &= (node.child_value("pId") == peerId);
return cachIdEqual;
}
std::string peerId;
std::string subId;
};
void p3GroupDistrib::locked_removeCacheTableEntry(const pCacheId& pCid)
{
// search through cache document for all entries with this cache id
pugi::xml_node_iterator nit = mCacheDoc.begin();
by_cacheid bCid;
bCid.peerId = pCid.first;
char subIdBuffer[6];
std::string subId;
sprintf(subIdBuffer, "%d", pCid.second);
subId = subIdBuffer;
bCid.subId = subId;
// for each grp, remove message nodes that match pCid
for(; nit != mCacheDoc.end(); nit++)
{
pugi::xml_node msgNode = nit->child("messages");
if(msgNode)
{
while(pugi::xml_node cNode= msgNode.find_child(bCid))
{
msgNode.remove_child(cNode);
}
}
}
locked_buildCacheTable();
return;
}
void p3GroupDistrib::locked_updateCacheTableGrp(const std::vector<grpNodePair>& grpNodes, bool historical) void p3GroupDistrib::locked_updateCacheTableGrp(const std::vector<grpNodePair>& grpNodes, bool historical)
{ {
@ -553,6 +601,7 @@ bool p3GroupDistrib::locked_historyCached(const std::string& grpId, bool& cached
std::map<std::string, nodeCache>::iterator cit; std::map<std::string, nodeCache>::iterator cit;
if(mCacheTable.end() != (cit = mCacheTable.find(grpId))) if(mCacheTable.end() != (cit = mCacheTable.find(grpId)))
{ {
cached = cit->second.cached; cached = cit->second.cached;
return true; return true;
} }
@ -561,6 +610,8 @@ bool p3GroupDistrib::locked_historyCached(const std::string& grpId, bool& cached
return false; return false;
} }
bool p3GroupDistrib::locked_historyCached(const pCacheId& cId) bool p3GroupDistrib::locked_historyCached(const pCacheId& cId)
{ {
@ -588,6 +639,9 @@ bool p3GroupDistrib::locked_buildCacheTable(){
return false; return false;
} }
// clear cache table
mCacheTable.clear();
pugi::xml_node_iterator grpIt = mCacheDoc.begin(), msgIt; pugi::xml_node_iterator grpIt = mCacheDoc.begin(), msgIt;
pugi::xml_node messages_node; pugi::xml_node messages_node;
std::map<std::string, std::set<pCacheId> > msgCacheMap; std::map<std::string, std::set<pCacheId> > msgCacheMap;
@ -769,7 +823,6 @@ void p3GroupDistrib::locked_getHistoryCacheData(const std::string& grpId, std::l
} }
else else
locked_getStoredCache(cDataTemp); locked_getStoredCache(cDataTemp);
cDataSet.push_back(cDataTemp); cDataSet.push_back(cDataTemp);
} }
} }
@ -1869,6 +1922,8 @@ void p3GroupDistrib::locked_publishPendingMsgs()
newCache.cid.type = CacheSource::getCacheType(); newCache.cid.type = CacheSource::getCacheType();
newCache.cid.subid = locked_determineCacheSubId(); newCache.cid.subid = locked_determineCacheSubId();
// remove old cache entry using this pid
locked_removeCacheTableEntry(pCacheId(newCache.pid, newCache.cid.subid));
/* create filename */ /* create filename */
std::string path = CacheSource::getCacheDir(); std::string path = CacheSource::getCacheDir();
@ -1916,9 +1971,6 @@ void p3GroupDistrib::locked_publishPendingMsgs()
{ {
ok &= false; ok &= false;
} }
} }
/* Extract File Information from pqistore */ /* Extract File Information from pqistore */

View file

@ -413,6 +413,15 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
*/ */
bool locked_loadHistoryCacheFile(); bool locked_loadHistoryCacheFile();
/*!
* this removes the given cache id and associated msgs nodes from
* all grp nodes
* cache table is updated to reflect document
* this costly, and is here to be called once a year has been reached on
* @param pCid the cache id to remove from cache document
*/
void locked_removeCacheTableEntry(const pCacheId& pCid);
private: private:
/* these lists are filled by the overloaded fns... then cleared by the thread */ /* these lists are filled by the overloaded fns... then cleared by the thread */
@ -667,6 +676,9 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
void locked_publishPendingMsgs(); void locked_publishPendingMsgs();
/*! /*!
* This function is key to determining how long caches permeate
* a distributed network, after mStorePeriod has elapsed for a message
* it is over written since its cache subid is used for the cache file name
* @return cache sub id * @return cache sub id
*/ */
uint16_t locked_determineCacheSubId(); uint16_t locked_determineCacheSubId();