Skip to content

Commit

Permalink
Cache the VRG retrieved from S3 store to improve retrieval efficiency
Browse files Browse the repository at this point in the history
Signed-off-by: Benamar Mekhissi <bmekhiss@ibm.com>
  • Loading branch information
Benamar Mekhissi committed Jun 8, 2024
1 parent 00d3f10 commit b7e0305
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 8 additions & 10 deletions controllers/drplacementcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ type DRPCInstance struct {
mcvRequestInProgress bool
volSyncDisabled bool
userPlacement client.Object
vrgs map[string]*rmn.VolumeReplicationGroup // Populated using MCV
vrgsFromMCV map[string]*rmn.VolumeReplicationGroup // Populated using MCV
vrgFromS3 *rmn.VolumeReplicationGroup // Cache the vrg from s3 if found
vrgNamespace string
ramenConfig *rmn.RamenConfig
mwu rmnutil.MWUtil
Expand Down Expand Up @@ -282,7 +283,7 @@ func (d *DRPCInstance) getCachedVRG(clusterName string) *rmn.VolumeReplicationGr
// inaccessible or not represented in the MCV data.
//
// The function performs the following steps:
// 1. Iterates over all managed clusters and tries to find their corresponding VRGs in `d.vrgs`.
// 1. Iterates over all managed clusters and tries to find their corresponding VRGs in `d.vrgsFromMCV`.
// If found, it adds them to the `vrgs` map and checks if any VRG is marked as primary.
// 2. If the number of retrieved VRGs matches the number of DR clusters, it returns the `vrgs` map immediately
// as a shortcut, indicating that all required VRGs have been collected.
Expand All @@ -298,7 +299,7 @@ func (d *DRPCInstance) fetchVRGsFromMClusterOrS3() map[string]*rmn.VolumeReplica
var primaryFound bool

for _, drCluster := range d.drClusters {
vrg, found := d.vrgs[drCluster.Name]
vrg, found := d.vrgsFromMCV[drCluster.Name]
if !found {
continue
}
Expand All @@ -317,15 +318,12 @@ func (d *DRPCInstance) fetchVRGsFromMClusterOrS3() map[string]*rmn.VolumeReplica

// If MCV didn't return a primary VRG, then we need to get it from the s3 store.
if !primaryFound {
vrg := GetLastKnownVRGPrimaryFromS3(d.ctx, d.reconciler.APIReader,
AvailableS3Profiles(d.drClusters), d.instance.GetName(),
d.vrgNamespace, d.reconciler.ObjStoreGetter, d.log)
if vrg != nil {
primaryCluster := vrg.GetAnnotations()[DestinationClusterAnnotationKey]
if d.vrgFromS3 != nil {
primaryCluster := d.vrgFromS3.GetAnnotations()[DestinationClusterAnnotationKey]
// Double check that we don't have already an entry in the vrgs populated using MCV
_, found := d.vrgs[primaryCluster]
_, found := d.vrgsFromMCV[primaryCluster]
if !found {
vrgs[primaryCluster] = vrg
vrgs[primaryCluster] = d.vrgFromS3
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,14 @@ func (r *DRPlacementControlReconciler) createDRPCInstance(
return nil, err
}

vrgs, _, _, err := getVRGsFromManagedClusters(r.MCVGetter, drpc, drClusters, vrgNamespace, log)
vrgsFromMCV, _, _, err := getVRGsFromManagedClusters(r.MCVGetter, drpc, drClusters, vrgNamespace, log)
if err != nil {
return nil, err
}

vrgFromS3 := GetLastKnownVRGPrimaryFromS3(ctx, r.APIReader,
AvailableS3Profiles(drClusters), drpc.GetName(), vrgNamespace, r.ObjStoreGetter, log)

d := &DRPCInstance{
reconciler: r,
ctx: ctx,
Expand All @@ -952,7 +955,8 @@ func (r *DRPlacementControlReconciler) createDRPCInstance(
userPlacement: placementObj,
drPolicy: drPolicy,
drClusters: drClusters,
vrgs: vrgs,
vrgsFromMCV: vrgsFromMCV,
vrgFromS3: vrgFromS3,
vrgNamespace: vrgNamespace,
volSyncDisabled: ramenConfig.VolSync.Disabled,
ramenConfig: ramenConfig,
Expand Down Expand Up @@ -1025,7 +1029,7 @@ func (r *DRPlacementControlReconciler) reconcileDRPCInstance(d *DRPCInstance, lo
beforeProcessing = *d.instance.Status.LastUpdateTime
}

if !ensureVRGsManagedByDRPC(d.log, d.mwu, d.vrgs, d.instance, d.vrgNamespace) {
if !ensureVRGsManagedByDRPC(d.log, d.mwu, d.vrgsFromMCV, d.instance, d.vrgNamespace) {
log.Info("Requeing... VRG adoption in progress")

return ctrl.Result{Requeue: true}, nil
Expand Down Expand Up @@ -2936,3 +2940,4 @@ func (r *DRPlacementControlReconciler) drpcHaveCommonClusters(ctx context.Contex

return drpolicyClusters.Intersection(otherDrpolicyClusters).Len() > 0, nil
}

0 comments on commit b7e0305

Please sign in to comment.