From af4431f60b92619d82ead0974070fb519e6e1c1c Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 15 Apr 2025 17:52:30 +0200 Subject: [PATCH] rbd: prevent calling mirror.Resync() if the mirror is syncing Signed-off-by: Niels de Vos --- internal/csi-addons/rbd/replication.go | 8 +++++++- internal/rbd/mirror.go | 18 +++++++++++++++--- internal/rbd/types/mirror.go | 4 ++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/internal/csi-addons/rbd/replication.go b/internal/csi-addons/rbd/replication.go index 58c1d80cd..40982e90a 100644 --- a/internal/csi-addons/rbd/replication.go +++ b/internal/csi-addons/rbd/replication.go @@ -718,7 +718,13 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, return nil, status.Errorf(codes.Internal, "failed to parse image creation time: %s", sErr.Error()) } log.DebugLog(ctx, "image %s, savedImageTime=%v, currentImageTime=%v", rbdVol, st, creationTime) - if req.GetForce() && st.Equal(*creationTime) { + + syncInfo, sErr := localStatus.GetLastSyncInfo(ctx) + if sErr != nil { + return nil, status.Errorf(codes.Internal, "failed to get last sync info: %s", sErr.Error()) + } + + if req.GetForce() && st.Equal(*creationTime) && !syncInfo.IsSyncing() { err = mirror.Resync(ctx) if err != nil { return nil, getGRPCError(err) diff --git a/internal/rbd/mirror.go b/internal/rbd/mirror.go index 16780c491..b129d1c6c 100644 --- a/internal/rbd/mirror.go +++ b/internal/rbd/mirror.go @@ -335,11 +335,19 @@ func (status SiteMirrorImageStatus) GetLastSyncInfo(ctx context.Context) (types. } type syncInfo struct { - LocalSnapshotTime int64 `json:"local_snapshot_timestamp"` - LastSnapshotBytes int64 `json:"last_snapshot_bytes"` - LastSnapshotDuration *int64 `json:"last_snapshot_sync_seconds"` + LocalSnapshotTime int64 `json:"local_snapshot_timestamp"` + LastSnapshotBytes int64 `json:"last_snapshot_bytes"` + LastSnapshotDuration *int64 `json:"last_snapshot_sync_seconds"` + ReplayState replayState `json:"replay_state"` } +type replayState string + +const ( + idle replayState = "idle" + syncing replayState = "syncing" +) + // Type assertion for ensuring an implementation of the full SyncInfo interface. var _ types.SyncInfo = &syncInfo{} @@ -401,3 +409,7 @@ func (si *syncInfo) GetLastSyncDuration() *time.Duration { return &duration } + +func (si *syncInfo) IsSyncing() bool { + return si.ReplayState == syncing +} diff --git a/internal/rbd/types/mirror.go b/internal/rbd/types/mirror.go index 1d844ea0f..f658dd894 100644 --- a/internal/rbd/types/mirror.go +++ b/internal/rbd/types/mirror.go @@ -110,4 +110,8 @@ type SyncInfo interface { // case there is no last snapshot bytes returns 0 as the LastSyncBytes is // optional. GetLastSyncBytes() int64 + + // IsSyncing returns true if the SyncInfo for the SiteStatus is actively + // syncing. + IsSyncing() bool }