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: reconstruct ActiveChain and SnapshotLvolMap while creating replica #284

Merged
merged 2 commits into from
Dec 26, 2024

Conversation

derekbit
Copy link
Member

@derekbit derekbit commented Dec 25, 2024

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10033

What this PR does / why we need it:

If the replica's ActiveChain is not constructed while creating the replica, the mismatch found by the validateAndUpdate() will result in the error state.

```
....
        newSnapshotLvolMap, err := constructSnapshotLvolMap(r.Name, bdevLvolMap)
        if err != nil {
                return err
        }
        if len(r.SnapshotLvolMap) != len(newSnapshotLvolMap) {
                return fmt.Errorf("replica current active snapshot ....")
        }
...
````

Special notes for your reviewer:

Additional documentation or context

Longhorn 10049

Signed-off-by: Derek Su <[email protected]>
@derekbit derekbit self-assigned this Dec 25, 2024
Copy link

coderabbitai bot commented Dec 25, 2024

Walkthrough

The pull request introduces modifications to the replica management in the SPDK (Storage Performance Development Kit) package. The changes primarily focus on enhancing the Replica struct's state handling and creation process in pkg/spdk/replica.go. The modifications include expanding the conditions for replica construction, improving error handling, and updating the replica map verification logic in pkg/spdk/server.go.

Changes

File Change Summary
pkg/spdk/replica.go - Updated construct method to allow types.InstanceStateStopped state
- Enhanced Create method with new logic for snapshot lvol map construction
- Improved error handling with more descriptive error messages
pkg/spdk/server.go - Removed reflect package import
- Simplified replica map update verification by using length comparison instead of deep equality check

Assessment against linked issues

Objective Addressed Explanation
Identify Bug: v2 volumes stuck in state loop after cluster restart [#10033]
Error Messages: Address mismatch in snapshot lvol map lengths [#10033]
Expected Behavior: Volume should not get stuck in attaching/attached/detaching states [#10033]

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.

@derekbit
Copy link
Member Author

The failure will be fixed in #278

@derekbit derekbit requested a review from c3y1huang December 25, 2024 13:19
…ing replica

If a replica's ActiveChain is not constructed while creating it, the mismatch
found by the validateAndUpdate() will result in the error state.

```
....
	newSnapshotLvolMap, err := constructSnapshotLvolMap(r.Name, bdevLvolMap)
	if err != nil {
		return err
	}
	if len(r.SnapshotLvolMap) != len(newSnapshotLvolMap) {
		return fmt.Errorf("replica current active snapshot ....")
	}
...
````

Longhorn 10033

Signed-off-by: Derek Su <[email protected]>
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/replica.go (1)

Line range hint 1-1: Consider improving state management architecture

The current implementation handles complex state management through multiple methods and conditions. Consider the following architectural improvements:

  1. Extract state management logic into a dedicated state machine component to:

    • Centralize state transition logic
    • Make state transitions more explicit and traceable
    • Reduce the risk of invalid state transitions
  2. Consider using the State pattern to encapsulate state-specific behavior and transitions.

This would improve maintainability and make the code more resilient to future changes.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 402da16 and 387771b.

📒 Files selected for processing (1)
  • pkg/spdk/replica.go (2 hunks)
🔇 Additional comments (2)
pkg/spdk/replica.go (2)

252-252: LGTM: Valid state addition for replica construction

Adding types.InstanceStateStopped to the allowed states is appropriate as it enables proper reconstruction of stopped replicas.


738-747: LGTM: Proper construction of replica state after head preparation

The addition of snapshot lvol map and active chain construction after head preparation ensures that the replica's state is properly initialized. This change directly addresses the issue where ActiveChain and SnapshotLvolMap were not properly constructed during replica creation.

@derekbit
Copy link
Member Author

derekbit commented Dec 25, 2024

After applying the fix, the e2e test can successfully ran 8 times without hitting the errors, but it hit

Writing random data to pod e2e-test-deployment-0-6456f6c484-przqc failed with error (0)
Reason: Handshake status 500 Internal Server Error -+-+- {'content-length': '29', 'content-type': 'text/plain; charset=utf-8', 'date': 'Wed, 25 Dec 2024 14:38:58 GMT'} -+-+- b'container not found ("sleep")'

The error has nothing to do with the issue. It will be investigated in longhorn/longhorn#8207.

cc @shuo-wu @c3y1huang @yangchiu @innobead

@derekbit derekbit changed the title fix(server): fix replica map count check fix: reconstruct ActiveChain and SnapshotLvolMap while creating replica Dec 25, 2024
@innobead
Copy link
Member

Because the construction happens when creating a replica, it becomes a blocking operation. Do you think this will be a concern? if multiple replicas are created and re-constructed at the same time.

Copy link
Member

@innobead innobead left a comment

Choose a reason for hiding this comment

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

LGTM.

We might need to consider whether the current implementation is scalable.

@innobead
Copy link
Member

Writing random data to pod e2e-test-deployment-0-6456f6c484-przqc failed with error (0)
Reason: Handshake status 500 Internal Server Error -+-+- {'content-length': '29', 'content-type': 'text/plain; charset=utf-8', 'date': 'Wed, 25 Dec 2024 14:38:58 GMT'} -+-+- b'container not found ("sleep")'

Do we know what server returned this error? Usually, it just means a server error.

@derekbit
Copy link
Member Author

Because the construction happens when creating a replica, it becomes a blocking operation. Do you think this will be a concern? if multiple replicas are created and re-constructed at the same time.

It is per-replica lock, so multiple replicas shouldn't be an issue.

Do we know what server returned this error? Usually, it just means a server error.

After investigating the support bundle, volume controller is unable to salvage because of the disk pressure (codes) due to the orphaned replicas created while restarting nodes.
The check is introduced by the longhorn/longhorn#1974. This is a bit weird. Do we really need to give up the failed replica because of the disk pressure? cc @shuo-wu @PhanLe1010 @innobead

@derekbit derekbit merged commit 10e420d into longhorn:main Dec 26, 2024
8 of 10 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 26, 2024
@innobead
Copy link
Member

After investigating the support bundle, volume controller is unable to salvage because of the disk pressure (codes) due to the orphaned replicas created while restarting nodes. The check is introduced by the longhorn/longhorn#1974. This is a bit weird. Do we really need to give up the failed replica because of the disk pressure? cc @shuo-wu @PhanLe1010 @innobead

This issue seems related to the current implementation, where failed replicas cannot be reused. The failed salvage due to unused orphaned replicas appears to be expected in this context.

We should revisit this once we have complete snapshot reuse in version 1.9, including intact snapshot reuse (introduced in 1.8) and delta snapshot reuse (planned for 1.9). cc @longhorn/dev-data-plane

@derekbit
Copy link
Member Author

Added a support bundle for the future improvement
supportbundle_f141eeb1-d42b-4def-a700-b189bbe84ac6_2024-12-25T13-34-39Z.zip

problematic volume: pvc-a9c26ee9-3918-4ef6-b243-c340b160b41b

@yangchiu
Copy link
Member

After applying the fix, the e2e test can successfully ran 8 times without hitting the errors, but it hit


Writing random data to pod e2e-test-deployment-0-6456f6c484-przqc failed with error (0)

Reason: Handshake status 500 Internal Server Error -+-+- {'content-length': '29', 'content-type': 'text/plain; charset=utf-8', 'date': 'Wed, 25 Dec 2024 14:38:58 GMT'} -+-+- b'container not found ("sleep")'

The error has nothing to do with the issue. It will be investigated in longhorn/longhorn#8207.

cc @shuo-wu @c3y1huang @yangchiu @innobead

@derekbit This message simply indicates that the test is waiting for a pod that isn't currently running. It doesn't draw any conclusions and requires human intervention to investigate any potential issues. Possible causes could include:

  1. AWS instances entering an abnormal state following a reboot (infrastructure issue).
  2. The pod taking an unexpectedly long time to be recreated after a node reboot, which can be resolved by increasing the timeout in the test code.
  3. The pod getting stuck in the creating, pending, or terminating states, rather than running. There's a high chance that the corresponding volume isn't in an attached/healthy state (product issue).

Just for your information.

@derekbit
Copy link
Member Author

After applying the fix, the e2e test can successfully ran 8 times without hitting the errors, but it hit


Writing random data to pod e2e-test-deployment-0-6456f6c484-przqc failed with error (0)

Reason: Handshake status 500 Internal Server Error -+-+- {'content-length': '29', 'content-type': 'text/plain; charset=utf-8', 'date': 'Wed, 25 Dec 2024 14:38:58 GMT'} -+-+- b'container not found ("sleep")'

The error has nothing to do with the issue. It will be investigated in longhorn/longhorn#8207.
cc @shuo-wu @c3y1huang @yangchiu @innobead

@derekbit This message simply indicates that the test is waiting for a pod that isn't currently running. It doesn't draw any conclusions and requires human intervention to investigate any potential issues. Possible causes could include:

  1. AWS instances entering an abnormal state following a reboot (infrastructure issue).
  2. The pod taking an unexpectedly long time to be recreated after a node reboot, which can be resolved by increasing the timeout in the test code.
  3. The pod getting stuck in the creating, pending, or terminating states, rather than running. There's a high chance that the corresponding volume isn't in an attached/healthy state (product issue).

Just for your information.

Thanks @yangchiu
We have found the root cause. Please check #284 (comment).

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