Skip to content

Commit

Permalink
rbd: get description from remote status
Browse files Browse the repository at this point in the history
This commit gets the description from remote status
instead of local status.
Local status doesn't have ',' due to which we get
array index out of range panic.

Fixes: #3388

Signed-off-by: Yati Padia <[email protected]>
Co-authored-by: shyam Ranganathan <[email protected]>
  • Loading branch information
yati1998 and ShyamsundarR committed Sep 14, 2022
1 parent e5c5646 commit 171e4e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 21 additions & 3 deletions internal/rbd/replicationcontrollerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,14 +898,14 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
return nil, status.Error(codes.Internal, err.Error())
}

localStatus, err := mirrorStatus.LocalStatus()
remoteStatus, err := RemoteStatus(mirrorStatus)
if err != nil {
log.ErrorLog(ctx, err.Error())

return nil, fmt.Errorf("failed to get local status: %w", err)
return nil, fmt.Errorf("failed to get remote status: %w", err)
}

description := localStatus.Description
description := remoteStatus.Description
lastSyncTime, err := getLastSyncTime(description)
if err != nil {
return nil, fmt.Errorf("failed to get last sync time: %w", err)
Expand All @@ -918,6 +918,24 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
return resp, nil
}

// RemoteStatus returns one SiteMirrorImageStatus item from the SiteStatuses
// slice that corresponds to the remote site's status. If the remote status
// is not found than the error ErrNotExist will be returned.
func RemoteStatus(gmis *librbd.GlobalMirrorImageStatus) (librbd.SiteMirrorImageStatus, error) {
var (
ss librbd.SiteMirrorImageStatus
err error = librbd.ErrNotExist
)
for i := range gmis.SiteStatuses {
if gmis.SiteStatuses[i].MirrorUUID != "" {
ss = gmis.SiteStatuses[i]
err = nil
break
}
}
return ss, err
}

// This function gets the local snapshot time from the description
// of localStatus and converts it into required type.
func getLastSyncTime(description string) (*timestamppb.Timestamp, error) {
Expand Down
6 changes: 6 additions & 0 deletions internal/rbd/replicationcontrollerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ func TestValidateLastSyncTime(t *testing.T) {
nil,
"failed to unmarshal description",
},
{
"description with no JSON",
`replaying`,
nil,
"",
},
}
for _, tt := range tests {
tt := tt
Expand Down

0 comments on commit 171e4e3

Please sign in to comment.