@@ -537,6 +537,7 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
537537 allSnapshotsForDate = []opensearch.Snapshot {}
538538 }
539539
540+ var snapshotTasks []utils.SnapshotTask
540541 for _ , group := range snapshotGroups {
541542 if state , ok , err := utils .CheckSnapshotStateInRepo (client , defaultRepo , group .SnapshotName ); err == nil && ok {
542543 if state == "SUCCESS" {
@@ -570,17 +571,19 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
570571 newSnapshotName := baseName + "-" + randomSuffix + "-" + datePart
571572 logger .Info (fmt .Sprintf ("Some indices missing in existing snapshot, creating additional snapshot original=%s new=%s missingIndicesCount=%d" , group .SnapshotName , newSnapshotName , len (missingIndices )))
572573 indicesStr := strings .Join (missingIndices , "," )
573- logger .Info (fmt .Sprintf ("Creating snapshot %s" , newSnapshotName ))
574- logger .Info (fmt .Sprintf ("Snapshot indices %s" , indicesStr ))
575- err = utils .CreateSnapshotWithRetry (client , newSnapshotName , indicesStr , defaultRepo , cfg .GetKubeNamespace (), today , madisonClient , logger , 10 * time .Minute )
576- if err != nil {
577- logger .Error (fmt .Sprintf ("Failed to create snapshot after retries snapshot=%s error=%v" , newSnapshotName , err ))
578- failedSnapshots = append (failedSnapshots , newSnapshotName )
579- } else {
580- successfulSnapshots = append (successfulSnapshots , newSnapshotName )
574+ var totalSize int64
575+ for _ , idx := range missingIndices {
576+ totalSize += indexSizes [idx ]
581577 }
582- logger .Info ("Waiting 10 minutes before next snapshot creation" )
583- time .Sleep (10 * time .Minute )
578+ snapshotTasks = append (snapshotTasks , utils.SnapshotTask {
579+ SnapshotName : newSnapshotName ,
580+ IndicesStr : indicesStr ,
581+ Repo : defaultRepo ,
582+ Namespace : cfg .GetKubeNamespace (),
583+ DateStr : today ,
584+ PollInterval : 10 * time .Minute ,
585+ Size : totalSize ,
586+ })
584587 }
585588 continue
586589 }
@@ -602,18 +605,25 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
602605 }
603606
604607 indicesStr := strings .Join (group .Indices , "," )
605- logger .Info (fmt .Sprintf ("Creating snapshot snapshot=%s" , group .SnapshotName ))
606- logger .Info (fmt .Sprintf ("Snapshot indices %s" , indicesStr ))
607- err = utils .CreateSnapshotWithRetry (client , group .SnapshotName , indicesStr , defaultRepo , cfg .GetKubeNamespace (), today , madisonClient , logger , 10 * time .Minute )
608- if err != nil {
609- logger .Error (fmt .Sprintf ("Failed to create snapshot after retries snapshot=%s error=%v" , group .SnapshotName , err ))
610- failedSnapshots = append (failedSnapshots , group .SnapshotName )
611- continue
608+ var totalSize int64
609+ for _ , idx := range group .Indices {
610+ totalSize += indexSizes [idx ]
612611 }
613- successfulSnapshots = append (successfulSnapshots , group .SnapshotName )
612+ snapshotTasks = append (snapshotTasks , utils.SnapshotTask {
613+ SnapshotName : group .SnapshotName ,
614+ IndicesStr : indicesStr ,
615+ Repo : defaultRepo ,
616+ Namespace : cfg .GetKubeNamespace (),
617+ DateStr : today ,
618+ PollInterval : 10 * time .Minute ,
619+ Size : totalSize ,
620+ })
621+ }
614622
615- logger .Info ("Waiting 10 minutes before next snapshot creation" )
616- time .Sleep (10 * time .Minute )
623+ if len (snapshotTasks ) > 0 {
624+ successful , failed := utils .CreateSnapshotsInParallel (client , snapshotTasks , cfg .GetMaxConcurrentSnapshots (), madisonClient , logger )
625+ successfulSnapshots = append (successfulSnapshots , successful ... )
626+ failedSnapshots = append (failedSnapshots , failed ... )
617627 }
618628
619629 if len (repoGroups ) > 0 {
@@ -623,6 +633,7 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
623633 repo := parts [0 ]
624634 perRepo [repo ] = append (perRepo [repo ], g )
625635 }
636+ var repoSnapshotTasks []utils.SnapshotTask
626637 for repo , groups := range perRepo {
627638 sort .Slice (groups , func (i , j int ) bool {
628639 var sizeI , sizeJ int64
@@ -675,17 +686,19 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
675686 newSnapshotName := baseName + "-" + randomSuffix + "-" + datePart
676687 logger .Info (fmt .Sprintf ("Some indices missing in existing snapshot, creating additional snapshot repo=%s original=%s new=%s missingIndicesCount=%d" , repo , g .SnapshotName , newSnapshotName , len (missingIndices )))
677688 indicesStr := strings .Join (missingIndices , "," )
678- logger .Info (fmt .Sprintf ("Creating snapshot repo=%s snapshot=%s" , repo , newSnapshotName ))
679- logger .Info (fmt .Sprintf ("Snapshot indices %s" , indicesStr ))
680- err = utils .CreateSnapshotWithRetry (client , newSnapshotName , indicesStr , repo , cfg .GetKubeNamespace (), today , madisonClient , logger , 10 * time .Minute )
681- if err != nil {
682- logger .Error (fmt .Sprintf ("Failed to create snapshot after retries repo=%s snapshot=%s error=%v" , repo , newSnapshotName , err ))
683- failedSnapshots = append (failedSnapshots , fmt .Sprintf ("%s (repo=%s)" , newSnapshotName , repo ))
684- } else {
685- successfulSnapshots = append (successfulSnapshots , fmt .Sprintf ("%s (repo=%s)" , newSnapshotName , repo ))
689+ var totalSize int64
690+ for _ , idx := range missingIndices {
691+ totalSize += indexSizes [idx ]
686692 }
687- logger .Info ("Waiting 10 minutes before next snapshot creation" )
688- time .Sleep (10 * time .Minute )
693+ repoSnapshotTasks = append (repoSnapshotTasks , utils.SnapshotTask {
694+ SnapshotName : newSnapshotName ,
695+ IndicesStr : indicesStr ,
696+ Repo : repo ,
697+ Namespace : cfg .GetKubeNamespace (),
698+ DateStr : today ,
699+ PollInterval : 10 * time .Minute ,
700+ Size : totalSize ,
701+ })
689702 }
690703 continue
691704 }
@@ -704,20 +717,26 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
704717 continue
705718 }
706719 indicesStr := strings .Join (g .Indices , "," )
707- logger .Info (fmt .Sprintf ("Creating snapshot repo=%s snapshot=%s" , repo , g .SnapshotName ))
708- logger .Info (fmt .Sprintf ("Snapshot indices %s" , indicesStr ))
709- err = utils .CreateSnapshotWithRetry (client , g .SnapshotName , indicesStr , repo , cfg .GetKubeNamespace (), today , madisonClient , logger , 10 * time .Minute )
710- if err != nil {
711- logger .Error (fmt .Sprintf ("Failed to create snapshot after retries repo=%s snapshot=%s error=%v" , repo , g .SnapshotName , err ))
712- failedSnapshots = append (failedSnapshots , fmt .Sprintf ("%s (repo=%s)" , g .SnapshotName , repo ))
713- continue
720+ var totalSize int64
721+ for _ , idx := range g .Indices {
722+ totalSize += indexSizes [idx ]
714723 }
715- successfulSnapshots = append (successfulSnapshots , fmt .Sprintf ("%s (repo=%s)" , g .SnapshotName , repo ))
716-
717- logger .Info ("Waiting 10 minutes before next snapshot creation" )
718- time .Sleep (10 * time .Minute )
724+ repoSnapshotTasks = append (repoSnapshotTasks , utils.SnapshotTask {
725+ SnapshotName : g .SnapshotName ,
726+ IndicesStr : indicesStr ,
727+ Repo : repo ,
728+ Namespace : cfg .GetKubeNamespace (),
729+ DateStr : today ,
730+ PollInterval : 10 * time .Minute ,
731+ Size : totalSize ,
732+ })
719733 }
720734 }
735+ if len (repoSnapshotTasks ) > 0 {
736+ successful , failed := utils .CreateSnapshotsInParallel (client , repoSnapshotTasks , cfg .GetMaxConcurrentSnapshots (), madisonClient , logger )
737+ successfulSnapshots = append (successfulSnapshots , successful ... )
738+ failedSnapshots = append (failedSnapshots , failed ... )
739+ }
721740 }
722741 }
723742 }
0 commit comments