Skip to content

Commit

Permalink
perf(squash): simplified the retrieval of bundle keys before squashing
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <frederic@oneconcern.com>
  • Loading branch information
fredbi committed Jan 7, 2023
1 parent de66c6a commit c419926
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
7 changes: 7 additions & 0 deletions pkg/core/bundle_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ func downloadBundleDescriptor(store storage.Store, repo, key string, settings Se
return model.BundleDescriptor{}, err
}

if settings.withMinimalBundle {
// in this configuration, don't fetch the bundle descriptor: we are only interested about the key
return model.BundleDescriptor{
ID: apc.BundleID,
}, nil
}

r, err := store.Get(context.Background(), model.GetArchivePathToBundle(repo, apc.BundleID))
if err != nil {
return model.BundleDescriptor{}, err
Expand Down
7 changes: 7 additions & 0 deletions pkg/core/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Settings struct {
retainTags bool
retainSemverTags bool
retainNLatest int
withMinimalBundle bool
// m *M // TODO(fred): enable metrics for list operations
}

Expand Down Expand Up @@ -122,6 +123,12 @@ func WithRetainNLatest(n int) Option {
}
}

func WithMinimalBundle(enabled bool) Option {
return func(s *Settings) {
s.withMinimalBundle = enabled
}
}

func defaultSettings() Settings {
return Settings{
concurrentList: defaultListConcurrency,
Expand Down
20 changes: 12 additions & 8 deletions pkg/core/repo_squash.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package core

import (
"sort"

"github.com/blang/semver"
context2 "github.com/oneconcern/datamon/pkg/context"
)

func RepoSquash(stores context2.Stores, repoName string, opts ...Option) error {
opts = append(opts, WithMinimalBundle(true))

bundles, err := ListBundles(repoName, stores, opts...)
if err != nil {
return err
Expand Down Expand Up @@ -49,12 +49,16 @@ func RepoSquash(stores context2.Stores, repoName string, opts ...Option) error {
}
}

// bundles are ordered from oldest to most recent (with natural ksuid ordering).
// However, ksuid is imperfect when timings differ only slightly (e.g. when running tests).
// Hence the explicit re-sorting on a slice that is essentially already almost sorted.
sort.SliceStable(bundles, func(i, j int) bool {
return bundles[i].Timestamp.Before(bundles[j].Timestamp)
})
/*
// Disabled since we no longer retrieve the actual timestamp. It is okay for all practical purposes.
//
// bundles are ordered from oldest to most recent (with natural ksuid ordering).
// However, ksuid is imperfect when timings differ only slightly (e.g. when running tests).
// Hence the explicit re-sorting on a slice that is essentially already almost sorted.
sort.SliceStable(bundles, func(i, j int) bool {
return bundles[i].Timestamp.Before(bundles[j].Timestamp)
})
*/
for _, bundle := range bundles[:len(bundles)-settings.retainNLatest] {
if settings.retainTags || settings.retainSemverTags {
if _, retain := labelsIndex[bundle.ID]; retain {
Expand Down

0 comments on commit c419926

Please sign in to comment.