diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-22 22:10:04 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-22 22:10:04 +0100 |
commit | 4c99d9a644d86410a93b683d1a34ab6d499b99f9 (patch) | |
tree | 81914740d57ba40a0bcdc5d83237abbdaaffc8fd /common/storage | |
parent | b05edd5644738e7608d13a8b5b679f43d70f4dd4 (diff) | |
download | sink-4c99d9a644d86410a93b683d1a34ab6d499b99f9.tar.gz sink-4c99d9a644d86410a93b683d1a34ab6d499b99f9.zip |
Fixed revision cleanup
Diffstat (limited to 'common/storage')
-rw-r--r-- | common/storage/entitystore.cpp | 13 | ||||
-rw-r--r-- | 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 | |||
326 | return true; | 326 | return true; |
327 | } | 327 | } |
328 | 328 | ||
329 | void EntityStore::cleanupRevision(qint64 revision) | 329 | void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) |
330 | { | 330 | { |
331 | const auto uid = DataStore::getUidFromRevision(d->transaction, revision); | 331 | const auto uid = DataStore::getUidFromRevision(d->transaction, revision); |
332 | const auto bufferType = DataStore::getTypeFromRevision(d->transaction, revision); | 332 | const auto bufferType = DataStore::getTypeFromRevision(d->transaction, revision); |
@@ -340,18 +340,23 @@ void EntityStore::cleanupRevision(qint64 revision) | |||
340 | } else { | 340 | } else { |
341 | const auto metadata = flatbuffers::GetRoot<Metadata>(buffer.metadataBuffer()); | 341 | const auto metadata = flatbuffers::GetRoot<Metadata>(buffer.metadataBuffer()); |
342 | const qint64 rev = metadata->revision(); | 342 | const qint64 rev = metadata->revision(); |
343 | const auto isRemoval = metadata->operation() == Operation_Removal; | ||
343 | // Remove old revisions, and the current if the entity has already been removed | 344 | // Remove old revisions, and the current if the entity has already been removed |
344 | if (rev < revision || metadata->operation() == Operation_Removal) { | 345 | if (rev < revision || isRemoval) { |
345 | DataStore::removeRevision(d->transaction, rev); | 346 | DataStore::removeRevision(d->transaction, rev); |
346 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); | 347 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); |
347 | } | 348 | } |
348 | if (metadata->operation() == Operation_Removal) { | 349 | if (isRemoval) { |
349 | const auto directory = d->entityBlobStoragePath(uid); | 350 | const auto directory = d->entityBlobStoragePath(uid); |
350 | QDir dir(directory); | 351 | QDir dir(directory); |
351 | if (!dir.removeRecursively()) { | 352 | if (!dir.removeRecursively()) { |
352 | SinkError() << "Failed to cleanup: " << directory; | 353 | SinkError() << "Failed to cleanup: " << directory; |
353 | } | 354 | } |
354 | } | 355 | } |
356 | //Don't cleanup more than specified | ||
357 | if (rev >= revision) { | ||
358 | return false; | ||
359 | } | ||
355 | } | 360 | } |
356 | 361 | ||
357 | return true; | 362 | return true; |
@@ -373,7 +378,7 @@ bool EntityStore::cleanupRevisions(qint64 revision) | |||
373 | if (cleanupIsNecessary) { | 378 | if (cleanupIsNecessary) { |
374 | SinkTraceCtx(d->logCtx) << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; | 379 | SinkTraceCtx(d->logCtx) << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; |
375 | for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { | 380 | for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { |
376 | cleanupRevision(rev); | 381 | cleanupEntityRevisionsUntil(rev); |
377 | } | 382 | } |
378 | } | 383 | } |
379 | if (implicitTransaction) { | 384 | 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: | |||
46 | bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &); | 46 | bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &); |
47 | bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &); | 47 | bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &); |
48 | bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &); | 48 | bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &); |
49 | void cleanupRevision(qint64 revision); | ||
50 | bool cleanupRevisions(qint64 revision); | 49 | bool cleanupRevisions(qint64 revision); |
51 | 50 | ||
52 | void startTransaction(Sink::Storage::DataStore::AccessMode); | 51 | void startTransaction(Sink::Storage::DataStore::AccessMode); |
@@ -112,6 +111,10 @@ public: | |||
112 | Sink::Log::Context logContext() const; | 111 | Sink::Log::Context logContext() const; |
113 | 112 | ||
114 | private: | 113 | private: |
114 | /* | ||
115 | * Remove any old revisions of the same entity up until @param revision | ||
116 | */ | ||
117 | void cleanupEntityRevisionsUntil(qint64 revision); | ||
115 | void copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision); | 118 | void copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision); |
116 | class Private; | 119 | class Private; |
117 | const QSharedPointer<Private> d; | 120 | const QSharedPointer<Private> d; |