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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2021-10-14 17:04:18 +05:30 committed by mergify[bot]
parent 7c4b29bd57
commit 0d51f6d833

View File

@ -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
}