diff --git a/internal/rbd/rbd_journal.go b/internal/rbd/rbd_journal.go index 5e8cc1f7a..0b798c167 100644 --- a/internal/rbd/rbd_journal.go +++ b/internal/rbd/rbd_journal.go @@ -314,7 +314,7 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er } // TODO: check image needs flattening and completed? - err = rv.repairImageID(ctx, j) + err = rv.repairImageID(ctx, j, false) if err != nil { return false, err } @@ -351,7 +351,13 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er // repairImageID checks if rv.ImageID is already available (if so, it was // fetched from the journal), in case it is missing, the imageID is obtained // and stored in the journal. -func (rv *rbdVolume) repairImageID(ctx context.Context, j *journal.Connection) error { +// if the force is set to true, the latest imageID will get added/updated in OMAP. +func (rv *rbdVolume) repairImageID(ctx context.Context, j *journal.Connection, force bool) error { + if force { + // reset the imageID so that we can fetch latest imageID from ceph cluster. + rv.ImageID = "" + } + if rv.ImageID != "" { return nil } diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index 7d6659abc..29f4bc3c4 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -756,6 +756,11 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context, return nil, status.Error(codes.Internal, err.Error()) } + err = repairResyncedImageID(ctx, rbdVol, ready) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to resync Image ID: %s", err.Error()) + } + resp := &replication.ResyncVolumeResponse{ Ready: ready, } @@ -798,3 +803,23 @@ func resyncRequired(localStatus librbd.SiteMirrorImageStatus) bool { return false } + +// repairResyncedImageID updates the existing image ID with new one. +func repairResyncedImageID(ctx context.Context, rv *rbdVolume, ready bool) error { + // During resync operation the local image will get deleted and a new + // image is recreated by the rbd mirroring. The new image will have a + // new image ID. Once resync is completed update the image ID in the OMAP + // to get the image removed from the trash during DeleteVolume. + + // if the image is not completely resynced skip repairing image ID. + if !ready { + return nil + } + j, err := volJournal.Connect(rv.Monitors, rv.RadosNamespace, rv.conn.Creds) + if err != nil { + return err + } + defer j.Destroy() + // reset the image ID which is stored in the existing OMAP + return rv.repairImageID(ctx, j, true) +}