Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(system-backup): handle snapshot of last backup removed #3478

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

mantissahz
Copy link
Contributor

@mantissahz mantissahz commented Jan 15, 2025

Which issue(s) this PR fixes:

Issue # longhorn/longhorn#10215

What this PR does / why we need it:

The snapshot of the last backup of the volume might be removed. Therefore, volume backup will not be up to date and needs to create a new backup.

Special notes for your reviewer:

Additional documentation or context

https://ci.longhorn.io/job/private/job/longhorn-tests-regression/8300/ - passed

@mantissahz mantissahz requested review from innobead, derekbit, c3y1huang and a team January 15, 2025 13:32
Copy link

coderabbitai bot commented Jan 15, 2025

Walkthrough

The pull request introduces enhancements to error handling in the isVolumeBackupUpToDate method of the SystemBackupController class. It adds checks to verify the existence of the last backup and its associated snapshot. If either is missing, a warning is logged, and the method returns false without raising an error. Additionally, the test cases are updated to include a new field for existing backups, improving test coverage and ensuring that the reconciliation logic accounts for existing backup scenarios.

Changes

File Change Summary
controller/system_backup_controller.go Added error handling for scenarios where the last backup or its snapshot is missing, including logging warnings and returning false.
controller/system_backup_controller_test.go Added existBackups field to SystemBackupTestCase struct for existing backups, updating test cases to reflect this change and modifying logic in TestReconcileSystemBackup to include checks for existing backups.

Possibly related PRs

Suggested reviewers

  • innobead
  • derekbit

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80168bf and e6b40bc.

📒 Files selected for processing (2)
  • controller/system_backup_controller.go (1 hunks)
  • controller/system_backup_controller_test.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • controller/system_backup_controller_test.go
  • controller/system_backup_controller.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
controller/system_backup_controller.go (1)

918-921: LGTM! Good error handling for missing backup.

The defensive error handling for missing backup is well implemented. It prevents potential panics and provides clear logging.

Consider making the warning message more consistent with the snapshot case by using "not found" instead of "not found for":

-			log.Warnf("Last Backup %v not found for volume %v", lastBackup.Name, volume.Name)
+			log.Warnf("Last Backup %v not found when checking volume %v", lastBackup.Name, volume.Name)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c50e4f and 522b96b.

📒 Files selected for processing (1)
  • controller/system_backup_controller.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (1)
controller/system_backup_controller.go (1)

927-930: LGTM! Good error handling for missing snapshot.

The defensive error handling for missing snapshot is well implemented. It prevents potential panics and provides clear logging.

derekbit
derekbit previously approved these changes Jan 15, 2025
Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM

@derekbit
Copy link
Member

@mergify backport v1.8.x

Copy link

mergify bot commented Jan 15, 2025

backport v1.8.x

✅ Backports have been created

@mantissahz
Copy link
Contributor Author

Fixing unit tests now.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
controller/system_backup_controller_test.go (1)

278-288: Consider adding validation for snapshot readiness.

The test assumes the snapshot is immediately ready (ReadyToUse: true). Consider adding a delay or validation step to ensure this matches real-world behavior.

 existBackupSnap := &longhorn.Snapshot{
     ObjectMeta: metav1.ObjectMeta{Name: "exists"},
     Spec:       longhorn.SnapshotSpec{Volume: TestVolumeName},
     Status: longhorn.SnapshotStatus{
-        ReadyToUse:   true,
+        ReadyToUse:   false, // Initial state
         CreationTime: metav1.Now().Time.String(),
     },
 }
 fakeSystemRolloutSnapshot(existBackupSnap, c, informerFactories.LhInformerFactory, lhClient)
+
+// Simulate snapshot becoming ready after a delay
+time.Sleep(100 * time.Millisecond)
+existBackupSnap.Status.ReadyToUse = true
+fakeSystemRolloutSnapshot(existBackupSnap, c, informerFactories.LhInformerFactory, lhClient)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a7835d and 80168bf.

📒 Files selected for processing (2)
  • controller/system_backup_controller.go (1 hunks)
  • controller/system_backup_controller_test.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/system_backup_controller.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (2)
controller/system_backup_controller_test.go (2)

49-49: LGTM! Field addition enhances test coverage.

The new existBackups field in SystemBackupTestCase allows testing scenarios with pre-existing backups, improving test coverage.


106-114: Test cases effectively cover backup policy behaviors.

The test cases "if-not-present when backup exists" and "always" thoroughly validate the two backup policies:

  1. if-not-present: Skips backup creation when a valid backup exists
  2. always: Creates new backup regardless of existing backups

This ensures proper handling of both backup policies.

Also applies to: 128-136

controller/system_backup_controller_test.go Outdated Show resolved Hide resolved
The snapshot of the last backup of the volume might be removed.
Therefore, volume backup will be not up-to-date and it needs to
create a new backup.

ref: longhorn/longhorn 10215

Signed-off-by: James Lu <james.lu@suse.com>
Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM

@derekbit derekbit merged commit 36f3ed2 into longhorn:master Jan 16, 2025
8 of 9 checks passed
derekbit pushed a commit that referenced this pull request Jan 16, 2025
…3478) (#3479)

The snapshot of the last backup of the volume might be removed.
Therefore, volume backup will be not up-to-date and it needs to
create a new backup.

ref: longhorn/longhorn 10215

Signed-off-by: James Lu <james.lu@suse.com>
(cherry picked from commit 36f3ed2)

Co-authored-by: James Lu <james.lu@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants