Skip to content

Sync Scheduler: Ensure the current sync is actually running - #452

Merged
TheOneRing merged 2 commits into
mainfrom
work/scheduler
Aug 5, 2025
Merged

TheOneRing merged 2 commits into
mainfrom
work/scheduler

Conversation

@TheOneRing

Copy link
Copy Markdown
Contributor

No description provided.

@TheOneRing TheOneRing changed the title Improve logging in sync scheduler Sync Scheduler: Ensure the current sync is actually running Aug 5, 2025
@TheOneRing TheOneRing linked an issue Aug 5, 2025 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SyncResult status 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

Comment on lines +159 to +162
} else if (!OC_ENSURE(_currentSync->isSyncRunning())) {
// the sync is not running, this should never happen, enqueue next
_currentSync.clear();
startNext();

Copilot AI Aug 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
} 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();
}

Copilot uses AI. Check for mistakes.
Comment thread src/gui/folder.cpp
bool Folder::isSyncRunning() const
{
return !hasSetupError() && _engine->isSyncRunning();
return _syncResult.status() == SyncResult::SyncPrepare || _syncResult.status() == SyncResult::SyncRunning;

Copilot AI Aug 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _syncResult.status() method is called twice. Consider storing the result in a local variable to avoid potential redundant calls.

Suggested change
return _syncResult.status() == SyncResult::SyncPrepare || _syncResult.status() == SyncResult::SyncRunning;
auto status = _syncResult.status();
return status == SyncResult::SyncPrepare || status == SyncResult::SyncRunning;

Copilot uses AI. Check for mistakes.
return;
}
std::tie(_currentSync, syncPriority) = _queue->pop();
// If the folder is deleted in the meantime, we skip it

Copilot AI Aug 5, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
@TheOneRing
TheOneRing merged commit a2fb5e1 into main Aug 5, 2025
@TheOneRing
TheOneRing deleted the work/scheduler branch August 5, 2025 11:59
@openclouders openclouders mentioned this pull request Aug 5, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mac: no sync after opening laptop lid

2 participants