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: bug cannot use the disk which has failed replica #3499

Merged
merged 1 commit into from
Jan 19, 2025

Conversation

PhanLe1010
Copy link
Contributor

@PhanLe1010 PhanLe1010 commented Jan 19, 2025

Root cause:

The root cause of the issue longhorn/longhorn#10210 with the reproducing steps is that when Replica Disk Level Soft Anti-Affinity is false, Longhorn never considers a disk which contains a failed replica as a valid candidate.

Propose solution:

We should not exclude the disk which has failed replica in 2 cases:

  1. The caller is trying to reuse the failed replica, this disk is a valid candidate
  2. The failed replica is no longer reusable, this disk is a valid candidate

Test plan:

longhorn/longhorn#10210 (comment)

longhorn/longhorn#10210

Copy link

coderabbitai bot commented Jan 19, 2025

Warning

Rate limit exceeded

@PhanLe1010 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f8289bd and d0a30ea.

📒 Files selected for processing (2)
  • scheduler/replica_scheduler.go (2 hunks)
  • scheduler/replica_scheduler_test.go (3 hunks)

Walkthrough

The changes modify the replica scheduling logic in the ReplicaScheduler to improve handling of failed replicas. A new parameter ignoreFailedReplicas is introduced to the filterDisksWithMatchingReplicas function, allowing more flexible filtering of disk candidates. This enhancement provides more nuanced control over how failed replicas are treated during the scheduling process, potentially optimizing resource allocation and replica placement strategies.

Changes

File Change Summary
scheduler/replica_scheduler.go - Updated filterDisksWithMatchingReplicas function signature to include ignoreFailedReplicas parameter
- Modified filtering logic to conditionally skip failed replicas based on the new parameter

Sequence Diagram

sequenceDiagram
    participant Scheduler
    participant filterDisksWithMatchingReplicas
    
    Scheduler->>filterDisksWithMatchingReplicas: Call with disks, replicas, diskSoftAntiAffinity, ignoreFailedReplicas
    alt ignoreFailedReplicas is true
        filterDisksWithMatchingReplicas-->>Scheduler: Filter out failed replicas
    else ignoreFailedReplicas is false
        filterDisksWithMatchingReplicas-->>Scheduler: Include all replicas
    end
Loading

The sequence diagram illustrates how the new ignoreFailedReplicas parameter influences the replica filtering process, allowing dynamic handling of failed replicas during scheduling.


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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5fef491 and f8289bd.

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

470-470: LGTM! Clear and purposeful parameter addition.

The new ignoreFailedReplicas parameter effectively supports the PR's objective of allowing disk reuse when the caller intends to reuse failed replicas.


473-480: LGTM! Implementation aligns with requirements.

The logic correctly implements both key requirements:

  1. Skips failed replicas when the caller intends to reuse them (ignoreFailedReplicas=true)
  2. Skips non-reusable failed replicas by checking IsPotentiallyReusableReplica

This ensures that disks with failed replicas are considered as valid candidates under the right conditions.

scheduler/replica_scheduler.go Show resolved Hide resolved
derekbit
derekbit previously approved these changes Jan 19, 2025
@derekbit
Copy link
Member

Cool @PhanLe1010 ! I just found the same root cause as you did. ;)

@derekbit
Copy link
Member

@mergify backport v1.8.x

Copy link

mergify bot commented Jan 19, 2025

backport v1.8.x

✅ Backports have been created

@derekbit
Copy link
Member

@PhanLe1010 CI failed

vet: scheduler/replica_scheduler_test.go:1466:107: not enough arguments in call to filterDisksWithMatchingReplicas
	have (map[string]*Disk, map[string]*"github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2".Replica, bool)
	want (map[string]*Disk, map[string]*"github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2".Replica, bool, bool)
time="2025-01-19T04:52:25Z" level=fatal msg="exit status 1"

@derekbit derekbit self-requested a review January 19, 2025 05:01
We should not exclude the disk which has failed replica in 2 cases:
1. The caller is trying to reuse the failed replica, this disk is a
   valid candidate
2. The failed replica is no longer reusable, this disk is a valid candidate

longhorn-10210

Signed-off-by: Phan Le <[email protected]>
@PhanLe1010
Copy link
Contributor Author

@PhanLe1010 CI failed

vet: scheduler/replica_scheduler_test.go:1466:107: not enough arguments in call to filterDisksWithMatchingReplicas
	have (map[string]*Disk, map[string]*"github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2".Replica, bool)
	want (map[string]*Disk, map[string]*"github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2".Replica, bool, bool)
time="2025-01-19T04:52:25Z" level=fatal msg="exit status 1"

@derekbit Fixed. Thank you

@derekbit derekbit merged commit 82ada80 into longhorn:master Jan 19, 2025
8 of 9 checks passed
@derekbit
Copy link
Member

@mergify backport v1.6.x v1.7.x

Copy link

mergify bot commented Jan 19, 2025

backport v1.6.x v1.7.x

✅ Backports have been created

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