Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ebs br: provide fsr warmup to tikv data volumes (#47272) #48052

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
*: address review comments
Signed-off-by: BornChanger <dawn_catcher@126.com>
  • Loading branch information
BornChanger authored and ti-chi-bot committed Oct 27, 2023
commit aba8736813d448d63066f27cb32d0d6410914ee5
32 changes: 19 additions & 13 deletions br/pkg/aws/ebs.go
Original file line number Diff line number Diff line change
@@ -284,12 +284,12 @@ func (e *EC2Session) DeleteSnapshots(snapIDMap map[string]string) {

// EnableDataFSR enables FSR for data volume snapshots
func (e *EC2Session) EnableDataFSR(meta *config.EBSBasedBRMeta, targetAZ string) ([]*string, error) {
sourceSnapshotIDs, availableZones := fetchTargetSnapshots(meta, targetAZ)
sourceSnapshotIDs := fetchTargetSnapshots(meta)

log.Info("Start enable FSR for", zap.Int("snapshot number", len(sourceSnapshotIDs)), zap.Any("Snapshots", sourceSnapshotIDs), zap.String("available zone", targetAZ))

resp, err := e.ec2.EnableFastSnapshotRestores(&ec2.EnableFastSnapshotRestoresInput{
AvailabilityZones: availableZones,
AvailabilityZones: []*string{&targetAZ},
SourceSnapshotIds: sourceSnapshotIDs,
})

@@ -309,9 +309,13 @@ func (e *EC2Session) EnableDataFSR(meta *config.EBSBasedBRMeta, targetAZ string)

// WaitDataFSREnabled waits FSR for data volume snapshots are all enabled
func (e *EC2Session) WaitDataFSREnabled(snapShotIDs []*string, targetAZ string, progress glue.Progress) error {
pendingSnapshots := make([]*string, 0, len(snapShotIDs))
// Create a map to store the strings as keys
pendingSnapshots := make(map[string]struct{})

pendingSnapshots = append(pendingSnapshots, snapShotIDs...)
// Populate the map with the strings from the array
for _, str := range snapShotIDs {
pendingSnapshots[*str] = struct{}{}
}

log.Info("starts check fsr pending snapshots", zap.Any("snapshots", pendingSnapshots))
for {
@@ -341,23 +345,26 @@ func (e *EC2Session) WaitDataFSREnabled(snapShotIDs []*string, targetAZ string,
return errors.Trace(err)
}

var uncompletedSnapshots []*string
var uncompletedSnapshots map[string]struct{}
for _, fastRestore := range result.FastSnapshotRestores {
uncompletedSnapshots = append(uncompletedSnapshots, fastRestore.SnapshotId)
progress.IncBy(int64(len(pendingSnapshots) - len(uncompletedSnapshots)))
_, found := pendingSnapshots[*fastRestore.SnapshotId]
if found {
uncompletedSnapshots[*fastRestore.SnapshotId] = struct{}{}
}
}
progress.IncBy(int64(len(pendingSnapshots) - len(uncompletedSnapshots)))
pendingSnapshots = uncompletedSnapshots
}
}

// DisableDataFSR disables FSR for data volume snapshots
func (e *EC2Session) DisableDataFSR(meta *config.EBSBasedBRMeta, targetAZ string) error {
sourceSnapshotIDs, availableZones := fetchTargetSnapshots(meta, targetAZ)
sourceSnapshotIDs := fetchTargetSnapshots(meta)

log.Info("Start disable FSR", zap.Int("snapshot number", len(sourceSnapshotIDs)), zap.Any("Snapshots", sourceSnapshotIDs), zap.String("available zone", targetAZ))

resp, err := e.ec2.DisableFastSnapshotRestores(&ec2.DisableFastSnapshotRestoresInput{
AvailabilityZones: availableZones,
AvailabilityZones: []*string{&targetAZ},
SourceSnapshotIds: sourceSnapshotIDs,
})

@@ -375,21 +382,20 @@ func (e *EC2Session) DisableDataFSR(meta *config.EBSBasedBRMeta, targetAZ string
return nil
}

func fetchTargetSnapshots(meta *config.EBSBasedBRMeta, targetAZ string) ([]*string, []*string) {
var sourceSnapshotIDs, availableZones []*string
func fetchTargetSnapshots(meta *config.EBSBasedBRMeta) []*string {
var sourceSnapshotIDs []*string
for i := range meta.TiKVComponent.Stores {
store := meta.TiKVComponent.Stores[i]
for j := range store.Volumes {
oldVol := store.Volumes[j]
// Handle data volume snapshots only
if strings.Compare(oldVol.Type, "storage.data-dir") == 0 {
sourceSnapshotIDs = append(sourceSnapshotIDs, &oldVol.SnapshotID)
availableZones = append(availableZones, &targetAZ)
}
}
}

return sourceSnapshotIDs, availableZones
return sourceSnapshotIDs
}

// CreateVolumes create volumes from snapshots