diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-08 21:34:06 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-08 21:34:06 +0100 |
commit | 44744e281a56488c7ef257e12ca379ec4ceb2cdd (patch) | |
tree | 5fd45d6c6cf5e68ba2323fac3f498c6afa6f2ddf /common | |
parent | d82f0f6e52b601c3067ca70183458f5ce9b22c22 (diff) | |
download | sink-44744e281a56488c7ef257e12ca379ec4ceb2cdd.tar.gz sink-44744e281a56488c7ef257e12ca379ec4ceb2cdd.zip |
Executed database removal in the resource instead of the client.
The resource doesn't really notify all clients properly about the
removal, but the tests all still pass.
Diffstat (limited to 'common')
-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 |
11 files changed, 64 insertions, 6 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 |