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: not allow more than 250 snapshots including all kind of snapshots #1404

Closed
wants to merge 1 commit into from

Conversation

derekbit
Copy link
Member

@derekbit derekbit commented Feb 7, 2025

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10308

What this PR does / why we need it:

Not allow creation of more than 250 snapshots including all kind of snapshots (volume-head, backing image, removed snapshot, ...) because we use 8-bit map for snapshot indexing.

Special notes for your reviewer:

Additional documentation or context

Copy link

coderabbitai bot commented Feb 7, 2025

Walkthrough

The pull request simplifies the snapshot counting mechanism in the Replica component. Specifically, the GetSnapshotCountUsage method no longer calculates or excludes a backing disk based on active disk data. Instead, it now iterates over the diskData list and counts every non-nil disk entry, with associated comments regarding backing disk handling also removed.

Changes

File(s) Change Summary
pkg/replica/replica.go Removed backingDiskName variable and its logic; modified GetSnapshotCountUsage to count all non-nil disks without excluding the backing disk.

Sequence Diagram(s)

sequenceDiagram
    participant U as Caller
    participant R as Replica
    U->>R: GetSnapshotCountUsage()
    loop For each disk in diskData
        R->>R: Check if disk is non-nil
        alt Disk exists
            R->>R: Increment snapshot count
        end
    end
    R-->>U: Return snapshot count
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure snapshot count includes all snapshots to enforce the 250 snapshot limit (#10308)

📜 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 5746804 and b01d1fa.

📒 Files selected for processing (1)
  • pkg/replica/replica.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/replica/replica.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build AMD64 binaries
  • GitHub Check: Build ARM64 binaries
  • 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 (3)
pkg/replica/replica.go (3)

414-415: Update the comment to reflect the new counting logic.

The comment "exclude volume head, backing disk, and removed disks" is incorrect as the new implementation only excludes nil disks.

-        // exclude volume head, backing disk, and removed disks
+        // exclude nil disks

1401-1406: Rename method to better reflect its purpose.

The method name GetSnapshotCountUsage is misleading since it counts all non-nil disks, not just snapshots. Consider renaming it to better reflect its actual functionality.

-func (r *Replica) GetSnapshotCountUsage() int {
+func (r *Replica) GetTotalDiskCount() int {

1409-1421: Optimize disk counting implementation.

The current implementation can be more efficient by using a counter variable and avoiding unnecessary assignments.

 func (r *Replica) getSnapshotCountUsage() int {
-    var (
-        snapshotCount int
-    )
+    count := 0
     for _, disk := range r.diskData {
-        // exclude volume head, backing disk, and removed disks
         if disk == nil {
             continue
         }
-        snapshotCount++
+        count++
     }
-    return snapshotCount
+    return count
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 77974e7 and 5746804.

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

32-32: LGTM! The maximum chain length constant aligns with the 8-bit map limitation.

The constant value of 250 provides a safe buffer below the 8-bit maximum of 256, which is crucial for preventing overflow issues.

@derekbit
Copy link
Member Author

derekbit commented Feb 7, 2025

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

Copy link

mergify bot commented Feb 7, 2025

backport v1.8.x v1.7.x v1.6.x

🟠 Waiting for conditions to match

  • merged [📌 backport requirement]

innobead
innobead previously approved these changes Feb 7, 2025
@innobead
Copy link
Member

innobead commented Feb 7, 2025

Need to review if the documentation needs to be updated accordingly.

Not allow creation of more than 250 snapshots including all kind of snapshots
(volume-head, backing image, removed snapshot, ...) because we use 8-bit
map for snapshot indexing.

Longhorn 10308

Signed-off-by: Derek Su <[email protected]>
@derekbit
Copy link
Member Author

derekbit commented Feb 7, 2025

Removed the outdated comment.
@innobead Can you help review again? Thanks.

Copy link
Contributor

@PhanLe1010 PhanLe1010 left a comment

Choose a reason for hiding this comment

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

Reviewing. Putting a change request here to hold the merge as there is a concern about behavior change

@PhanLe1010
Copy link
Contributor

PhanLe1010 commented Feb 8, 2025

Proposing an alternative solution #1405 because this PR has behavior change which might cause confusion/regression in the following case:

  1. User create a volume with backing image
  2. User set maximum snapshot count for the volume to be 2
  3. Longhorn would not allow user to take any snapshot because there are already 2 (backing image + volume-head). This might be a behavior change, or confusion, or regression

cc @derekbit @innobead

@derekbit
Copy link
Member Author

derekbit commented Feb 8, 2025

Proposing an alternative solution #1405 because this PR has behavior change which might cause confusion/regression in the following case:

  1. User create a volume with backing image
  2. User set maximum snapshot count for the volume to be 2
  3. Longhorn would not allow user to take any snapshot because there are already 2 (backing image + volume-head). This might be a behavior change, or confusion, or regression

cc @derekbit @innobead

@PhanLe1010
The difference of the solutions is how we define "snapshot" for users: can a backing image or a volume-head be regarded as a snapshot for user? So, volume-head and backing-image should not count in #1405 except countTotal (len(r.diskData)) >= types.MaximumTotalSnapshotCount. Is it correct?

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.

3 participants