From 47dc9cf28dcada5f6bd0a2416f5eb03fa2c64a6b Mon Sep 17 00:00:00 2001 From: Shyamsundar Ranganathan Date: Tue, 14 Sep 2021 11:29:25 -0400 Subject: [PATCH] rbd: Report errors when a resync maybe in progress Currently we return a !ready status if an image is not found when a replication resync is issued. We also return a !ready just post issuing a resync. The change is to ensure we return errors in these cases for the caller to retry the operation till we can determine we are actually resyncing, and then return !ready with nil errors. Part of addressing: https://github.com/csi-addons/volume-replication-operator/issues/101 Signed-off-by: Shyamsundar Ranganathan --- internal/rbd/replicationcontrollerserver.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index e0389c6d3..95cfb30ba 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -599,14 +599,13 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, mirrorStatus, err := rbdVol.getImageMirroringStatus() if err != nil { - // the image gets recreated after issuing resync in that case return - // volume as not ready. + // the image gets recreated after issuing resync if errors.Is(err, ErrImageNotFound) { - resp := &replication.ResyncVolumeResponse{ - Ready: false, - } - - return resp, nil + // caller retries till RBD syncs an initial version of the image to + // report its status in the resync call. Ideally, this line will not + // be executed as the error would get returned due to getImageMirroringInfo + // failing to find an image above. + return nil, status.Error(codes.Aborted, err.Error()) } log.ErrorLog(ctx, err.Error()) @@ -643,6 +642,11 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, return nil, status.Error(codes.Internal, err.Error()) } + + // If we issued a resync, return a non-final error as image needs to be recreated + // locally. Caller retries till RBD syncs an initial version of the image to + // report its status in the resync request. + return nil, status.Error(codes.Unavailable, "awaiting initial resync due to split brain") } // convert the last update time to UTC