From ecc2a18e1afc1b99df6725066c9ae552d09e90d8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 30 Dec 2015 18:01:58 +0100 Subject: Centralize where we create the stores --- common/genericresource.cpp | 6 ++++-- common/genericresource.h | 2 +- examples/dummyresource/resourcefactory.cpp | 2 +- examples/dummyresource/resourcefactory.h | 2 +- examples/maildirresource/maildirresource.cpp | 6 ++---- examples/maildirresource/maildirresource.h | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 42153ec..29acce4 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -282,7 +282,9 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c QObject::connect(mProcessor, &CommandProcessor::error, [this](int errorCode, const QString &msg) { onProcessorError(errorCode, msg); }); QObject::connect(mPipeline.data(), &Pipeline::revisionUpdated, this, &Resource::revisionUpdated); mSourceChangeReplay = new ChangeReplay(resourceInstanceIdentifier, [this](const QByteArray &type, const QByteArray &key, const QByteArray &value) { - return this->replay(type, key, value); + //This results in a deadlock when a sync is in progress and we try to create a second writing transaction (which is why we turn changereplay off during the sync) + auto synchronizationStore = QSharedPointer::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); + return this->replay(*synchronizationStore, type, key, value).then([synchronizationStore](){}); }); enableChangeReplay(true); mClientLowerBoundRevision = mPipeline->cleanedUpRevision(); @@ -317,7 +319,7 @@ void GenericResource::addType(const QByteArray &type, DomainTypeAdaptorFactoryIn mPipeline->setAdaptorFactory(type, factory); } -KAsync::Job GenericResource::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) +KAsync::Job GenericResource::replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) { return KAsync::null(); } diff --git a/common/genericresource.h b/common/genericresource.h index c12c631..f47c6f8 100644 --- a/common/genericresource.h +++ b/common/genericresource.h @@ -60,7 +60,7 @@ private Q_SLOTS: protected: void enableChangeReplay(bool); void addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector &preprocessors); - virtual KAsync::Job replay(const QByteArray &type, const QByteArray &key, const QByteArray &value); + virtual KAsync::Job replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value); void onProcessorError(int errorCode, const QString &errorMessage); void enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data); diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index a24ff27..08e3594 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -164,7 +164,7 @@ KAsync::Job DummyResource::synchronizeWithSource() }); } -KAsync::Job DummyResource::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) +KAsync::Job DummyResource::replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) { Trace() << "Replaying " << key; return KAsync::null(); diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 3216e13..c638b7c 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h @@ -40,7 +40,7 @@ public: KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE; static void removeFromDisk(const QByteArray &instanceIdentifier); private: - KAsync::Job replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; + KAsync::Job replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; QString resolveRemoteId(const QByteArray &type, const QString &remoteId, Akonadi2::Storage::Transaction &transaction); void createEvent(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb, Akonadi2::Storage::Transaction &); void createMail(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb, Akonadi2::Storage::Transaction &); diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 273b996..b49a27e 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -212,11 +212,9 @@ KAsync::Job MaildirResource::synchronizeWithSource(Akonadi2::Storage &main }); } -KAsync::Job MaildirResource::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) +KAsync::Job MaildirResource::replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) { - //This results in a deadlock during sync - Akonadi2::Storage store(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite); - auto synchronizationTransaction = store.createTransaction(Akonadi2::Storage::ReadWrite); + auto synchronizationTransaction = synchronizationStore.createTransaction(Akonadi2::Storage::ReadWrite); Trace() << "Replaying " << key << type; if (type == ENTITY_TYPE_FOLDER) { diff --git a/examples/maildirresource/maildirresource.h b/examples/maildirresource/maildirresource.h index 48eac67..389b7f4 100644 --- a/examples/maildirresource/maildirresource.h +++ b/examples/maildirresource/maildirresource.h @@ -38,7 +38,7 @@ public: KAsync::Job synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; static void removeFromDisk(const QByteArray &instanceIdentifier); private: - KAsync::Job replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; + KAsync::Job replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; void synchronizeFolders(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction); void synchronizeMails(Akonadi2::Storage::Transaction &transaction, Akonadi2::Storage::Transaction &synchronizationTransaction, const QString &folder); -- cgit v1.2.3