@@ -27,6 +27,7 @@ import (
27
27
const (
28
28
pollingPendingSnapshotInterval = 30 * time .Second
29
29
errCodeTooManyPendingSnapshots = "PendingSnapshotLimitExceeded"
30
+ FsrApiSnapshotsThreshold = 10
30
31
)
31
32
32
33
type EC2Session struct {
@@ -294,24 +295,32 @@ func (e *EC2Session) EnableDataFSR(meta *config.EBSBasedBRMeta, targetAZ string)
294
295
295
296
for availableZone := range snapshotsIDsMap {
296
297
targetAZ := availableZone
297
- eg .Go (func () error {
298
- log .Info ("enable fsr for snapshots" , zap .String ("available zone" , targetAZ ))
299
- resp , err := e .ec2 .EnableFastSnapshotRestores (& ec2.EnableFastSnapshotRestoresInput {
300
- AvailabilityZones : []* string {& targetAZ },
301
- SourceSnapshotIds : snapshotsIDsMap [targetAZ ],
302
- })
303
-
304
- if err != nil {
305
- return errors .Trace (err )
298
+ // We have to control the batch size to avoid the error of "parameter SourceSnapshotIds must be less than or equal to 10"
299
+ for i := 0 ; i < len (snapshotsIDsMap [targetAZ ]); i += FsrApiSnapshotsThreshold {
300
+ start := i
301
+ end := i + FsrApiSnapshotsThreshold
302
+ if end > len (snapshotsIDsMap [targetAZ ]) {
303
+ end = len (snapshotsIDsMap [targetAZ ])
306
304
}
305
+ eg .Go (func () error {
306
+ log .Info ("enable fsr for snapshots" , zap .String ("available zone" , targetAZ ), zap .Any ("snapshots" , snapshotsIDsMap [targetAZ ][start :end ]))
307
+ resp , err := e .ec2 .EnableFastSnapshotRestores (& ec2.EnableFastSnapshotRestoresInput {
308
+ AvailabilityZones : []* string {& targetAZ },
309
+ SourceSnapshotIds : snapshotsIDsMap [targetAZ ][start :end ],
310
+ })
307
311
308
- if len (resp .Unsuccessful ) > 0 {
309
- log .Warn ("not all snapshots enabled FSR" )
310
- return errors .Errorf ("Some snapshot fails to enable FSR for available zone %s, such as %s, error code is %v" , targetAZ , * resp .Unsuccessful [0 ].SnapshotId , resp .Unsuccessful [0 ].FastSnapshotRestoreStateErrors )
311
- }
312
+ if err != nil {
313
+ return errors .Trace (err )
314
+ }
312
315
313
- return e .waitDataFSREnabled (snapshotsIDsMap [targetAZ ], targetAZ )
314
- })
316
+ if len (resp .Unsuccessful ) > 0 {
317
+ log .Warn ("not all snapshots enabled FSR" )
318
+ return errors .Errorf ("Some snapshot fails to enable FSR for available zone %s, such as %s, error code is %v" , targetAZ , * resp .Unsuccessful [0 ].SnapshotId , resp .Unsuccessful [0 ].FastSnapshotRestoreStateErrors )
319
+ }
320
+
321
+ return e .waitDataFSREnabled (snapshotsIDsMap [targetAZ ][start :end ], targetAZ )
322
+ })
323
+ }
315
324
}
316
325
return snapshotsIDsMap , eg .Wait ()
317
326
}
@@ -329,7 +338,7 @@ func (e *EC2Session) waitDataFSREnabled(snapShotIDs []*string, targetAZ string)
329
338
log .Info ("starts check fsr pending snapshots" , zap .Any ("snapshots" , pendingSnapshots ), zap .String ("available zone" , targetAZ ))
330
339
for {
331
340
if len (pendingSnapshots ) == 0 {
332
- log .Info ("all snapshots fsr enablement is finished" , zap .String ("available zone" , targetAZ ))
341
+ log .Info ("all snapshots in current batch fsr enablement is finished" , zap .String ("available zone" , targetAZ ), zap . Any ( "snapshots" , snapShotIDs ))
333
342
return nil
334
343
}
335
344
@@ -380,25 +389,33 @@ func (e *EC2Session) DisableDataFSR(snapshotsIDsMap map[string][]*string) error
380
389
381
390
for availableZone := range snapshotsIDsMap {
382
391
targetAZ := availableZone
383
- eg .Go (func () error {
384
- resp , err := e .ec2 .DisableFastSnapshotRestores (& ec2.DisableFastSnapshotRestoresInput {
385
- AvailabilityZones : []* string {& targetAZ },
386
- SourceSnapshotIds : snapshotsIDsMap [targetAZ ],
387
- })
388
-
389
- if err != nil {
390
- return errors .Trace (err )
392
+ // We have to control the batch size to avoid the error of "parameter SourceSnapshotIds must be less than or equal to 10"
393
+ for i := 0 ; i < len (snapshotsIDsMap [targetAZ ]); i += FsrApiSnapshotsThreshold {
394
+ start := i
395
+ end := i + FsrApiSnapshotsThreshold
396
+ if end > len (snapshotsIDsMap [targetAZ ]) {
397
+ end = len (snapshotsIDsMap [targetAZ ])
391
398
}
399
+ eg .Go (func () error {
400
+ resp , err := e .ec2 .DisableFastSnapshotRestores (& ec2.DisableFastSnapshotRestoresInput {
401
+ AvailabilityZones : []* string {& targetAZ },
402
+ SourceSnapshotIds : snapshotsIDsMap [targetAZ ][start :end ],
403
+ })
392
404
393
- if len (resp .Unsuccessful ) > 0 {
394
- log .Warn ("not all snapshots disabled FSR" , zap .String ("available zone" , targetAZ ))
395
- return errors .Errorf ("Some snapshot fails to disable FSR for available zone %s, such as %s, error code is %v" , targetAZ , * resp .Unsuccessful [0 ].SnapshotId , resp .Unsuccessful [0 ].FastSnapshotRestoreStateErrors )
396
- }
405
+ if err != nil {
406
+ return errors .Trace (err )
407
+ }
397
408
398
- log .Info ("Disable FSR issued" , zap .String ("available zone" , targetAZ ))
409
+ if len (resp .Unsuccessful ) > 0 {
410
+ log .Warn ("not all snapshots disabled FSR" , zap .String ("available zone" , targetAZ ))
411
+ return errors .Errorf ("Some snapshot fails to disable FSR for available zone %s, such as %s, error code is %v" , targetAZ , * resp .Unsuccessful [0 ].SnapshotId , resp .Unsuccessful [0 ].FastSnapshotRestoreStateErrors )
412
+ }
399
413
400
- return nil
401
- })
414
+ log .Info ("Disable FSR issued" , zap .String ("available zone" , targetAZ ), zap .Any ("snapshots" , snapshotsIDsMap [targetAZ ][start :end ]))
415
+
416
+ return nil
417
+ })
418
+ }
402
419
}
403
420
return eg .Wait ()
404
421
}
0 commit comments