From 4c99d9a644d86410a93b683d1a34ab6d499b99f9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 22 Jan 2017 22:10:04 +0100 Subject: Fixed revision cleanup --- common/storage/entitystore.cpp | 13 +++++++++---- common/storage/entitystore.h | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index b1b3c86..96c8ccd 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -326,7 +326,7 @@ bool EntityStore::remove(const QByteArray &type, const QByteArray &uid, bool rep return true; } -void EntityStore::cleanupRevision(qint64 revision) +void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) { const auto uid = DataStore::getUidFromRevision(d->transaction, revision); const auto bufferType = DataStore::getTypeFromRevision(d->transaction, revision); @@ -340,18 +340,23 @@ void EntityStore::cleanupRevision(qint64 revision) } else { const auto metadata = flatbuffers::GetRoot(buffer.metadataBuffer()); const qint64 rev = metadata->revision(); + const auto isRemoval = metadata->operation() == Operation_Removal; // Remove old revisions, and the current if the entity has already been removed - if (rev < revision || metadata->operation() == Operation_Removal) { + if (rev < revision || isRemoval) { DataStore::removeRevision(d->transaction, rev); DataStore::mainDatabase(d->transaction, bufferType).remove(key); } - if (metadata->operation() == Operation_Removal) { + if (isRemoval) { const auto directory = d->entityBlobStoragePath(uid); QDir dir(directory); if (!dir.removeRecursively()) { SinkError() << "Failed to cleanup: " << directory; } } + //Don't cleanup more than specified + if (rev >= revision) { + return false; + } } return true; @@ -373,7 +378,7 @@ bool EntityStore::cleanupRevisions(qint64 revision) if (cleanupIsNecessary) { SinkTraceCtx(d->logCtx) << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { - cleanupRevision(rev); + cleanupEntityRevisionsUntil(rev); } } if (implicitTransaction) { diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index b8e1065..fe75a02 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h @@ -46,7 +46,6 @@ public: bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &); 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); bool cleanupRevisions(qint64 revision); void startTransaction(Sink::Storage::DataStore::AccessMode); @@ -112,6 +111,10 @@ public: Sink::Log::Context logContext() const; private: + /* + * Remove any old revisions of the same entity up until @param revision + */ + void cleanupEntityRevisionsUntil(qint64 revision); void copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision); class Private; const QSharedPointer d; -- cgit v1.2.3