diff options
-rw-r--r-- | common/clientapi.cpp | 22 | ||||
-rw-r--r-- | common/clientapi.h | 5 | ||||
-rw-r--r-- | common/commands.cpp | 2 | ||||
-rw-r--r-- | common/commands.h | 1 | ||||
-rw-r--r-- | common/genericresource.cpp | 6 | ||||
-rw-r--r-- | common/genericresource.h | 1 | ||||
-rw-r--r-- | common/listener.cpp | 8 | ||||
-rw-r--r-- | common/resource.cpp | 5 | ||||
-rw-r--r-- | common/resource.h | 5 | ||||
-rw-r--r-- | common/storage.h | 7 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 8 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 5 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.h | 1 | ||||
-rw-r--r-- | tests/dummyresourcetest.cpp | 6 |
14 files changed, 71 insertions, 11 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 5eb4b55..73bc194 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp | |||
@@ -197,12 +197,22 @@ KAsync::Job<void> Store::start(const QByteArray &identifier) | |||
197 | 197 | ||
198 | void Store::removeFromDisk(const QByteArray &identifier) | 198 | void Store::removeFromDisk(const QByteArray &identifier) |
199 | { | 199 | { |
200 | //TODO By calling the resource executable with a --remove option instead | 200 | removeDataFromDisk(identifier).exec().waitForFinished(); |
201 | //we can ensure that no other resource process is running at the same time | 201 | } |
202 | QDir dir(Sink::storageLocation()); | 202 | |
203 | for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { | 203 | KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) |
204 | Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadWrite).removeFromDisk(); | 204 | { |
205 | } | 205 | //All databases are going to become invalid, nuke the environments |
206 | //TODO: all clients should react to a notification the resource | ||
207 | Sink::Storage::clearEnv(); | ||
208 | Trace() << "Remove data from disk " << identifier; | ||
209 | auto time = QSharedPointer<QTime>::create(); | ||
210 | time->start(); | ||
211 | auto resourceAccess = QSharedPointer<Sink::ResourceAccess>::create(identifier); | ||
212 | resourceAccess->open(); | ||
213 | return resourceAccess->sendCommand(Sink::Commands::RemoveFromDiskCommand).then<void>([resourceAccess, time]() { | ||
214 | Trace() << "Remove from disk complete." << Log::TraceTime(time->elapsed()); | ||
215 | }); | ||
206 | } | 216 | } |
207 | 217 | ||
208 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) | 218 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) |
diff --git a/common/clientapi.h b/common/clientapi.h index d0910df..45c5390 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -110,6 +110,11 @@ public: | |||
110 | */ | 110 | */ |
111 | static void removeFromDisk(const QByteArray &resourceIdentifier); | 111 | static void removeFromDisk(const QByteArray &resourceIdentifier); |
112 | 112 | ||
113 | /** | ||
114 | * Removes a resource from disk. | ||
115 | */ | ||
116 | static KAsync::Job<void> removeDataFromDisk(const QByteArray &resourceIdentifier); | ||
117 | |||
113 | template <class DomainType> | 118 | template <class DomainType> |
114 | static KAsync::Job<DomainType> fetchOne(const Sink::Query &query); | 119 | static KAsync::Job<DomainType> fetchOne(const Sink::Query &query); |
115 | 120 | ||
diff --git a/common/commands.cpp b/common/commands.cpp index 8b915f0..5d38afa 100644 --- a/common/commands.cpp +++ b/common/commands.cpp | |||
@@ -61,6 +61,8 @@ QByteArray name(int commandId) | |||
61 | return "RevisionReplayed"; | 61 | return "RevisionReplayed"; |
62 | case InspectionCommand: | 62 | case InspectionCommand: |
63 | return "Inspection"; | 63 | return "Inspection"; |
64 | case RemoveFromDiskCommand: | ||
65 | return "RemoveFromDisk"; | ||
64 | case CustomCommand: | 66 | case CustomCommand: |
65 | return "Custom"; | 67 | return "Custom"; |
66 | }; | 68 | }; |
diff --git a/common/commands.h b/common/commands.h index fa4712b..adf2094 100644 --- a/common/commands.h +++ b/common/commands.h | |||
@@ -48,6 +48,7 @@ enum CommandIds { | |||
48 | PingCommand, | 48 | PingCommand, |
49 | RevisionReplayedCommand, | 49 | RevisionReplayedCommand, |
50 | InspectionCommand, | 50 | InspectionCommand, |
51 | RemoveFromDiskCommand, | ||
51 | CustomCommand = 0xffff | 52 | CustomCommand = 0xffff |
52 | }; | 53 | }; |
53 | 54 | ||
diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 6087896..c097893 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp | |||
@@ -396,12 +396,18 @@ KAsync::Job<void> GenericResource::replay(Sink::Storage &synchronizationStore, c | |||
396 | return KAsync::null<void>(); | 396 | return KAsync::null<void>(); |
397 | } | 397 | } |
398 | 398 | ||
399 | void GenericResource::removeDataFromDisk() | ||
400 | { | ||
401 | removeFromDisk(mResourceInstanceIdentifier); | ||
402 | } | ||
403 | |||
399 | void GenericResource::removeFromDisk(const QByteArray &instanceIdentifier) | 404 | void GenericResource::removeFromDisk(const QByteArray &instanceIdentifier) |
400 | { | 405 | { |
401 | Sink::Storage(Sink::storageLocation(), instanceIdentifier, Sink::Storage::ReadWrite).removeFromDisk(); | 406 | Sink::Storage(Sink::storageLocation(), instanceIdentifier, Sink::Storage::ReadWrite).removeFromDisk(); |
402 | Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".userqueue", Sink::Storage::ReadWrite).removeFromDisk(); | 407 | Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".userqueue", Sink::Storage::ReadWrite).removeFromDisk(); |
403 | Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronizerqueue", Sink::Storage::ReadWrite).removeFromDisk(); | 408 | Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronizerqueue", Sink::Storage::ReadWrite).removeFromDisk(); |
404 | Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".changereplay", Sink::Storage::ReadWrite).removeFromDisk(); | 409 | Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".changereplay", Sink::Storage::ReadWrite).removeFromDisk(); |
410 | Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::ReadWrite).removeFromDisk(); | ||
405 | } | 411 | } |
406 | 412 | ||
407 | qint64 GenericResource::diskUsage(const QByteArray &instanceIdentifier) | 413 | qint64 GenericResource::diskUsage(const QByteArray &instanceIdentifier) |
diff --git a/common/genericresource.h b/common/genericresource.h index 1bbb0f5..ae505a6 100644 --- a/common/genericresource.h +++ b/common/genericresource.h | |||
@@ -52,6 +52,7 @@ public: | |||
52 | 52 | ||
53 | int error() const; | 53 | int error() const; |
54 | 54 | ||
55 | void removeDataFromDisk() Q_DECL_OVERRIDE; | ||
55 | static void removeFromDisk(const QByteArray &instanceIdentifier); | 56 | static void removeFromDisk(const QByteArray &instanceIdentifier); |
56 | static qint64 diskUsage(const QByteArray &instanceIdentifier); | 57 | static qint64 diskUsage(const QByteArray &instanceIdentifier); |
57 | 58 | ||
diff --git a/common/listener.cpp b/common/listener.cpp index 323252b..d2fa266 100644 --- a/common/listener.cpp +++ b/common/listener.cpp | |||
@@ -275,6 +275,14 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c | |||
275 | loadResource()->setLowerBoundRevision(lowerBoundRevision()); | 275 | loadResource()->setLowerBoundRevision(lowerBoundRevision()); |
276 | } | 276 | } |
277 | break; | 277 | break; |
278 | case Sink::Commands::RemoveFromDiskCommand: { | ||
279 | Log() << QString("\tReceived a remove from disk command from %1").arg(client.name); | ||
280 | m_resource->removeDataFromDisk(); | ||
281 | delete m_resource; | ||
282 | m_resource = nullptr; | ||
283 | loadResource()->setLowerBoundRevision(0); | ||
284 | } | ||
285 | break; | ||
278 | default: | 286 | default: |
279 | if (commandId > Sink::Commands::CustomCommand) { | 287 | if (commandId > Sink::Commands::CustomCommand) { |
280 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; | 288 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; |
diff --git a/common/resource.cpp b/common/resource.cpp index 6972efe..5cbb2f2 100644 --- a/common/resource.cpp +++ b/common/resource.cpp | |||
@@ -63,6 +63,11 @@ void Resource::setLowerBoundRevision(qint64 revision) | |||
63 | Q_UNUSED(revision) | 63 | Q_UNUSED(revision) |
64 | } | 64 | } |
65 | 65 | ||
66 | void Resource::removeDataFromDisk() | ||
67 | { | ||
68 | } | ||
69 | |||
70 | |||
66 | class ResourceFactory::Private | 71 | class ResourceFactory::Private |
67 | { | 72 | { |
68 | public: | 73 | public: |
diff --git a/common/resource.h b/common/resource.h index f6ca039..368759c 100644 --- a/common/resource.h +++ b/common/resource.h | |||
@@ -55,6 +55,11 @@ public: | |||
55 | */ | 55 | */ |
56 | virtual void setLowerBoundRevision(qint64 revision); | 56 | virtual void setLowerBoundRevision(qint64 revision); |
57 | 57 | ||
58 | /** | ||
59 | * Remove the data from disk | ||
60 | */ | ||
61 | virtual void removeDataFromDisk(); | ||
62 | |||
58 | Q_SIGNALS: | 63 | Q_SIGNALS: |
59 | void revisionUpdated(qint64); | 64 | void revisionUpdated(qint64); |
60 | void notify(Notification); | 65 | void notify(Notification); |
diff --git a/common/storage.h b/common/storage.h index 84175b3..8ec3f1d 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -180,6 +180,13 @@ public: | |||
180 | qint64 diskUsage() const; | 180 | qint64 diskUsage() const; |
181 | void removeFromDisk() const; | 181 | void removeFromDisk() const; |
182 | 182 | ||
183 | /** | ||
184 | * Clears all cached environments. | ||
185 | * | ||
186 | * This only ever has to be called if a database was removed from another process. | ||
187 | */ | ||
188 | static void clearEnv(); | ||
189 | |||
183 | static qint64 maxRevision(const Sink::Storage::Transaction &); | 190 | static qint64 maxRevision(const Sink::Storage::Transaction &); |
184 | static void setMaxRevision(Sink::Storage::Transaction &, qint64 revision); | 191 | static void setMaxRevision(Sink::Storage::Transaction &, qint64 revision); |
185 | 192 | ||
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index e2c623e..1efffc4 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -615,4 +615,12 @@ void Storage::removeFromDisk() const | |||
615 | mdb_env_close(env); | 615 | mdb_env_close(env); |
616 | } | 616 | } |
617 | 617 | ||
618 | void Storage::clearEnv() | ||
619 | { | ||
620 | for (auto env : Storage::Private::sEnvironments) { | ||
621 | mdb_env_close(env); | ||
622 | } | ||
623 | Storage::Private::sEnvironments.clear(); | ||
624 | } | ||
625 | |||
618 | } // namespace Sink | 626 | } // namespace Sink |
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 31633d7..36866ec 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -128,6 +128,11 @@ KAsync::Job<void> DummyResource::replay(Sink::Storage &synchronizationStore, con | |||
128 | return KAsync::null<void>(); | 128 | return KAsync::null<void>(); |
129 | } | 129 | } |
130 | 130 | ||
131 | void DummyResource::removeDataFromDisk() | ||
132 | { | ||
133 | removeFromDisk(mResourceInstanceIdentifier); | ||
134 | } | ||
135 | |||
131 | void DummyResource::removeFromDisk(const QByteArray &instanceIdentifier) | 136 | void DummyResource::removeFromDisk(const QByteArray &instanceIdentifier) |
132 | { | 137 | { |
133 | GenericResource::removeFromDisk(instanceIdentifier); | 138 | GenericResource::removeFromDisk(instanceIdentifier); |
diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 240bb9f..865f6e5 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h | |||
@@ -39,6 +39,7 @@ public: | |||
39 | DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::Pipeline> &pipeline = QSharedPointer<Sink::Pipeline>()); | 39 | DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer<Sink::Pipeline> &pipeline = QSharedPointer<Sink::Pipeline>()); |
40 | KAsync::Job<void> synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) Q_DECL_OVERRIDE; | 40 | KAsync::Job<void> synchronizeWithSource(Sink::Storage &mainStore, Sink::Storage &synchronizationStore) Q_DECL_OVERRIDE; |
41 | using GenericResource::synchronizeWithSource; | 41 | using GenericResource::synchronizeWithSource; |
42 | void removeDataFromDisk() Q_DECL_OVERRIDE; | ||
42 | static void removeFromDisk(const QByteArray &instanceIdentifier); | 43 | static void removeFromDisk(const QByteArray &instanceIdentifier); |
43 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; | 44 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; |
44 | private: | 45 | private: |
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 82c713d..c5b2f30 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp | |||
@@ -31,11 +31,7 @@ private Q_SLOTS: | |||
31 | 31 | ||
32 | void cleanup() | 32 | void cleanup() |
33 | { | 33 | { |
34 | Sink::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); | 34 | Sink::Store::removeDataFromDisk(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); |
35 | DummyResource::removeFromDisk("org.kde.dummy.instance1"); | ||
36 | auto factory = Sink::ResourceFactory::load("org.kde.dummy"); | ||
37 | QVERIFY(factory); | ||
38 | Sink::Store::start(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); | ||
39 | } | 35 | } |
40 | 36 | ||
41 | void init() | 37 | void init() |