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(v2 upgrade): support engine live upgrade #716

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

derekbit
Copy link
Member

Signed-off-by: Derek Su [email protected]#### Which issue(s) this PR fixes:

Issue longhorn/longhorn#9104

What this PR does / why we need it:

Special notes for your reviewer:

Additional documentation or context

@derekbit derekbit self-assigned this Nov 19, 2024
Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

The pull request introduces modifications to the InstanceStatus struct in pkg/api/instance.go by adding two new integer fields: StandbyTargetPortStart and StandbyTargetPortEnd. It also updates the RPCToInstanceStatus function to handle these new fields. In pkg/instance/instance.go, the InstanceResponse structure is updated to include the new standby target port fields, and several methods in the V2DataEngineInstanceOps type are modified to improve error handling for unsupported operations. Overall, the changes enhance the data model and refine instance management logic.

Changes

File Change Summary
pkg/api/instance.go - Added fields StandbyTargetPortStart and StandbyTargetPortEnd to InstanceStatus struct.
- Updated RPCToInstanceStatus function to assign new fields from rpc.InstanceStatus.
pkg/instance/instance.go - Adjusted import statement for emptypb.
- Updated InstanceResponse to include StandbyTargetPortStart and StandbyTargetPortEnd fields.
- Enhanced error handling in InstanceSuspend, InstanceResume, and InstanceSwitchOverTarget methods.
- Ensured correct population of instances in InstanceList method for both V1DataEngineInstanceOps and V2DataEngineInstanceOps.

Assessment against linked issues

Objective Addressed Explanation
Support for live upgrade for control plane (#9104) The changes do not directly address live upgrade functionality.

Suggested reviewers

  • DamiaSan
  • innobead

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

🧹 Outside diff range and nitpick comments (4)
pkg/api/instance.go (2)

80-88: Consider adding port range validation.

While the mapping is correct, consider adding validation to ensure StandbyTargetPortStart is less than StandbyTargetPortEnd to prevent potential runtime issues.

Example validation:

 func RPCToInstanceStatus(obj *rpc.InstanceStatus) InstanceStatus {
+	if obj.StandbyTargetPortStart > obj.StandbyTargetPortEnd {
+		// Either swap the values or log a warning
+		obj.StandbyTargetPortStart, obj.StandbyTargetPortEnd = obj.StandbyTargetPortEnd, obj.StandbyTargetPortStart
+	}
 	return InstanceStatus{
 		State:                  obj.State,
 		ErrorMsg:               obj.ErrorMsg,

67-88: Consider documenting the live upgrade port management strategy.

The addition of standby target ports is a crucial part of the live upgrade infrastructure. Consider adding documentation that explains:

  • The lifecycle of standby ports during upgrades
  • Port allocation strategy and potential range conflicts
  • Coordination between active and standby ports

Add a comment block above the InstanceStatus struct explaining the role of standby ports in live upgrades:

+// InstanceStatus represents the current state of an instance including its port configurations.
+// During live upgrades, the instance can maintain both active ports (TargetPort*) and
+// standby ports (StandbyTargetPort*) to facilitate seamless transitions.
 type InstanceStatus struct {
pkg/instance/instance.go (2)

723-731: Consistent port assignments for standby target ports.

Setting both StandbyTargetPortStart and StandbyTargetPortEnd to e.StandbyTargetPort is acceptable if StandbyTargetPort represents a single port value. If a range of ports is intended, consider adjusting these fields to reflect the correct port range.


723-731: Initialize the 'Conditions' map appropriately.

The Conditions field is initialized with an empty map using make(map[string]bool). Ensure that this map is populated with relevant condition statuses where necessary, or consider removing it if it remains unused to improve clarity.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ee26f75 and fc70fdf.

⛔ Files ignored due to path filters (9)
  • go.mod is excluded by !go.mod
  • go.sum is excluded by !**/*.sum, !go.sum
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/api/types.go is excluded by !vendor/**
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/client/client.go is excluded by !vendor/**
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/spdk/engine.go is excluded by !vendor/**
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/spdk/server.go is excluded by !vendor/**
  • vendor/github.com/longhorn/types/pkg/generated/imrpc/instance.pb.go is excluded by !**/*.pb.go, !**/generated/**, !vendor/**
  • vendor/github.com/longhorn/types/pkg/generated/spdkrpc/spdk.pb.go is excluded by !**/*.pb.go, !**/generated/**, !vendor/**
  • vendor/modules.txt is excluded by !vendor/**
📒 Files selected for processing (2)
  • pkg/api/instance.go (1 hunks)
  • pkg/instance/instance.go (3 hunks)
🔇 Additional comments (3)
pkg/api/instance.go (1)

67-75: LGTM! The new standby target port fields are well-structured.

The addition of StandbyTargetPortStart and StandbyTargetPortEnd fields follows consistent naming and typing patterns with existing port fields, supporting the live upgrade functionality.

Let's verify the port range usage across the codebase:

✅ Verification successful

Let me search for port validation logic to ensure proper range checks:


Let me search for port assignment and validation in the instance creation flow:


Based on the search results, I can now provide a final response:

Port range validation is properly handled in the codebase

The standby target port fields are well integrated with existing port management:

  • Port range validation exists in the SPDK replica code ensuring PortStart < PortEnd
  • Port allocation is handled through a dedicated allocator that manages ranges
  • Port cleanup and release is properly implemented when instances are deleted
  • The new standby target ports follow the same pattern as existing port fields
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for proper port range validation and usage
# Expected: Find validation logic ensuring StandbyTargetPortStart < StandbyTargetPortEnd

# Search for port range validation logic
rg -t go "StandbyTargetPort(Start|End)" -A 5 -B 5

Length of output: 5868


Script:

#!/bin/bash
# Search for validation logic in instance-related files
rg -t go "func.*Instance.*Create" -A 20 -B 5

# Also check for any port validation functions
rg -t go "func.*(ValidatePort|CheckPort|PortRange)" -A 10

Length of output: 26667


Script:

#!/bin/bash
# Search for port-related logic in instance creation
rg -t go "Port.*Start.*End" -B 5 -A 5

# Look for port validation in the instance package
rg -t go "func.*Instance.*Port" -A 10

Length of output: 11909

pkg/instance/instance.go (2)

12-13: Addition of 'emptypb' import is appropriate.

The import of emptypb is required for methods returning *emptypb.Empty, such as InstanceSuspend and InstanceResume. This inclusion is necessary for handling empty protobuf messages.


155-155: Parameters passed to EngineCreate are correctly updated.

The inclusion of additional parameters in the EngineCreate function call aligns with the enhanced functionality for engine live upgrades. Ensure that req.Spec.PortCount, req.Spec.InitiatorAddress, req.Spec.TargetAddress, and req.Spec.SpdkInstanceSpec.SalvageRequested are correctly handled within the EngineCreate method.

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 (8)
pkg/instance/instance.go (8)

723-731: Consistency in Port Assignments in engineResponseToInstanceResponse

In the engineResponseToInstanceResponse function, both PortStart and PortEnd are assigned the same value e.Port. Similarly, TargetPortStart and TargetPortEnd are assigned e.TargetPort, and StandbyTargetPortStart and StandbyTargetPortEnd are assigned e.StandbyTargetPort. If these fields are intended to represent a single port, this is acceptable. However, if port ranges are expected in the future, consider updating the implementation to support port ranges.


731-731: Initialization of Conditions Field

The Conditions field is initialized as an empty map with make(map[string]bool). If this field is expected to hold condition statuses, consider populating it with meaningful data or remove it if it's not needed.


Line range hint 846-851: Correct Error Code for Unsupported Operation in InstanceSuspend

In the InstanceSuspend method for V2DataEngineInstanceOps, when suspending a replica instance (which is not supported), the error code grpccodes.InvalidArgument is used. Since the operation is not implemented for replicas, it's more appropriate to use grpccodes.Unimplemented to indicate that the method is not supported for this instance type.

Apply this diff to correct the error code:

-     return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "suspend is not supported for instance type %v", req.Type)
+     return nil, grpcstatus.Errorf(grpccodes.Unimplemented, "suspend is not supported for instance type %v", req.Type)

Line range hint 871-876: Correct Error Code for Unsupported Operation in InstanceResume

Similarly, in the InstanceResume method for V2DataEngineInstanceOps, return grpccodes.Unimplemented when the resume operation is not supported for replicas, instead of grpccodes.InvalidArgument.

Apply this diff:

-     return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "resume is not supported for instance type %v", req.Type)
+     return nil, grpcstatus.Errorf(grpccodes.Unimplemented, "resume is not supported for instance type %v", req.Type)

Line range hint 896-901: Correct Error Code for Unsupported Operation in InstanceSwitchOverTarget

In the InstanceSwitchOverTarget method, use grpccodes.Unimplemented to indicate that target switch over is not supported for replicas.

Apply this diff:

-     return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "target switch over is not supported for instance type %v", req.Type)
+     return nil, grpcstatus.Errorf(grpccodes.Unimplemented, "target switch over is not supported for instance type %v", req.Type)

Line range hint 921-926: Correct Error Code for Unsupported Operation in InstanceDeleteTarget

In the InstanceDeleteTarget method, adjust the error code to grpccodes.Unimplemented when the operation is not supported for replicas.

Apply this diff:

-     return nil, grpcstatus.Errorf(grpccodes.InvalidArgument, "target deletion is not supported for instance type %v", req.Type)
+     return nil, grpcstatus.Errorf(grpccodes.Unimplemented, "target deletion is not supported for instance type %v", req.Type)

Line range hint 636-656: Consider Implementing InstanceReplace for V2 Data Engine

The InstanceReplace method for V2DataEngineInstanceOps returns an unimplemented error. If replacing instances is a required functionality for the V2 data engine, consider implementing this method to provide consistency across data engine versions.


Line range hint 676-684: Consider Implementing InstanceLog for V2 Data Engine

The InstanceLog method for V2DataEngineInstanceOps is currently unimplemented. Providing logging functionality is crucial for debugging and monitoring. Consider implementing this method to allow users to retrieve logs from instances managed by the V2 data engine.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc70fdf and 413cf47.

⛔ Files ignored due to path filters (9)
  • go.mod is excluded by !go.mod
  • go.sum is excluded by !**/*.sum, !go.sum
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/api/types.go is excluded by !vendor/**
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/client/client.go is excluded by !vendor/**
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/spdk/engine.go is excluded by !vendor/**
  • vendor/github.com/longhorn/longhorn-spdk-engine/pkg/spdk/server.go is excluded by !vendor/**
  • vendor/github.com/longhorn/types/pkg/generated/imrpc/instance.pb.go is excluded by !**/*.pb.go, !**/generated/**, !vendor/**
  • vendor/github.com/longhorn/types/pkg/generated/spdkrpc/spdk.pb.go is excluded by !**/*.pb.go, !**/generated/**, !vendor/**
  • vendor/modules.txt is excluded by !vendor/**
📒 Files selected for processing (2)
  • pkg/api/instance.go (1 hunks)
  • pkg/instance/instance.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/api/instance.go
🔇 Additional comments (2)
pkg/instance/instance.go (2)

729-730: Verify Proper Handling of Standby Target Ports

Ensure that the new fields StandbyTargetPortStart and StandbyTargetPortEnd correctly represent the standby target ports. Verify that these fields are properly utilized throughout the system and that any consumers of this API are updated to handle these new fields appropriately.

Run the following script to find usages of the new standby target port fields:

✅ Verification successful

Let me gather more context about the usage and implementation of these fields.


Based on the search results, I can now provide a conclusive response about the standby target port fields.

Standby Target Port Fields Are Correctly Implemented

The implementation is correct and consistent with the codebase's behavior:

  • The original StandbyTargetPort field from the engine is properly mapped to both StandbyTargetPortStart and StandbyTargetPortEnd
  • This mapping maintains backward compatibility while adapting to the new port range structure
  • The implementation is consistent across the API layer (pkg/api/instance.go) and instance management (pkg/instance/instance.go)
  • The engine's implementation shows that standby target ports are properly managed, allocated, and released as single ports, which aligns with setting both start and end to the same value
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for references to 'StandbyTargetPortStart' and 'StandbyTargetPortEnd'.

# Test: Find all occurrences of the new standby target port fields in the codebase.
rg 'StandbyTargetPort(Start|End)'

Length of output: 1541


Script:

#!/bin/bash
# Search for StandbyTargetPort to understand the original field and its usage
rg "StandbyTargetPort[^S][^t]" -A 2

# Also check the protobuf definition
fd "instance.proto" --exec cat {}

Length of output: 6492


155-155: Removal of UpgradeRequired Parameter in EngineCreate

In the InstanceCreate method for V2DataEngineInstanceOps, the UpgradeRequired parameter has been removed from the EngineCreate call. Ensure that this change is intentional and that the EngineCreate function no longer requires this parameter. Verify that this does not affect the upgrade functionality or introduce any unintended behavior.

Run the following script to check if the UpgradeRequired parameter is used elsewhere:

Copy link

mergify bot commented Nov 23, 2024

This pull request is now in conflict. Could you fix it @derekbit? 🙏

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