-
Notifications
You must be signed in to change notification settings - Fork 601
rbd: check local image state during promote operation #2684
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -536,6 +536,11 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context, | |
| } | ||
| } | ||
|
|
||
| err = checkHealthyPrimary(ctx, rbdVol) | ||
| if err != nil { | ||
| return nil, status.Error(codes.Internal, err.Error()) | ||
Madhu-1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| var mode librbd.ImageMirrorMode | ||
| mode, err = getMirroringMode(ctx, req.GetParameters()) | ||
| if err != nil { | ||
|
|
@@ -565,6 +570,35 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context, | |
| return &replication.PromoteVolumeResponse{}, nil | ||
| } | ||
|
|
||
| // checkHealthyPrimary checks if the image is a healhty primary or not. | ||
| // healthy primary image will be in up+stopped state, for states other | ||
| // than this it returns an error message. | ||
| func checkHealthyPrimary(ctx context.Context, rbdVol *rbdVolume) error { | ||
| mirrorStatus, err := rbdVol.getImageMirroringStatus() | ||
| if err != nil { | ||
| return err | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| localStatus, err := mirrorStatus.LocalStatus() | ||
| if err != nil { | ||
| // LocalStatus can fail if the local site status is not found in | ||
| // mirroring status. Log complete sites status to debug why getting | ||
| // local status failed | ||
| log.ErrorLog(ctx, "mirroring status is %+v", mirrorStatus) | ||
|
|
||
| return fmt.Errorf("failed to get local status: %w", err) | ||
| } | ||
|
|
||
| if !localStatus.Up && localStatus.State != librbd.MirrorImageStatusStateStopped { | ||
| return fmt.Errorf("%s %w. State is up=%t, state=%q", | ||
| rbdVol, | ||
| ErrUnHealthyMirroredImage, | ||
| localStatus.Up, | ||
| localStatus.State) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // DemoteVolume extracts the RBD volume information from the | ||
| // volumeID, If the image is present, mirroring is enabled and the | ||
| // image is in promoted state it will demote the volume as secondary. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.