cleaned-up circles cache. Needs testing.

This commit is contained in:
csoler 2020-05-07 17:31:58 +02:00
parent 65fa29e789
commit 11a4b6540f
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 880 additions and 879 deletions

File diff suppressed because it is too large Load Diff

View File

@ -130,9 +130,9 @@ public:
class RsGxsCircleCache
{
public:
public:
RsGxsCircleCache();
bool loadBaseCircle(const RsGxsCircleGroup &circle);
bool loadSubCircle(const RsGxsCircleCache &subcircle);
@ -142,28 +142,44 @@ class RsGxsCircleCache
bool addAllowedPeer(const RsPgpId &pgpid);
bool addLocalFriend(const RsPgpId &pgpid);
// Cache related data
enum CircleEntryCacheStatus: uint8_t // This enum
{
UNKNOWN = 0x00, // Used to detect uninitialized memory
NO_DATA = 0x01, // Used in the constuctor
LOADING = 0x02, // When the token request to load cache has been sent and no data is present
UPDATING = 0x03, // Starting from this level the cache entry can be used
CHECKING_MEMBERSHIP = 0x04, // Means we're actually looking into msgs to update membership status
UP_TO_DATE = 0x05, // Everything should be loaded here.
};
rstime_t mLastUpdatedMembershipTS ; // Last time the subscribe messages have been requested. Should be reset when new messages arrive.
rstime_t mLastUpdateTime; // Last time the cache entry was loaded
CircleEntryCacheStatus mStatus; // Overall state of the cache entry
bool mAllIdsHere ; // True when all ids are knwon and available.
// GxsCircle related data
RsGxsCircleId mCircleId;
std::string mCircleName;
RsGxsCircleType mCircleType;
bool mIsExternal;
RsGxsCircleId mRestrictedCircleId ; // circle ID that circle is restricted to.
RsGxsCircleId mRestrictedCircleId ; // circle ID that circle is restricted to.
uint32_t mGroupStatus;
uint32_t mGroupSubscribeFlags;
rstime_t mUpdateTime;
#ifdef SUBSCIRCLES
std::set<RsGxsCircleId> mUnprocessedCircles;
std::set<RsGxsCircleId> mProcessedCircles;
#endif
std::map<RsGxsId,RsGxsCircleMembershipStatus> mMembershipStatus;
rstime_t mLastUpdatedMembershipTS ; // last time the subscribe messages have been requested. Should be reset when new messages arrive.
std::set<RsGxsId> mAllowedGxsIds; // IDs that are allowed in the circle and have requested membership. This is the official members list.
std::set<RsPgpId> mAllowedNodes;
RsPeerId mOriginator ; // peer who sent the data, in case we need to ask for ids
RsPeerId mOriginator ; // peer who sent the data, in case we need to ask for ids
};
@ -319,20 +335,17 @@ public:
std::list<RsGxsCircleId> mCirclePersonalIdList;
/***** Caching Circle Info, *****/
// initial load queue
std::list<RsGxsCircleId> mCacheLoad_ToCache;
// waiting for subcircle to load. (first is part of each of the second list)
// TODO.
//std::map<RsGxsCircleId, std::list<RsGxsCircleId> > mCacheLoad_SubCircle;
// Circles that are being loaded.
std::map<RsGxsCircleId, RsGxsCircleCache> mLoadingCache;
std::set<RsGxsCircleId> mCirclesToLoad; // list of circles to update/load, so that we can treat them by groups.
RsMemCache<RsGxsCircleId, RsGxsCircleCache> mCircleCache; // actual cache data
// actual cache.
RsMemCache<RsGxsCircleId, RsGxsCircleCache> mCircleCache;
private:
void debug_dumpCache(); // debug method to overview what's going on
bool debug_dumpCacheEntry(RsGxsCircleCache &cache);
private:
std::string genRandomId();
@ -347,6 +360,7 @@ public:
std::list<RsGxsId> mDummyOwnIds;
bool mCacheUpdated ;
rstime_t mLastCacheUpdateEvent;
rstime_t mLastDebugPrintTS;
RS_SET_CONTEXT_DEBUG_LEVEL(2)
};

View File

@ -60,7 +60,12 @@ public:
bool is_cached(const Key &key) const;
bool fetch(const Key &key, Value &data);
Value &ref(const Key &key); // like map[] installs empty one if non-existent.
// Like map[] installs empty one if non-existent.
Value& ref(const Key &key);
Value& operator[](const Key& key) { return ref(key); }
bool store(const Key &key, const Value &data);
bool erase(const Key &key); // clean up cache.
@ -70,7 +75,8 @@ public:
template<class ClientClass> bool applyToAllCachedEntries(ClientClass& c,bool (ClientClass::*method)(Value&));
uint32_t size() const { return mDataMap.size() ; }
uint32_t size() const { return mDataMap.size() ; }
void printStats(std::ostream& out);
private:
bool update_lrumap(const Key &key, rstime_t old_ts, rstime_t new_ts);
@ -96,7 +102,6 @@ private:
std::string mName;
// some statistics.
void printStats(std::ostream &out);
void clearStats();
mutable uint32_t mStats_inserted;