diff --git a/pkg/service/backup/worker_deduplicate.go b/pkg/service/backup/worker_deduplicate.go index 5d8d1dd40..34f513e5c 100644 --- a/pkg/service/backup/worker_deduplicate.go +++ b/pkg/service/backup/worker_deduplicate.go @@ -52,7 +52,12 @@ func (w *worker) deduplicateHost(ctx context.Context, h hostInfo) error { Recurse: true, } if err := w.Client.RcloneListDirIter(ctx, h.IP, dataDst, listOpts, func(f *scyllaclient.RcloneListDirItem) { - id := sstable.ExtractID(f.Name) + id, err := sstable.ExtractID(f.Name) + if err != nil { + // just log and continue (should never happen) + w.Logger.Error(ctx, "Extracting SSTable generation ID of remote SSTable", "error", err) + return + } remoteFilesSSTableIDSet[id] = struct{}{} }); err != nil { return errors.Wrapf(err, "host %s: listing all files from %s", h.IP, dataDst) @@ -61,7 +66,12 @@ func (w *worker) deduplicateHost(ctx context.Context, h hostInfo) error { // Iterate over all SSTable IDs and group files per ID. ssTablesGroupByID := make(map[string][]string) for _, file := range d.Progress.files { - id := sstable.ExtractID(file.Name) + id, err := sstable.ExtractID(file.Name) + if err != nil { + // just log and continue + w.Logger.Error(ctx, "Extracting SSTable generation ID", "error", err) + continue + } ssTablesGroupByID[id] = append(ssTablesGroupByID[id], file.Name) } diff --git a/pkg/service/restore/tablesdir_worker.go b/pkg/service/restore/tablesdir_worker.go index 54ac75655..b2942a9eb 100644 --- a/pkg/service/restore/tablesdir_worker.go +++ b/pkg/service/restore/tablesdir_worker.go @@ -571,7 +571,10 @@ type bundle []string func newBundles(fm FilesMeta) map[string]bundle { bundles := make(map[string]bundle) for _, f := range fm.Files { - id := sstable.ExtractID(f) + id, err := sstable.ExtractID(f) + if err != nil { + panic(err) + } bundles[id] = append(bundles[id], f) } return bundles diff --git a/pkg/sstable/sstable_naming.go b/pkg/sstable/sstable_naming.go index d7c71dd9c..8aa88349a 100644 --- a/pkg/sstable/sstable_naming.go +++ b/pkg/sstable/sstable_naming.go @@ -29,17 +29,17 @@ const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz" // Supported SSTable format versions are: "mc", "md", "me", "la", "ka". // Scylla code validating SSTable format can be found here: // https://github.com/scylladb/scylladb/blob/decbc841b749d8dd3e2ddd4be4817c57d905eff2/sstables/sstables.cc#L2115-L2117 -func ExtractID(sstable string) string { +func ExtractID(sstable string) (string, error) { parts := strings.Split(sstable, "-") if regexLaMx.MatchString(sstable) || regexNewLaMx.MatchString(sstable) { - return parts[1] + return parts[1], nil } if regexKa.MatchString(sstable) { - return parts[3] + return parts[3], nil } - panic(unknownSSTableError(sstable)) + return "", unknownSSTableError(sstable) } // Crc32FileNameFromGivenSSTableFile returns name of the .crc32 file generated for the SSTable which contains @@ -101,7 +101,10 @@ func RenameSStables(sstables []string, nameGen func(id string) string) map[strin out := make(map[string]string) for _, sst := range sstables { - id := ExtractID(sst) + id, err := ExtractID(sst) + if err != nil { + panic(err) + } newID, ok := idMapping[id] if !ok { newID = nameGen(id) diff --git a/pkg/sstable/sstable_naming_test.go b/pkg/sstable/sstable_naming_test.go index ffcd9d4e8..cb8d5e988 100644 --- a/pkg/sstable/sstable_naming_test.go +++ b/pkg/sstable/sstable_naming_test.go @@ -55,7 +55,10 @@ func TestSExtractID(t *testing.T) { tcase := testCases[id] t.Run(tcase.in, func(t *testing.T) { t.Parallel() - val := ExtractID(tcase.in) + val, err := ExtractID(tcase.in) + if err != nil { + t.Fatalf("invalid sstable, error = {%v}", err) + } if tcase.expected != val { t.Fatalf("expected %s, received %s", tcase.expected, val) }