From 256fe3fc561f1690e5c29640b9081e805ceb5532 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 18:57:07 +0200 Subject: Don't commit after every replayed revision If we didn't actually do anything we just carry on. Failing to commit is harmless in that case and committing for every revision is rather expensive. --- common/changereplay.cpp | 36 ++++++++++++++++++------------------ common/changereplay.h | 1 + common/synchronizer.h | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) (limited to 'common') diff --git a/common/changereplay.cpp b/common/changereplay.cpp index da36b3e..75b9a4c 100644 --- a/common/changereplay.cpp +++ b/common/changereplay.cpp @@ -105,7 +105,7 @@ KAsync::Job ChangeReplay::replayNextRevision() } Q_ASSERT(mMainStoreTransaction); - KAsync::Job replayJob = KAsync::null(); + auto replayJob = KAsync::null(); qint64 revision = *lastReplayedRevision + 1; while (revision <= *topRevision) { const auto uid = DataStore::getUidFromRevision(mMainStoreTransaction, revision); @@ -129,14 +129,14 @@ KAsync::Job ChangeReplay::replayNextRevision() if (canReplay(type, key, entityBuffer)) { SinkTraceCtx(mLogCtx) << "Replaying " << key; replayJob = replay(type, key, entityBuffer); + //Set the last revision we tried to replay + *lastReplayedRevision = revision; + //Execute replay job and commit + break; } else { - SinkTraceCtx(mLogCtx) << "Cannot replay " << key; + SinkTraceCtx(mLogCtx) << "Not replaying " << key; //We silently skip over revisions that cannot be replayed, as this is not an error. - replayJob = KAsync::null(); } - //Set the last revision we tried to replay - *lastReplayedRevision = revision; - break; } } //Bump the revision if we failed to even attempt to replay. This will simply skip over those revisions, as we can't recover from those situations. @@ -148,20 +148,20 @@ KAsync::Job ChangeReplay::replayNextRevision() SinkWarningCtx(mLogCtx) << "Change replay failed: " << error << "Last replayed revision: " << *lastReplayedRevision; //We're probably not online or so, so postpone retrying return KAsync::value(KAsync::Break); + } + SinkTraceCtx(mLogCtx) << "Replayed until: " << *lastReplayedRevision; + + recordReplayedRevision(*lastReplayedRevision); + reportProgress(*lastReplayedRevision, *topRevision); + + const bool gotMoreToReplay = (*lastReplayedRevision < *topRevision); + if (gotMoreToReplay) { + SinkTraceCtx(mLogCtx) << "Replaying some more..."; + //Replay more if we have more + return KAsync::wait(0).then(KAsync::value(KAsync::Continue)); } else { - SinkTraceCtx(mLogCtx) << "Replayed until: " << *lastReplayedRevision; - recordReplayedRevision(*lastReplayedRevision); - if (*lastReplayedRevision < *topRevision) { - SinkTraceCtx(mLogCtx) << "Replaying some more..."; - //Replay more if we have more - return KAsync::wait(0).then(KAsync::value(KAsync::Continue)); - } else { - return KAsync::value(KAsync::Break); - } + return KAsync::value(KAsync::Break); } - //We shouldn't ever get here - Q_ASSERT(false); - return KAsync::value(KAsync::Break); }).guard(&mGuard); }); }) diff --git a/common/changereplay.h b/common/changereplay.h index ab2d857..c509735 100644 --- a/common/changereplay.h +++ b/common/changereplay.h @@ -54,6 +54,7 @@ public slots: protected: virtual KAsync::Job replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) = 0; virtual bool canReplay(const QByteArray &type, const QByteArray &key, const QByteArray &value) = 0; + virtual void reportProgress(int progress, int total){}; Sink::Storage::DataStore mStorage; KAsync::Job replayNextRevision(); diff --git a/common/synchronizer.h b/common/synchronizer.h index bb24c2b..935c139 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h @@ -197,7 +197,7 @@ protected: /** * Report progress for current task */ - void reportProgress(int progress, int total); + virtual void reportProgress(int progress, int total) Q_DECL_OVERRIDE; protected: Sink::Log::Context mLogCtx; -- cgit v1.2.3