-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe pull request introduces new functionality for managing snapshot checksums in the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 theXattrs
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:
- Add validation methods for the request types
- 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 detailsConsider 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 APIsThe newly added functions
BdevLvolRegisterSnapshotChecksum
andBdevLvolGetSnapshotChecksum
enhance snapshot management capabilities. To ensure their correctness and reliability, consider adding corresponding unit tests.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 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 handlingBdevLvolGetSnapshotChecksum
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.
type BdevLvolRegisterSnapshotChecksumRequest struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
type BdevLvolGetSnapshotChecksumRequest struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
type BdevLvolSnapshotChecksum struct { | ||
Checksum uint64 `json:"checksum"` | ||
} |
There was a problem hiding this comment.
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 forBdevLvolRegisterSnapshotChecksum
andBdevLvolGetSnapshotChecksum
methodspkg/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
b5a686e
to
db380dc
Compare
There was a problem hiding this 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 implicationsThe checksum implementation should consider:
- Performance impact:
- Consider implementing async checksum computation for large snapshots
- Add progress tracking for long-running computations
- Storage requirements:
- Document the checksum storage location
- Consider cleanup mechanisms for orphaned checksums
- 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
📒 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:
- Verify that the target is actually a snapshot before attempting to register its checksum
- 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 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]>
db380dc
to
6f82fcd
Compare
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.