From ca4bf66035ee4f0c1a0bc83ad7f48992a21e0551 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 25 Oct 2021 15:58:37 +0530 Subject: [PATCH] rbd: log the remote site details during resync logging the remote site details during resyncing for better debugging. Signed-off-by: Madhu Rajanna (cherry picked from commit b92a6f5ccb5ac9381de0672439a808ce32d060c9) --- internal/rbd/replicationcontrollerserver.go | 52 ++++++++------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index 1ad01aa50..600d8ca91 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -43,18 +43,6 @@ const ( imageMirrorModeSnapshot imageMirroringMode = "snapshot" ) -// imageMirroringState represents the image mirroring state. -type imageMirroringState string - -const ( - // If the state is unknown means the rbd-mirror daemon is - // running and the image is demoted on both the clusters. - unknown imageMirroringState = "unknown" - - // If the state is error means image need resync. - errorState imageMirroringState = "error" -) - const ( // mirroringMode + key to get the imageMirroringMode from parameters. imageMirroringKey = "mirroringMode" @@ -523,16 +511,15 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context, func checkRemoteSiteStatus(ctx context.Context, mirrorStatus *librbd.GlobalMirrorImageStatus) bool { ready := true for _, s := range mirrorStatus.SiteStatuses { + util.UsefulLog( + ctx, + "peer site mirrorUUID=%s, mirroring state=%s, description=%s and lastUpdate=%s", + s.MirrorUUID, + s.State.String(), + s.Description, + s.LastUpdate) if s.MirrorUUID != "" { - if imageMirroringState(s.State.String()) != unknown && !s.Up { - util.UsefulLog( - ctx, - "peer site mirrorUUID=%s, mirroring state=%s, description=%s and lastUpdate=%s", - s.MirrorUUID, - s.State.String(), - s.Description, - s.LastUpdate) - + if s.State != librbd.MirrorImageStatusStateUnknown && !s.Up { ready = false } } @@ -619,7 +606,16 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, return nil, fmt.Errorf("failed to get local status: %w", err) } - state := imageMirroringState(localStatus.State.String()) + + // convert the last update time to UTC + lastUpdateTime := time.Unix(localStatus.LastUpdate, 0).UTC() + util.UsefulLog( + ctx, + "local image mirroring state=%s, description=%s and lastUpdate=%s", + localStatus.State.String(), + localStatus.Description, + lastUpdateTime) + // To recover from split brain (up+error) state the image need to be // demoted and requested for resync on site-a and then the image on site-b // should be demoted. The volume should be marked to ready=true when the @@ -630,17 +626,9 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, // If the image state on both the sites are up+unknown consider that // complete data is synced as the last snapshot // gets exchanged between the clusters. - if state == unknown && localStatus.Up { + if localStatus.State == librbd.MirrorImageStatusStateUnknown && localStatus.Up { ready = checkRemoteSiteStatus(ctx, mirrorStatus) } - // convert the last update time to UTC - lastUpdateTime := time.Unix(localStatus.LastUpdate, 0).UTC() - util.UsefulLog( - ctx, - "image mirroring state=%s, description=%s and lastUpdate=%s", - localStatus.State.String(), - localStatus.Description, - lastUpdateTime) if resyncRequired(localStatus) { err = rbdVol.resyncImage() @@ -696,7 +684,7 @@ func resyncRequired(localStatus librbd.SiteMirrorImageStatus) bool { // be in an error state. It would be also worth considering the `description` // field to make sure about split-brain. splitBrain := "split-brain" - if strings.Contains(localStatus.State.String(), string(errorState)) || + if localStatus.State == librbd.MirrorImageStatusStateError || strings.Contains(localStatus.Description, splitBrain) { return true }