Skip to content

Commit

Permalink
FMWK-644-udf-index-backup-xdr
Browse files Browse the repository at this point in the history
- tweaking sorting
  • Loading branch information
filkeith committed Jan 15, 2025
1 parent e507fee commit e9552c9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
8 changes: 7 additions & 1 deletion internal/util/files_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func parseFileName(name string) (backupFile, error) {

// SortBackupFiles sort files for better restore performance.
func SortBackupFiles(files []string) ([]string, error) {
sort.Strings(files)
// Prepare strings for sorting.
presort := make([][]backupFile, len(files))
maxPrefix := 0
Expand All @@ -67,6 +66,13 @@ func SortBackupFiles(files []string) ([]string, error) {
// Trim nils.
presort = presort[:maxPrefix+1]

// sort each group.
for o := range presort {
sort.Slice(presort[o], func(i, j int) bool {
return presort[o][i].suffix < presort[o][j].suffix
})
}

result := make([]string, 0, len(files))

// Iterator.
Expand Down
56 changes: 28 additions & 28 deletions internal/util/files_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ func Test_SortBackupFiles(t *testing.T) {

list := []string{
"0_source-ns1_1.asbx",
"0_source-ns1_6.asbx",
"0_source-ns1_7.asbx",
"0_source-ns1_8.asbx",
"0_source-ns1_2.asbx",
"0_source-ns1_3.asbx",
"0_source-ns1_4.asbx",
"0_source-ns1_5.asbx",
"0_source-ns1_6.asbx",
"0_source-ns1_7.asbx",
"0_source-ns1_8.asbx",
"0_source-ns1_9.asbx",
"0_source-ns1_11.asbx",
"0_source-ns1_121.asbx",
"0_source-ns1_122.asbx",
"0_source-ns1_123.asbx",
"0_source-ns1_157.asbx",
"1_source-ns1_10.asbx",
"1_source-ns1_124.asbx",
"1_source-ns1_125.asbx",
"1_source-ns1_126.asbx",
"1_source-ns1_158.asbx",
"1_source-ns1_12.asbx",
"1_source-ns1_13.asbx",
"1_source-ns1_14.asbx",
Expand All @@ -34,20 +38,8 @@ func Test_SortBackupFiles(t *testing.T) {
"1_source-ns1_18.asbx",
"1_source-ns1_19.asbx",
"1_source-ns1_20.asbx",
"1_source-ns1_124.asbx",
"1_source-ns1_125.asbx",
"1_source-ns1_126.asbx",
"1_source-ns1_158.asbx",
"2_source-ns1_21.asbx",
"2_source-ns1_22.asbx",
"2_source-ns1_23.asbx",
"2_source-ns1_24.asbx",
"2_source-ns1_25.asbx",
"2_source-ns1_26.asbx",
"2_source-ns1_27.asbx",
"2_source-ns1_28.asbx",
"2_source-ns1_29.asbx",
"2_source-ns1_31.asbx",
"2_source-ns1_127.asbx",
"2_source-ns1_128.asbx",
"2_source-ns1_129.asbx",
Expand All @@ -62,6 +54,14 @@ func Test_SortBackupFiles(t *testing.T) {
"3_source-ns1_38.asbx",
"3_source-ns1_39.asbx",
"3_source-ns1_40.asbx",
"2_source-ns1_23.asbx",
"2_source-ns1_24.asbx",
"2_source-ns1_25.asbx",
"2_source-ns1_26.asbx",
"2_source-ns1_27.asbx",
"2_source-ns1_28.asbx",
"2_source-ns1_29.asbx",
"2_source-ns1_31.asbx",
"3_source-ns1_130.asbx",
"3_source-ns1_131.asbx",
"3_source-ns1_132.asbx",
Expand All @@ -72,14 +72,6 @@ func Test_SortBackupFiles(t *testing.T) {
"4_source-ns1_44.asbx",
"4_source-ns1_45.asbx",
"4_source-ns1_46.asbx",
"4_source-ns1_47.asbx",
"4_source-ns1_48.asbx",
"4_source-ns1_49.asbx",
"4_source-ns1_50.asbx",
"4_source-ns1_133.asbx",
"4_source-ns1_134.asbx",
"4_source-ns1_135.asbx",
"4_source-ns1_161.asbx",
"5_source-ns1_51.asbx",
"5_source-ns1_52.asbx",
"5_source-ns1_53.asbx",
Expand All @@ -96,6 +88,19 @@ func Test_SortBackupFiles(t *testing.T) {
"5_source-ns1_162.asbx",
"6_source-ns1_61.asbx",
"6_source-ns1_62.asbx",
"4_source-ns1_47.asbx",
"4_source-ns1_48.asbx",
"4_source-ns1_49.asbx",
"4_source-ns1_50.asbx",
"4_source-ns1_133.asbx",
"4_source-ns1_134.asbx",
"4_source-ns1_135.asbx",
"4_source-ns1_161.asbx",
"6_source-ns1_139.asbx",
"6_source-ns1_140.asbx",
"6_source-ns1_141.asbx",
"6_source-ns1_163.asbx",
"7_source-ns1_71.asbx",
"6_source-ns1_63.asbx",
"6_source-ns1_64.asbx",
"6_source-ns1_65.asbx",
Expand All @@ -104,11 +109,6 @@ func Test_SortBackupFiles(t *testing.T) {
"6_source-ns1_68.asbx",
"6_source-ns1_69.asbx",
"6_source-ns1_70.asbx",
"6_source-ns1_139.asbx",
"6_source-ns1_140.asbx",
"6_source-ns1_141.asbx",
"6_source-ns1_163.asbx",
"7_source-ns1_71.asbx",
"7_source-ns1_72.asbx",
"7_source-ns1_73.asbx",
"7_source-ns1_74.asbx",
Expand Down

0 comments on commit e9552c9

Please sign in to comment.