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: improve lvol snapshot checksum get #185

Merged
merged 1 commit into from
Dec 25, 2024
Merged

Conversation

shuo-wu
Copy link
Collaborator

@shuo-wu shuo-wu commented Dec 25, 2024

Which issue(s) this PR fixes:

Issue
longhorn/longhorn#8666
longhorn/longhorn#9488

What this PR does / why we need it:

We need a convenient way to get all info of a snapshot lvol including its checksum. For now, we can put the checksum in lvol xattr map.

Special notes for your reviewer:

Additional documentation or context

Longhorn 8666, 9488

Signed-off-by: Shuo Wu <[email protected]>
@shuo-wu shuo-wu requested review from innobead and derekbit December 25, 2024 06:23
Copy link

coderabbitai bot commented Dec 25, 2024

Walkthrough

The changes involve modifications to snapshot checksum handling in the SPDK (Storage Performance Development Kit) client implementation. The primary updates focus on how snapshot checksums are retrieved, stored, and processed. The modifications include changing the checksum representation from a pointer to a uint64 to a string, updating error handling, and adding logic to retrieve and store checksums for logical volumes with snapshots.

Changes

File Change Summary
pkg/spdk/client/basic.go - Added SnapshotChecksum constant
- Updated BdevLvolGetSnapshotChecksum method signature to return string instead of *uint64
- Modified checksum retrieval logic in BdevLvolGetWithFilter to store checksum in extended attributes
app/cmd/basic/bdev_lvol.go - Updated checksum handling to check for empty string instead of nil
- Modified checksum output to use string directly instead of dereferencing

Sequence Diagram

sequenceDiagram
    participant Client
    participant SPDKClient
    participant LogicalVolume

    Client->>SPDKClient: BdevLvolGetWithFilter()
    SPDKClient->>LogicalVolume: Check for Snapshot
    alt Has Snapshot
        SPDKClient->>SPDKClient: BdevLvolGetSnapshotChecksum()
        SPDKClient-->>LogicalVolume: Store Checksum in Xattrs
    end
    SPDKClient-->>Client: Return Logical Volume Details
Loading

The sequence diagram illustrates the new flow of retrieving and storing snapshot checksums during the logical volume retrieval process, highlighting the conditional checksum extraction when a snapshot is present.

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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)
pkg/spdk/client/basic.go (1)

300-305: Snapshot checksum retrieval gracefully handles errors.
When a snapshot is detected, retrieving and storing its checksum in Xattrs is efficient. If an error occurs, the code continues without halting, which is good for resiliency. Nevertheless, consider logging or documenting the failure reason to ease debugging.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0c0c2a and bdf2c32.

📒 Files selected for processing (2)
  • app/cmd/basic/bdev_lvol.go (1 hunks)
  • pkg/spdk/client/basic.go (3 hunks)
🔇 Additional comments (7)
app/cmd/basic/bdev_lvol.go (2)

746-746: Use consistent checks for "not found" vs. "invalid" checksums.
Switching from a nil-check to an empty-string check aligns well with the updated return type. However, consider making the error message more explicit if you suspect an "empty" checksum to encompass both "not found" or "invalid format."


750-750: Returning the checksum as a string is more straightforward.
Printing the string checksum directly is an improvement over dereferencing a pointer. Ensure the calling code is updated to receive a string rather than a pointer.

pkg/spdk/client/basic.go (5)

21-21: New SnapshotChecksum constant is well-defined.
Defining a dedicated constant introduces better consistency and readability for referencing the snapshot checksum xattr name.


531-531: Returning a string from BdevLvolGetSnapshotChecksum is simpler.
This updated signature is more intuitive for external calls, removing the complexity of pointer handling.


538-538: Empty return on error is consistent with the updated approach.
Returning "" on error (rather than an uninitialized pointer) prevents potential panics and simplifies caller logic.


544-544: Error handling is consistent.
Maintaining a uniform approach for error returns across the function clarifies code flow and avoids confusion.


547-547: Converting checksum to string ensures flexible usage downstream.
Using strconv.FormatUint means consumers can log or compare checksums without extra conversions. Ensure edge cases (e.g., zero checksums) are handled appropriately.

Copy link

codecov bot commented Dec 25, 2024

Codecov Report

Attention: Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.

Project coverage is 22.61%. Comparing base (f0c0c2a) to head (bdf2c32).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/spdk/client/basic.go 44.44% 4 Missing and 1 partial ⚠️
app/cmd/basic/bdev_lvol.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #185      +/-   ##
==========================================
+ Coverage   22.41%   22.61%   +0.19%     
==========================================
  Files          34       34              
  Lines        4944     4949       +5     
==========================================
+ Hits         1108     1119      +11     
+ Misses       3659     3652       -7     
- Partials      177      178       +1     
Flag Coverage Δ
unittests 22.61% <36.36%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shuo-wu shuo-wu changed the title improve: improve lvol snapshot checksum get fix: improve lvol snapshot checksum get Dec 25, 2024
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 a58a028 into longhorn:main Dec 25, 2024
8 of 10 checks passed
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