From 6e3d09fda5b825f054f8f6f934d9c2877f69c594 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Mon, 6 Jan 2025 17:16:12 +0700 Subject: [PATCH] Configurable Kopia Maintenance Interval Signed-off-by: Tiger Kaovilai --- pkg/repository/udmrepo/kopialib/lib_repo.go | 13 +++++++++++-- pkg/repository/udmrepo/repo_options.go | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/pkg/repository/udmrepo/kopialib/lib_repo.go b/pkg/repository/udmrepo/kopialib/lib_repo.go index d4e1f88133..1b70704326 100644 --- a/pkg/repository/udmrepo/kopialib/lib_repo.go +++ b/pkg/repository/udmrepo/kopialib/lib_repo.go @@ -79,6 +79,8 @@ const ( defaultMaintainCheckPeriod = time.Hour overwriteFullMaintainInterval = time.Duration(0) overwriteQuickMaintainInterval = time.Duration(0) + eagerGCFullInterval = time.Duration(12) + eagerGCQuickInterval = time.Duration(6) ) var kopiaRepoOpen = repo.Open @@ -595,12 +597,19 @@ func writeInitParameters(ctx context.Context, repoOption udmrepo.RepoOptions, lo logger.Infof("Full maintenance interval change from %v to %v", p.FullCycle.Interval, overwriteFullMaintainInterval) p.FullCycle.Interval = overwriteFullMaintainInterval } - + if overwriteQuickMaintainInterval != time.Duration(0) { logger.Infof("Quick maintenance interval change from %v to %v", p.QuickCycle.Interval, overwriteQuickMaintainInterval) p.QuickCycle.Interval = overwriteQuickMaintainInterval } - + if repoOption.FullMaintenanceInterval == udmrepo.FastGC { + logger.Infof("Full maintenance interval change from %v to %v", p.FullCycle.Interval, udmrepo.FastGCInterval) + p.FullCycle.Interval = udmrepo.FastGCInterval + } + if repoOption.FullMaintenanceInterval == udmrepo.EagerGC { + logger.Infof("Full maintenance interval change from %v to %v", p.FullCycle.Interval, udmrepo.EagerGCInterval) + p.FullCycle.Interval = udmrepo.EagerGCInterval + } p.Owner = r.ClientOptions().UsernameAtHost() if err := maintenance.SetParams(ctx, w, &p); err != nil { diff --git a/pkg/repository/udmrepo/repo_options.go b/pkg/repository/udmrepo/repo_options.go index 28eadfdb9b..4c8915ab3f 100644 --- a/pkg/repository/udmrepo/repo_options.go +++ b/pkg/repository/udmrepo/repo_options.go @@ -20,6 +20,7 @@ import ( "os" "path/filepath" "strings" + "time" ) const ( @@ -70,8 +71,14 @@ const ( ThrottleOptionListOps = "listOPS" ThrottleOptionUploadBytes = "uploadBytes" ThrottleOptionDownloadBytes = "downloadBytes" + FastGC FullMaintenanceIntervalOptions = "fastGC" + FastGCInterval time.Duration = 12 * time.Hour + EagerGC FullMaintenanceIntervalOptions = "eagerGC" + EagerGCInterval time.Duration = 6 * time.Hour ) +type FullMaintenanceIntervalOptions string + const ( defaultUsername = "default" defaultDomain = "default" @@ -88,6 +95,9 @@ type RepoOptions struct { GeneralOptions map[string]string // StorageOptions takes storage specific options StorageOptions map[string]string + // FullMaintenanceInterval will overwrite kopia maintenance interval + // options are fastGC for 12 hours, eagerGC for 6 hours + FullMaintenanceInterval FullMaintenanceIntervalOptions // Description is a description of the backup repository/backup repository operation. // It is for logging/debugging purpose only and doesn't control any behavior of the backup repository. @@ -156,6 +166,14 @@ func WithGenOptions(genOptions map[string]string) func(*RepoOptions) error { } } +// WithFullMaintenanceInterval +func WithFullMaintenanceInterval(interval FullMaintenanceIntervalOptions) func(*RepoOptions) error { + return func(options *RepoOptions) error { + options.FullMaintenanceInterval = interval + return nil + } +} + // WithStoreOptions sets the StorageOptions to RepoOptions, the store options are acquired through // the provided interface func WithStoreOptions(getter StoreOptionsGetter, param interface{}) func(*RepoOptions) error {