Skip to content

Commit fa9e254

Browse files
Rakshith-Rmergify[bot]
authored andcommitted
rbd: consider lastSyncTimeNotFound as image not syncing
This commit modifies code to consider image as not syncing when the lastSyncTime is not found. Currently replication's Resync call fails if the lastSyncTime of an image is not found. Instead, we should treat missing lastSyncTime as the image not being in Syncing state. Signed-off-by: Rakshith R <rar@redhat.com>
1 parent 99e93b3 commit fa9e254

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

internal/csi-addons/rbd/replication.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,19 +716,32 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
716716
err.Error())
717717
}
718718

719+
// If the savedImageTime is not empty,
720+
// then the image might be in need of resync.
719721
if savedImageTime != "" {
720722
st, sErr := timestampFromString(savedImageTime)
721723
if sErr != nil {
722724
return nil, status.Errorf(codes.Internal, "failed to parse image creation time: %s", sErr.Error())
723725
}
724726
log.DebugLog(ctx, "image %s, savedImageTime=%v, currentImageTime=%v", rbdVol, st, creationTime)
725727

728+
// Fetch the last sync info from the local status in order
729+
// to determine if the image is syncing or not.
726730
syncInfo, sErr := localStatus.GetLastSyncInfo(ctx)
727-
if sErr != nil {
731+
if sErr != nil && !errors.Is(sErr, rbderrors.ErrLastSyncTimeNotFound) {
728732
return nil, status.Errorf(codes.Internal, "failed to get last sync info: %s", sErr.Error())
729733
}
730-
731-
if req.GetForce() && st.Equal(*creationTime) && !syncInfo.IsSyncing() {
734+
// consider the image to be not syncing if either
735+
// - the last sync time was not found
736+
// or
737+
// - the sync info indicates the image is not syncing
738+
isNotSyncing := errors.Is(sErr, rbderrors.ErrLastSyncTimeNotFound) || !syncInfo.IsSyncing()
739+
740+
// image needs to be resynced if
741+
// - force option is set
742+
// - image creation time is equal to the saved image creation time
743+
// - image is not already in syncing state
744+
if req.GetForce() && st.Equal(*creationTime) && isNotSyncing {
732745
err = mirror.Resync(ctx)
733746
if err != nil {
734747
return nil, getGRPCError(err)

0 commit comments

Comments
 (0)