From 0d51f6d833f749214377c8c9616cd68760c7de58 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 14 Oct 2021 17:04:18 +0530 Subject: [PATCH] rbd: check local image description for split-brain In some corner case like `re-player shutdown` the local image will not be in error state. It would be also worth considering `description` field to make sure about split-brain. Signed-off-by: Madhu Rajanna --- internal/rbd/replicationcontrollerserver.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index 95cfb30ba..26bee0a8a 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -634,8 +634,7 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, ready = checkRemoteSiteStatus(ctx, mirrorStatus) } - // resync only if the image is in error state - if strings.Contains(localStatus.State.String(), string(errorState)) { + if resyncRequired(localStatus) { err = rbdVol.resyncImage() if err != nil { log.ErrorLog(ctx, err.Error()) @@ -664,3 +663,20 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, return resp, nil } + +// resyncRequired returns true if local image is in split-brain state and image +// needs resync. +func resyncRequired(localStatus librbd.SiteMirrorImageStatus) bool { + // resync is required if the image is in error state or the description + // contains split-brain message. + // In some corner cases like `re-player shutdown` the local image will not + // 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)) || + strings.Contains(localStatus.Description, splitBrain) { + return true + } + + return false +}