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

feat(lvol): add snapshot checksum APIs #169

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DamiaSan
Copy link
Contributor

@DamiaSan DamiaSan commented Nov 28, 2024

Which issue(s) this PR fixes:

Issue longhorn/longhorn#9709

What this PR does / why we need it:

Special notes for your reviewer:

Additional documentation or context

This PR depends on the PR longhorn/spdk#38, so it is still a draft. Will convert to a regular PR when the SPDK PR will be merged.

@DamiaSan DamiaSan requested review from innobead, derekbit, c3y1huang, shuo-wu and a team November 28, 2024 10:22
Copy link

coderabbitai bot commented Nov 28, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces new functionality for managing snapshot checksums in the BdevLvolCmd command set. It adds two commands: one for registering a checksum for a snapshot and another for retrieving that checksum. Corresponding methods are implemented in the SPDK client to handle these operations. Additionally, a new field is added to the snapshot request structure to facilitate extended attribute management during snapshot creation.

Changes

File Path Change Summary
app/cmd/basic/bdev_lvol.go Added commands: BdevLvolRegisterSnapshotChecksumCmd, BdevLvolGetSnapshotChecksumCmd; methods for checksum registration and retrieval.
pkg/spdk/client/basic.go Added methods: BdevLvolRegisterSnapshotChecksum, BdevLvolGetSnapshotChecksum; modified BdevLvolSnapshot to include EnableAddUpdateXattrs.
pkg/spdk/types/lvol.go Added field: EnableAddUpdateXattrs to BdevLvolSnapshotRequest; added types for checksum requests and responses.

Assessment against linked issues

Objective Addressed Explanation
Implement snapshot checksum in go-spdk-helper (#9709)

Possibly related PRs

  • feat: add API bdev_lvol_rename #157: Modifications to the bdev_lvol command set, enhancing functionality related to snapshot management, directly related to the new commands in this PR.

Suggested reviewers

  • innobead
  • c3y1huang
  • shuo-wu
  • derekbit

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. (Experiment)
  • @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: 4

🧹 Outside diff range and nitpick comments (4)
pkg/spdk/types/lvol.go (2)

107-110: LGTM! Consider adding field documentation.

The new EnableAddUpdateXattrs field is well-structured and follows Go conventions. Its purpose is clear from the name, but consider adding a godoc comment to explain when this flag should be used, especially its interaction with the Xattrs field.

 type BdevLvolSnapshotRequest struct {
+    // LvolName is the name of the logical volume to snapshot
     LvolName              string            `json:"lvol_name"`
+    // SnapshotName is the name to give the new snapshot
     SnapshotName          string            `json:"snapshot_name"`
+    // Xattrs are extended attributes to set on the snapshot
     Xattrs                map[string]string `json:"xattrs,omitempty"`
+    // EnableAddUpdateXattrs controls whether extended attributes can be added or updated during snapshot creation
     EnableAddUpdateXattrs bool              `json:"enable_add_update_xattrs,omitempty"`
 }

154-164: LGTM! Consider adding validation and documentation.

The new checksum-related types are well-structured and consistent with the codebase. Consider these enhancements:

  1. Add validation methods for the request types
  2. Document the checksum algorithm or format used
+// BdevLvolRegisterSnapshotChecksumRequest represents a request to register a checksum for a snapshot
 type BdevLvolRegisterSnapshotChecksumRequest struct {
+    // Name is the name of the snapshot
     Name string `json:"name"`
 }
+
+func (r *BdevLvolRegisterSnapshotChecksumRequest) Validate() error {
+    if r.Name == "" {
+        return fmt.Errorf("snapshot name cannot be empty")
+    }
+    return nil
+}

+// BdevLvolGetSnapshotChecksumRequest represents a request to retrieve a snapshot's checksum
 type BdevLvolGetSnapshotChecksumRequest struct {
+    // Name is the name of the snapshot
     Name string `json:"name"`
 }
+
+func (r *BdevLvolGetSnapshotChecksumRequest) Validate() error {
+    if r.Name == "" {
+        return fmt.Errorf("snapshot name cannot be empty")
+    }
+    return nil
+}

+// BdevLvolSnapshotChecksum represents a snapshot's checksum value
+// The checksum is calculated using [specify algorithm here]
 type BdevLvolSnapshotChecksum struct {
+    // Checksum is the calculated checksum value of the snapshot
     Checksum uint64 `json:"checksum"`
 }
app/cmd/basic/bdev_lvol.go (1)

662-674: Document checksum implementation details

Consider adding documentation in the command usage that specifies:

  • The checksum algorithm being used
  • Format of the checksum output
  • Best practices for when to register and verify checksums
  • Any performance implications of checksum operations

Also applies to: 704-716

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

506-542: Consider adding unit tests for new snapshot checksum APIs

The newly added functions BdevLvolRegisterSnapshotChecksum and BdevLvolGetSnapshotChecksum enhance snapshot management capabilities. To ensure their correctness and reliability, consider adding corresponding unit tests.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c396ae7 and b5a686e.

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

36-37: LGTM: Command registration follows established patterns

The new snapshot checksum commands are properly integrated into the existing command structure.


694-695: Verify SPDK client implementation

Ensure that the corresponding SPDK client methods are properly implemented:

  • BdevLvolRegisterSnapshotChecksum
  • BdevLvolGetSnapshotChecksum

Also applies to: 736-737

✅ Verification successful

SPDK client methods are properly implemented

The verification shows that both methods are fully implemented in pkg/spdk/client/basic.go:

  • BdevLvolRegisterSnapshotChecksum is implemented with proper request handling
  • BdevLvolGetSnapshotChecksum is implemented with proper request handling

Both methods are properly integrated with:

  • Request types defined in pkg/spdk/types/lvol.go
  • Client struct defined in pkg/spdk/client/client.go
  • JSON-RPC communication layer through jsonCli.SendCommandWithLongTimeout
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the client method implementations
ast-grep --pattern 'func (client *Client) BdevLvolRegisterSnapshotChecksum($$$) {
  $$$
}'

ast-grep --pattern 'func (client *Client) BdevLvolGetSnapshotChecksum($$$) {
  $$$
}'

Length of output: 180


Script:

#!/bin/bash
# Let's try a broader search for these method names using ripgrep
rg "BdevLvolRegisterSnapshotChecksum|BdevLvolGetSnapshotChecksum" -A 5

# Also search for the SPDK client interface/struct definition
rg "type.*Client.*struct" -A 10

Length of output: 6114

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

313-315: Enable extended attributes during snapshot creation

The addition of EnableAddUpdateXattrs: true in the BdevLvolSnapshot request enables adding or updating extended attributes during snapshot creation, which is necessary for the snapshot checksum functionality.


509-520: Implementation of BdevLvolRegisterSnapshotChecksum is correct

The BdevLvolRegisterSnapshotChecksum function correctly constructs the request and handles the response, following the established patterns in the client. It effectively computes and stores the checksum of snapshot data.

Comment on lines +154 to +163
type BdevLvolRegisterSnapshotChecksumRequest struct {
Name string `json:"name"`
}

type BdevLvolGetSnapshotChecksumRequest struct {
Name string `json:"name"`
}

type BdevLvolSnapshotChecksum struct {
Checksum uint64 `json:"checksum"`
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Let me generate the final response based on the verification results.

Implementation appears consistent but lacks test coverage

The implementation shows proper integration:

  • The new types are correctly used in the client implementation
  • RPC method names match between types and client calls
  • JSON request/response structures are properly handled

However, there are no test files found for these new snapshot checksum features.

  • pkg/spdk/client/basic.go: Add unit tests for BdevLvolRegisterSnapshotChecksum and BdevLvolGetSnapshotChecksum methods
  • pkg/spdk/types/lvol.go: Consider adding validation tests for the new types
🔗 Analysis chain

Verify integration with dependent PR.

Since this implementation depends on PR #38 from longhorn/spdk, let's verify the consistency between these changes and the dependent PR.


Let me analyze the results and generate additional verification scripts to check the implementation details.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any existing usage of the new types and verify consistency

# Check for any existing usage of the new types
echo "Checking for existing usage of new types..."
rg "BdevLvolRegisterSnapshotChecksumRequest|BdevLvolGetSnapshotChecksumRequest|BdevLvolSnapshotChecksum" --type go

# Look for any related command implementations
echo "Checking for command implementations..."
rg "RegisterSnapshotChecksum|GetSnapshotChecksum" --type go

# Look for any test files
echo "Checking for test coverage..."
fd -e go -e test

Length of output: 33142


Script:

#!/bin/bash
# Check the implementation of the snapshot checksum methods in client

# Look for the client implementation details
echo "Checking client implementation..."
rg -A 10 "BdevLvolRegisterSnapshotChecksum|BdevLvolGetSnapshotChecksum" pkg/spdk/client/basic.go

# Check for any RPC method definitions
echo "Checking RPC method definitions..."
rg "bdev_lvol_register_snapshot_checksum|bdev_lvol_get_snapshot_checksum" --type go

# Look for any test files related to snapshot checksum
echo "Checking test files..."
rg -l "TestBdevLvolRegisterSnapshotChecksum|TestBdevLvolGetSnapshotChecksum" --type go

Length of output: 1990

app/cmd/basic/bdev_lvol.go Outdated Show resolved Hide resolved
app/cmd/basic/bdev_lvol.go Outdated Show resolved Hide resolved
pkg/spdk/client/basic.go Outdated Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (1)
app/cmd/basic/bdev_lvol.go (1)

659-751: Consider performance and storage implications

The checksum implementation should consider:

  1. Performance impact:
    • Consider implementing async checksum computation for large snapshots
    • Add progress tracking for long-running computations
  2. Storage requirements:
    • Document the checksum storage location
    • Consider cleanup mechanisms for orphaned checksums
  3. Consistency guarantees:
    • Document the behavior when a snapshot is modified after checksum computation
    • Consider adding a timestamp to the checksum metadata
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b5a686e and db380dc.

📒 Files selected for processing (3)
  • app/cmd/basic/bdev_lvol.go (2 hunks)
  • pkg/spdk/client/basic.go (2 hunks)
  • pkg/spdk/types/lvol.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/spdk/client/basic.go
  • pkg/spdk/types/lvol.go
🔇 Additional comments (3)
app/cmd/basic/bdev_lvol.go (3)

36-37: LGTM: Command registration follows established patterns

The new commands are properly integrated into the existing command set.


705-751: LGTM: Proper validation and error handling

The implementation includes:

  • Input validation for alias/UUID
  • Protection against nil pointer dereference
  • Descriptive error messages

660-703: Consider additional validation for snapshot registration

While the implementation is solid, consider these improvements:

  1. Verify that the target is actually a snapshot before attempting to register its checksum
  2. Add a dry-run flag for validation without computation
 func BdevLvolRegisterSnapshotChecksumCmd() cli.Command {
 	return cli.Command{
 		Name: "register-snapshot-checksum",
 		Flags: []cli.Flag{
+			cli.BoolFlag{
+				Name:  "dry-run",
+				Usage: "Validate input without computing checksum",
+			},
 			cli.StringFlag{
 				Name:  "alias",
 				Usage: "The alias of a snapshot is <LVSTORE NAME>/<SNAPSHOT NAME>. Specify this or uuid",
 			},
 			cli.StringFlag{
 				Name:  "uuid",
 				Usage: "Specify this or alias",
 			},
 		},

@DamiaSan DamiaSan marked this pull request as draft November 28, 2024 10:44
@derekbit
Copy link
Member

derekbit commented Dec 4, 2024

@DamiaSan Ready for review?

@DamiaSan
Copy link
Contributor Author

DamiaSan commented Dec 4, 2024

@DamiaSan Ready for review?

It depends on SPDK PR longhorn/spdk#38. Otherwise CI build will fail.

Longhorn 9709

Signed-off-by: Damiano Cipriani <[email protected]>
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 0% with 102 lines in your changes missing coverage. Please review.

Project coverage is 22.41%. Comparing base (92898a8) to head (6f82fcd).

Files with missing lines Patch % Lines
app/cmd/basic/bdev_lvol.go 0.00% 77 Missing ⚠️
pkg/spdk/client/basic.go 0.00% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #169      +/-   ##
==========================================
- Coverage   22.88%   22.41%   -0.48%     
==========================================
  Files          34       34              
  Lines        4842     4944     +102     
==========================================
  Hits         1108     1108              
- Misses       3557     3659     +102     
  Partials      177      177              
Flag Coverage Δ
unittests 22.41% <0.00%> (-0.48%) ⬇️

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.

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