Skip to content

Commit fb623c7

Browse files
author
anton.voskresensky
committed
add parallel snapshots
1 parent f9beb01 commit fb623c7

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

commands/snapshots.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func runSnapshot(cmd *cobra.Command, args []string) error {
362362
}
363363

364364
if len(snapshotTasks) > 0 {
365-
successful, failed := utils.CreateSnapshotsInParallel(client, snapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger)
365+
successful, failed := utils.CreateSnapshotsInParallel(client, snapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger, true)
366366
successfulSnapshots = append(successfulSnapshots, successful...)
367367
failedSnapshots = append(failedSnapshots, failed...)
368368
}
@@ -474,7 +474,7 @@ func runSnapshot(cmd *cobra.Command, args []string) error {
474474
}
475475
}
476476
if len(repoSnapshotTasks) > 0 {
477-
successful, failed := utils.CreateSnapshotsInParallel(client, repoSnapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger)
477+
successful, failed := utils.CreateSnapshotsInParallel(client, repoSnapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger, true)
478478
successfulSnapshots = append(successfulSnapshots, successful...)
479479
failedSnapshots = append(failedSnapshots, failed...)
480480
}

commands/snapshotsbackfill.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
621621
}
622622

623623
if len(snapshotTasks) > 0 {
624-
successful, failed := utils.CreateSnapshotsInParallel(client, snapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger)
624+
successful, failed := utils.CreateSnapshotsInParallel(client, snapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger, false)
625625
successfulSnapshots = append(successfulSnapshots, successful...)
626626
failedSnapshots = append(failedSnapshots, failed...)
627627
}
@@ -733,7 +733,7 @@ func runSnapshotsBackfill(cmd *cobra.Command, args []string) error {
733733
}
734734
}
735735
if len(repoSnapshotTasks) > 0 {
736-
successful, failed := utils.CreateSnapshotsInParallel(client, repoSnapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger)
736+
successful, failed := utils.CreateSnapshotsInParallel(client, repoSnapshotTasks, cfg.GetMaxConcurrentSnapshots(), madisonClient, logger, false)
737737
successfulSnapshots = append(successfulSnapshots, successful...)
738738
failedSnapshots = append(failedSnapshots, failed...)
739739
}

pkg/utils/snapshots.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ type SnapshotTask struct {
166166
Size int64
167167
}
168168

169-
func CreateSnapshotsInParallel(client *opensearch.Client, tasks []SnapshotTask, maxConcurrent int, madisonClient interface{}, logger *logging.Logger) ([]string, []string) {
169+
func CreateSnapshotsInParallel(client *opensearch.Client, tasks []SnapshotTask, maxConcurrent int, madisonClient interface{}, logger *logging.Logger, sortDescending bool) ([]string, []string) {
170170
var successful []string
171171
var failed []string
172172
var mu sync.Mutex
@@ -175,7 +175,10 @@ func CreateSnapshotsInParallel(client *opensearch.Client, tasks []SnapshotTask,
175175
sortedTasks := make([]SnapshotTask, len(tasks))
176176
copy(sortedTasks, tasks)
177177
sort.Slice(sortedTasks, func(i, j int) bool {
178-
return sortedTasks[i].Size > sortedTasks[j].Size
178+
if sortDescending {
179+
return sortedTasks[i].Size > sortedTasks[j].Size
180+
}
181+
return sortedTasks[i].Size < sortedTasks[j].Size
179182
})
180183

181184
taskChan := make(chan SnapshotTask, len(sortedTasks))

0 commit comments

Comments
 (0)