From 82b14370fc35e689f9b0bb7a61323831693bf6be Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 24 Oct 2014 10:57:16 +0200 Subject: [PATCH] Sync scheduling: Only retry up to twice after fail. #2386 Previously when a sync failed, we'd retry very soon (30s) no matter how often a sync had failed before. After this change we'll retry twice and then back off to the regular 5min interval. --- src/mirall/folder.cpp | 25 +++++++++++++++++++------ src/mirall/folder.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index 041cda19a..f2f1cfed9 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -61,6 +61,7 @@ Folder::Folder(const QString &alias, const QString &path, const QString& secondP , _wipeDb(false) , _proxyDirty(true) , _forceSyncOnPollTimeout(false) + , _consecutiveFailingSyncs(0) , _journal(path) , _csync_ctx(0) { @@ -272,12 +273,10 @@ void Folder::slotPollTimerTimeout() bool forceSyncIntervalExpired = quint64(_timeSinceLastSync.elapsed()) > MirallConfigFile().forceSyncInterval(); - bool okSyncResult = - _syncResult.status() == SyncResult::Success || - _syncResult.status() == SyncResult::Problem; + bool syncAgainAfterFail = _consecutiveFailingSyncs > 0 && _consecutiveFailingSyncs < 3; if (forceSyncIntervalExpired || _forceSyncOnPollTimeout || - !okSyncResult) { + syncAgainAfterFail) { if (forceSyncIntervalExpired) { qDebug() << "** Force Sync, because it has been " << _timeSinceLastSync.elapsed() << "ms " << "since the last sync"; @@ -285,8 +284,10 @@ void Folder::slotPollTimerTimeout() if (_forceSyncOnPollTimeout) { qDebug() << "** Force Sync, because it was requested"; } - if (!okSyncResult) { - qDebug() << "** Force Sync, because the last sync had status: " << _syncResult.statusString(); + if (syncAgainAfterFail) { + qDebug() << "** Force Sync, because the last" + << _consecutiveFailingSyncs << "syncs failed, last status:" + << _syncResult.statusString(); } _forceSyncOnPollTimeout = false; emit scheduleToSync(alias()); @@ -830,6 +831,18 @@ void Folder::slotSyncFinished() _syncResult.setStatus(SyncResult::Success); } + // Count the number of syncs that have failed in a row. + if (_syncResult.status() == SyncResult::Success + || _syncResult.status() == SyncResult::Problem) + { + _consecutiveFailingSyncs = 0; + } + else + { + _consecutiveFailingSyncs++; + qDebug() << "the last" << _consecutiveFailingSyncs << "syncs failed"; + } + emit syncStateChange(); // The syncFinished result that is to be triggered here makes the folderman diff --git a/src/mirall/folder.h b/src/mirall/folder.h index b67e957bf..57ccdd741 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -203,6 +203,7 @@ private: QString _lastEtag; QElapsedTimer _timeSinceLastSync; bool _forceSyncOnPollTimeout; + int _consecutiveFailingSyncs; // For the SocketAPI folder states QSet _stateLastSyncItemsWithErrorNew; // gets moved to _stateLastSyncItemsWithError at end of sync