Repository navigation
Sync Scheduler: Ensure the current sync is actually running - #452
Conversation
4de707a to
cd37a2d
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR improves the sync scheduler's ability to detect and handle cases where the current sync may not actually be running. The changes ensure better state tracking and recovery when sync operations are in an unexpected state.
- Enhanced sync state detection logic to use
SyncResultstatus instead of engine state - Added debug logging with sync timer information to track sync duration
- Improved error handling in the scheduler to detect and recover from invalid sync states
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/libsync/syncresult.h | Added explicit uint8_t type to Status enum for memory efficiency |
| src/gui/scheduling/syncscheduler.h | Added sync timer member and removed unused includes |
| src/gui/scheduling/syncscheduler.cpp | Enhanced logging, added sync state validation, and improved queue processing logic |
| src/gui/folder.cpp | Updated sync state detection logic and reordered sync initialization |
| } else if (!OC_ENSURE(_currentSync->isSyncRunning())) { | ||
| // the sync is not running, this should never happen, enqueue next | ||
| _currentSync.clear(); | ||
| startNext(); |
There was a problem hiding this comment.
The OC_ENSURE macro appears to be used for both assertion and conditional logic. Consider using a clear assertion followed by an explicit condition check for better readability and to separate validation from business logic.
| } else if (!OC_ENSURE(_currentSync->isSyncRunning())) { | |
| // the sync is not running, this should never happen, enqueue next | |
| _currentSync.clear(); | |
| startNext(); | |
| } else { | |
| Q_ASSERT(_currentSync->isSyncRunning()); | |
| if (!_currentSync->isSyncRunning()) { | |
| // the sync is not running, this should never happen, enqueue next | |
| _currentSync.clear(); | |
| startNext(); | |
| } |
| bool Folder::isSyncRunning() const | ||
| { | ||
| return !hasSetupError() && _engine->isSyncRunning(); | ||
| return _syncResult.status() == SyncResult::SyncPrepare || _syncResult.status() == SyncResult::SyncRunning; |
There was a problem hiding this comment.
The _syncResult.status() method is called twice. Consider storing the result in a local variable to avoid potential redundant calls.
| return _syncResult.status() == SyncResult::SyncPrepare || _syncResult.status() == SyncResult::SyncRunning; | |
| auto status = _syncResult.status(); | |
| return status == SyncResult::SyncPrepare || status == SyncResult::SyncRunning; |
| return; | ||
| } | ||
| std::tie(_currentSync, syncPriority) = _queue->pop(); | ||
| // If the folder is deleted in the meantime, we skip it |
There was a problem hiding this comment.
[nitpick] The method name 'isReady()' is ambiguous in this context. The comment mentions 'deleted in the meantime', but 'isReady()' doesn't clearly indicate folder deletion status. Consider using a more specific method name or adding a clarifying comment.
| // If the folder is deleted in the meantime, we skip it | |
| // If the folder is deleted in the meantime, we skip it | |
| // isReady() returns false if the folder has been deleted or is otherwise unavailable. |
No description provided.