added some more debug info and proper error output to GxsDb

This commit is contained in:
csoler 2020-03-26 23:19:34 +01:00
parent 8cf78b072b
commit c18dfb39c3
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
8 changed files with 98 additions and 46 deletions

View File

@ -26,6 +26,10 @@
* #define RS_DATA_SERVICE_DEBUG_CACHE 1 * #define RS_DATA_SERVICE_DEBUG_CACHE 1
****/ ****/
#define RS_DATA_SERVICE_DEBUG 1
#define RS_DATA_SERVICE_DEBUG_TIME 1
#define RS_DATA_SERVICE_DEBUG_CACHE 1
#include <fstream> #include <fstream>
#include <util/rsdir.h> #include <util/rsdir.h>
#include <algorithm> #include <algorithm>
@ -1312,7 +1316,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
{ {
locked_retrieveMsgMeta(c, metaSet); locked_retrieveMsgMeta(c, metaSet);
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving (all) Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl; std::cerr << mDbName << ": Retrieving (all) Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
#endif #endif
} }
}else{ }else{
@ -1329,7 +1333,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
{ {
locked_retrieveMsgMeta(c, metaSet); locked_retrieveMsgMeta(c, metaSet);
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl; std::cerr << mDbName << ": Retrieving Msg metadata grpId=" << grpId << ", " << std::dec << metaSet.size() << " messages" << std::endl;
#endif #endif
} }
} }
@ -1414,7 +1418,7 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
{ {
grp[g->mGroupId] = g; grp[g->mGroupId] = g;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void *)this << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl; std::cerr << (void *)this << " " << mDbName << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl;
#endif #endif
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -1441,14 +1445,14 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
if(itt != mGrpMetaDataCache.end()) if(itt != mGrpMetaDataCache.end())
{ {
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first << " from cache!" << std::endl; std::cerr << mDbName << ": Retrieving Grp metadata grpId=" << mit->first << " from cache!" << std::endl;
#endif #endif
grp[mit->first] = itt->second ; grp[mit->first] = itt->second ;
} }
else else
{ {
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first ; std::cerr << mDbName << ": Retrieving Grp metadata grpId=" << mit->first ;
#endif #endif
const RsGxsGroupId& grpId = mit->first; const RsGxsGroupId& grpId = mit->first;

View File

@ -726,7 +726,7 @@ public:
virtual void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs) ; virtual void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs) ;
virtual bool getGroupNetworkStats(const RsGxsGroupId& grpId,RsGroupNetworkStats& stats); virtual bool getGroupNetworkStats(const RsGxsGroupId& grpId,RsGroupNetworkStats& stats);
uint16_t serviceType() const { return mServType ; } uint16_t serviceType() const override { return mServType ; }
uint32_t serviceFullType() const { return RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(mServType); } uint32_t serviceFullType() const { return RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(mServType); }
virtual RsReputationLevel minReputationForForwardingMessages( virtual RsReputationLevel minReputationForForwardingMessages(

View File

@ -30,6 +30,8 @@
* #define DATA_DEBUG 1 * #define DATA_DEBUG 1
**********/ **********/
#define DATA_DEBUG 1
RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds) : RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds) :
mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0) {} mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0) {}

View File

@ -110,6 +110,12 @@ struct RsGxsChanges : RsEvent
*/ */
struct RsGxsIface struct RsGxsIface
{ {
/*!
* \brief serviceType
* \return The 16-bits service type. See @serialiser/rsserviceids.h
*/
virtual uint16_t serviceType() const =0;
/*! /*!
* Gxs services should call this for automatic handling of * Gxs services should call this for automatic handling of
* changes, send * changes, send

View File

@ -26,6 +26,7 @@
#include <thread> #include <thread>
#include "retroshare/rsgxsiface.h" #include "retroshare/rsgxsiface.h"
#include "retroshare/rsservicecontrol.h"
#include "retroshare/rsreputations.h" #include "retroshare/rsreputations.h"
#include "rsgxsflags.h" #include "rsgxsflags.h"
#include "util/rsdeprecate.h" #include "util/rsdeprecate.h"
@ -454,9 +455,19 @@ private:
void locked_dumpTokens() void locked_dumpTokens()
{ {
std::cerr << "Active tokens (this=" << (void*)this << "): " ; uint16_t service_id = mGxs.serviceType();
for(auto it: mActiveTokens)
std::cerr << std::dec << it.first << " (" << static_cast<int>(it.second) << ") " ; uint32_t count[7] = {0};
std::cerr << "Service 0x0" << std::hex << service_id
<< " (" << rsServiceControl->getServiceName(RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(service_id))
<< ") this=0x" << (void*)this << ") Active tokens (per type): " ;
for(auto& it: mActiveTokens) // let's count how many token of each type we've got.
++count[static_cast<int>(it.second)];
for(uint32_t i=0;i<7;++i)
std::cerr /* << i << ":" */ << count[i] << " ";
std::cerr << std::endl; std::cerr << std::endl;
} }
}; };

View File

@ -175,7 +175,7 @@ void GxsGroupFrameDialog::initUi()
void GxsGroupFrameDialog::showEvent(QShowEvent *event) void GxsGroupFrameDialog::showEvent(QShowEvent *event)
{ {
if (!mInitialized || ui->groupTreeWidget->treeWidget()->topLevelItemCount() == 0) if (!mInitialized )
{ {
/* Problem: virtual methods cannot be used in constructor */ /* Problem: virtual methods cannot be used in constructor */
@ -1028,6 +1028,8 @@ void GxsGroupFrameDialog::updateGroupSummary()
std::cerr << __PRETTY_FUNCTION__ << " failed to collect group info " << std::endl; std::cerr << __PRETTY_FUNCTION__ << " failed to collect group info " << std::endl;
return; return;
} }
if(groupInfo.empty())
return;
RsQThreadUtils::postToObject( [this,groupInfo]() RsQThreadUtils::postToObject( [this,groupInfo]()
{ {
@ -1049,17 +1051,18 @@ void GxsGroupFrameDialog::updateGroupSummary()
mNavigatePendingGroupId.clear(); mNavigatePendingGroupId.clear();
mNavigatePendingMsgId.clear(); mNavigatePendingMsgId.clear();
} }
// update the local cache in order to avoid re-asking the data when the UI wants it (this happens on ::show() for instance)
mCachedGroupMetas.clear(); // update the local cache in order to avoid re-asking the data when the UI wants it (this happens on ::show() for instance)
mCachedGroupMetas.clear();
// now delete the data that is not used anymore // now delete the data that is not used anymore
for(auto& g:groupInfo) for(auto& g:groupInfo)
{ {
mCachedGroupMetas[g->mMeta.mGroupId] = g->mMeta; mCachedGroupMetas[g->mMeta.mGroupId] = g->mMeta;
delete g; delete g;
} }
}, this ); }, this );
}); });

View File

@ -1102,6 +1102,19 @@ void GxsForumThreadWidget::insertMessage()
// markMsgAsRead(); // markMsgAsRead();
} }
void GxsForumThreadWidget::setMessageLoadingError(const QString& error)
{
ui->time_label->setText(QString(""));
ui->by_label->setId(RsGxsId());
ui->lineRight->show();
ui->lineLeft->show();
ui->by_text_label->show();
ui->by_label->show();
ui->threadTreeWidget->setFocus();
ui->postText->setText(error);
}
void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg) void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
{ {
/* As some time has elapsed since request - check that this is still the current msg. /* As some time has elapsed since request - check that this is still the current msg.
@ -1735,28 +1748,32 @@ void GxsForumThreadWidget::updateGroupData()
else else
success = true; success = true;
// 2 - sort the messages into a proper hierarchy if(success)
RsGxsForumGroup group(groups[0]); // we use a copy to share the object in order to avoid group deletion while we're in the thread.
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [group,success,this]()
{ {
/* Here it goes any code you want to be executed on the Qt Gui // 2 - sort the messages into a proper hierarchy
RsGxsForumGroup group(groups[0]); // we use a copy to share the object in order to avoid group deletion while we're in the thread.
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [group,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information * thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */ * after a blocking call to RetroShare API complete */
mForumGroup = group; mForumGroup = group;
mThreadId.clear(); mThreadId.clear();
ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags))); ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ; ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ;
updateForumDescription(success); updateForumDescription(true);
}, this );
}, this );
}
else
RsQThreadUtils::postToObject( [this]() { updateForumDescription(false); },this);
}); });
} }
@ -1774,17 +1791,18 @@ void GxsForumThreadWidget::updateMessageData(const RsGxsMessageId& msgId)
std::vector<RsGxsForumMsg> msgs; std::vector<RsGxsForumMsg> msgs;
msgs_to_request.insert(msgId); msgs_to_request.insert(msgId);
QString error_string;
if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs)) if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs))
{ {
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message info for forum " << groupId() << " and MsgId " << msgId << std::endl; std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message info for forum " << groupId() << " and MsgId " << msgId << std::endl;
return; error_string = tr("Failed to retrieve this message. Is the database currently overloaded?");
} }
if(msgs.empty()) if(msgs.empty())
{ {
std::cerr << __PRETTY_FUNCTION__ << " no posts for msgId " << msgId << ". Database corruption?" << std::endl; std::cerr << __PRETTY_FUNCTION__ << " no posts for msgId " << msgId << ". Database corruption?" << std::endl;
return; error_string = tr("No data for this message. Is the database corrupted?");
} }
if(msgs.size() > 1) if(msgs.size() > 1)
{ {
@ -1792,25 +1810,32 @@ void GxsForumThreadWidget::updateMessageData(const RsGxsMessageId& msgId)
std::cerr << "Messages are:" << std::endl; std::cerr << "Messages are:" << std::endl;
for(auto it(msgs.begin());it!=msgs.end();++it) for(auto it(msgs.begin());it!=msgs.end();++it)
std::cerr << (*it).mMeta << std::endl; std::cerr << (*it).mMeta << std::endl;
error_string = tr("More than one entry for this message. Is the database corrupted?");
} }
// 2 - sort the messages into a proper hierarchy if(error_string.isNull())
RsGxsForumMsg msg(msgs[0]);
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [msg,this]()
{ {
/* Here it goes any code you want to be executed on the Qt Gui // 2 - sort the messages into a proper hierarchy
RsGxsForumMsg msg(msgs[0]);
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [msg,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information * thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */ * after a blocking call to RetroShare API complete */
insertMessageData(msg); insertMessageData(msg);
ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags))); ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ; ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ;
}, this ); }, this );
}
else
RsQThreadUtils::postToObject( [error_string,this](){ setMessageLoadingError(error_string); } );
}); });
} }

View File

@ -92,6 +92,7 @@ protected:
/* GxsMessageFrameWidget */ /* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token); virtual void setAllMessagesReadDo(bool read, uint32_t &token);
void setMessageLoadingError(const QString& error);
private slots: private slots:
/** Create the context popup menu and it's submenus */ /** Create the context popup menu and it's submenus */
void threadListCustomPopupMenu(QPoint point); void threadListCustomPopupMenu(QPoint point);