Merge pull request #1826 from csoler/v0.6-FT4

attempt to solve GXS data access problems in new blocking API
This commit is contained in:
csoler 2020-03-13 14:37:53 +01:00 committed by GitHub
commit 4c4b7ce754
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 73 additions and 50 deletions

View file

@ -164,7 +164,9 @@ struct RsGxsCommentService
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &comments ) = 0;
virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0;
virtual bool createNewComment(uint32_t &token, const RsGxsComment &comment) = 0; // async API
virtual bool createComment(RsGxsComment& comment) = 0; // blocking API. Updates comment with new metadata.
virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0;
virtual bool acknowledgeComment(

View file

@ -274,8 +274,7 @@ struct RsGxsIfaceHelper
{ mTokenService.requestGroupStatistic(token, grpId); }
/// @see RsTokenService::cancelRequest
bool cancelRequest(uint32_t token)
{ return mTokenService.cancelRequest(token); }
bool cancelRequest(uint32_t token) { return mTokenService.cancelRequest(token); }
/**
* @deprecated
@ -291,12 +290,21 @@ protected:
* @param[in] token token associated to the request caller is waiting for
* @param[in] maxWait maximum waiting time in milliseconds
* @param[in] checkEvery time in millisecond between status checks
* @param[in] auto_delete_if_unsuccessful delete the request when it fails. This avoid leaving useless pending requests in the queue that would slow down additional calls.
*/
RsTokenService::GxsRequestStatus waitToken(
uint32_t token,
std::chrono::milliseconds maxWait = std::chrono::milliseconds(2000),
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20))
{ return mTokenService.waitToken(token, maxWait, checkEvery); }
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20),
bool auto_delete_if_unsuccessful=true)
{
RsTokenService::GxsRequestStatus res = mTokenService.waitToken(token, maxWait, checkEvery);
if(res != RsTokenService::COMPLETE && auto_delete_if_unsuccessful)
cancelRequest(token);
return res;
}
private:
RsGxsIface& mGxs;

View file

@ -232,7 +232,8 @@ public:
RsTokenService::GxsRequestStatus waitToken(
uint32_t token,
std::chrono::milliseconds maxWait = std::chrono::milliseconds(500),
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(2))
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(2),
bool auto_delete_if_unsuccessful=true)
{
#if defined(__ANDROID__) && (__ANDROID_API__ < 24)
auto wkStartime = std::chrono::steady_clock::now();
@ -241,12 +242,13 @@ LLwaitTokenBeginLabel:
#endif
auto timeout = std::chrono::steady_clock::now() + maxWait;
auto st = requestStatus(token);
while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE)
&& std::chrono::steady_clock::now() < timeout )
while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE) && std::chrono::steady_clock::now() < timeout )
{
std::this_thread::sleep_for(checkEvery);
st = requestStatus(token);
}
if(st != RsTokenService::COMPLETE && auto_delete_if_unsuccessful)
cancelRequest(token);
#if defined(__ANDROID__) && (__ANDROID_API__ < 24)
/* Work around for very slow/old android devices, we don't expect this

View file

@ -140,7 +140,7 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
std::vector<RsGxsComment> &msgs ) override
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override
virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override
{
return mCommentService->createGxsComment(token, msg);
}
@ -277,7 +277,7 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
/// @deprecated Implementation of @see RsGxsChannels::createComment
RS_DEPRECATED_FOR(createCommentV2)
bool createComment(RsGxsComment& comment) override;
bool createComment(RsGxsComment &comment) override;
/// @deprecated Implementation of @see RsGxsChannels::createVote
RS_DEPRECATED_FOR(createVoteV2)

View file

@ -278,9 +278,13 @@ bool p3GxsCircles::getCirclesSummaries(std::list<RsGroupMetaData>& circles)
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
if( !requestGroupInfo(token, opts)
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
return getGroupSummary(token, circles);
if( !requestGroupInfo(token, opts) || waitToken(token) != RsTokenService::COMPLETE )
{
std::cerr << "Cannot get circles summary. Token queue is overloaded?" << std::endl;
return false;
}
else
return getGroupSummary(token, circles);
}
bool p3GxsCircles::getCirclesInfo( const std::list<RsGxsGroupId>& circlesIds,
@ -289,9 +293,13 @@ bool p3GxsCircles::getCirclesInfo( const std::list<RsGxsGroupId>& circlesIds,
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
if( !requestGroupInfo(token, opts, circlesIds)
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
return getGroupData(token, circlesInfo);
if( !requestGroupInfo(token, opts, circlesIds) || waitToken(token) != RsTokenService::COMPLETE )
{
std::cerr << "Cannot get circle info. Token queue is overloaded?" << std::endl;
return false;
}
else
return getGroupData(token, circlesInfo);
}
bool p3GxsCircles::getCircleRequests( const RsGxsGroupId& circleId,

View file

@ -425,7 +425,7 @@ double p3GxsCommentService::calculateBestScore(int upVotes, int downVotes)
/********************************************************************************************/
bool p3GxsCommentService::createGxsComment(uint32_t &token, RsGxsComment &msg)
bool p3GxsCommentService::createGxsComment(uint32_t &token, const RsGxsComment &msg)
{
#ifdef DEBUG_GXSCOMMON
std::cerr << "p3GxsCommentService::createGxsComment() GroupId: " << msg.mMeta.mGroupId;

View file

@ -66,7 +66,7 @@ class p3GxsCommentService: public GxsTokenQueue
bool getGxsCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs);
bool getGxsRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs);
bool createGxsComment(uint32_t &token, RsGxsComment &msg);
bool createGxsComment(uint32_t &token, const RsGxsComment &msg);
bool createGxsVote(uint32_t &token, RsGxsVote &msg);
// Special Acknowledge.

View file

@ -85,7 +85,7 @@ public:
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override
virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override
{
return mCommentService->createGxsComment(token, msg);
}

View file

@ -96,10 +96,16 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
std::vector<RsGxsComment> &msgs )
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg)
virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override
{
return mCommentService->createGxsComment(token, msg);
}
virtual bool createComment(RsGxsComment& msg) override
{
uint32_t token;
return mCommentService->createGxsComment(token, msg) && waitToken(token) == RsTokenService::COMPLETE ;
}
virtual bool createNewVote(uint32_t &token, RsGxsVote &msg)
{