From 17d47a4c319d2e7c619342c36d53d89960787678 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 27 Jul 2022 11:02:53 +0530 Subject: [PATCH] rbd: remove checkHealthyPrimary check After Failover of workloads to the secondary cluster when the primary cluster is down, RBD Image is not marked healthy, and VR resources are not promoted to the Primary, In VolumeReplication, the `CURRENT STATE` remains Unknown and doesn't change to Primary. This happens because the primary cluster went down, and we have force promoted the image on the secondary cluster. and the image stays in up+stopping_replay or could be any other states. Currently assumption was that the image will always be `up+stopped`. But the image will be in `up+stopped` only for planned failover and it could be in any other state if its a forced failover. For this reason, removing checkHealthyPrimary from the PromoteVolume RPC call. Signed-off-by: Madhu Rajanna (cherry picked from commit 8c5563a9bcef229b6cfe54ae9fbfbbbed70089be) --- internal/rbd/errors.go | 2 - internal/rbd/replicationcontrollerserver.go | 35 --------- .../rbd/replicationcontrollerserver_test.go | 72 ------------------- 3 files changed, 109 deletions(-) diff --git a/internal/rbd/errors.go b/internal/rbd/errors.go index 32937c058..2443b8797 100644 --- a/internal/rbd/errors.go +++ b/internal/rbd/errors.go @@ -42,6 +42,4 @@ var ( ErrMissingImageNameInVolID = errors.New("rbd image name information can not be empty in volID") // ErrDecodeClusterIDFromMonsInVolID is returned when mons hash decoding on migration volID. ErrDecodeClusterIDFromMonsInVolID = errors.New("failed to get clusterID from monitors hash in volID") - // ErrUnHealthyMirroredImage is returned when mirrored image is not healthy. - ErrUnHealthyMirroredImage = errors.New("mirrored image is not healthy") ) diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index 57c0b7bf8..00f06a7bc 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -580,16 +580,6 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context, } } - mirrorStatus, err := rbdVol.getImageMirroringStatus() - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - err = checkHealthyPrimary(ctx, rbdVol, mirrorStatus) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - var mode librbd.ImageMirrorMode mode, err = getMirroringMode(ctx, req.GetParameters()) if err != nil { @@ -619,31 +609,6 @@ 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, mirrorStatus *librbd.GlobalMirrorImageStatus) error { - 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. diff --git a/internal/rbd/replicationcontrollerserver_test.go b/internal/rbd/replicationcontrollerserver_test.go index 87f60a38f..401292587 100644 --- a/internal/rbd/replicationcontrollerserver_test.go +++ b/internal/rbd/replicationcontrollerserver_test.go @@ -279,75 +279,3 @@ func TestCheckVolumeResyncStatus(t *testing.T) { }) } } - -func Test_checkHealthyPrimary(t *testing.T) { - t.Parallel() - rbdVol := &rbdVolume{ - rbdImage: rbdImage{ - RbdImageName: "test", - Pool: "test-pool", - }, - } - tests := []struct { - name string - ctx context.Context - rbdVol *rbdVolume - mirrorStatus *librbd.GlobalMirrorImageStatus - wantErr bool - }{ - { - name: "when image is in up+stopped state", - ctx: context.TODO(), - rbdVol: rbdVol, - mirrorStatus: &librbd.GlobalMirrorImageStatus{ - SiteStatuses: []librbd.SiteMirrorImageStatus{ - { - MirrorUUID: "", - State: librbd.MirrorImageStatusStateStopped, - Up: true, - }, - }, - }, - wantErr: false, - }, - { - name: "when image is in up+error state", - ctx: context.TODO(), - rbdVol: rbdVol, - mirrorStatus: &librbd.GlobalMirrorImageStatus{ - SiteStatuses: []librbd.SiteMirrorImageStatus{ - { - MirrorUUID: "", - State: librbd.MirrorImageStatusStateError, - Up: false, - }, - }, - }, - wantErr: true, - }, - { - name: "when image is in up+replaying state", - ctx: context.TODO(), - rbdVol: rbdVol, - mirrorStatus: &librbd.GlobalMirrorImageStatus{ - SiteStatuses: []librbd.SiteMirrorImageStatus{ - { - MirrorUUID: "", - State: librbd.MirrorImageStatusStateReplaying, - Up: true, - }, - }, - }, - wantErr: true, - }, - } - for _, tt := range tests { - ts := tt - t.Run(ts.name, func(t *testing.T) { - t.Parallel() - if err := checkHealthyPrimary(ts.ctx, ts.rbdVol, ts.mirrorStatus); (err != nil) != ts.wantErr { - t.Errorf("checkHealthyPrimary() error = %v, wantErr %v", err, ts.wantErr) - } - }) - } -}