diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-17 20:16:25 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-17 20:16:25 +0100 |
commit | 979276a574e615213891463ab23569f7bbaf07b4 (patch) | |
tree | 0fcae3b28f04833f6bf5a8f28445c6243a8f2bce /common/synchronizer.cpp | |
parent | 48cb4a237e92ead33fa32b120c503bcbb1dafce5 (diff) | |
download | sink-979276a574e615213891463ab23569f7bbaf07b4.tar.gz sink-979276a574e615213891463ab23569f7bbaf07b4.zip |
Handle errors without crashing.
Diffstat (limited to 'common/synchronizer.cpp')
-rw-r--r-- | common/synchronizer.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index a341f63..cfe1f09 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -279,10 +279,11 @@ KAsync::Job<void> Synchronizer::processSyncQueue() | |||
279 | if (mSyncRequestQueue.isEmpty() || mSyncInProgress) { | 279 | if (mSyncRequestQueue.isEmpty() || mSyncInProgress) { |
280 | return KAsync::null<void>(); | 280 | return KAsync::null<void>(); |
281 | } | 281 | } |
282 | mSyncInProgress = true; | ||
283 | mMessageQueue->startTransaction(); | ||
284 | 282 | ||
285 | auto job = KAsync::null<void>(); | 283 | auto job = KAsync::syncStart<void>([this] { |
284 | mMessageQueue->startTransaction(); | ||
285 | mSyncInProgress = true; | ||
286 | }); | ||
286 | while (!mSyncRequestQueue.isEmpty()) { | 287 | while (!mSyncRequestQueue.isEmpty()) { |
287 | auto request = mSyncRequestQueue.takeFirst(); | 288 | auto request = mSyncRequestQueue.takeFirst(); |
288 | if (request.requestType == Synchronizer::SyncRequest::Synchronization) { | 289 | if (request.requestType == Synchronizer::SyncRequest::Synchronization) { |
@@ -334,13 +335,17 @@ KAsync::Job<void> Synchronizer::processSyncQueue() | |||
334 | Sink::Commands::FinishFlushBuffer(fbb, location); | 335 | Sink::Commands::FinishFlushBuffer(fbb, location); |
335 | enqueueCommand(Sink::Commands::FlushCommand, BufferUtils::extractBuffer(fbb)); | 336 | enqueueCommand(Sink::Commands::FlushCommand, BufferUtils::extractBuffer(fbb)); |
336 | } | 337 | } |
337 | } else { | 338 | } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { |
338 | job = replayNextRevision(); | 339 | job = replayNextRevision(); |
340 | } else { | ||
341 | SinkWarning() << "Unknown request type: " << request.requestType; | ||
342 | return KAsync::error(KAsync::Error{"Unknown request type."}); | ||
339 | } | 343 | } |
340 | } | 344 | } |
341 | return job.then<void>([this](const KAsync::Error &error) { | 345 | return job.then<void>([this](const KAsync::Error &error) { |
342 | mSyncStore.clear(); | 346 | mSyncTransaction.abort(); |
343 | mMessageQueue->commit(); | 347 | mMessageQueue->commit(); |
348 | mSyncStore.clear(); | ||
344 | mSyncInProgress = false; | 349 | mSyncInProgress = false; |
345 | if (allChangesReplayed()) { | 350 | if (allChangesReplayed()) { |
346 | emit changesReplayed(); | 351 | emit changesReplayed(); |
@@ -399,6 +404,18 @@ KAsync::Job<void> Synchronizer::replay(const QByteArray &type, const QByteArray | |||
399 | Sink::EntityBuffer buffer(value); | 404 | Sink::EntityBuffer buffer(value); |
400 | const Sink::Entity &entity = buffer.entity(); | 405 | const Sink::Entity &entity = buffer.entity(); |
401 | const auto metadataBuffer = Sink::EntityBuffer::readBuffer<Sink::Metadata>(entity.metadata()); | 406 | const auto metadataBuffer = Sink::EntityBuffer::readBuffer<Sink::Metadata>(entity.metadata()); |
407 | if (!metadataBuffer) { | ||
408 | SinkError() << "No metadata buffer available."; | ||
409 | return KAsync::error("No metadata buffer"); | ||
410 | } | ||
411 | if (mSyncTransaction) { | ||
412 | SinkError() << "Leftover sync transaction."; | ||
413 | mSyncTransaction.abort(); | ||
414 | } | ||
415 | if (mSyncStore) { | ||
416 | SinkError() << "Leftover sync store."; | ||
417 | mSyncStore.clear(); | ||
418 | } | ||
402 | Q_ASSERT(metadataBuffer); | 419 | Q_ASSERT(metadataBuffer); |
403 | Q_ASSERT(!mSyncStore); | 420 | Q_ASSERT(!mSyncStore); |
404 | Q_ASSERT(!mSyncTransaction); | 421 | Q_ASSERT(!mSyncTransaction); |
@@ -411,13 +428,7 @@ KAsync::Job<void> Synchronizer::replay(const QByteArray &type, const QByteArray | |||
411 | 428 | ||
412 | if (operation != Sink::Operation_Creation) { | 429 | if (operation != Sink::Operation_Creation) { |
413 | oldRemoteId = syncStore().resolveLocalId(type, uid); | 430 | oldRemoteId = syncStore().resolveLocalId(type, uid); |
414 | if (oldRemoteId.isEmpty()) { | 431 | //oldRemoteId can be empty if the resource implementation didn't return a remoteid |
415 | SinkWarning() << "Couldn't find the remote id for: " << type << uid; | ||
416 | mSyncStore.clear(); | ||
417 | mSyncTransaction.abort(); | ||
418 | mEntityStore->abortTransaction(); | ||
419 | return KAsync::error<void>(1, "Couldn't find the remote id."); | ||
420 | } | ||
421 | } | 432 | } |
422 | SinkTrace() << "Replaying " << key << type << uid << oldRemoteId; | 433 | SinkTrace() << "Replaying " << key << type << uid << oldRemoteId; |
423 | 434 | ||