From 64d7d7bdd1edb2bcc305ca007784d0708cf7ef3c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 24 Nov 2016 09:57:34 +0100 Subject: Deal with not using the implicit internal transaction. --- common/pipeline.cpp | 4 +++- common/storage/entitystore.cpp | 13 +++++++++---- common/storage/entitystore.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/pipeline.cpp b/common/pipeline.cpp index d3668bc..1eea631 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -287,7 +287,9 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) void Pipeline::cleanupRevisions(qint64 revision) { - d->entityStore.cleanupRevisions(revision); + //We have to set revisionChanged, otherwise a call to commit might abort + //the transaction when not using the implicit internal transaction + d->revisionChanged = d->entityStore.cleanupRevisions(revision); } diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 79314ad..f6b8f43 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -307,7 +307,7 @@ void EntityStore::cleanupRevision(qint64 revision) DataStore::setCleanedUpRevision(d->transaction, revision); } -void EntityStore::cleanupRevisions(qint64 revision) +bool EntityStore::cleanupRevisions(qint64 revision) { bool implicitTransaction = false; if (!d->transaction) { @@ -315,13 +315,18 @@ void EntityStore::cleanupRevisions(qint64 revision) implicitTransaction = true; } const auto lastCleanRevision = DataStore::cleanedUpRevision(d->transaction); - SinkTrace() << "Cleaning up from " << lastCleanRevision + 1 << " to " << revision; - for (qint64 rev = lastCleanRevision + 1; rev <= revision; rev++) { - cleanupRevision(revision); + const auto firstRevisionToCleanup = lastCleanRevision + 1; + bool cleanupIsNecessary = firstRevisionToCleanup <= revision; + if (cleanupIsNecessary) { + SinkTrace() << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; + for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { + cleanupRevision(revision); + } } if (implicitTransaction) { commitTransaction(); } + return cleanupIsNecessary; } QVector EntityStore::fullScan(const QByteArray &type) diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index be3817b..06ca8c4 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h @@ -47,7 +47,7 @@ public: bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &); bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &); void cleanupRevision(qint64 revision); - void cleanupRevisions(qint64 revision); + bool cleanupRevisions(qint64 revision); void startTransaction(Sink::Storage::DataStore::AccessMode); void commitTransaction(); -- cgit v1.2.3