@@ -91,11 +91,18 @@ func (cvg *commonVolumeGroup) generateVolumeGroup(csiID util.CSIIdentifier) erro
9191
9292// generateVolumeGroupFromMapping checks the clusterID and poolID mapping and
9393// generates commonVolumeGroup structure for the mapped clusterID and poolID.
94+ // If the mapping is not found, it returns ErrRBDGroupNotFound.
9495func (cvg * commonVolumeGroup ) generateVolumeGroupFromMapping (
9596 ctx context.Context ,
9697 csiID util.CSIIdentifier ,
9798 mapping * []util.ClusterMappingInfo ,
9899) error {
100+ var (
101+ volumeGroupGenerationError error
102+ volumeGroupExistsError error
103+ volumeGroupExists bool
104+ )
105+
99106 mcsiID := csiID
100107 existingClusterID := csiID .ClusterID
101108 existingPoolID := strconv .FormatInt (csiID .LocationID , 10 )
@@ -126,18 +133,27 @@ func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
126133 return err
127134 }
128135 mcsiID .LocationID = mPID
129- err = cvg .generateVolumeGroup (mcsiID )
130- if ShouldRetryVolumeGroupGeneration (err ) {
136+ volumeGroupGenerationError = cvg .generateVolumeGroup (mcsiID )
137+ if volumeGroupGenerationError == nil {
138+ // Check if the volume group exists in the journal.
139+ volumeGroupExists , volumeGroupExistsError = cvg .Exists (ctx )
140+ if ! errors .Is (volumeGroupExistsError , rbd_errors .ErrRBDGroupNotFound ) {
141+ return volumeGroupExistsError
142+ }
143+ }
144+ // If Volume Group doesn't exists or the error is a retryable error,
145+ // we should try to get the cluster mapping and generate the volume group from the mapping.
146+ if ! volumeGroupExists || ShouldRetryVolumeGroupGeneration (volumeGroupGenerationError ) {
131147 continue
132148 }
133149
134- return err
150+ return volumeGroupGenerationError
135151 }
136152 }
137153 }
138154 }
139155
140- return util . ErrPoolNotFound
156+ return volumeGroupGenerationError
141157}
142158
143159func (cvg * commonVolumeGroup ) initCommonVolumeGroup (
@@ -146,6 +162,11 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
146162 csiDriver string ,
147163 creds * util.Credentials ,
148164) error {
165+ var (
166+ volumeGroupGenerationError error
167+ volumeGroupExistsError error
168+ volumeGroupExists bool
169+ )
149170 csiID := util.CSIIdentifier {}
150171
151172 err := csiID .DecomposeCSIID (id )
@@ -160,15 +181,21 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
160181 cvg .objectUUID = csiID .ObjectUUID
161182 // cvg.monitors, cvg.namespace, cvg.pool are set in generateVolumeGroup
162183
163- err = cvg .generateVolumeGroup (csiID )
184+ volumeGroupGenerationError = cvg .generateVolumeGroup (csiID )
164185 // If the error is not a retryable error, return from here.
165- if err != nil && ! ShouldRetryVolumeGroupGeneration (err ) {
166- return err
186+ if volumeGroupGenerationError != nil && ! ShouldRetryVolumeGroupGeneration (volumeGroupGenerationError ) {
187+ return volumeGroupGenerationError
188+ } else {
189+ // Check if the volume group exists in the journal.
190+ volumeGroupExists , volumeGroupExistsError = cvg .Exists (ctx )
191+ if ! errors .Is (volumeGroupExistsError , rbd_errors .ErrRBDGroupNotFound ) {
192+ return volumeGroupExistsError
193+ }
167194 }
168195
169- // If the error is a retryable error, we should try to get the cluster mapping
170- // and generate the volume group from the mapping.
171- if ShouldRetryVolumeGroupGeneration (err ) {
196+ // If Volume Group doesn't exists or the error is a retryable error,
197+ // we should try to get the cluster mapping and generate the volume group from the mapping.
198+ if ! volumeGroupExists || ShouldRetryVolumeGroupGeneration (volumeGroupGenerationError ) {
172199 mapping , err := util .GetClusterMappingInfo (csiID .ClusterID )
173200 if err != nil {
174201 return err
@@ -443,3 +470,13 @@ func ShouldRetryVolumeGroupGeneration(err error) bool {
443470 errors .Is (err , rbd_errors .ErrRBDGroupNotFound ) ||
444471 errors .Is (err , rados .ErrPermissionDenied ))
445472}
473+
474+ // Exists checks if the volume group exists in the journal.
475+ func (cvg * commonVolumeGroup ) Exists (ctx context.Context ) (bool , error ) {
476+ _ , err := cvg .getVolumeGroupAttributes (ctx )
477+ if err != nil {
478+ return false , err
479+ }
480+
481+ return true , nil
482+ }
0 commit comments