fixed deletion of groups using the proper method in RsGenExchange, and disabled debug output

This commit is contained in:
csoler 2020-11-26 20:03:03 +01:00
parent bce514115d
commit 5a7f95f443
7 changed files with 61 additions and 13 deletions

View File

@ -263,7 +263,19 @@ void RsGenExchange::tick()
if( (mNetService && (mNetService->msgAutoSync() || mNetService->grpAutoSync())) && (mLastClean + MSG_CLEANUP_PERIOD < now) )
{
RsGxsCleanUp(mDataStore,this,1).clean(mNextGroupToCheck); // no need to lock here, because all access below (RsGenExchange, RsDataStore) are properly mutexed
GxsMsgReq msgs_to_delete;
std::vector<RsGxsGroupId> grps_to_delete;
RsGxsCleanUp(mDataStore,this,1).clean(mNextGroupToCheck,grps_to_delete,msgs_to_delete); // no need to lock here, because all access below (RsGenExchange, RsDataStore) are properly mutexed
uint32_t token1=0;
deleteMsgs(token1,msgs_to_delete);
for(auto& grpId: grps_to_delete)
{
uint32_t token2=0;
deleteGroup(token2,grpId);
}
RS_STACK_MUTEX(mGenMtx) ;
mLastClean = now;

View File

@ -52,13 +52,12 @@ RsGxsCleanUp::RsGxsCleanUp(RsGeneralDataService* const dataService, RsGenExchang
{
}
bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check)
bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check,std::vector<RsGxsGroupId>& grps_to_delete,GxsMsgReq& messages_to_delete)
{
RsGxsGrpMetaTemporaryMap grpMetaMap;
mDs->retrieveGxsGrpMetaData(grpMetaMap);
rstime_t now = time(NULL);
std::vector<RsGxsGroupId> grps_to_delete;
#ifdef DEBUG_GXSUTIL
uint16_t service_type = mGenExchangeClient->serviceType() ;
@ -108,8 +107,6 @@ bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check)
#ifdef DEBUG_GXSUTIL
GXSUTIL_DEBUG() << " Cleaning up group message for group ID " << grpId << std::endl;
#endif
GxsMsgReq messages_to_delete;
uint32_t store_period = mGenExchangeClient->getStoragePeriod(grpId) ;
for(; mit != result.end(); ++mit)
@ -151,7 +148,6 @@ bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check)
if( remove )
{
messages_to_delete[grpId].insert(meta->mMsgId);
#ifdef DEBUG_GXSUTIL
std::cerr << " Scheduling for removal." << std::endl;
#endif
@ -163,8 +159,6 @@ bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check)
//delete meta;
}
}
mDs->removeMsgs(messages_to_delete);
}
++it;
@ -195,8 +189,6 @@ bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check)
}
}
mDs->removeGroups(grps_to_delete);
return full_round;
}

View File

@ -143,7 +143,7 @@ public:
* Deletion will process by chunk size
* @return true if no more messages to delete, false otherwise
*/
bool clean(RsGxsGroupId &last_checked_group);
bool clean(RsGxsGroupId& next_group_to_check,std::vector<RsGxsGroupId>& grps_to_delete,GxsMsgReq& messages_to_delete);
private:

View File

@ -452,7 +452,9 @@ void p3GxsChannels::service_tick()
bool p3GxsChannels::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << "p3gxsChannels: Checking unused channel: called by GxsCleaning." << std::endl;
#endif
// request all group infos at once
@ -463,14 +465,18 @@ bool p3GxsChannels::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta
auto it = mKnownChannels.find(meta.mGroupId);
bool unknown_channel = it == mKnownChannels.end();
#ifdef GXSFORUMS_CHANNELS
std::cerr << " Channel " << meta.mGroupId ;
#endif
if(unknown_channel)
{
// This case should normally not happen. It does because this channel was never registered since it may
// arrived before this code was here
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Not known yet. Adding current time as new TS." << std::endl;
#endif
mKnownChannels[meta.mGroupId] = now;
IndicateConfigChanged();
@ -481,16 +487,22 @@ bool p3GxsChannels::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta
bool used_by_friends = (now < it->second + CHANNEL_UNUSED_BY_FRIENDS_DELAY);
bool subscribed = static_cast<bool>(meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED);
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". subscribed: " << subscribed << ", used_by_friends: " << used_by_friends << " last TS: " << now - it->second << " secs ago (" << (now-it->second)/86400 << " days)";
#endif
if(!subscribed && !used_by_friends)
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Scheduling for deletion" << std::endl;
#endif
return false;
}
else
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Keeping!" << std::endl;
#endif
return true;
}
}

View File

@ -49,7 +49,7 @@
/*static*/ const std::string RsGxsCircles::CIRCLE_URL_ID_FIELD = "circleId";
/*static*/ const std::string RsGxsCircles::CIRCLE_URL_DATA_FIELD = "circleData";
static const uint32_t CIRCLES_UNUSED_BY_FRIENDS_DELAY = 7*86400 ; // 7 days ...O...
static const uint32_t CIRCLES_UNUSED_BY_FRIENDS_DELAY = 60*86400 ; // 60 days ...O...
RsGxsCircles::~RsGxsCircles() = default;
RsGxsCircleMsg::~RsGxsCircleMsg() = default;
@ -1733,7 +1733,9 @@ void p3GxsCircles::addCircleIdToList(const RsGxsCircleId &circleId, uint32_t cir
bool p3GxsCircles::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << "p3gxsChannels: Checking unused circles: called by GxsCleaning." << std::endl;
#endif
// request all group infos at once
@ -1744,14 +1746,18 @@ bool p3GxsCircles::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
auto it = mKnownCircles.find(meta.mGroupId);
bool unknown_posted = (it == mKnownCircles.end());
#ifdef GXSFORUMS_CHANNELS
std::cerr << " Circle " << meta.mGroupId ;
#endif
if(unknown_posted)
{
// This case should normally not happen. It does because this board was never registered since it may
// arrived before this code was here
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Not known yet. Adding current time as new TS." << std::endl;
#endif
mKnownCircles[meta.mGroupId] = now;
IndicateConfigChanged();
@ -1766,12 +1772,16 @@ bool p3GxsCircles::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
if(!subscribed && !used_by_friends)
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Scheduling for deletion" << std::endl;
#endif
return false;
}
else
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Keeping!" << std::endl;
#endif
return true;
}
}

View File

@ -48,7 +48,7 @@ RsGxsForums *rsGxsForums = NULL;
#define FORUM_TESTEVENT_DUMMYDATA 0x0001
#define DUMMYDATA_PERIOD 60 // long enough for some RsIdentities to be generated.
#define FORUM_UNUSED_BY_FRIENDS_DELAY (2*5*86400) // unused forums are deleted after 2 months
#define FORUM_UNUSED_BY_FRIENDS_DELAY (2*30*86400) // unused forums are deleted after 2 months
/********************************************************************************/
/******************* Startup / Tick ******************************************/
@ -407,7 +407,9 @@ void p3GxsForums::service_tick()
bool p3GxsForums::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
{
#ifdef GXSFORUMS_DEBUG
std::cerr << "p3gxsForums: Checking unused forums: called by GxsCleaning." << std::endl;
#endif
// request all group infos at once
@ -418,14 +420,18 @@ bool p3GxsForums::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
auto it = mKnownForums.find(meta.mGroupId);
bool unknown_forum = it == mKnownForums.end();
#ifdef GXSFORUMS_DEBUG
std::cerr << " Forum " << meta.mGroupId ;
#endif
if(unknown_forum)
{
// This case should normally not happen. It does because this forum was never registered since it may
// arrived before this code was here
#ifdef GXSFORUMS_DEBUG
std::cerr << ". Not known yet. Adding current time as new TS." << std::endl;
#endif
mKnownForums[meta.mGroupId] = now;
IndicateConfigChanged();
@ -436,16 +442,22 @@ bool p3GxsForums::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
bool used_by_friends = (now < it->second + FORUM_UNUSED_BY_FRIENDS_DELAY);
bool subscribed = static_cast<bool>(meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED);
#ifdef GXSFORUMS_DEBUG
std::cerr << ". subscribed: " << subscribed << ", used_by_friends: " << used_by_friends << " last TS: " << now - it->second << " secs ago (" << (now-it->second)/86400 << " days)";
#endif
if(!subscribed && !used_by_friends)
{
#ifdef GXSFORUMS_DEBUG
std::cerr << ". Scheduling for deletion" << std::endl;
#endif
return false;
}
else
{
#ifdef GXSFORUMS_DEBUG
std::cerr << ". Keeping!" << std::endl;
#endif
return true;
}
}

View File

@ -910,7 +910,9 @@ public:
bool p3PostBase::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << "p3gxsChannels: Checking unused board: called by GxsCleaning." << std::endl;
#endif
// request all group infos at once
@ -921,14 +923,18 @@ bool p3PostBase::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
auto it = mKnownPosted.find(meta.mGroupId);
bool unknown_posted = (it == mKnownPosted.end());
#ifdef GXSFORUMS_CHANNELS
std::cerr << " Board " << meta.mGroupId ;
#endif
if(unknown_posted)
{
// This case should normally not happen. It does because this board was never registered since it may
// arrived before this code was here
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Not known yet. Adding current time as new TS." << std::endl;
#endif
mKnownPosted[meta.mGroupId] = now;
IndicateConfigChanged();
@ -943,12 +949,16 @@ bool p3PostBase::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
if(!subscribed && !used_by_friends)
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Scheduling for deletion" << std::endl;
#endif
return false;
}
else
{
#ifdef GXSFORUMS_CHANNELS
std::cerr << ". Keeping!" << std::endl;
#endif
return true;
}
}